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

Commit

Permalink
Refactor from private to public
Browse files Browse the repository at this point in the history
- Remove unused variable desecration
- Remove unused import
- Fix doc string
- instance to static method
  • Loading branch information
JMSwag committed May 20, 2017
1 parent 632af84 commit 4f3aea3
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 58 deletions.
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
9 changes: 5 additions & 4 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 @@ -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
12 changes: 6 additions & 6 deletions pyupdater/client/updates.py
Expand Up @@ -47,7 +47,7 @@
log = logging.getLogger(__name__)


def _get_highest_version(name, plat, channel, easy_data, strict):
def get_highest_version(name, plat, channel, easy_data, strict):
"""Parses version file and returns the highest version number.
Args:
Expand Down Expand Up @@ -120,7 +120,7 @@ def _get_highest_version(name, plat, channel, easy_data, strict):
return version


def _gen_user_friendly_version(internal_version):
def gen_user_friendly_version(internal_version):
channel = {0: 'Alpha', 1: 'Beta'}
v = list(map(int, internal_version.split('.')))

Expand Down Expand Up @@ -294,9 +294,9 @@ def _init_app(self, data):
self.max_download_retries = data.get('max_download_retries')

# The latest version available
self.latest = _get_highest_version(self.name, self.platform,
self.channel, self.easy_data,
self.strict)
self.latest = get_highest_version(self.name, self.platform,
self.channel, self.easy_data,
self.strict)

# The name of the current versions update archive.
# Will be used to check if the current archive is available for a
Expand All @@ -321,7 +321,7 @@ def version(self):
######Returns (str): User friendly version string
"""
if self._version == "":
self._version = _gen_user_friendly_version(self.latest)
self._version = gen_user_friendly_version(self.latest)
return self._version

def is_downloaded(self):
Expand Down
5 changes: 3 additions & 2 deletions pyupdater/key_handler/keys.py
Expand Up @@ -165,7 +165,8 @@ def _look_for_keypack():
return False
return True

def _load_keypack(self):
@staticmethod
def _load_keypack():
json_data = None
try:
with io.open(settings.KEYPACK_FILENAME, 'r',
Expand All @@ -184,7 +185,7 @@ def start(self):
found = KeyImporter._look_for_keypack()
if found is False:
return False
keypack = self._load_keypack()
keypack = KeyImporter._load_keypack()
if keypack is None:
return False
self.db.save(settings.CONFIG_DB_KEY_KEYPACK, keypack)
Expand Down
2 changes: 1 addition & 1 deletion pyupdater/package_handler/__init__.py
Expand Up @@ -457,7 +457,7 @@ def _check_make_patch(self, json_data, name, platform):
if bsdiff4 is None:
log.warning('Bsdiff is missing. Cannot create patches')
return None
src_file_path = None

if os.path.exists(self.files_dir):
with ChDir(self.files_dir):
files = os.listdir(os.getcwd())
Expand Down
3 changes: 2 additions & 1 deletion pyupdater/uploader.py
Expand Up @@ -47,7 +47,7 @@ class Uploader(object):
Args:
obj (instance): config object
config (instance): config object
"""
def __init__(self, config=None):
# Specifies whether to keep a file after uploading
Expand Down Expand Up @@ -173,6 +173,7 @@ def _retry_upload(self, failed_uploads):
return failed_uploads


# noinspection PyProtectedMember
class AbstractBaseUploaderMeta(type):

def __call__(cls, *args, **kwargs):
Expand Down
1 change: 0 additions & 1 deletion pyupdater/utils/__init__.py
Expand Up @@ -32,7 +32,6 @@
import subprocess
import sys
import tarfile
import time
import zipfile
try:
from UserDict import DictMixin
Expand Down
4 changes: 2 additions & 2 deletions pyupdater/utils/config.py
Expand Up @@ -107,11 +107,11 @@ def save_config(self, obj):
log.info('Saving Config')
self.db.save(self.config_key, obj)
log.info('Config saved')
self._write_config_py(obj)
self.write_config_py(obj)
log.info('Wrote client config')

# Writes client config to client_config.py
def _write_config_py(self, obj):
def write_config_py(self, obj):
keypack_data = self.db.load(settings.CONFIG_DB_KEY_KEYPACK)
if keypack_data is None:
log.debug('*** Keypack data is None ***')
Expand Down
1 change: 1 addition & 0 deletions tests/data/update_repo_restart/app_restart_01.py
@@ -1,4 +1,5 @@
from __future__ import print_function
import os
import sys

from pyupdater.client import Client
Expand Down
42 changes: 21 additions & 21 deletions tests/test_cli.py
Expand Up @@ -29,7 +29,7 @@

import pytest

from pyupdater.cli import commands, _dispatch_command
from pyupdater.cli import commands, dispatch_command
from pyupdater.cli.options import (add_build_parser, add_clean_parser,
add_keys_parser, add_make_spec_parser,
add_package_parser, add_upload_parser,
Expand Down Expand Up @@ -66,44 +66,44 @@ def __getattribute__(self, name):
class TestCommandDispatch(object):

def test_build(self):
assert _dispatch_command(NamespaceHelper(command='build'),
test=True) is True
assert dispatch_command(NamespaceHelper(command='build'),
test=True) is True

def test_clean(self):
assert _dispatch_command(NamespaceHelper(command='clean'),
test=True) is True
assert dispatch_command(NamespaceHelper(command='clean'),
test=True) is True

def test_settings(self):
assert _dispatch_command(NamespaceHelper(command='settings'),
test=True) is True
assert dispatch_command(NamespaceHelper(command='settings'),
test=True) is True

def test_init(self):
assert _dispatch_command(NamespaceHelper(command='init'),
test=True) is True
assert dispatch_command(NamespaceHelper(command='init'),
test=True) is True

def test_keys(self):
assert _dispatch_command(NamespaceHelper(command='keys'),
test=True) is True
assert dispatch_command(NamespaceHelper(command='keys'),
test=True) is True

def test_make_spec(self):
assert _dispatch_command(NamespaceHelper(command='make-spec'),
test=True) is True
assert dispatch_command(NamespaceHelper(command='make-spec'),
test=True) is True

def test_pkg(self):
assert _dispatch_command(NamespaceHelper(command='pkg'),
test=True) is True
assert dispatch_command(NamespaceHelper(command='pkg'),
test=True) is True

def test_collect_debug_info(self):
assert _dispatch_command(NamespaceHelper(command='collect-debug-info'),
test=True) is True
assert dispatch_command(NamespaceHelper(command='collect-debug-info'),
test=True) is True

def test_upload(self):
assert _dispatch_command(NamespaceHelper(command='upload'),
test=True) is True
assert dispatch_command(NamespaceHelper(command='upload'),
test=True) is True

def test_version(self):
assert _dispatch_command(NamespaceHelper(command='version'),
test=True) is True
assert dispatch_command(NamespaceHelper(command='version'),
test=True) is True


@pytest.mark.usefixtures('cleandir')
Expand Down
32 changes: 16 additions & 16 deletions tests/test_client.py
Expand Up @@ -36,8 +36,8 @@
import six

from pyupdater.client import Client
from pyupdater.client.updates import (_gen_user_friendly_version,
_get_highest_version)
from pyupdater.client.updates import (gen_user_friendly_version,
get_highest_version)
from tconfig import TConfig


Expand Down Expand Up @@ -220,10 +220,10 @@ def test_extract_no_file(self, client):
class TestGenVersion(object):

def test1(self):
assert _gen_user_friendly_version('1.0.0.2.0') == '1.0'
assert _gen_user_friendly_version('1.2.2.2.0') == '1.2.2'
assert _gen_user_friendly_version('2.0.5.0.3') == '2.0.5 Alpha 3'
assert _gen_user_friendly_version('2.2.1.1.0') == '2.2.1 Beta'
assert gen_user_friendly_version('1.0.0.2.0') == '1.0'
assert gen_user_friendly_version('1.2.2.2.0') == '1.2.2'
assert gen_user_friendly_version('2.0.5.0.3') == '2.0.5 Alpha 3'
assert gen_user_friendly_version('2.2.1.1.0') == '2.2.1 Beta'


class TestChannelStrict(object):
Expand All @@ -246,12 +246,12 @@ class TestChannelStrict(object):

def test1(self):
data = EasyAccessDict(self.version_data)
assert _get_highest_version('Acme', 'mac', 'alpha',
data, strict=True) == '4.4.2.0.5'
assert _get_highest_version('Acme', 'mac', 'beta',
data, strict=True) == '4.4.1.1.0'
assert _get_highest_version('Acme', 'mac', 'stable',
data, strict=True) == '4.4.3.2.0'
assert get_highest_version('Acme', 'mac', 'alpha',
data, strict=True) == '4.4.2.0.5'
assert get_highest_version('Acme', 'mac', 'beta',
data, strict=True) == '4.4.1.1.0'
assert get_highest_version('Acme', 'mac', 'stable',
data, strict=True) == '4.4.3.2.0'


class TestChannelLessStrict(object):
Expand All @@ -274,8 +274,8 @@ class TestChannelLessStrict(object):

def test1(self):
data = EasyAccessDict(self.version_data)
assert _get_highest_version('Acme', 'mac', 'alpha',
data, strict=False) == '4.4.3.2.0'
assert get_highest_version('Acme', 'mac', 'alpha',
data, strict=False) == '4.4.3.2.0'


class TestMissingStable(object):
Expand All @@ -295,5 +295,5 @@ class TestMissingStable(object):

def test1(self):
data = EasyAccessDict(self.version_data)
assert _get_highest_version('Acme', 'mac', 'stable',
data, strict=True) is None
assert get_highest_version('Acme', 'mac', 'stable',
data, strict=True) is None
2 changes: 1 addition & 1 deletion tests/test_config.py
Expand Up @@ -82,5 +82,5 @@ def test_write_config(cleandir):
prod_config = ProdConfig()
config.from_object(prod_config)
cm = ConfigManager()
cm._write_config_py(config)
cm.write_config_py(config)
assert 'client_config.py' in os.listdir(os.getcwd())

0 comments on commit 4f3aea3

Please sign in to comment.