Beispiel #1
0
def test_write_config(cleandir):
    config = Config()
    prod_config = ProdConfig()
    config.from_object(prod_config)
    cm = ConfigManager()
    cm._write_config_py(config)
    assert 'client_config.py' in os.listdir(os.getcwd())
Beispiel #2
0
def test_write_config(cleandir):
    config = Config()
    prod_config = ProdConfig()
    config.from_object(prod_config)
    cm = ConfigManager()
    cm.write_config_py(config)
    assert 'client_config.py' in os.listdir(os.getcwd())
Beispiel #3
0
 def __init__(self, args, pyi_args):
     check_repo()
     # We only need to grab appname
     cm = ConfigManager()
     self.app_name = cm.get_app_name()
     self.args = args
     self.app_info, self.pyi_args = self._check_input_file(pyi_args)
Beispiel #4
0
def loader():
    default_config = {
        "APP_NAME": "PyUpdater Test",
        "COMPANY_NAME": "ACME",
        "UPDATE_PATCHES": True,
    }

    cm = ConfigManager()
    config = cm.load_config()
    config.update(default_config)
    cm.save_config(config)
    return config
Beispiel #5
0
def _cmd_keys(*args):  # pragma: no cover
    check = check_repo_ex()

    ns = args[0]
    # We try to prevent developers from creating root keys on the dev
    # machines.
    if ns.create is True and ns.import_keys is True:
        log.error('Only one options is allowed at a time')
        return

    # Okay the actual check is pretty weak but we are all grown ups here :)
    if ns.create is True and check is True:
        log.error('You can not create off-line keys on your dev machine')
        return

    # Can't import if we don't have a config to place it in.
    if ns.import_keys is True and check is False:
        return

    # We are supposed to be on another secure computer.
    # Security is in the eye of the beholder.
    # That was deep.
    if ns.create is True and check is False:
        if hasattr(ns, 'test'):
            log.debug('We are testing!')
            app_name = 'test'
            # Starting up with some testing in mind.
            k = Keys(test=True)
        else:
            k = Keys()
            # Get the app name for the soon to be generated keypack.pyu
            app_name = get_correct_answer('Please enter app name',
                                          required=True)

        # Create the keypack for this particular application.
        # make_keypack will return True if successful.
        if k.make_keypack(app_name):
            log.info('Keypack placed in cwd')
        else:
            log.error('Failed to create keypack')
            return

    # Save the keypack.pyu that's in the current directory to the
    # .pyupdater/config.pyu file.
    if ns.import_keys is True and check is True:
        cm = ConfigManager()
        config = cm.load_config()
        ki = KeyImporter()
        if ki.start():
            log.info('Keypack import successfully')
            cm.save_config(config)
        else:
            log.warning('Keypack import failed')
Beispiel #6
0
def _cmd_keys(*args):  # pragma: no cover
    check = check_repo_ex()

    ns = args[0]
    # We try to prevent developers from creating root keys on the dev
    # machines.
    if ns.create_keys is True and ns.import_keys is True:
        log.error('Only one options is allowed at a time')
        return

    # Okay the actual check is pretty weak but we are all grown ups here :)
    if ns.create_keys is True and check is True:
        log.error('You can not create off-line keys on your dev machine')
        return

    # Can't import if we don't have a config to place it in.
    if ns.import_keys is True and check is False:
        return

    # We are supposed to be on another secure computer.
    # Security is in the eye of the beholder.
    # That was deep.
    if ns.create_keys is True and check is False:
        if hasattr(ns, 'test'):
            log.debug('We are testing!')
            app_name = 'test'
            # Starting up with some testing in mind.
            k = Keys(test=True)
        else:
            k = Keys()
            # Get the app name for the soon to be generated keypack.pyu
            app_name = get_correct_answer('Please enter app name',
                                          required=True)

        # Create the keypack for this particular application.
        # make_keypack will return True if successful.
        if k.make_keypack(app_name):
            log.info('Keypack placed in cwd')
        else:
            log.error('Failed to create keypack')
            return

    # Save the keypack.pyu that's in the current directory to the
    # .pyupdater/config.pyu file.
    if ns.import_keys is True and check is True:
        cm = ConfigManager()
        config = cm.load_config()
        ki = KeyImporter()
        if ki.start():
            log.info('Keypack import successfully')
            cm.save_config(config)
        else:
            log.error('Keypack import failed')
Beispiel #7
0
def loader():
    CONFIG = {
        'APP_NAME': 'PyUpdater Test',
        'COMPANY_NAME': 'ACME',
        'UPDATE_PATCHES': True,
    }

    cm = ConfigManager()
    config = cm.load_config()
    config.update(CONFIG)
    cm.save_config(config)
    return config
Beispiel #8
0
def loader():
    default_config = {
        'APP_NAME': 'PyUpdater Test',
        'COMPANY_NAME': 'ACME',
        'UPDATE_PATCHES': True,
    }

    cm = ConfigManager()
    config = cm.load_config()
    config.update(default_config)
    cm.save_config(config)
    return config
Beispiel #9
0
def _cmd_settings(*args):  # pragma: no cover
    check_repo_ex(exit_on_error=True)

    ns = args[0]
    # Used to specify if config needs to be saved
    save_config = True
    cm = ConfigManager()
    config = cm.load_config()

    # Set the path of the client_config.py relative to the root of
    # the repository
    if ns.config_path is True:
        setup_client_config_path(config)

    # Change the company name. This will effect the file path on the end users
    # computer to place update files & meta data
    if ns.company is True:
        setup_company(config)

    # The amount of times the client retries downloads
    if ns.max_download_retries is True:
        setup_max_download_retries(config)

    # The http timeout for FileDownloader
    if ns.http_timeout is True:
        setup_http_timeout(config)

    # Base urls to online updates & meta data
    if ns.urls is True:
        setup_urls(config)

    # Enable/Disable binary patches
    if ns.patches is True:
        setup_patches(config)

    # Setup config for requested upload plugin
    if ns.plugin is not None:
        setup_plugin(ns.plugin, config)

    # Show list of installed upload plugins
    if ns.show_plugin is not None:
        save_config = False
        print_plugin_settings(ns.show_plugin, config)

    # If any changes have been made, save data to disk.
    if save_config is True:
        cm.save_config(config)
        log.info("Saved config")
Beispiel #10
0
def _cmd_upload(*args):  # pragma: no cover
    check_repo_ex(exit_on_error=True)

    ns = args[0]

    # The upload plugin requested
    upload_service = ns.service

    # We need something to work with
    if upload_service is None:
        log.error("Must provide service name")
        return

    cm = ConfigManager()
    pyu = PyUpdater(cm.load_config())
    try:
        # Configure PyUpdater to use the requested upload plugin
        pyu.set_uploader(upload_service, ns.keep)
    # Something happened during uploading
    except UploaderError as err:
        log.error(err)
        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")
        return

    # Try to upload the files in the deploy directory. Get it...
    # In all seriousness, I really want this to go smoothly.
    log.info("Starting upload")
    try:
        complete = pyu.upload()
    except Exception as err:
        complete = False
        log.debug(err, exc_info=True)
        log.error(err)

    if complete:
        print("")
        log.info("Upload successful")
    else:
        log.error("Upload failed!")
Beispiel #11
0
def _cmd_upload(*args):  # pragma: no cover
    check_repo_ex(exit_on_error=True)

    ns = args[0]

    # The upload plugin requested
    upload_service = ns.service

    # We need something to work with
    if upload_service is None:
        log.error('Must provide service name')
        return

    cm = ConfigManager()
    pyu = PyUpdater(cm.load_config())
    try:
        # Configure PyUpdater to use the requested upload plugin
        pyu.set_uploader(upload_service, ns.keep)
    # Something happened during uploading
    except UploaderError as err:
        log.error(err)
        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')
        return

    # Try to upload the files in the deploy directory. Get it...
    # In all seriousness, I really want this to go smoothly.
    log.info("Starting upload")
    try:
        complete = pyu.upload()
    except Exception as err:
        complete = False
        log.debug(err, exc_info=True)
        log.error(err)

    if complete:
        log.info("Upload successful")
    else:
        log.error("Upload failed!")
Beispiel #12
0
def _cmd_settings(*args):  # pragma: no cover
    check_repo_ex(exit_on_error=True)

    ns = args[0]
    # Used to specify if config needs to be saved
    save_config = True
    cm = ConfigManager()
    config = cm.load_config()

    # Set the path of the client_config.py relative to the root of
    # the repository
    if ns.config_path is True:
        setup_client_config_path(config)

    # Change the company name. This will effect the file path on the end users
    # computer to place update files & meta data
    if ns.company is True:
        setup_company(config)

    # The amount of times the client retries downloads
    if ns.max_download_retries is True:
        setup_max_download_retries(config)

    # Base urls to online updates & meta data
    if ns.urls is True:
        setup_urls(config)

    # Enable/Disable binary patches
    if ns.patches is True:
        setup_patches(config)

    # Setup config for requested upload plugin
    if ns.plugin is not None:
        setup_plugin(ns.plugin, config)

    # Show list of installed upload plugins
    if ns.show_plugin is not None:
        save_config = False
        print_plugin_settings(ns.show_plugin, config)

    # If any changes have been made, save data to disk.
    if save_config is True:
        cm.save_config(config)
        log.info('Saved config')
Beispiel #13
0
def _cmd_init(*args):  # pragma: no cover
    if not os.path.exists(os.path.join(settings.CONFIG_DATA_FOLDER,
                                       settings.CONFIG_FILE_USER)):
        # Load a basic config.
        config = Config()

        # Run config through all of the setup functions
        config = initial_setup(config)
        log.info('Creating pyu-data dir...')

        # Initialize PyUpdater with newly created config
        pyu = PyUpdater(config)

        # Setup repository
        pyu.setup()

        # Load config manager & save config to disk
        cm = ConfigManager()
        cm.save_config(config)
        log.info('Setup complete')
    else:
        log.error('Not an empty PyUpdater repository')
Beispiel #14
0
def _cmd_pkg(*args):
    check_repo_ex(exit_on_error=True)

    ns = args[0]
    cm = ConfigManager()
    pyu = PyUpdater(cm.load_config())

    # Please give pkg something to do
    if ns.process is False and ns.sign is False:
        log.error('You must specify a command')
        return

    # Gather meta data and save to disk
    if ns.process is True:
        log.info('Processing packages...')
        pyu.process_packages(ns.verbose)
        log.info('Processing packages complete')

    # Sign the update meta-data with the repo private key.
    if ns.sign is True:
        log.info('Signing packages...')
        pyu.sign_update()
        log.info('Signing packages complete')
Beispiel #15
0
def _cmd_pkg(*args):
    check_repo_ex(exit_on_error=True)

    ns = args[0]
    cm = ConfigManager()
    pyu = PyUpdater(cm.load_config())

    # Please give pkg something to do
    if ns.process is False and ns.sign is False:
        log.error('You must specify a command')
        return

    # Gather meta data and save to disk
    if ns.process is True:
        log.info('Processing packages...')
        pyu.process_packages(ns.verbose)
        log.info('Processing packages complete')

    # Sign the update meta-data with the repo private key.
    if ns.sign is True:
        log.info('Signing packages...')
        pyu.sign_update()
        log.info('Signing packages complete')
Beispiel #16
0
def _cmd_init(*args):  # pragma: no cover
    if not os.path.exists(
            os.path.join(settings.CONFIG_DATA_FOLDER,
                         settings.CONFIG_FILE_USER)):
        # Load a basic config.
        config = Config()

        # Run config through all of the setup functions
        config = initial_setup(config)
        log.info('Creating pyu-data dir...')

        # Initialize PyUpdater with newly created config
        pyu = PyUpdater(config)

        # Setup repository
        pyu.setup()

        # Load config manager & save config to disk
        cm = ConfigManager()
        cm.save_config(config)
        log.info('Setup complete')
    else:
        log.error('Not an empty PyUpdater repository')
Beispiel #17
0
 def test_build(self):
     cm = ConfigManager()
     config = cm.load_config()
     config.update(CONFIG)
     cm.save_config(config)
Beispiel #18
0
 def test_build(self):
     cm = ConfigManager()
     config = cm.load_config()
     config.update(CONFIG)
     cm.save_config(config)