arm_pack_manager - Add Descritpion of subcommands

pull/2975/head
Jimmy Brisson 2016-06-10 13:41:28 -05:00 committed by Anna Bridge
parent 3141d0bdf8
commit 6923f5d41b
2 changed files with 36 additions and 9 deletions

View File

@ -74,7 +74,7 @@ class Cache () :
self.silent = silent
self.counter = 0
self.total = 1
self.index = None
self._index = {}
self.urls = None
self.no_timeouts = no_timeouts
@ -168,7 +168,7 @@ class Cache () :
def _generate_index_helper(self, d) :
try :
self.index.update(dict([(dev['dname'], self._extract_dict(dev, d)) for dev in
self._index.update(dict([(dev['dname'], self._extract_dict(dev, d)) for dev in
(self.pull_from_cache(d)("device"))]))
except AttributeError as e :
print(e)
@ -185,7 +185,6 @@ class Cache () :
:return: A file-like object that, when read, is the ELF file that describes the flashing algorithm
:rtype: ZipExtFile
"""
self.load_index()
device = self.index[device_name]
pack = ZipFile(join(save_data_path('arm-pack-manager'),
strip_protocol(self.pdsc_to_pack(device['file']))))
@ -200,7 +199,6 @@ class Cache () :
stdout.write("\n")
def find_device(self, match) :
self.load_index()
choices = process.extract(match, self.index.keys(), limit=len(self.index))
choices = sorted([(v, k) for k, v in choices], reverse=True)
if not choices : return []

View File

@ -1,6 +1,11 @@
import argparse
from os.path import basename
from tools.arm_pack_manager import Cache
from os.path import basename, join, dirname, exists
from os import makedirs
from itertools import takewhile
from fuzzywuzzy import process
from tools.arm_pack_manager import Cache
parser = argparse.ArgumentParser(description='A Handy little utility for keeping your cache of pack files up to date.')
subparsers = parser.add_subparsers(title="Commands")
@ -75,7 +80,8 @@ def fuzzy_find(matches, urls) :
dict(name=['-d','--descriptors'], action="store_true",
help="download all descriptors"),
dict(name=["-b","--batch"], action="store_true",
help="don't ask for user input and assume download all"))
help="don't ask for user input and assume download all"),
help="Cache a group of PACK or PDSC files")
def command_cache (cache, matches, everything=False, descriptors=False, batch=False, verbose= False) :
if everything :
cache.cache_everything()
@ -102,22 +108,45 @@ def command_cache (cache, matches, everything=False, descriptors=False, batch=Fa
@subcommand('find-part',
dict(name='matches', nargs="+", help="words to match to processors"),
dict(name=['-l',"--long"], action="store_true",
help="print out part details with part"))
help="print out part details with part"),
help="Find a Part and it's description within the cache")
def command_find_part (cache, matches, long=False) :
if long :
import pprint
pp = pprint.PrettyPrinter()
parts = cache.load_index()
parts = cache.index
choices = fuzzy_find(matches, parts.keys())
for part in choices :
print part
if long :
pp.pprint(cache.index[part])
@subcommand('dump-parts',
dict(name='out', help='directory to dump to'),
dict(name='parts', nargs='+', help='parts to dump'),
help='Create a directory with an index.json describing the part and all of their associated flashing algorithms.'
)
def command_dump_parts (cache, out, parts) :
index = {}
for part in parts :
index.update(dict(cache.find_device(part)))
for n, p in index.iteritems() :
try :
if not exists(join(out, dirname(p['algorithm']))) :
makedirs(join(out, dirname(p['algorithm'])))
with open(join(out, p['algorithm']), "wb+") as fd :
fd.write(cache.get_flash_algorthim_binary(n).read())
except KeyError:
print("[Warning] {} does not have an associated flashing algorithm".format(n))
with open(join(out, "index.json"), "wb+") as fd :
dump(index,fd)
@subcommand('cache-part',
dict(name='matches', nargs="+", help="words to match to devices"))
dict(name='matches', nargs="+", help="words to match to devices"),
help='Cache PACK files associated with the parts matching the provided words')
def command_cache_part (cache, matches) :
index = cache.load_index()
index = cache.index
choices = fuzzy_find(matches, index.keys())
urls = [index[c]['file'] for c in choices]
cache.cache_pack_list(urls)