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

Commit

Permalink
Doc strings & pep 8
Browse files Browse the repository at this point in the history
  • Loading branch information
JMSwag committed May 20, 2017
1 parent 29f0ae3 commit 632af84
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 54 deletions.
1 change: 1 addition & 0 deletions pyupdater/__init__.py
Original file line number Diff line number Diff line change
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
1 change: 1 addition & 0 deletions pyupdater/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def _setup(self):
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
2 changes: 1 addition & 1 deletion pyupdater/client/__init__.py
Original file line number Diff line number Diff line change
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
3 changes: 1 addition & 2 deletions pyupdater/client/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def _download_to_storage(self, check_hash=True):
# If content length is None we will return a static percent
# -.-%
percent = FileDownloader._calc_progress_percent(received_data,
self.content_length)
self.content_length)

# If content length is None we will return a static time remaining
# --:--
Expand Down Expand Up @@ -314,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
3 changes: 2 additions & 1 deletion pyupdater/client/patcher.py
Original file line number Diff line number Diff line change
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 @@ -272,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
8 changes: 4 additions & 4 deletions pyupdater/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def _update(self, config):
self.up = Uploader(config)

def setup(self):
"Sets up root dir with required PyUpdater folders"
"""Sets up root dir with required PyUpdater folders"""
self.ph.setup()

def process_packages(self, report_errors=False):
Expand All @@ -89,16 +89,16 @@ def set_uploader(self, requested_uploader, keep=False):
self.up.set_uploader(requested_uploader, keep)

def upload(self):
"Uploads files in deploy folder"
"""Uploads files in deploy folder"""
self.up.upload()

def get_plugin_names(self):
return self.up.get_plugin_names()

def import_keypack(self):
"Creates signing keys"
"""Creates signing keys"""
self.key_importer.start()

def sign_update(self):
"Signs version file with signing key"
"""Signs version file with signing key"""
self.kh.sign_update()
2 changes: 1 addition & 1 deletion pyupdater/package_handler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def init_app(self, obj):
self.setup()

def setup(self):
"Creates working directories & loads json files."
"""Creates working directories & loads json files."""
if self.data_dir is not None:
self._setup()

Expand Down
4 changes: 2 additions & 2 deletions pyupdater/package_handler/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def parse_platform(name):


def remove_previous_versions(directory, filename):
"Removes previous version of named file"
"""Removes previous version of named file"""
if filename is None:
log.debug('Cleanup Failed - Filename is None')
return
Expand Down Expand Up @@ -125,7 +125,7 @@ def remove_previous_versions(directory, filename):

# ToDo: Remove in version 3.0
def cleanup_old_archives(filename=None, directory=None):
"Removes previous version of named file"
"""Removes previous version of named file"""
remove_previous_versions(directory, filename)
# End Todo

Expand Down
2 changes: 1 addition & 1 deletion pyupdater/pyinstaller_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def run_makespec(args, opts=None):
_pyi_log.init()
# We are hacking into pyinstaller here & are aware of the risks
# using noqa below so landscape.io will ignore it
_pyi_log.__process_options(parser, args) # noqa
_pyi_log.__process_options(parser, args) # noqa
# End hacking

run_makespec(args)
Expand Down
50 changes: 19 additions & 31 deletions pyupdater/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
from __future__ import unicode_literals
import io
import logging
try:
import simplejson as json
except ImportError:
import json
import json
import os
import shutil
import subprocess
Expand All @@ -38,9 +35,9 @@
import time
import zipfile
try:
from UserDict import DictMixin as dictmixin
from UserDict import DictMixin
except ImportError:
from collections import MutableMapping as dictmixin
from collections import MutableMapping as DictMixin

from dsdev_utils import paths
from dsdev_utils import system
Expand Down Expand Up @@ -163,7 +160,7 @@ def get_plugin_names(self):
# Init is false by default. Used when you want
# to get a plugin without initialization
def get_plugin(self, name, init=False):
"Returns the named plugin"
"""Returns the named plugin"""
plugin = self._get_plugin(name)
if plugin is not None and init is True:
config = self._get_plugin_config(plugin)
Expand Down Expand Up @@ -204,7 +201,7 @@ def print_plugin_settings(plugin_name, config):


def check_repo():
"Checks if current directory is a pyupdater repository"
"""Checks if current directory is a pyupdater repository"""
repo = True
if not os.path.exists(settings.CONFIG_DATA_FOLDER):
log.debug('PyUpdater config data folder is missing')
Expand All @@ -223,10 +220,8 @@ def setup_appname(config): # pragma: no cover
default = config.APP_NAME
else:
default = None
config.APP_NAME = terminal.get_correct_answer('Please enter '
'app name',
required=True,
default=default)
config.APP_NAME = terminal.get_correct_answer('Please enter app name',
required=True, default=default)


def setup_client_config_path(config): # pragma: no cover
Expand All @@ -237,8 +232,7 @@ def setup_client_config_path(config): # pragma: no cover
"initialize the update process. \nExamples:\n\n"
"lib/utils, src/lib, src. \n\nLeave blank to use "
"the current directory")
answer = terminal.get_correct_answer(question,
default=_default_dir)
answer = terminal.get_correct_answer(question, default=_default_dir)

if answer == _default_dir:
config.CLIENT_CONFIG_PATH = settings.DEFAULT_CLIENT_CONFIG
Expand All @@ -254,20 +248,16 @@ def setup_company(config): # pragma: no cover
default = config.COMPANY_NAME
else:
default = None
temp = terminal.get_correct_answer('Please enter your comp'
'any or name',
required=True,
default=default)
temp = terminal.get_correct_answer('Please enter your name or company name',
required=True, default=default)
config.COMPANY_NAME = temp


def setup_max_download_retries(config): # pragma: no cover
default = config.MAX_DOWNLOAD_RETRIES
while 1:
temp = terminal.get_correct_answer('Enter max download '
'retries',
required=True,
default=default)
temp = terminal.get_correct_answer('Enter max download retries',
required=True, default=str(default))
try:
temp = int(temp)
except Exception as err:
Expand All @@ -286,8 +276,7 @@ def setup_max_download_retries(config): # pragma: no cover

def setup_patches(config): # pragma: no cover
question = 'Would you like to enable patch updates?'
config.UPDATE_PATCHES = terminal.ask_yes_no(question,
default='yes')
config.UPDATE_PATCHES = terminal.ask_yes_no(question, default='yes')


def setup_plugin(name, config):
Expand All @@ -300,16 +289,15 @@ def setup_plugin(name, config):


def setup_urls(config): # pragma: no cover
url = terminal.get_correct_answer('Enter a url to ping for '
'updates.', required=True)
url = terminal.get_correct_answer('Enter a url to ping for updates.',
required=True)
config.UPDATE_URLS = [url]
while 1:
answer = terminal.ask_yes_no('Would you like to add '
'another url for backup?',
default='no')
'another url for backup?',
default='no')
if answer is True:
url = terminal.get_correct_answer('Enter another url.',
required=True)
url = terminal.get_correct_answer('Enter another url.', required=True)
config.UPDATE_URLS.append(url)
else:
break
Expand Down Expand Up @@ -448,7 +436,7 @@ def run(cmd):
return exit_code


class JSONStore(dictmixin):
class JSONStore(DictMixin):

def __init__(self, path, json_kw=None):
"""Create a JSONStore object backed by the file at `path`.
Expand Down
12 changes: 6 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
except ImportError:
from SimpleHTTPServer import SimpleHTTPRequestHandler as RequestHandler
try:
import socketserver as socket_server
import socketserver as SocketServer
except ImportError:
import SocketServer as socket_server
import SocketServer

import pytest

Expand Down Expand Up @@ -75,15 +75,15 @@ def db():

@pytest.fixture
def loader():
CONFIG = {
default_config = {
'APP_NAME': 'PyUpdater Test',
'COMPANY_NAME': 'ACME',
'UPDATE_PATCHES': True,
}

cm = ConfigManager()
config = cm.load_config()
config.update(CONFIG)
config.update(default_config)
cm.save_config(config)
return config

Expand Down Expand Up @@ -115,8 +115,8 @@ def start(self, port=None):
self.count += 1
if self._server is not None:
return
socket_server.TCPServer.allow_reuse_address = True
httpd = socket_server.TCPServer(("", port), RequestHandler)
SocketServer.TCPServer.allow_reuse_address = True
httpd = SocketServer.TCPServer(("", port), RequestHandler)

self._server = threading.Thread(target=httpd.serve_forever)
self._server.daemon = True
Expand Down
2 changes: 1 addition & 1 deletion tests/data/update_repo_extract/app_extract_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def cb(status):

def main():
print(VERSION)
data_dir= None
data_dir = None
config = client_config.ClientConfig()
if getattr(config, 'USE_CUSTOM_DIR', False):
data_dir = os.path.join(os.path.dirname(sys.executable), '.update')
Expand Down
2 changes: 1 addition & 1 deletion tests/data/update_repo_restart/app_restart_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def cb(status):

def main():
print(VERSION)
data_dir= None
data_dir = None
config = client_config.ClientConfig()
if getattr(config, 'USE_CUSTOM_DIR', False):
data_dir = os.path.join(os.path.dirname(sys.executable), '.update')
Expand Down
2 changes: 2 additions & 0 deletions tests/test_patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def cb2(status):
}


# noinspection PyStatementEffect,PyStatementEffect
@pytest.mark.usefixtures("cleandir")
class TestFails(object):

Expand Down Expand Up @@ -94,6 +95,7 @@ def test_missing_version(self, datadir, json_data):
assert p.start() is False


# noinspection PyStatementEffect,PyStatementEffect
@pytest.mark.usefixtures("cleandir")
class TestExecution(object):

Expand Down
5 changes: 2 additions & 3 deletions tests/test_pyupdater.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,11 @@ def test_directory_creation(self):
@pytest.mark.usefixtures('cleandir')
class TestExecutionExtraction(object):

@pytest.mark.parametrize("custom_dir, port",
[])
@pytest.mark.parametrize("custom_dir, port", [])
# [(True, 8000),])
# [(True, 8000), (False, 8001)])
def test_execution_onefile_extract(self, datadir, simpleserver, pyu,
custom_dir, port):
custom_dir, port):
data_dir = datadir['update_repo_extract']
pyu.setup()

Expand Down

0 comments on commit 632af84

Please sign in to comment.