def test_easy_access_dict(self): good_data = {'test': True} easy = EasyAccessDict() assert easy('bad-key') is None good_easy = EasyAccessDict(good_data) assert good_easy.get('test') is True assert good_easy.get('no-test') is None
def _update_version_file(self, json_data, package_manifest): # Updates version file with package meta-data log.info('Adding package meta-data to version manifest') easy_dict = EasyAccessDict(json_data) for p in package_manifest: patch_name = p.patch_info.get('patch_name') patch_hash = p.patch_info.get('patch_hash') # Converting info to format compatible for version file info = {'file_hash': p.file_hash, 'filename': p.filename} if patch_name and patch_hash: info['patch_name'] = patch_name info['patch_hash'] = patch_hash version_key = '{}*{}*{}'.format(settings.UPDATES_KEY, p.name, p.version) version = easy_dict.get(version_key) log.debug('Package Info: {}'.format(version)) if version is None: log.debug('Adding new version to file') # First version this package name json_data[settings.UPDATES_KEY][p.name][p.version] = {} platform_key = '{}*{}*{}*{}'.format(settings.UPDATES_KEY, p.name, p.version, 'platform') platform = easy_dict.get(platform_key) if platform is None: name_ = json_data[settings.UPDATES_KEY][p.name] name_[p.version][p.platform] = info else: # package already present, adding another version to it log.debug('Appending info data to version file') json_data[settings.UPDATES_KEY][p.name][p.version][ p.platform] = info # Will add each individual platform version update # to latest. Now can update platforms independently json_data['latest'][p.name][p.platform] = p.version return json_data
def _get_update_manifest(self): # Downloads & Verifies version file signature. log.info('Loading version file...') data = self._download_manifest() if data is None: # Its ok if this is None. If any exceptions are raised # that we can't handle we will just return an empty # dictionary. data = self._get_manifest_filesystem() try: log.debug('Data type: {}'.format(type(data))) self.json_data = json.loads(data) # Ready to check for updates. # If json fails to load self.ready will stay false # which will cause _update_check to exit early self.ready = True except ValueError as err: # Malformed json??? log.debug(str(err), exc_info=True) log.error('Json failed to load: ValueError') except Exception as err: # Catch all for debugging purposes. # If seeing this line come up a lot in debug logs # please open an issue on github or submit a pull request log.error(str(err)) log.debug(str(err), exc_info=True) # Setting to default dict to not raise any errors # in _verify_sig if self.json_data is None: self.json_data = {} # If verified we set self.verified to True. # We return the data either way self.json_data = self._verify_sig(self.json_data) self.easy_data = EasyAccessDict(self.json_data) log.debug('Version Data:\n{}'.format(str(self.easy_data)))
def __init__(self, **kwargs): self.name = kwargs.get('name') self.json_data = kwargs.get('json_data') self.star_access_update_data = EasyAccessDict(self.json_data) self.current_version = Version(kwargs.get('current_version')) self.highest_version = kwargs.get('highest_version') self.update_folder = kwargs.get('update_folder') self.update_urls = kwargs.get('update_urls', []) self.verify = kwargs.get('verify', True) self.progress_hooks = kwargs.get('progress_hooks', []) self.patch_data = [] self.patch_binary_data = [] self.og_binary = None # ToDo: Update tests with linux archives. # Used for testing. self.platform = kwargs.get('platform', _platform) self.current_filename = kwargs.get('current_filename') self.current_file_hash = kwargs.get('current_file_hash') file_info = self._current_file_info(self.name, self.current_version) if self.current_filename is None: self.current_filename = file_info['filename'] if self.current_file_hash is None: self.current_file_hash = file_info['file_hash']