Clone of official tools

Revision:
36:96847d42f010
Parent:
35:da9c89f8be7d
Child:
43:2a7da56ebd24
--- a/arm_pack_manager/__init__.py	Wed Feb 15 13:53:18 2017 -0600
+++ b/arm_pack_manager/__init__.py	Thu Jun 22 11:12:28 2017 -0500
@@ -7,12 +7,17 @@
 from Queue import Queue
 from re import compile, sub
 from sys import stderr, stdout
-from fuzzywuzzy import process
 from itertools import takewhile
 import argparse
 from json import dump, load
 from zipfile import ZipFile
 from tempfile import gettempdir
+import warnings
+from distutils.version import LooseVersion
+
+warnings.filterwarnings("ignore")
+
+from fuzzywuzzy import process
 
 RootPackURL = "http://www.keil.com/pack/index.idx"
 
@@ -27,7 +32,7 @@
 
 def largest_version(content) :
     return sorted([t['version'] for t in content.package.releases('release')],
-                  reverse=True, key=lambda v: map(int, v.split(".")))[0]
+                  reverse=True, key=lambda v: LooseVersion(v))[0]
 
 def do_queue(Class, function, interable) :
     q = Queue()
@@ -242,19 +247,23 @@
         self.counter += 1
         self.display_counter("Scanning for Aliases")
 
-    def get_flash_algorthim_binary(self, device_name) :
+    def get_flash_algorthim_binary(self, device_name, all=False) :
         """Retrieve the flash algorithm file for a particular part.
 
         Assumes that both the PDSC and the PACK file associated with that part are in the cache.
 
         :param device_name: The exact name of a device
+        :param all: Return an iterator of all flash algos for this device
         :type device_name: str
         :return: A file-like object that, when read, is the ELF file that describes the flashing algorithm
-        :rtype: ZipExtFile
+        :return: A file-like object that, when read, is the ELF file that describes the flashing algorithm.
+                 When "all" is set to True then an iterator for file-like objects is returned
+        :rtype: ZipExtFile or ZipExtFile iterator if all is True
         """
         device = self.index[device_name]
         pack = self.pack_from_cache(device)
-        return pack.open(device['algorithm'].keys()[0])
+        algo_itr = (pack.open(path) for path in device['algorithm'].keys())
+        return algo_itr if all else algo_itr.next()
 
     def get_svd_file(self, device_name) :
         """Retrieve the flash algorithm file for a particular part.
@@ -348,7 +357,7 @@
 
         """
         if not self._aliases :
-            with open(join(self.data_path, "aliases.json")) as i :
+            with open(LocalPackAliases) as i :
                 self._aliases = load(i)
         return self._aliases