the other jimmy / mbed-sdk-tools

Fork of mbed-sdk-tools by mbed official

Committer:
The Other Jimmy
Date:
Wed Jan 04 11:58:24 2017 -0600
Revision:
31:182518299918
Update tools to follow mbed-os tools release 5.3.1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
The Other Jimmy 31:182518299918 1 from urllib2 import urlopen, URLError
The Other Jimmy 31:182518299918 2 from bs4 import BeautifulSoup
The Other Jimmy 31:182518299918 3 from os.path import join, dirname, basename
The Other Jimmy 31:182518299918 4 from os import makedirs
The Other Jimmy 31:182518299918 5 from errno import EEXIST
The Other Jimmy 31:182518299918 6 from threading import Thread
The Other Jimmy 31:182518299918 7 from Queue import Queue
The Other Jimmy 31:182518299918 8 from re import compile, sub
The Other Jimmy 31:182518299918 9 from sys import stderr, stdout
The Other Jimmy 31:182518299918 10 from fuzzywuzzy import process
The Other Jimmy 31:182518299918 11 from itertools import takewhile
The Other Jimmy 31:182518299918 12 import argparse
The Other Jimmy 31:182518299918 13 from json import dump, load
The Other Jimmy 31:182518299918 14 from zipfile import ZipFile
The Other Jimmy 31:182518299918 15 from tempfile import gettempdir
The Other Jimmy 31:182518299918 16
The Other Jimmy 31:182518299918 17 RootPackURL = "http://www.keil.com/pack/index.idx"
The Other Jimmy 31:182518299918 18
The Other Jimmy 31:182518299918 19 LocalPackDir = dirname(__file__)
The Other Jimmy 31:182518299918 20 LocalPackIndex = join(LocalPackDir, "index.json")
The Other Jimmy 31:182518299918 21 LocalPackAliases = join(LocalPackDir, "aliases.json")
The Other Jimmy 31:182518299918 22
The Other Jimmy 31:182518299918 23
The Other Jimmy 31:182518299918 24 protocol_matcher = compile("\w*://")
The Other Jimmy 31:182518299918 25 def strip_protocol(url) :
The Other Jimmy 31:182518299918 26 return protocol_matcher.sub("", str(url))
The Other Jimmy 31:182518299918 27
The Other Jimmy 31:182518299918 28 def largest_version(content) :
The Other Jimmy 31:182518299918 29 return sorted([t['version'] for t in content.package.releases('release')], reverse=True)[0]
The Other Jimmy 31:182518299918 30
The Other Jimmy 31:182518299918 31 def do_queue(Class, function, interable) :
The Other Jimmy 31:182518299918 32 q = Queue()
The Other Jimmy 31:182518299918 33 threads = [Class(q, function) for each in range(20)]
The Other Jimmy 31:182518299918 34 for each in threads :
The Other Jimmy 31:182518299918 35 each.setDaemon(True)
The Other Jimmy 31:182518299918 36 each.start()
The Other Jimmy 31:182518299918 37 for thing in interable :
The Other Jimmy 31:182518299918 38 q.put(thing)
The Other Jimmy 31:182518299918 39 q.join()
The Other Jimmy 31:182518299918 40
The Other Jimmy 31:182518299918 41 class Reader (Thread) :
The Other Jimmy 31:182518299918 42 def __init__(self, queue, func) :
The Other Jimmy 31:182518299918 43 Thread.__init__(self)
The Other Jimmy 31:182518299918 44 self.queue = queue
The Other Jimmy 31:182518299918 45 self.func = func
The Other Jimmy 31:182518299918 46 def run(self) :
The Other Jimmy 31:182518299918 47 while True :
The Other Jimmy 31:182518299918 48 url = self.queue.get()
The Other Jimmy 31:182518299918 49 self.func(url)
The Other Jimmy 31:182518299918 50 self.queue.task_done()
The Other Jimmy 31:182518299918 51
The Other Jimmy 31:182518299918 52
The Other Jimmy 31:182518299918 53 class Cache () :
The Other Jimmy 31:182518299918 54 """ The Cache object is the only relevant API object at the moment
The Other Jimmy 31:182518299918 55
The Other Jimmy 31:182518299918 56 Constructing the Cache object does not imply any caching.
The Other Jimmy 31:182518299918 57 A user of the API must explicitly call caching functions.
The Other Jimmy 31:182518299918 58
The Other Jimmy 31:182518299918 59 :param silent: A boolean that, when True, significantly reduces the printing of this Object
The Other Jimmy 31:182518299918 60 :type silent: bool
The Other Jimmy 31:182518299918 61 :param no_timeouts: A boolean that, when True, disables the default connection timeout and low speed timeout for downloading things.
The Other Jimmy 31:182518299918 62 :type no_timeouts: bool
The Other Jimmy 31:182518299918 63 """
The Other Jimmy 31:182518299918 64 def __init__ (self, silent, no_timeouts) :
The Other Jimmy 31:182518299918 65 self.silent = silent
The Other Jimmy 31:182518299918 66 self.counter = 0
The Other Jimmy 31:182518299918 67 self.total = 1
The Other Jimmy 31:182518299918 68 self._index = {}
The Other Jimmy 31:182518299918 69 self._aliases = {}
The Other Jimmy 31:182518299918 70 self.urls = None
The Other Jimmy 31:182518299918 71 self.no_timeouts = no_timeouts
The Other Jimmy 31:182518299918 72 self.data_path = gettempdir()
The Other Jimmy 31:182518299918 73
The Other Jimmy 31:182518299918 74 def display_counter (self, message) :
The Other Jimmy 31:182518299918 75 stdout.write("{} {}/{}\r".format(message, self.counter, self.total))
The Other Jimmy 31:182518299918 76 stdout.flush()
The Other Jimmy 31:182518299918 77
The Other Jimmy 31:182518299918 78 def cache_file (self, url) :
The Other Jimmy 31:182518299918 79 """Low level interface to caching a single file.
The Other Jimmy 31:182518299918 80
The Other Jimmy 31:182518299918 81 :param url: The URL to cache.
The Other Jimmy 31:182518299918 82 :type url: str
The Other Jimmy 31:182518299918 83 :rtype: None
The Other Jimmy 31:182518299918 84 """
The Other Jimmy 31:182518299918 85 if not self.silent : print("Caching {}...".format(url))
The Other Jimmy 31:182518299918 86 dest = join(self.data_path, strip_protocol(url))
The Other Jimmy 31:182518299918 87 try :
The Other Jimmy 31:182518299918 88 makedirs(dirname(dest))
The Other Jimmy 31:182518299918 89 except OSError as exc :
The Other Jimmy 31:182518299918 90 if exc.errno == EEXIST : pass
The Other Jimmy 31:182518299918 91 else : raise
The Other Jimmy 31:182518299918 92 try:
The Other Jimmy 31:182518299918 93 with open(dest, "wb+") as fd :
The Other Jimmy 31:182518299918 94 fd.write(urlopen(url).read())
The Other Jimmy 31:182518299918 95 except URLError as e:
The Other Jimmy 31:182518299918 96 stderr.write(e.reason)
The Other Jimmy 31:182518299918 97 self.counter += 1
The Other Jimmy 31:182518299918 98 self.display_counter("Caching Files")
The Other Jimmy 31:182518299918 99
The Other Jimmy 31:182518299918 100 def pdsc_to_pack (self, url) :
The Other Jimmy 31:182518299918 101 """Find the URL of the specified pack file described by a PDSC.
The Other Jimmy 31:182518299918 102
The Other Jimmy 31:182518299918 103 The PDSC is assumed to be cached and is looked up in the cache by its URL.
The Other Jimmy 31:182518299918 104
The Other Jimmy 31:182518299918 105 :param url: The url used to look up the PDSC.
The Other Jimmy 31:182518299918 106 :type url: str
The Other Jimmy 31:182518299918 107 :return: The url of the PACK file.
The Other Jimmy 31:182518299918 108 :rtype: str
The Other Jimmy 31:182518299918 109 """
The Other Jimmy 31:182518299918 110 content = self.pdsc_from_cache(url)
The Other Jimmy 31:182518299918 111 new_url = content.package.url.get_text()
The Other Jimmy 31:182518299918 112 if not new_url.endswith("/") :
The Other Jimmy 31:182518299918 113 new_url = new_url + "/"
The Other Jimmy 31:182518299918 114 return (new_url + content.package.vendor.get_text() + "." +
The Other Jimmy 31:182518299918 115 content.package.find('name').get_text() + "." +
The Other Jimmy 31:182518299918 116 largest_version(content) + ".pack")
The Other Jimmy 31:182518299918 117
The Other Jimmy 31:182518299918 118 def cache_pdsc_and_pack (self, url) :
The Other Jimmy 31:182518299918 119 self.cache_file(url)
The Other Jimmy 31:182518299918 120 try :
The Other Jimmy 31:182518299918 121 self.cache_file(self.pdsc_to_pack(url))
The Other Jimmy 31:182518299918 122 except AttributeError :
The Other Jimmy 31:182518299918 123 stderr.write("[ ERROR ] {} does not appear to be a conforming .pdsc file\n".format(url))
The Other Jimmy 31:182518299918 124 self.counter += 1
The Other Jimmy 31:182518299918 125
The Other Jimmy 31:182518299918 126 def get_urls(self):
The Other Jimmy 31:182518299918 127 """Extract the URLs of all know PDSC files.
The Other Jimmy 31:182518299918 128
The Other Jimmy 31:182518299918 129 Will pull the index from the internet if it is not cached.
The Other Jimmy 31:182518299918 130
The Other Jimmy 31:182518299918 131 :return: A list of all PDSC URLs
The Other Jimmy 31:182518299918 132 :rtype: [str]
The Other Jimmy 31:182518299918 133 """
The Other Jimmy 31:182518299918 134 if not self.urls :
The Other Jimmy 31:182518299918 135 try : root_data = self.pdsc_from_cache(RootPackURL)
The Other Jimmy 31:182518299918 136 except IOError : root_data = self.cache_and_parse(RootPackURL)
The Other Jimmy 31:182518299918 137 self.urls = ["/".join([pdsc.get('url').strip("/"),
The Other Jimmy 31:182518299918 138 pdsc.get('name').strip("/")])
The Other Jimmy 31:182518299918 139 for pdsc in root_data.find_all("pdsc")]
The Other Jimmy 31:182518299918 140 return self.urls
The Other Jimmy 31:182518299918 141
The Other Jimmy 31:182518299918 142 def _extract_dict(self, device, filename, pack) :
The Other Jimmy 31:182518299918 143 to_ret = dict(pdsc_file=filename, pack_file=pack)
The Other Jimmy 31:182518299918 144 try : to_ret["memory"] = dict([(m["id"], dict(start=m["start"],
The Other Jimmy 31:182518299918 145 size=m["size"]))
The Other Jimmy 31:182518299918 146 for m in device("memory")])
The Other Jimmy 31:182518299918 147 except (KeyError, TypeError, IndexError) as e : pass
The Other Jimmy 31:182518299918 148 try: algorithms = device("algorithm")
The Other Jimmy 31:182518299918 149 except:
The Other Jimmy 31:182518299918 150 try: algorithms = device.parent("algorithm")
The Other Jimmy 31:182518299918 151 except: pass
The Other Jimmy 31:182518299918 152 else:
The Other Jimmy 31:182518299918 153 if not algorithms:
The Other Jimmy 31:182518299918 154 try: algorithms = device.parent("algorithm")
The Other Jimmy 31:182518299918 155 except: pass
The Other Jimmy 31:182518299918 156 try : to_ret["algorithm"] = dict([(algo.get("name").replace('\\','/'),
The Other Jimmy 31:182518299918 157 dict(start=algo["start"],
The Other Jimmy 31:182518299918 158 size=algo["size"],
The Other Jimmy 31:182518299918 159 ramstart=algo.get("ramstart",None),
The Other Jimmy 31:182518299918 160 ramsize=algo.get("ramsize",None),
The Other Jimmy 31:182518299918 161 default=algo.get("default",1)))
The Other Jimmy 31:182518299918 162 for algo in algorithms])
The Other Jimmy 31:182518299918 163 except (KeyError, TypeError, IndexError) as e: pass
The Other Jimmy 31:182518299918 164 try: to_ret["debug"] = device.parent.parent.debug["svd"]
The Other Jimmy 31:182518299918 165 except (KeyError, TypeError, IndexError) as e : pass
The Other Jimmy 31:182518299918 166 try: to_ret["debug"] = device.parent.debug["svd"]
The Other Jimmy 31:182518299918 167 except (KeyError, TypeError, IndexError) as e : pass
The Other Jimmy 31:182518299918 168 try: to_ret["debug"] = device.debug["svd"]
The Other Jimmy 31:182518299918 169 except (KeyError, TypeError, IndexError) as e : pass
The Other Jimmy 31:182518299918 170
The Other Jimmy 31:182518299918 171 to_ret["compile"] = {}
The Other Jimmy 31:182518299918 172 try: compile_l1 = device.parent("compile")
The Other Jimmy 31:182518299918 173 except (KeyError, TypeError, IndexError) as e : compile_l1 = []
The Other Jimmy 31:182518299918 174 try: compile_l2 = device.parent.parent("compile")
The Other Jimmy 31:182518299918 175 except (KeyError, TypeError, IndexError) as e : compile_l2 = []
The Other Jimmy 31:182518299918 176 compile = compile_l2 + compile_l1
The Other Jimmy 31:182518299918 177 for c in compile:
The Other Jimmy 31:182518299918 178 try: to_ret["compile"]["header"] = c["header"]
The Other Jimmy 31:182518299918 179 except (KeyError, TypeError, IndexError) as e : pass
The Other Jimmy 31:182518299918 180 try: to_ret["compile"]["define"] = c["define"]
The Other Jimmy 31:182518299918 181 except (KeyError, TypeError, IndexError) as e : pass
The Other Jimmy 31:182518299918 182
The Other Jimmy 31:182518299918 183 try: to_ret["core"] = device.parent.processor['dcore']
The Other Jimmy 31:182518299918 184 except (KeyError, TypeError, IndexError) as e : pass
The Other Jimmy 31:182518299918 185 try: to_ret["core"] = device.parent.parent.processor['dcore']
The Other Jimmy 31:182518299918 186 except (KeyError, TypeError, IndexError) as e : pass
The Other Jimmy 31:182518299918 187
The Other Jimmy 31:182518299918 188 to_ret["processor"] = {}
The Other Jimmy 31:182518299918 189 try: proc_l1 = device("processor")
The Other Jimmy 31:182518299918 190 except (KeyError, TypeError, IndexError) as e: proc_l1 = []
The Other Jimmy 31:182518299918 191 try: proc_l2 = device.parent("processor")
The Other Jimmy 31:182518299918 192 except (KeyError, TypeError, IndexError) as e: proc_l2 = []
The Other Jimmy 31:182518299918 193 try: proc_l3 = device.parent.parent("processor")
The Other Jimmy 31:182518299918 194 except (KeyError, TypeError, IndexError) as e: proc_l3 = []
The Other Jimmy 31:182518299918 195 proc = proc_l3 + proc_l2 + proc_l1
The Other Jimmy 31:182518299918 196 for p in proc:
The Other Jimmy 31:182518299918 197 try: to_ret["processor"]["fpu"] = p['dfpu']
The Other Jimmy 31:182518299918 198 except (KeyError, TypeError, IndexError) as e: pass
The Other Jimmy 31:182518299918 199 try: to_ret["processor"]["endianness"] = p['dendian']
The Other Jimmy 31:182518299918 200 except (KeyError, TypeError, IndexError) as e: pass
The Other Jimmy 31:182518299918 201 try: to_ret["processor"]["clock"] = p['dclock']
The Other Jimmy 31:182518299918 202 except (KeyError, TypeError, IndexError) as e: pass
The Other Jimmy 31:182518299918 203
The Other Jimmy 31:182518299918 204 try: to_ret["vendor"] = device.parent['dvendor']
The Other Jimmy 31:182518299918 205 except (KeyError, TypeError, IndexError) as e: pass
The Other Jimmy 31:182518299918 206 try: to_ret["vendor"] = device.parent.parent['dvendor']
The Other Jimmy 31:182518299918 207 except (KeyError, TypeError, IndexError) as e: pass
The Other Jimmy 31:182518299918 208
The Other Jimmy 31:182518299918 209 if not to_ret["processor"]:
The Other Jimmy 31:182518299918 210 del to_ret["processor"]
The Other Jimmy 31:182518299918 211
The Other Jimmy 31:182518299918 212 if not to_ret["compile"]:
The Other Jimmy 31:182518299918 213 del to_ret["compile"]
The Other Jimmy 31:182518299918 214
The Other Jimmy 31:182518299918 215 to_ret['debug-interface'] = []
The Other Jimmy 31:182518299918 216
The Other Jimmy 31:182518299918 217 return to_ret
The Other Jimmy 31:182518299918 218
The Other Jimmy 31:182518299918 219 def _generate_index_helper(self, d) :
The Other Jimmy 31:182518299918 220 try :
The Other Jimmy 31:182518299918 221 pack = self.pdsc_to_pack(d)
The Other Jimmy 31:182518299918 222 self._index.update(dict([(dev['dname'], self._extract_dict(dev, d, pack)) for dev in
The Other Jimmy 31:182518299918 223 (self.pdsc_from_cache(d)("device"))]))
The Other Jimmy 31:182518299918 224 except AttributeError as e :
The Other Jimmy 31:182518299918 225 stderr.write("[ ERROR ] file {}\n".format(d))
The Other Jimmy 31:182518299918 226 print(e)
The Other Jimmy 31:182518299918 227 self.counter += 1
The Other Jimmy 31:182518299918 228 self.display_counter("Generating Index")
The Other Jimmy 31:182518299918 229
The Other Jimmy 31:182518299918 230 def _generate_aliases_helper(self, d) :
The Other Jimmy 31:182518299918 231 try :
The Other Jimmy 31:182518299918 232 mydict = []
The Other Jimmy 31:182518299918 233 for dev in self.pdsc_from_cache(d)("board"):
The Other Jimmy 31:182518299918 234 try :
The Other Jimmy 31:182518299918 235 mydict.append((dev['name'], dev.mounteddevice['dname']))
The Other Jimmy 31:182518299918 236 except (KeyError, TypeError, IndexError) as e:
The Other Jimmy 31:182518299918 237 pass
The Other Jimmy 31:182518299918 238 self._aliases.update(dict(mydict))
The Other Jimmy 31:182518299918 239 except (AttributeError, TypeError) as e :
The Other Jimmy 31:182518299918 240 pass
The Other Jimmy 31:182518299918 241 self.counter += 1
The Other Jimmy 31:182518299918 242 self.display_counter("Scanning for Aliases")
The Other Jimmy 31:182518299918 243
The Other Jimmy 31:182518299918 244 def get_flash_algorthim_binary(self, device_name) :
The Other Jimmy 31:182518299918 245 """Retrieve the flash algorithm file for a particular part.
The Other Jimmy 31:182518299918 246
The Other Jimmy 31:182518299918 247 Assumes that both the PDSC and the PACK file associated with that part are in the cache.
The Other Jimmy 31:182518299918 248
The Other Jimmy 31:182518299918 249 :param device_name: The exact name of a device
The Other Jimmy 31:182518299918 250 :type device_name: str
The Other Jimmy 31:182518299918 251 :return: A file-like object that, when read, is the ELF file that describes the flashing algorithm
The Other Jimmy 31:182518299918 252 :rtype: ZipExtFile
The Other Jimmy 31:182518299918 253 """
The Other Jimmy 31:182518299918 254 pack = self.pack_from_cache(self.index[device_name])
The Other Jimmy 31:182518299918 255 return pack.open(device['algorithm']['file'])
The Other Jimmy 31:182518299918 256
The Other Jimmy 31:182518299918 257 def get_svd_file(self, device_name) :
The Other Jimmy 31:182518299918 258 """Retrieve the flash algorithm file for a particular part.
The Other Jimmy 31:182518299918 259
The Other Jimmy 31:182518299918 260 Assumes that both the PDSC and the PACK file associated with that part are in the cache.
The Other Jimmy 31:182518299918 261
The Other Jimmy 31:182518299918 262 :param device_name: The exact name of a device
The Other Jimmy 31:182518299918 263 :type device_name: str
The Other Jimmy 31:182518299918 264 :return: A file-like object that, when read, is the ELF file that describes the flashing algorithm
The Other Jimmy 31:182518299918 265 :rtype: ZipExtFile
The Other Jimmy 31:182518299918 266 """
The Other Jimmy 31:182518299918 267 pack = self.pack_from_cache(self.index[device_name])
The Other Jimmy 31:182518299918 268 return pack.open(device['debug'])
The Other Jimmy 31:182518299918 269
The Other Jimmy 31:182518299918 270 def generate_index(self) :
The Other Jimmy 31:182518299918 271 self._index = {}
The Other Jimmy 31:182518299918 272 self.counter = 0
The Other Jimmy 31:182518299918 273 do_queue(Reader, self._generate_index_helper, self.get_urls())
The Other Jimmy 31:182518299918 274 with open(LocalPackIndex, "wb+") as out:
The Other Jimmy 31:182518299918 275 self._index["version"] = "0.1.0"
The Other Jimmy 31:182518299918 276 dump(self._index, out)
The Other Jimmy 31:182518299918 277 stdout.write("\n")
The Other Jimmy 31:182518299918 278
The Other Jimmy 31:182518299918 279 def generate_aliases(self) :
The Other Jimmy 31:182518299918 280 self._aliases = {}
The Other Jimmy 31:182518299918 281 self.counter = 0
The Other Jimmy 31:182518299918 282 do_queue(Reader, self._generate_aliases_helper, self.get_urls())
The Other Jimmy 31:182518299918 283 with open(LocalPackAliases, "wb+") as out:
The Other Jimmy 31:182518299918 284 dump(self._aliases, out)
The Other Jimmy 31:182518299918 285 stdout.write("\n")
The Other Jimmy 31:182518299918 286
The Other Jimmy 31:182518299918 287 def find_device(self, match) :
The Other Jimmy 31:182518299918 288 choices = process.extract(match, self.index.keys(), limit=len(self.index))
The Other Jimmy 31:182518299918 289 choices = sorted([(v, k) for k, v in choices], reverse=True)
The Other Jimmy 31:182518299918 290 if choices : choices = list(takewhile(lambda t: t[0] == choices[0][0], choices))
The Other Jimmy 31:182518299918 291 return [(v, self.index[v]) for k,v in choices]
The Other Jimmy 31:182518299918 292
The Other Jimmy 31:182518299918 293 def dump_index_to_file(self, file) :
The Other Jimmy 31:182518299918 294 with open(file, "wb+") as out:
The Other Jimmy 31:182518299918 295 dump(self.index, out)
The Other Jimmy 31:182518299918 296
The Other Jimmy 31:182518299918 297 @property
The Other Jimmy 31:182518299918 298 def index(self) :
The Other Jimmy 31:182518299918 299 """An index of most of the important data in all cached PDSC files.
The Other Jimmy 31:182518299918 300
The Other Jimmy 31:182518299918 301 :Example:
The Other Jimmy 31:182518299918 302
The Other Jimmy 31:182518299918 303 >>> from ArmPackManager import Cache
The Other Jimmy 31:182518299918 304 >>> a = Cache()
The Other Jimmy 31:182518299918 305 >>> a.index["LPC1768"]
The Other Jimmy 31:182518299918 306 {u'algorithm': {u'RAMsize': u'0x0FE0',
The Other Jimmy 31:182518299918 307 u'RAMstart': u'0x10000000',
The Other Jimmy 31:182518299918 308 u'name': u'Flash/LPC_IAP_512.FLM',
The Other Jimmy 31:182518299918 309 u'size': u'0x80000',
The Other Jimmy 31:182518299918 310 u'start': u'0x00000000'},
The Other Jimmy 31:182518299918 311 u'compile': [u'Device/Include/LPC17xx.h', u'LPC175x_6x'],
The Other Jimmy 31:182518299918 312 u'debug': u'SVD/LPC176x5x.svd',
The Other Jimmy 31:182518299918 313 u'pdsc_file': u'http://www.keil.com/pack/Keil.LPC1700_DFP.pdsc',
The Other Jimmy 31:182518299918 314 u'memory': {u'IRAM1': {u'size': u'0x8000', u'start': u'0x10000000'},
The Other Jimmy 31:182518299918 315 u'IRAM2': {u'size': u'0x8000', u'start': u'0x2007C000'},
The Other Jimmy 31:182518299918 316 u'IROM1': {u'size': u'0x80000', u'start': u'0x00000000'}}}
The Other Jimmy 31:182518299918 317
The Other Jimmy 31:182518299918 318
The Other Jimmy 31:182518299918 319 """
The Other Jimmy 31:182518299918 320 if not self._index :
The Other Jimmy 31:182518299918 321 with open(LocalPackIndex) as i :
The Other Jimmy 31:182518299918 322 self._index = load(i)
The Other Jimmy 31:182518299918 323 return self._index
The Other Jimmy 31:182518299918 324 @property
The Other Jimmy 31:182518299918 325 def aliases(self) :
The Other Jimmy 31:182518299918 326 """An index of most of the important data in all cached PDSC files.
The Other Jimmy 31:182518299918 327
The Other Jimmy 31:182518299918 328 :Example:
The Other Jimmy 31:182518299918 329
The Other Jimmy 31:182518299918 330 >>> from ArmPackManager import Cache
The Other Jimmy 31:182518299918 331 >>> a = Cache()
The Other Jimmy 31:182518299918 332 >>> a.index["LPC1768"]
The Other Jimmy 31:182518299918 333 {u'algorithm': {u'RAMsize': u'0x0FE0',
The Other Jimmy 31:182518299918 334 u'RAMstart': u'0x10000000',
The Other Jimmy 31:182518299918 335 u'name': u'Flash/LPC_IAP_512.FLM',
The Other Jimmy 31:182518299918 336 u'size': u'0x80000',
The Other Jimmy 31:182518299918 337 u'start': u'0x00000000'},
The Other Jimmy 31:182518299918 338 u'compile': [u'Device/Include/LPC17xx.h', u'LPC175x_6x'],
The Other Jimmy 31:182518299918 339 u'debug': u'SVD/LPC176x5x.svd',
The Other Jimmy 31:182518299918 340 u'pdsc_file': u'http://www.keil.com/pack/Keil.LPC1700_DFP.pdsc',
The Other Jimmy 31:182518299918 341 u'memory': {u'IRAM1': {u'size': u'0x8000', u'start': u'0x10000000'},
The Other Jimmy 31:182518299918 342 u'IRAM2': {u'size': u'0x8000', u'start': u'0x2007C000'},
The Other Jimmy 31:182518299918 343 u'IROM1': {u'size': u'0x80000', u'start': u'0x00000000'}}}
The Other Jimmy 31:182518299918 344
The Other Jimmy 31:182518299918 345
The Other Jimmy 31:182518299918 346 """
The Other Jimmy 31:182518299918 347 if not self._aliases :
The Other Jimmy 31:182518299918 348 with open(join(self.data_path, "aliases.json")) as i :
The Other Jimmy 31:182518299918 349 self._aliases = load(i)
The Other Jimmy 31:182518299918 350 return self._aliases
The Other Jimmy 31:182518299918 351
The Other Jimmy 31:182518299918 352 def cache_everything(self) :
The Other Jimmy 31:182518299918 353 """Cache every PACK and PDSC file known.
The Other Jimmy 31:182518299918 354
The Other Jimmy 31:182518299918 355 Generates an index afterwards.
The Other Jimmy 31:182518299918 356
The Other Jimmy 31:182518299918 357 .. note:: This process may use 4GB of drive space and take upwards of 10 minutes to complete.
The Other Jimmy 31:182518299918 358 """
The Other Jimmy 31:182518299918 359 self.cache_pack_list(self.get_urls())
The Other Jimmy 31:182518299918 360 self.generate_index()
The Other Jimmy 31:182518299918 361 self.generate_aliases()
The Other Jimmy 31:182518299918 362
The Other Jimmy 31:182518299918 363 def cache_descriptors(self) :
The Other Jimmy 31:182518299918 364 """Cache every PDSC file known.
The Other Jimmy 31:182518299918 365
The Other Jimmy 31:182518299918 366 Generates an index afterwards.
The Other Jimmy 31:182518299918 367
The Other Jimmy 31:182518299918 368 .. note:: This process may use 11MB of drive space and take upwards of 1 minute.
The Other Jimmy 31:182518299918 369 """
The Other Jimmy 31:182518299918 370 self.cache_descriptor_list(self.get_urls())
The Other Jimmy 31:182518299918 371 self.generate_index()
The Other Jimmy 31:182518299918 372 self.generate_aliases()
The Other Jimmy 31:182518299918 373
The Other Jimmy 31:182518299918 374 def cache_descriptor_list(self, list) :
The Other Jimmy 31:182518299918 375 """Cache a list of PDSC files.
The Other Jimmy 31:182518299918 376
The Other Jimmy 31:182518299918 377 :param list: URLs of PDSC files to cache.
The Other Jimmy 31:182518299918 378 :type list: [str]
The Other Jimmy 31:182518299918 379 """
The Other Jimmy 31:182518299918 380 self.total = len(list)
The Other Jimmy 31:182518299918 381 self.display_counter("Caching Files")
The Other Jimmy 31:182518299918 382 do_queue(Reader, self.cache_file, list)
The Other Jimmy 31:182518299918 383 stdout.write("\n")
The Other Jimmy 31:182518299918 384
The Other Jimmy 31:182518299918 385 def cache_pack_list(self, list) :
The Other Jimmy 31:182518299918 386 """Cache a list of PACK files, referenced by their PDSC URL
The Other Jimmy 31:182518299918 387
The Other Jimmy 31:182518299918 388 :param list: URLs of PDSC files to cache.
The Other Jimmy 31:182518299918 389 :type list: [str]
The Other Jimmy 31:182518299918 390 """
The Other Jimmy 31:182518299918 391 self.total = len(list) * 2
The Other Jimmy 31:182518299918 392 self.display_counter("Caching Files")
The Other Jimmy 31:182518299918 393 do_queue(Reader, self.cache_pdsc_and_pack, list)
The Other Jimmy 31:182518299918 394 stdout.write("\n")
The Other Jimmy 31:182518299918 395
The Other Jimmy 31:182518299918 396 def pdsc_from_cache(self, url) :
The Other Jimmy 31:182518299918 397 """Low level inteface for extracting a PDSC file from the cache.
The Other Jimmy 31:182518299918 398
The Other Jimmy 31:182518299918 399 Assumes that the file specified is a PDSC file and is in the cache.
The Other Jimmy 31:182518299918 400
The Other Jimmy 31:182518299918 401 :param url: The URL of a PDSC file.
The Other Jimmy 31:182518299918 402 :type url: str
The Other Jimmy 31:182518299918 403 :return: A parsed representation of the PDSC file.
The Other Jimmy 31:182518299918 404 :rtype: BeautifulSoup
The Other Jimmy 31:182518299918 405 """
The Other Jimmy 31:182518299918 406 dest = join(self.data_path, strip_protocol(url))
The Other Jimmy 31:182518299918 407 with open(dest, "r") as fd :
The Other Jimmy 31:182518299918 408 return BeautifulSoup(fd, "html.parser")
The Other Jimmy 31:182518299918 409
The Other Jimmy 31:182518299918 410 def pack_from_cache(self, url) :
The Other Jimmy 31:182518299918 411 """Low level inteface for extracting a PACK file from the cache.
The Other Jimmy 31:182518299918 412
The Other Jimmy 31:182518299918 413 Assumes that the file specified is a PACK file and is in the cache.
The Other Jimmy 31:182518299918 414
The Other Jimmy 31:182518299918 415 :param url: The URL of a PACK file.
The Other Jimmy 31:182518299918 416 :type url: str
The Other Jimmy 31:182518299918 417 :return: A parsed representation of the PACK file.
The Other Jimmy 31:182518299918 418 :rtype: ZipFile
The Other Jimmy 31:182518299918 419 """
The Other Jimmy 31:182518299918 420 return ZipFile(join(self.data_path,
The Other Jimmy 31:182518299918 421 strip_protocol(device['pack_file'])))
The Other Jimmy 31:182518299918 422
The Other Jimmy 31:182518299918 423 def gen_dict_from_cache() :
The Other Jimmy 31:182518299918 424 pdsc_files = pdsc_from_cache(RootPackUrl)
The Other Jimmy 31:182518299918 425
The Other Jimmy 31:182518299918 426 def cache_and_parse(self, url) :
The Other Jimmy 31:182518299918 427 """A low level shortcut that Caches and Parses a PDSC file.
The Other Jimmy 31:182518299918 428
The Other Jimmy 31:182518299918 429 :param url: The URL of the PDSC file.
The Other Jimmy 31:182518299918 430 :type url: str
The Other Jimmy 31:182518299918 431 :return: A parsed representation of the PDSC file.
The Other Jimmy 31:182518299918 432 :rtype: BeautifulSoup
The Other Jimmy 31:182518299918 433 """
The Other Jimmy 31:182518299918 434 self.cache_file(url)
The Other Jimmy 31:182518299918 435 return self.pdsc_from_cache(url)
The Other Jimmy 31:182518299918 436