Skip to content

Commit c5b3cf2

Browse files
committed
Add support for adding local pack files
*** Is alpha *** I added options to tools/arm_pack_manager/pack_manager.py and tools/flash_algo/extract.py to allow a user to specify a single pack on disk to add to the cache. The syntax is as follows: - python tools/arm_pack_manager/pack_manager.py add-local-pack <local-pack> - cd tools/flash_algo; python extract.py --local-pack <local-pack> Both of these methods will add your pack to the index and copy the pack file into the location that arm_pack_manager would have placed it if it was downloaded from the internet.
1 parent 567dbf7 commit c5b3cf2

File tree

3 files changed

+65
-2
lines changed

3 files changed

+65
-2
lines changed

tools/arm_pack_manager/__init__.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from urllib2 import urlopen, URLError
22
from bs4 import BeautifulSoup
3-
from os.path import join, dirname, basename
3+
from os.path import join, dirname, basename, exists
44
from os import makedirs
5+
from shutil import copyfile
56
from errno import EEXIST
67
from threading import Thread
78
from Queue import Queue
@@ -446,3 +447,38 @@ def cache_and_parse(self, url) :
446447
self.cache_file(url)
447448
return self.pdsc_from_cache(url)
448449

450+
def add_local_pack_file(self, filename):
451+
"""Add a single pack file to the index
452+
453+
:param filename: The pack file to add to the index
454+
"""
455+
_ = self.index # Force the cache to be loaded
456+
zipfile = ZipFile(open(filename))
457+
for zipinfo in zipfile.infolist():
458+
if (zipinfo.filename.endswith(".pdsc") or
459+
zipinfo.filename.endswith(".PDSC")):
460+
pdsc_filename = zipinfo.filename
461+
print("Found PDSC file in archive: %s" % pdsc_filename)
462+
break
463+
else:
464+
raise Exception("No `.pdsc` file found in pack archive.")
465+
with zipfile.open(pdsc_filename) as pdsc:
466+
pdsc_content = BeautifulSoup(pdsc, "html.parser")
467+
new_url = pdsc_content.package.url.get_text()
468+
if not new_url.endswith("/") :
469+
new_url += "/"
470+
pdsc_url = new_url + pdsc_filename
471+
pack_url = (new_url + pdsc_content.package.vendor.get_text() + "." +
472+
pdsc_content.package.find('name').get_text() + "." +
473+
largest_version(pdsc_content) + ".pack")
474+
for dev in pdsc_content("device"):
475+
print("Adding device %s" % dev['dname'])
476+
self._index[dev['dname']] = self._extract_dict(dev, pdsc_url, pack_url)
477+
with open(LocalPackIndex, "wb+") as out:
478+
self._index["version"] = "0.1.0"
479+
dump(self._index, out)
480+
new_path = join(self.data_path, strip_protocol(pack_url))
481+
print("Copying pack file to index.")
482+
if not exists(dirname(new_path)):
483+
makedirs(dirname(new_path))
484+
copyfile(filename, new_path)

tools/arm_pack_manager/pack_manager.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import argparse
22
from os.path import basename
3-
from tools.arm_pack_manager import Cache
3+
import sys
4+
from os.path import join, abspath, dirname
5+
# Be sure that the tools directory is in the search path
6+
ROOT = abspath(join(dirname(__file__), "..", ".."))
7+
sys.path.insert(0, ROOT)
8+
49
from os.path import basename, join, dirname, exists
510
from os import makedirs
611
from itertools import takewhile
@@ -189,3 +194,19 @@ def main() :
189194
args = parser.parse_args()
190195
args.command(args)
191196

197+
@subcommand('add-local-pack',
198+
dict(name='filename', help="pack file to add to cache"),
199+
help='add a local pack file to the index')
200+
def command_add_local_pack(cache, filename) :
201+
cache.add_local_pack_file(filename)
202+
203+
def get_argparse() :
204+
return parser
205+
206+
def main() :
207+
args = parser.parse_args()
208+
args.command(args)
209+
210+
if __name__ == "__main__":
211+
main()
212+

tools/flash_algo/extract.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ def main():
4444
help="Name of target to generate algo for")
4545
parser.add_argument("--all", action="store_true",
4646
help="Build all flash algos for devcies")
47+
parser.add_argument("--local-pack", dest="local_pack",
48+
default=None,
49+
help="Build all flash algos for devcies")
4750
args = parser.parse_args()
4851

4952
cache = Cache(True, True)
@@ -57,6 +60,9 @@ def main():
5760
print("Descriptors rebuilt")
5861
return
5962

63+
if args.local_pack:
64+
cache.add_local_pack_file(args.local_pack)
65+
6066
if args.target is None:
6167
device_and_filenames = [(target.device_name, target.name) for target
6268
in TARGETS if hasattr(target, "device_name")]

0 commit comments

Comments
 (0)