Skip to content

Make the presence of cmsis-pack-manager package optional #10089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 61 additions & 18 deletions tools/arm_pack_manager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
from os.path import join, dirname
from json import load, dump
import warnings
from cmsis_pack_manager import Cache as _Cache

try:
from cmsis_pack_manager import Cache as _Cache
_CPM_PRESENT = True
except ImportError:
_CPM_PRESENT = False

from tools.flash_algo import PackFlashAlgo

Expand Down Expand Up @@ -60,10 +65,14 @@ class Cache(object):
:type no_timeouts: bool
"""
def __init__(self, silent, no_timeouts):
self._cache = _Cache(
silent, no_timeouts,
json_path=LocalPackDir, data_path=LocalPackDir
)
if _CPM_PRESENT:
self._cache = _Cache(
silent, no_timeouts,
json_path=LocalPackDir, data_path=LocalPackDir
)
else:
self._cache = None

try:
self._legacy_names = load(open(LocalPackLegacyNames))
except IOError:
Expand Down Expand Up @@ -101,17 +110,36 @@ def _get_sectors(self, device):

@property
def index(self):
return _CacheLookup(self._cache.index, self._legacy_names)
if _CPM_PRESENT:
return _CacheLookup(self._cache.index, self._legacy_names)
else:
local_index = load(open(LocalPackIndex))
return _CacheLookup(local_index, self._legacy_names)

def cache_descriptors(self):
self._cache.cache_descriptors
if _CPM_PRESENT:
return self._cache.cache_descriptors()
else:
print(
'The Python package "cmsis-pack-manager" is not installed. '
'To cache CMSIS Pack descriptors, please install this '
'package with "pip install cmsis-pack-manager".'
)
return []

def cache_everything(self):
self._cache.cache_everything()
for name, device in self._cache.index.items():
if name != "version":
device["sectors"] = self._get_sectors(device)
self.generate_index()
if _CPM_PRESENT:
self._cache.cache_everything()
for name, device in self._cache.index.items():
if name != "version":
device["sectors"] = self._get_sectors(device)
self.generate_index()
else:
print(
'The Python package "cmsis-pack-manager" is not installed. '
'To update the cache, please install this package with '
'"pip install cmsis-pack-manager".'
)

def get_svd_file(self, device_name):
"""Retrieve the flash algorithm file for a particular part.
Expand All @@ -125,11 +153,26 @@ def get_svd_file(self, device_name):
describes the flashing algorithm
:rtype: ZipExtFile
"""
device = self.index[device_name]
pack = self.pack_from_cache(device)
return pack.open(device['debug'])
if _CPM_PRESENT:
device = self.index[device_name]
pack = self._cache.pack_from_cache(device)
return pack.open(device['debug'])
else:
print(
'The Python package "cmsis-pack-manager" is not installed. '
'To use SVD files, please install this package with '
'"pip install cmsis-pack-manager".'
)
return None

def generate_index(self):
with open(LocalPackIndex, "w+") as out:
self._cache.index["version"] = "0.2.0"
dump(self._cache.index, out, indent=4, sort_keys=True)
if _CPM_PRESENT:
with open(LocalPackIndex, "w+") as out:
self._cache.index["version"] = "0.2.0"
dump(self._cache.index, out, indent=4, sort_keys=True)
else:
print(
'The Python package "cmsis-pack-manager" is not installed. '
'To generate a CMSIS Pack index, please install this package with '
'"pip install cmsis-pack-manager".'
)