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

Commit

Permalink
Merge branch 'fix-issue-68'
Browse files Browse the repository at this point in the history
  • Loading branch information
JMSwag committed Jun 4, 2017
2 parents 072d3cb + 2fb65d0 commit bcc5a6d
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 148 deletions.
4 changes: 1 addition & 3 deletions pyupdater/builder.py
Expand Up @@ -32,8 +32,7 @@
from pyupdater import settings
from pyupdater.hooks import get_hook_dir
from pyupdater.pyinstaller_compat import pyi_makespec
from pyupdater.utils import (check_repo,
create_asset_archive,
from pyupdater.utils import (create_asset_archive,
make_archive)
from pyupdater.utils.config import ConfigManager

Expand All @@ -60,7 +59,6 @@ class Builder(object): # pragma: no cover
"""

def __init__(self, args, pyi_args):
check_repo()
# We only need to grab appname
cm = ConfigManager()
self.app_name = cm.get_app_name()
Expand Down
61 changes: 42 additions & 19 deletions pyupdater/cli/commands.py
@@ -1,3 +1,27 @@
# --------------------------------------------------------------------------
# Copyright (c) 2015-2017 Digital Sapphire
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the
# following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
# ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
# TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
# OR OTHER DEALINGS IN THE SOFTWARE.
# --------------------------------------------------------------------------
import io
import json
import logging
Expand All @@ -8,18 +32,17 @@

from pyupdater import __version__, PyUpdater, settings
from pyupdater.builder import Builder, ExternalLib
from pyupdater.cli.helpers import (initial_setup,
print_plugin_settings,
setup_client_config_path,
setup_company,
setup_max_download_retries,
setup_patches,
setup_plugin,
setup_urls)
from pyupdater.client.downloader import get_http_pool
from pyupdater.key_handler.keys import Keys, KeyImporter
from pyupdater.utils import (check_repo as _check_repo,
initial_setup,
PluginManager,
print_plugin_settings,
setup_client_config_path,
setup_company,
setup_max_download_retries,
setup_patches,
setup_plugin,
setup_urls)
from pyupdater.utils import check_repo, PluginManager
from pyupdater.utils.config import Config, ConfigManager
from pyupdater.utils.exceptions import UploaderError, UploaderPluginError

Expand All @@ -32,8 +55,8 @@

# A wrapper for _check_repo that will log errors and
# exit the program if needed
def check_repo(exit_on_error=False):
check = _check_repo()
def check_repo_ex(exit_on_error=False):
check = check_repo()
if check is False:
log.error('Not a PyUpdater repo: You must initialize '
'your repository first')
Expand All @@ -44,7 +67,7 @@ def check_repo(exit_on_error=False):

# Archive an external asset
def _cmd_archive(*args):
check_repo(exit_on_error=True)
check_repo_ex(exit_on_error=True)

ns = args[0]
new_dir = os.path.join(CWD, settings.USER_DATA_FOLDER, 'new')
Expand All @@ -66,7 +89,7 @@ def _cmd_archive(*args):

# Will build and archive an exe from a python script file
def _cmd_build(*args):
check_repo(exit_on_error=True)
check_repo_ex(exit_on_error=True)

ns = args[0]
pyi_args = args[1]
Expand Down Expand Up @@ -114,7 +137,7 @@ def _clean(*args):
# cause issues with updates if not used carefully. If really need
# this value can be changed in the .pyupdater/config.pyu file.
def _cmd_settings(*args): # pragma: no cover
check_repo(exit_on_error=True)
check_repo_ex(exit_on_error=True)

ns = args[0]
# Used to specifiy if config needs to be saved
Expand Down Expand Up @@ -186,7 +209,7 @@ def _cmd_init(*args): # pragma: no cover

# We create and import keys with this puppy.
def _cmd_keys(*args): # pragma: no cover
check = check_repo()
check = check_repo_ex()

ns = args[0]
# We try to prevent developers from creating root keys on the dev
Expand Down Expand Up @@ -244,7 +267,7 @@ def _cmd_keys(*args): # pragma: no cover
# This will be used when the application being build goes a little
# beyond the basics. This is good!
def _cmd_make_spec(*args):
check_repo(exit_on_error=True)
check_repo_ex(exit_on_error=True)

ns = args[0]
pyi_args = args[1]
Expand All @@ -255,7 +278,7 @@ def _cmd_make_spec(*args):
# The pkg command will move, gather meta-data & sign all
# packages within the pyu-data folder
def _cmd_pkg(*args):
check_repo(exit_on_error=True)
check_repo_ex(exit_on_error=True)

ns = args[0]
cm = ConfigManager()
Expand Down Expand Up @@ -375,7 +398,7 @@ def _cmd_plugins(*args):

# Upload the assets with the requested upload plugin
def _cmd_upload(*args): # pragma: no cover
check_repo(exit_on_error=True)
check_repo_ex(exit_on_error=True)

ns = args[0]

Expand Down
142 changes: 142 additions & 0 deletions pyupdater/cli/helpers.py
@@ -0,0 +1,142 @@
# --------------------------------------------------------------------------
# Copyright (c) 2015-2017 Digital Sapphire
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the
# following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
# ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
# TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
# OR OTHER DEALINGS IN THE SOFTWARE.
# --------------------------------------------------------------------------
import logging
import os
import sys

from dsdev_utils import terminal


from pyupdater import settings
from pyupdater.utils import PluginManager

log = logging.getLevelName(__name__)


def print_plugin_settings(plugin_name, config):
pm = PluginManager(config)
config = pm.get_plugin_settings(plugin_name)
if len(config.keys()) == 0:
print('No config found for {}'.format(plugin_name))
else:
print(plugin_name)
print(config)


def setup_appname(config): # pragma: no cover
if config.APP_NAME is not None:
default = config.APP_NAME
else:
default = None
config.APP_NAME = terminal.get_correct_answer('Please enter app name',
required=True, default=default)


def setup_client_config_path(config): # pragma: no cover
_default_dir = os.path.basename(os.path.abspath(os.getcwd()))
question = ("Please enter the path to where pyupdater "
"will write the client_config.py file. "
"You'll need to import this file to "
"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)

if answer == _default_dir:
config.CLIENT_CONFIG_PATH = settings.DEFAULT_CLIENT_CONFIG
else:
answer = answer.split(os.sep)
answer.append(settings.DEFAULT_CLIENT_CONFIG[0])

config.CLIENT_CONFIG_PATH = answer


def setup_company(config): # pragma: no cover
if config.COMPANY_NAME is not None:
default = config.COMPANY_NAME
else:
default = None
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=str(default))
try:
temp = int(temp)
except Exception as err:
log.error(err)
log.debug(err, exc_info=True)
continue

if temp > 10 or temp < 1:
log.error('Max retries can only be from 1 to 10')
continue

break

config.MAX_DOWNLOAD_RETRIES = temp


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')


def setup_plugin(name, config):
pgm = PluginManager(config)
plugin = pgm.get_plugin(name)
if plugin is None:
sys.exit('Invalid plugin name...')

pgm.config_plugin(name, config)


def setup_urls(config): # pragma: no cover
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')
if answer is True:
url = terminal.get_correct_answer('Enter another url.', required=True)
config.UPDATE_URLS.append(url)
else:
break


def initial_setup(config): # pragma: no cover
setup_appname(config)
setup_company(config)
setup_urls(config)
setup_patches(config)
setup_client_config_path(config)
return config

0 comments on commit bcc5a6d

Please sign in to comment.