Skip to content
This repository has been archived by the owner on Sep 26, 2022. It is now read-only.

Commit

Permalink
Add lazy initialization for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
JMSwag committed Oct 29, 2016
1 parent ad363eb commit 9ffde16
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions pyupdater/client/updates.py
Expand Up @@ -203,9 +203,22 @@ class LibUpdate(object):
data (dict): Info dict
"""

def __init__(self, data):
def __init__(self, data=None):
self._updates_key = settings.UPDATES_KEY
self._current_app_dir = os.path.dirname(sys.executable)
self._status = False
# If user is using async download this will be True.
# Future calls to an download methods will not run
# until the current download is complete. Which will
# set this back to False.
self._is_downloading = False
self._version = ""

if data is not None:
self.init_app(data)

def init_app(self, data):
self.init_data = data
self.updates_key = settings.UPDATES_KEY
self.update_urls = data.get('update_urls')
self.name = data.get('name')
self.current_version = data.get('version')
Expand All @@ -221,20 +234,11 @@ def __init__(self, data):
settings.UPDATE_FOLDER)
self.verify = data.get('verify', True)
self.max_download_retries = data.get('max_download_retries')
self._current_app_dir = os.path.dirname(sys.executable)
self.status = False
# If user is using async download this will be True.
# Future calls to an download methods will not run
# until the current download is complete. Which will
# set this back to False.
self._is_downloading = False

# Used to generate file name of archive
self.latest = _get_highest_version(self.name, self.platform,
self.channel, self.easy_data)

self.version = _gen_user_friendly_version(self.latest)

self._current_archive_name = self._get_filename(self.name,
self.current_version,
self.platform,
Expand All @@ -249,6 +253,12 @@ def __init__(self, data):
# the updates folder.
self.cleanup()

@property
def version(self):
if self._version == "":
self._version = _gen_user_friendly_version(self.latest)
return self._version

def is_downloaded(self):
"""Used to check if update has been downloaded.
Expand Down Expand Up @@ -340,28 +350,28 @@ def _download(self):
"""
if self.name is not None:
if self._is_downloaded() is True: # pragma: no cover
self.status = True
self._status = True
else:
log.debug('Starting patch download')
patch_success = False
if self.channel == 'stable':
patch_success = self._patch_update()
# Tested elsewhere
if patch_success: # pragma: no cover
self.status = True
self._status = True
log.debug('Patch download successful')
else:
log.debug('Patch update failed')
log.debug('Starting full download')
update_success = self._full_update()
if update_success:
self.status = True
self._status = True
log.debug('Full download successful')
else: # pragma: no cover
log.debug('Full download failed')

self._is_downloading = False
return self.status
return self._status

def _extract_update(self):
with ChDir(self.update_folder):
Expand Down Expand Up @@ -398,9 +408,9 @@ def _extract_update(self):
raise ClientError('Update archive is corrupt')

def _get_file_hash_from_manifest(self):
hash_key = '{}*{}*{}*{}*{}'.format(self.updates_key, self.name,
self.latest, self.platform,
'file_hash')
hash_key = '{}*{}*{}*{}*{}'.format(self._updates_key,
self.name, self.latest,
self.platform, 'file_hash')
return self.easy_data.get(hash_key)

# Must be called from directory where file is located
Expand Down

0 comments on commit 9ffde16

Please sign in to comment.