Merge pull request #3067 from theotherjimmy/checkin-pack-index

Arm-Pack-Manager - Checkin pack index
pull/3084/head
Sam Grove 2016-10-19 16:49:59 -05:00 committed by GitHub
commit ff2a7db3f2
6 changed files with 27 additions and 22 deletions

View File

@ -9,7 +9,6 @@ requests
mbed-ls>=0.2.13 mbed-ls>=0.2.13
mbed-host-tests>=1.1.2 mbed-host-tests>=1.1.2
mbed-greentea>=0.2.24 mbed-greentea>=0.2.24
pyxdg>=0.25
pycurl>=4 pycurl>=4
beautifulsoup4>=4 beautifulsoup4>=4
fuzzywuzzy>=0.11 fuzzywuzzy>=0.11

View File

@ -1,4 +1,3 @@
from xdg.BaseDirectory import save_data_path
from pycurl import Curl from pycurl import Curl
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from os.path import join, dirname, basename from os.path import join, dirname, basename
@ -13,9 +12,14 @@ from itertools import takewhile
import argparse import argparse
from json import dump, load from json import dump, load
from zipfile import ZipFile from zipfile import ZipFile
from tempfile import gettempdir
RootPackURL = "http://www.keil.com/pack/index.idx" RootPackURL = "http://www.keil.com/pack/index.idx"
LocalPackDir = dirname(__file__)
LocalPackIndex = join(LocalPackDir, "index.json")
LocalPackAliases = join(LocalPackDir, "aliases.json")
protocol_matcher = compile("\w*://") protocol_matcher = compile("\w*://")
def strip_protocol(url) : def strip_protocol(url) :
@ -78,6 +82,7 @@ class Cache () :
self._aliases = {} self._aliases = {}
self.urls = None self.urls = None
self.no_timeouts = no_timeouts self.no_timeouts = no_timeouts
self.data_path = gettempdir()
def display_counter (self, message) : def display_counter (self, message) :
stdout.write("{} {}/{}\r".format(message, self.counter, self.total)) stdout.write("{} {}/{}\r".format(message, self.counter, self.total))
@ -93,7 +98,7 @@ class Cache () :
:rtype: None :rtype: None
""" """
if not self.silent : print("Caching {}...".format(url)) if not self.silent : print("Caching {}...".format(url))
dest = join(save_data_path('arm-pack-manager'), strip_protocol(url)) dest = join(self.data_path, strip_protocol(url))
try : try :
makedirs(dirname(dest)) makedirs(dirname(dest))
except OSError as exc : except OSError as exc :
@ -288,7 +293,7 @@ class Cache () :
self._index = {} self._index = {}
self.counter = 0 self.counter = 0
do_queue(Reader, self._generate_index_helper, self.get_urls()) do_queue(Reader, self._generate_index_helper, self.get_urls())
with open(join(save_data_path('arm-pack-manager'), "index.json"), "wb+") as out: with open(LocalPackIndex, "wb+") as out:
self._index["version"] = "0.1.0" self._index["version"] = "0.1.0"
dump(self._index, out) dump(self._index, out)
stdout.write("\n") stdout.write("\n")
@ -297,7 +302,7 @@ class Cache () :
self._aliases = {} self._aliases = {}
self.counter = 0 self.counter = 0
do_queue(Reader, self._generate_aliases_helper, self.get_urls()) do_queue(Reader, self._generate_aliases_helper, self.get_urls())
with open(join(save_data_path('arm-pack-manager'), "aliases.json"), "wb+") as out: with open(LocalPackAliases, "wb+") as out:
dump(self._aliases, out) dump(self._aliases, out)
stdout.write("\n") stdout.write("\n")
@ -335,11 +340,8 @@ class Cache () :
""" """
if not self._index : if not self._index :
try : with open(LocalPackIndex) as i :
with open(join(save_data_path('arm-pack-manager'), "index.json")) as i : self._index = load(i)
self._index = load(i)
except IOError :
self.generate_index()
return self._index return self._index
@property @property
def aliases(self) : def aliases(self) :
@ -365,11 +367,8 @@ class Cache () :
""" """
if not self._aliases : if not self._aliases :
try : with open(join(self.data_path, "aliases.json")) as i :
with open(join(save_data_path('arm-pack-manager'), "aliases.json")) as i : self._aliases = load(i)
self._aliases = load(i)
except IOError :
self.generate_aliases()
return self._aliases return self._aliases
def cache_everything(self) : def cache_everything(self) :
@ -426,7 +425,7 @@ class Cache () :
:return: A parsed representation of the PDSC file. :return: A parsed representation of the PDSC file.
:rtype: BeautifulSoup :rtype: BeautifulSoup
""" """
dest = join(save_data_path('arm-pack-manager'), strip_protocol(url)) dest = join(self.data_path, strip_protocol(url))
with open(dest, "r") as fd : with open(dest, "r") as fd :
return BeautifulSoup(fd, "html.parser") return BeautifulSoup(fd, "html.parser")
@ -440,7 +439,7 @@ class Cache () :
:return: A parsed representation of the PACK file. :return: A parsed representation of the PACK file.
:rtype: ZipFile :rtype: ZipFile
""" """
return ZipFile(join(save_data_path('arm-pack-manager'), return ZipFile(join(self.data_path,
strip_protocol(device['pack_file']))) strip_protocol(device['pack_file'])))
def gen_dict_from_cache() : def gen_dict_from_cache() :

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -6,8 +6,6 @@ import ntpath
import re import re
import json import json
from xdg.BaseDirectory import save_data_path
from tools.arm_pack_manager import Cache from tools.arm_pack_manager import Cache
from tools.targets import TARGET_MAP from tools.targets import TARGET_MAP
from tools.export.exporters import Exporter, TargetNotSupportedException from tools.export.exporters import Exporter, TargetNotSupportedException
@ -34,9 +32,6 @@ class DeviceCMSIS():
Encapsulates target information retrieved by arm-pack-manager""" Encapsulates target information retrieved by arm-pack-manager"""
def __init__(self, target): def __init__(self, target):
cache = Cache(True, False) cache = Cache(True, False)
data_path = join(save_data_path('arm-pack-manager'), "index.json")
if not exists(data_path) or not self.check_version(data_path):
cache.cache_descriptors()
t = TARGET_MAP[target] t = TARGET_MAP[target]
self.core = t.core self.core = t.core

View File

@ -175,6 +175,11 @@ def main():
default=[], default=[],
help="Toolchain profile") help="Toolchain profile")
parser.add_argument("--update-packs",
dest="update_packs",
action="store_true",
default=False)
options = parser.parse_args() options = parser.parse_args()
# Print available tests in order and exit # Print available tests in order and exit
@ -203,6 +208,11 @@ def main():
raise raise
exit(0) exit(0)
if options.update_packs:
from tools.arm_pack_manager import Cache
cache = Cache(True, True)
cache.cache_descriptors()
# Clean Export Directory # Clean Export Directory
if options.clean: if options.clean:
if exists(EXPORT_DIR): if exists(EXPORT_DIR):