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

Commit

Permalink
Remove some unused code
Browse files Browse the repository at this point in the history
Convert some methods into static

Fix tests

Mostly spell checking

Convert instance to static methods

- Update docs strings to m match function signature
- Remove typo in README.md

Instance to static method conversions

Doc strings & pep 8

Refactor from private to public

- Remove unused variable desecration
- Remove unused import
- Fix doc string
- instance to static method
  • Loading branch information
JMSwag committed May 20, 2017
1 parent 830b575 commit 45d061b
Show file tree
Hide file tree
Showing 32 changed files with 204 additions and 243 deletions.
7 changes: 3 additions & 4 deletions .python-version
@@ -1,4 +1,3 @@
2.7.13
3.3.3
3.4.3
3.5.1
system
3.4.5
3.5.2
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -7,6 +7,6 @@
[![Gitter](https://badges.gitter.im/pyupdater/Lobby.svg)](https://gitter.im/pyupdater/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

# PyUpdater
####An autoupdate framework for pyinstaller that enables simple, secure & efficient shipment of app updates.
#### An autoupdate framework for pyinstaller that enables simple, secure & efficient shipment of app updates.

####[Docs](http://www.pyupdater.org) - [Installation](http://www.pyupdater.org/installation) - [Changelog](http://www.pyupdater.org/changelog/) - [License](http://www.pyupdater.org/license/)
#### [Docs](http://www.pyupdater.org) - [Installation](http://www.pyupdater.org/installation) - [Changelog](http://www.pyupdater.org/changelog/) - [License](http://www.pyupdater.org/license/)
6 changes: 3 additions & 3 deletions docs/api.md
Expand Up @@ -65,7 +65,7 @@ then restart the application using the updated binary.
Used to check if update has been downloaded.

######Returns (bool): True - File is already downloaded.
False - File hasn't been downloaded.
False - File has not been downloaded.

##### AppUpdate.restart()

Expand All @@ -77,7 +77,7 @@ Deprecated: Used extract_restart instead.

##### AppUpdate.win_extract_overwrite()

Overwrite current binary with update bianry on windows.
Overwrite current binary with update binary on windows.

Deprecated: Use extract_overwrite instead.

Expand Down Expand Up @@ -203,5 +203,5 @@ complete update.
Used to check if update has been downloaded.

######Returns (bool): True - File is already downloaded.
False - File hasn't been downloaded.
False - File has not been downloaded.

8 changes: 4 additions & 4 deletions docs/changelog.md
Expand Up @@ -601,7 +601,7 @@

- Client
- Support for offline root keys
- Sanatizing url attributes
- Sanitizing url attributes
- Patches clients up to 4 versions behind
- Config is now a dict instead of class
- Logging errors for 3rd party services
Expand Down Expand Up @@ -857,7 +857,7 @@

- Potential incorrect comparison of pyinstaller versions
- Archive version parsing
- Crashing if directory doesn't exists
- Crashing if directory does not exists
- Pinning version of plugins
- Initial support for pre release versions
- Moved some uploader config to plugins. Check plugin docs for more info.
Expand All @@ -870,7 +870,7 @@
- Plugins

- from pyi_updater.uploader import BaseUploader
- from pyi_updater.uploader.commom import BaseUploader will
- from pyi_updater.uploader.common import BaseUploader will
be remove in v0.22+

###Fixed
Expand All @@ -893,4 +893,4 @@
- PyUpdater

- Some unused attributes on config object
- Unsed functions
- Unused functions
2 changes: 1 addition & 1 deletion docs/commands.md
Expand Up @@ -15,7 +15,7 @@ optional arguments:

Description:

The archive command will archive an external asset used by your application which will allow updating of the asset. An example of this would be if your application depended on ffmpeg but you didn't want to bundle ffmpeg within your app. See "Usage | CLI | Assets" & "Usage | Client | Assets" for more info.
The archive command will archive an external asset used by your application which will allow updating of the asset. An example of this would be if your application depended on ffmpeg but you did not want to bundle ffmpeg within your app. See "Usage | CLI | Assets" & "Usage | Client | Assets" for more info.

Example:
```
Expand Down
1 change: 1 addition & 0 deletions pyupdater/__init__.py
Expand Up @@ -31,6 +31,7 @@

log = logging.getLogger()

# noinspection PyPep8
from ._version import get_versions
__version__ = get_versions()['version']
del get_versions
Expand Down
11 changes: 7 additions & 4 deletions pyupdater/builder.py
Expand Up @@ -65,7 +65,7 @@ def __init__(self, args, pyi_args):
cm = ConfigManager()
self.app_name = cm.get_app_name()
self.args = args
self.app_info, self.pyi_args = self._check_input_file(pyi_args)
self.app_info, self.pyi_args = Builder._check_input_file(pyi_args)

# Creates & archives executable
def build(self):
Expand Down Expand Up @@ -111,9 +111,11 @@ def _setup(self):
os.mkdir(d)

# Ensure that a spec file or python script is present
def _check_input_file(self, pyi_args):
@staticmethod
def _check_input_file(pyi_args):
verified = False
new_args = []
app_info = None
for p in pyi_args:
if p.endswith('.py'):
log.debug('Building from python source file: %s', p)
Expand Down Expand Up @@ -189,7 +191,8 @@ def _build(self, args, spec_file_path):
pyi_build(build_args)

# Updates name of binary from mac to applications name
def _mac_binary_rename(self, temp_name, app_name):
@staticmethod
def _mac_binary_rename(temp_name, app_name):
bin_dir = os.path.join(temp_name, 'Contents', 'MacOS')
plist = os.path.join(temp_name, 'Contents', 'Info.plist')
with ChDir(bin_dir):
Expand Down Expand Up @@ -217,7 +220,7 @@ def _archive(self, args, temp_name):
if os.path.exists(temp_name + '.app'):
log.debug('Got mac .app')
app_name = temp_name + '.app'
self._mac_binary_rename(app_name, self.app_name)
Builder._mac_binary_rename(app_name, self.app_name)
elif os.path.exists(temp_name + '.exe'):
log.debug('Got win .exe')
app_name = temp_name + '.exe'
Expand Down
4 changes: 2 additions & 2 deletions pyupdater/cli/__init__.py
Expand Up @@ -82,12 +82,12 @@ def _real_main(args, namespace_test_helper=None): # pragma: no cover
# Used for tests
args = namespace_test_helper

_dispatch_command(args, pyi_args)
dispatch_command(args, pyi_args)


# Dispatch the passed in command to its respective function in
# pyupdater.cli.commands
def _dispatch_command(args, pyi_args=None, test=False):
def dispatch_command(args, pyi_args=None, test=False):
# Turns collect-debug-info into collect_debug_info
cmd_str = "_cmd_" + args.command.replace('-', '_')
try:
Expand Down
3 changes: 2 additions & 1 deletion pyupdater/cli/commands.py
Expand Up @@ -281,7 +281,7 @@ def _cmd_pkg(*args):

# ToDo: Remove in v3.0
# I wanted to make the commands uniform to enable the usage of
# _dispatch_command in pyupdater.cli
# dispatch_command in pyupdater.cli
def upload_debug_info(*args):
_cmd_collect_debug_info(*args)
# End ToDo
Expand Down Expand Up @@ -398,6 +398,7 @@ def _cmd_upload(*args): # pragma: no cover
return
# Something happened with the upload plugin
except UploaderPluginError as err:
log.debug(err)
log.error('Invalid upload plugin')
log.error('Use "pyupdater plugins" to get a '
'list of installed plugins')
Expand Down
30 changes: 14 additions & 16 deletions pyupdater/client/__init__.py
Expand Up @@ -42,7 +42,7 @@

from pyupdater import settings, __version__
from pyupdater.client.downloader import FileDownloader as _FD
from pyupdater.client.updates import AppUpdate, _get_highest_version, LibUpdate
from pyupdater.client.updates import AppUpdate, get_highest_version, LibUpdate
from pyupdater.utils.config import Config as _Config


Expand Down Expand Up @@ -133,7 +133,7 @@ def init_app(self, obj, refresh=False, test=False, data_dir=None):
update_urls = config.get('UPDATE_URLS', [])

# List of URL to check for update data
self.update_urls = self._sanatize_update_url(update_urls)
self.update_urls = Client._sanitize_update_url(update_urls)

# Name of the running application
self.app_name = config.get('APP_NAME', 'PyUpdater')
Expand Down Expand Up @@ -187,7 +187,7 @@ def init_app(self, obj, refresh=False, test=False, data_dir=None):
self.refresh()

def refresh(self):
"Will download and verify the version manifest."
"""Will download and verify the version manifest."""
self._get_signing_key()
self._get_update_manifest()

Expand Down Expand Up @@ -252,10 +252,10 @@ def _update_check(self, name, version, channel, strict):
app = True

log.debug('Checking for %s updates...', name)
latest = _get_highest_version(name, self.platform, channel,
self.easy_data, strict)
latest = get_highest_version(name, self.platform, channel,
self.easy_data, strict)
if latest is None:
# If None is returned _get_highest_version could
# If None is returned get_highest_version could
# not find the supplied name in the version file
log.debug('Could not find the latest version')
return None
Expand Down Expand Up @@ -380,6 +380,7 @@ def _get_manifest_from_disk(self):
try:
decompressed_data = _gzip_decompress(data)
except Exception as err:
log.debug(err)
return None

return decompressed_data
Expand Down Expand Up @@ -515,19 +516,16 @@ def _setup(self):
log.debug('Creating directory: %s', d)
os.makedirs(d)

# ToDo: Remove in v 3.0
# Legacy code used when migrating from single urls to
# A list of urls
def _sanatize_update_url(self, urls):
sanatized_urls = []
@staticmethod
def _sanitize_update_url(urls):
sanitized_urls = []
# Adds trailing slash to end of url if not already provided.
# Doing this so when requesting online resources we only
# need to add the resouce name to the end of the request.
# need to add the resource name to the end of the request.
for u in urls:
if not u.endswith('/'):
sanatized_urls.append(u + '/')
sanitized_urls.append(u + '/')
else:
sanatized_urls.append(u)
sanitized_urls.append(u)
# Removing duplicates
return list(set(sanatized_urls))
# End ToDo
return list(set(sanitized_urls))
32 changes: 17 additions & 15 deletions pyupdater/client/downloader.py
Expand Up @@ -208,7 +208,7 @@ def _download_to_storage(self, check_hash=True):
hash_ = hashlib.sha256()

# Getting length of file to show progress
self.content_length = self._get_content_length(data)
self.content_length = FileDownloader._get_content_length(data)
if self.content_length is None:
log.debug('Content-Length not in headers')
log.debug('Callbacks will not show time left '
Expand All @@ -221,11 +221,11 @@ def _download_to_storage(self, check_hash=True):
self.file_binary_type = 'memory'

# Setting start point to show progress
recieved_data = 0
received_data = 0

start_download = time.time()
block = data.read(1)
recieved_data += len(block)
received_data += len(block)
if self.file_binary_type == 'memory':
self.file_binary_data = [block]
else:
Expand Down Expand Up @@ -260,21 +260,22 @@ def _download_to_storage(self, check_hash=True):
hash_.update(block)

# Total data we've received so far
recieved_data += len(block)
self.data = received_data
self.data += len(block)

# If content length is None we will return a static percent
# -.-%
percent = self._calc_progress_percent(recieved_data,
self.content_length)
percent = FileDownloader._calc_progress_percent(received_data,
self.content_length)

# If content length is None we will return a static time remaining
# --:--
time_left = FileDownloader._calc_eta(start_download, time.time(),
self.content_length,
recieved_data)
received_data)

status = {'total': self.content_length,
'downloaded': recieved_data,
'downloaded': received_data,
'status': 'downloading',
'percent_complete': percent,
'time': time_left}
Expand All @@ -283,7 +284,7 @@ def _download_to_storage(self, check_hash=True):
self._call_progress_hooks(status)

status = {'total': self.content_length,
'downloaded': recieved_data,
'downloaded': received_data,
'status': 'finished',
'percent_complete': percent,
'time': '00:00'}
Expand All @@ -294,11 +295,11 @@ def _download_to_storage(self, check_hash=True):
# Checks hash of downloaded file
if self.hexdigest is None:
# No hash provided to check.
# So just return any data recieved
# So just return any data received
log.debug('No hash to verify')
return None
if self.file_binary_data is None:
# Exit quickly if we got nohting to compare
# Exit quickly if we got nothing to compare
# Also I'm sure we'll get an exception trying to
# pass None to get hash :)
log.debug('Cannot verify file hash - No Data')
Expand All @@ -313,7 +314,6 @@ def _download_to_storage(self, check_hash=True):
log.debug('Cannot verify file hash')
return False


# Calling all progress hooks
def _call_progress_hooks(self, data):
log.debug(data)
Expand Down Expand Up @@ -368,7 +368,8 @@ def _write_to_file(self):
os.unlink(self.filename)
os.rename(self.file_binary_path, self.filename)

def _get_content_length(self, data):
@staticmethod
def _get_content_length(data):
content_length = data.headers.get("Content-Length")
if content_length is not None:
content_length = int(content_length)
Expand All @@ -390,9 +391,10 @@ def _calc_eta(start, now, total, current):
return '--:--'
return '%02d:%02d' % (eta_mins, eta_secs)

def _calc_progress_percent(self, recieved, total):
@staticmethod
def _calc_progress_percent(received, total):
if total is None:
return '-.-%'
percent = float(recieved) / total * 100
percent = float(received) / total * 100
percent = '%.1f' % percent
return percent
8 changes: 5 additions & 3 deletions pyupdater/client/patcher.py
Expand Up @@ -106,7 +106,7 @@ def __init__(self, **kwargs):
self.current_file_hash = file_info['file_hash']

def start(self):
"Starts patching process"
"""Starts patching process"""
log.debug('Starting patch updater...')
# Check hash on installed binary to begin patching
binary_check = self._verify_installed_binary()
Expand Down Expand Up @@ -230,9 +230,10 @@ def _get_patch_info(self):
else:
return True
else:
return self._calc_diff(total_patch_size, latest_file_size)
return Patcher._calc_diff(total_patch_size, latest_file_size)

def _calc_diff(self, patch_size, file_size):
@staticmethod
def _calc_diff(patch_size, file_size):
if patch_size < file_size:
return True
else:
Expand Down Expand Up @@ -271,6 +272,7 @@ def _download_verify_patches(self):
# Downloads & verifies all patches
log.debug('Downloading patches')
downloaded = 0
percent = 0
total = len(self.patch_data)

for p in self.patch_data:
Expand Down

0 comments on commit 45d061b

Please sign in to comment.