Пример #1
3
    def test_build_fail_no_spec_or_src(self):
        with pytest.raises(SystemExit):
            t_config = TConfig()
            t_config.DATA_DIR = os.getcwd()
            pyu = PyUpdater(t_config)
            pyu.setup()
            build_cmd = ['build', '--app-name', 'MyApp', '--clean'
                         '--app-version', '0.1.0', '-F']

            parser = get_parser()
            args, pyu_args = parser.parse_known_args(build_cmd)
            b = Builder(args, pyu_args)
            b.build()
Пример #2
1
def pkg(args):
    check = check_repo()
    if check is False:
        _repo_error()

    loader = Loader()
    pyu = PyUpdater(loader.load_config())
    if args.process is False and args.sign is False:
        sys.exit('You must specify a command')

    if args.process is True:
        log.info('Processing packages...')
        pyu.process_packages(args.verbose)
        log.info('Processing packages complete')
    if args.sign is True:
        log.info('Signing packages...')
        pyu.sign_update()
        log.info('Signing packages complete')
Пример #3
0
    def test_make_spec(self):
        t_config = TConfig()
        t_config.DATA_DIR = os.getcwd()
        pyu = PyUpdater(t_config)
        pyu.setup()

        spec_cmd = [
            'make-spec', 'app.py', '-F', '--app-name', 'MyApp',
            '--app-version', '0.1.0'
        ]
        spec_file_name = get_system() + '.spec'
        build_cmd = [
            'build', '--app-name', 'MyApp', '--app-version', '0.1.0',
            spec_file_name
        ]

        build_cmd = [str(b) for b in build_cmd]
        parser = get_parser()
        with open('app.py', 'w') as f:
            f.write('print "Hello, World!"')
        args, pyu_args = parser.parse_known_args(spec_cmd)
        b = Builder(args, pyu_args)
        b.make_spec()
        assert os.path.exists(spec_file_name)
        args, pyu_args = parser.parse_known_args(build_cmd)
        b = Builder(args, pyu_args)
        b.build()
        with ChDir(new_folder):
            assert len(os.listdir(os.getcwd())) == 1
Пример #4
0
def upload(args):  # pragma: no cover
    check = check_repo()
    if check is False:
        _repo_error()

    error = False
    loader = Loader()
    upload_service = args.service
    if upload_service is None:
        log.error('Must provide service name')
        error = True

    if error is False:
        pyu = PyUpdater(loader.load_config())
        try:
            pyu.set_uploader(upload_service, args.keep)
        except UploaderError as err:
            log.error(err)
            error = True
        except UploaderPluginError as err:
            log.debug(err)
            error = True
            log.error('Invalid upload plugin')
            log.error('Use "pyupdater plugins" to get a '
                      'list of installed plugins')
    if error is False:
        try:
            pyu.upload()
        except Exception as e:
            msg = ('Looks like you forgot to add USERNAME '
                   'and/or REMOTE_DIR')
            log.debug(e, exc_info=True)
            log.error(msg)
Пример #5
0
    def test_make_spec(self):
        t_config = TConfig()
        t_config.DATA_DIR = os.getcwd()
        pyu = PyUpdater(t_config)
        pyu.setup()

        spec_cmd = ['make-spec', 'app.py', '-F', '--app-name', 'MyApp',
                    '--app-version', '0.1.0']
        spec_file_name = get_system() + '.spec'
        build_cmd = ['build', '--app-name', 'MyApp',
                     '--app-version', '0.1.0', spec_file_name]

        build_cmd = [str(b) for b in build_cmd]
        parser = get_parser()
        with open('app.py', 'w') as f:
            f.write('print "Hello, World!"')
        args, pyu_args = parser.parse_known_args(spec_cmd)
        b = Builder(args, pyu_args)
        b.make_spec()
        assert os.path.exists(spec_file_name)
        args, pyu_args = parser.parse_known_args(build_cmd)
        b = Builder(args, pyu_args)
        b.build()
        with ChDir(new_folder):
            assert len(os.listdir(os.getcwd())) == 1
 def test_directory_creation(self):
     data_dir = os.getcwd()
     pyu_data_dir = os.path.join(data_dir, 'pyu-data')
     t_config = TConfig()
     t_config.DATA_DIR = data_dir
     pyu = PyUpdater(t_config)
     pyu.setup()
     assert os.path.exists(pyu_data_dir)
     assert os.path.exists(os.path.join(pyu_data_dir, 'deploy'))
     assert os.path.exists(os.path.join(pyu_data_dir, 'files'))
     assert os.path.exists(os.path.join(pyu_data_dir, 'new'))
Пример #7
0
def init():  # pragma: no cover
    if not os.path.exists(os.path.join(settings.CONFIG_DATA_FOLDER,
                          settings.CONFIG_FILE_USER)):
        config = Config()
        config = initial_setup(config)
        log.info('Creating pyu-data dir...')
        pyu = PyUpdater(config)
        pyu.setup()
        loader = Loader()
        loader.save_config(config)
        log.info('Setup complete')
    else:
        sys.exit('Not an empty PyUpdater repository')
Пример #8
0
def init():  # pragma: no cover
    if not os.path.exists(os.path.join(settings.CONFIG_DATA_FOLDER,
                          settings.CONFIG_FILE_USER)):
        config = Config()
        config = initial_setup(config)
        log.info('Creating pyu-data dir...')
        pyu = PyUpdater(config)
        pyu.setup()
        loader = Loader()
        loader.save_config(config)
        log.info('Setup complete')
    else:
        sys.exit('Not an empty PyUpdater repository')
Пример #9
0
    def test_build_fail_no_spec_or_src(self):
        with pytest.raises(SystemExit):
            t_config = TConfig()
            t_config.DATA_DIR = os.getcwd()
            pyu = PyUpdater(t_config)
            pyu.setup()
            build_cmd = [
                'build', '--app-name', 'MyApp', '--clean'
                '--app-version', '0.1.0', '-F'
            ]

            parser = get_parser()
            args, pyu_args = parser.parse_known_args(build_cmd)
            b = Builder(args, pyu_args)
            b.build()
Пример #10
0
    def test_build_mac_dot_app(self):
        t_config = TConfig()
        t_config.DATA_DIR = os.getcwd()
        pyu = PyUpdater(t_config)
        pyu.setup()

        build_cmd = ['build', '-F', '-w', '--app-name', 'MyApp',
                     '--app-version', '0.1.0', 'app.py']
        build_cmd = [str(b) for b in build_cmd]
        parser = get_parser()
        with open('app.py', 'w') as f:
            f.write('print "Hello, World!"')
        args, pyu_args = parser.parse_known_args(build_cmd)
        b = Builder(args, pyu_args)
        b.build()
        with ChDir(new_folder):
            assert len(os.listdir(os.getcwd())) == 1
Пример #11
0
def pkg(args):
    check_repo()
    db = Storage()
    loader = Loader(db)
    pyu = PyUpdater(loader.load_config(), db)
    if args.process is False and args.sign is False:
        sys.exit('You must specify a command')

    if args.process is True:
        log.info('Processing packages...')
        pyu.process_packages()
        log.info('Processing packages complete')
    if args.sign is True:
        log.info('Signing packages...')
        pyu.sign_update()
        log.info('Signing packages complete')
    db._sync_db()
Пример #12
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!")
Пример #13
0
    def test_build(self):
        t_config = TConfig()
        t_config.DATA_DIR = os.getcwd()
        pyu = PyUpdater(t_config)
        pyu.setup()

        build_cmd = [
            'build', '--app-name', 'MyApp', '--app-version', '0.1.0', 'app.py'
        ]
        build_cmd = [str(b) for b in build_cmd]
        parser = get_parser()
        with open('app.py', 'w') as f:
            f.write('print "Hello, World!"')
        args, pyu_args = parser.parse_known_args(build_cmd)
        b = Builder(args, pyu_args)
        b.build()
        with ChDir(new_folder):
            assert len(os.listdir(os.getcwd())) == 1
Пример #14
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!")
Пример #15
0
def upload(args):  # pragma: no cover
    check = check_repo()
    if check is False:
        _repo_error()

    error = False
    loader = Loader()
    upload_service = args.service
    if upload_service is None:
        log.error('Must provide service name')
        error = True

    if error is False:
        pyu = PyUpdater(loader.load_config())
        try:
            pyu.set_uploader(upload_service)
        except UploaderError as err:
            log.error(err)
            error = True
        except UploaderPluginError as err:
            log.debug(err)
            error = True
            mgr = stevedore.ExtensionManager(settings.UPLOAD_PLUGIN_NAMESPACE)
            plugin_names = mgr.names()
            log.debug('Plugin names: {}'.format(plugin_names))
            if len(plugin_names) == 0:
                msg = ('*** No upload plugins instaled! ***\nYou can install '
                       'the aws s3 plugin with\n$ pip install PyUpdater'
                       '[s3]\n\nOr the scp plugin with\n$ pip install '
                       'PyUpdater[scp]')
            else:
                msg = ('Invalid Uploader\n\nAvailable options:\n'
                       '{}'.format(' '.join(plugin_names)))
            log.error(msg)
    if error is False:
        try:
            pyu.upload()
        except Exception as e:
            msg = ('Looks like you forgot to add USERNAME '
                   'and/or REMOTE_DIR')
            log.debug(e, exc_info=True)
            log.error(msg)
Пример #16
0
    def test_build_fail_script_syntax_error(self):
        with pytest.raises(SystemExit):
            t_config = TConfig()
            t_config.DATA_DIR = os.getcwd()
            pyu = PyUpdater(t_config)
            pyu.setup()
            spec_cmd = ['make-spec', 'app.py', '-F']
            spec_file_name = get_system() + '.spec'
            build_cmd = ['build', '--app-name', 'MyApp', '--clean'
                         '--app-version', '0.1.0', spec_file_name]

            parser = get_parser()
            with open('app.py', 'w') as f:
                # Missing closing quote
                f.write('print "Hello, World!')
            args, pyu_args = parser.parse_known_args(spec_cmd)
            b = Builder(args, pyu_args)
            b.make_spec()
            assert os.path.exists(spec_file_name)
            args, pyu_args = parser.parse_known_args(build_cmd)
            b = Builder(args, pyu_args)
Пример #17
0
def upload(args):  # pragma: no cover
    check = check_repo()
    if check is False:
        _repo_error()

    error = False
    loader = Loader()
    upload_service = args.service
    if upload_service is None:
        log.error('Must provide service name')
        error = True

    if error is False:
        pyu = PyUpdater(loader.load_config())
        try:
            pyu.set_uploader(upload_service, args.keep)
        except UploaderError as err:
            log.error(err)
            error = True
        except UploaderPluginError as err:
            log.debug(err)
            error = True
            log.error('Invalid upload plugin')
            log.error('Use "pyupdater plugins" to get a '
                      'list of installed plugins')
    if error is False:
        try:
            pyu.upload()
        except Exception as e:
            msg = ('Looks like you forgot to add USERNAME '
                   'and/or REMOTE_DIR')
            log.debug(e, exc_info=True)
            log.error(msg)
Пример #18
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')
Пример #19
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')
Пример #20
0
def _keys(args):  # pragma: no cover
    check_repo()
    db = Storage()
    loader = Loader(db)
    config = loader.load_config()
    pyu = PyUpdater(config, db)
    if args.count is not None:
        count = args.count
        pyu.revoke_key(count)
        config.PUBLIC_KEYS = pyu.get_public_keys()
        key = pyu.get_recent_revoked_key()
        if key is not None:
            log.info('* Most Recent Revoked Key *')
            log.info('Created: {}'.format(pretty_time(key['date'])))
            log.info('Type: {}'.format(key['key_type']))
            log.info('Public Key: {}'.format(key['public']))
            if args.private is True:
                log.info('Private Key: {}'.format(key['private']))
            else:
                log.info('Private Key: * Next time to show private key '
                         'use --show-private *')
        loader.save_config(config)
        db._sync_db()
Пример #21
0
    def test_build_fail_script_syntax_error(self):
        with pytest.raises(SystemExit):
            t_config = TConfig()
            t_config.DATA_DIR = os.getcwd()
            pyu = PyUpdater(t_config)
            pyu.setup()
            spec_cmd = ['make-spec', 'app.py', '-F']
            spec_file_name = get_system() + '.spec'
            build_cmd = [
                'build', '--app-name', 'MyApp', '--clean'
                '--app-version', '0.1.0', spec_file_name
            ]

            parser = get_parser()
            with open('app.py', 'w') as f:
                # Missing closing quote
                f.write('print "Hello, World!')
            args, pyu_args = parser.parse_known_args(spec_cmd)
            b = Builder(args, pyu_args)
            b.make_spec()
            assert os.path.exists(spec_file_name)
            args, pyu_args = parser.parse_known_args(build_cmd)
            b = Builder(args, pyu_args)
Пример #22
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')
Пример #23
0
def pkg(args):
    check_repo()
    db = Storage()
    loader = Loader(db)
    pyu = PyUpdater(loader.load_config(), db)
    if args.process is False and args.sign is False:
        sys.exit('You must specify a command')

    if args.process is True:
        log.info('Processing packages...')
        pyu.process_packages()
        log.info('Processing packages complete')
    if args.sign is True:
        log.info('Signing packages...')
        pyu.sign_update()
        log.info('Signing packages complete')
    db._sync_db()
Пример #24
0
def init(args):  # pragma: no cover
    db = Storage()
    loader = Loader(db)
    count = args.count
    if count > 10:
        sys.exit('Cannot be more then 10')
    if not os.path.exists(
            os.path.join(settings.CONFIG_DATA_FOLDER,
                         settings.CONFIG_FILE_USER)):
        config = initial_setup(SetupConfig())
        log.info('Creating pyu-data dir...')
        pyu = PyUpdater(config, db)
        pyu.setup()
        log.info('Making signing keys...')
        pyu.make_keys(count)
        config.PUBLIC_KEYS = pyu.get_public_keys()
        loader.save_config(config)
        log.info('Setup complete')
        db._sync_db()
    else:
        sys.exit('Not an empty PyUpdater repository')
Пример #25
0
def pkg(args):
    check = check_repo()
    if check is False:
        _repo_error()

    loader = Loader()
    pyu = PyUpdater(loader.load_config())
    if args.process is False and args.sign is False:
        sys.exit('You must specify a command')

    if args.process is True:
        log.info('Processing packages...')
        pyu.process_packages(args.verbose)
        log.info('Processing packages complete')
    if args.sign is True:
        log.info('Signing packages...')
        pyu.sign_update()
        log.info('Signing packages complete')
Пример #26
0
def init(args):  # pragma: no cover
    db = Storage()
    loader = Loader(db)
    count = args.count
    if count > 10:
        sys.exit('Cannot be more then 10')
    if not os.path.exists(os.path.join(settings.CONFIG_DATA_FOLDER,
                          settings.CONFIG_FILE_USER)):
        config = initial_setup(SetupConfig())
        log.info('Creating pyu-data dir...')
        pyu = PyUpdater(config, db)
        pyu.setup()
        log.info('Making signing keys...')
        pyu.make_keys(count)
        config.PUBLIC_KEYS = pyu.get_public_keys()
        loader.save_config(config)
        log.info('Setup complete')
        db._sync_db()
    else:
        sys.exit('Not an empty PyUpdater repository')
Пример #27
0
def upload(args):  # pragma: no cover
    error = False
    check_repo()
    db = Storage()
    loader = Loader(db)
    upload_service = args.service
    if upload_service is None:
        log.error('Must provide service name')
        error = True

    if error is False:
        pyu = PyUpdater(loader.load_config(), db)
        try:
            pyu.set_uploader(upload_service)
        except UploaderError as err:
            log.error(str(err))
            error = True
        except UploaderPluginError as err:
            log.debug(str(err))
            error = True
            mgr = stevedore.ExtensionManager(settings.UPLOAD_PLUGIN_NAMESPACE)
            plugin_names = mgr.names()
            log.debug('Plugin names: {}'.format(plugin_names))
            if len(plugin_names) == 0:
                msg = ('*** No upload plugins instaled! ***\nYou can install '
                       'the aws s3 plugin with\n$ pip install PyUpdater'
                       '[s3]\n\nOr the scp plugin with\n$ pip install '
                       'PyUpdater[scp]')
            else:
                msg = ('Invalid Uploader\n\nAvailable options:\n'
                       '{}'.format(' '.join(plugin_names)))
            log.error(msg)
    if error is False:
        try:
            pyu.upload()
        except Exception as e:
            msg = ('Looks like you forgot to add USERNAME '
                   'and/or REMOTE_DIR')
            log.debug(str(e), exc_info=True)
            log.error(msg)
    db._sync_db()
Пример #28
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')
Пример #29
0
def _keys(args):  # pragma: no cover
    check_repo()
    db = Storage()
    loader = Loader(db)
    config = loader.load_config()
    pyu = PyUpdater(config, db)
    if args.count is not None:
        count = args.count
        pyu.revoke_key(count)
        config.PUBLIC_KEYS = pyu.get_public_keys()
        key = pyu.get_recent_revoked_key()
        if key is not None:
            log.info('* Most Recent Revoked Key *')
            log.info('Created: {}'.format(pretty_time(key['date'])))
            log.info('Type: {}'.format(key['key_type']))
            log.info('Public Key: {}'.format(key['public']))
            if args.private is True:
                log.info('Private Key: {}'.format(key['private']))
            else:
                log.info('Private Key: * Next time to show private key '
                         'use --show-private *')
        loader.save_config(config)
        db._sync_db()
Пример #30
0
def pyu():
    t_config = TConfig()
    t_config.DATA_DIR = os.getcwd()
    pyu = PyUpdater(t_config)
    return pyu