Esempio n. 1
0
def delete_packages(config, should_delete, index, index_type, dry_run, quiet):
    from infi.logging.wrappers import script_logging_context
    from infi.gevent_utils.os import path
    from infi.app_repo.service import get_client
    client = get_client(config)
    show_warning = False
    with script_logging_context(syslog=False, logfile=False, stderr=True):
        artifacts = client.get_artifacts(index, index_type)
    files_to_remove = [
        filepath for filepath in artifacts
        if should_delete(path.basename(filepath))
    ]
    for filepath in files_to_remove:
        filepath_relative = path.relpath(filepath, config.base_directory)
        if dry_run:
            logger.info("[dry-run] deleting {}".format(filepath_relative))
            continue
        if not quiet:
            if not raw_input(
                    'delete {} [y/N]? '.format(filepath_relative)).lower() in (
                        'y', 'yes'):
                continue
        logger.info("deleting {} ".format(filepath_relative))
        show_warning = True
        client.delete_artifact(filepath)
    if show_warning:
        logger.warn(
            "do not forget to rebuild the index(es) after deleting all the packages that you wanted to delete"
        )
Esempio n. 2
0
        def decorator(*args, **kwargs):
            from infi.logging.wrappers import script_logging_context
            from logbook.concurrency import enable_gevent
            from infi.traceback import traceback_context
            from os import getpid, getuid
            from datetime import datetime
            from docopt import DocoptExit
            from sys import stderr
            import logbook
            if _bypass_console_script_logging:
                return f(*args, **kwargs)

            enable_gevent()
            filename = '/tmp/{}.log'.format(name if name else f.__name__)
            with script_logging_context(logfile_path=filename, logfile_max_size=20 * 1024 * 1024), traceback_context(), exception_handling_context():
                logbook.set_datetime_format("local")
                logger.info("Calling {}".format(f.__name__))
                result = f(*args, **kwargs)
                logger.info("Call to {} returned {}".format(f.__name__, result))
                return result
Esempio n. 3
0
        def decorator(*args, **kwargs):
            from infi.logging.wrappers import script_logging_context
            from logbook.concurrency import enable_gevent
            from infi.traceback import traceback_context
            from os import getpid, getuid
            from datetime import datetime
            from docopt import DocoptExit
            from sys import stderr
            import logbook
            if _bypass_console_script_logging:
                return f(*args, **kwargs)

            enable_gevent()
            filename = '/tmp/{}.log'.format(name if name else f.__name__)
            with script_logging_context(logfile_path=filename, logfile_max_size=20 * 1024 * 1024), traceback_context(), exception_handling_context():
                logbook.set_datetime_format("local")
                logger.info("Calling {}".format(f.__name__))
                result = f(*args, **kwargs)
                logger.info("Call to {} returned {}".format(f.__name__, result))
                return result
Esempio n. 4
0
def delete_packages(config, should_delete, index, index_type, dry_run, quiet):
    from infi.logging.wrappers import script_logging_context
    from infi.gevent_utils.os import path
    from infi.app_repo.service import get_client
    client = get_client(config)
    show_warning = False
    with script_logging_context(syslog=False, logfile=False, stderr=True):
        artifacts = client.get_artifacts(index, index_type)
    files_to_remove = [filepath for filepath in artifacts if should_delete(path.basename(filepath))]
    for filepath in files_to_remove:
        filepath_relative = path.relpath(filepath, config.base_directory)
        if dry_run:
            logger.info("[dry-run] deleting {}".format(filepath_relative))
            continue
        if not quiet:
            if not raw_input('delete {} [y/N]? '.format(filepath_relative)).lower() in ('y', 'yes'):
                continue
        logger.info("deleting {} ".format(filepath_relative))
        show_warning = True
        client.delete_artifact(filepath)
    if show_warning:
        logger.warn("do not forget to rebuild the index(es) after deleting all the packages that you wanted to delete")
Esempio n. 5
0
def eapp_repo(argv=argv[1:]):
    from infi.logging.wrappers import script_logging_context
    bypass_console_script_logging()
    args = docopt(__doc__, argv)
    config = get_config(args)

    if args['counters'] and args['show']:
        return show_counters(config)
    elif args['config'] and args['show']:
        print config.to_json()
    elif args['config'] and args['reset']:
        config.reset_to_development_defaults() if args['--development'] else config.reset_to_production_defaults()
    elif args['setup']:
        if args['--development']:
            config.reset_to_development_defaults()
        if args['--with-legacy']:
            config.webserver.support_legacy_uris = True
            config.to_disk()
        return setup(config, args['--with-mock'], args['--force-resignature'])
    elif args['destroy']:
        if args['--yes']:
            from infi.app_repo.install import destroy_all
            destroy_all(config)
        else:
            print "This command will destroy the application repository"
            print "If this is absolutely what you want, pass the --yes flag in the command-line.\nAborting."
    elif args['web-server']:
        return web_server(config, args['--signal-upstart'])
    elif args['ftp-server']:
        return ftp_server(config, args['--signal-upstart'])
    elif args['rpc-server']:
        return rpc_server(config, args['--signal-upstart'], args['--with-mock'])
    elif args['rpc-client']:
        return rpc_client(config, args['<method>'], args['<arg>'], args['--style'], args['--async'])
    elif args['service'] and args['upload-file']:
        return upload_file(config, args['--index'], args['<filepath>'])
    elif args['service'] and args['process-rejected-file']:
        return process_rejected_file(config, args['--index'], args['<filepath>'],
                                     args['<platform>'], args['<arch>'], args['--async'])
    elif args['service'] and args['process-incoming']:
        return process_incoming(config, args['<index>'], args['--async'])
    elif args['service'] and args['rebuild-index']:
        return rebuild_index(config, args['<index>'], args['<index-type>'], args['--async'])
    elif args['service'] and args['resign-packages']:
        return resign_packages(config, args['--async'])
    elif args['index'] and args['list']:
        print ' '.join(config.indexes)
    elif args['index'] and args['add']:
        return add_index(config, args['<index>'], args['--async'])
    elif args['index'] and args['remove']:
        if args['--yes']:
            return remove_index(config, args['<index>'], args['--async'])
        else:
            print "This command will remove index \"{0}\" from the application repository".format(args['<index>'])
            print "If this is absolutely what you want, pass the --yes flag in the command-line.\nAborting."
    elif args['package'] and args['list']:
        return show_packages(config, args['--index'])
    elif args['package'] and args['remote-list']:
        return show_remote_packages(config, args['<remote-server>'], args['<remote-index>'])
    elif args['package'] and args['pull']:
        from infi.app_repo.sync import pull_packages
        pull_packages = console_script(name="app_repo_pull")(pull_packages)
        return pull_packages(config, args['--index'], args['<remote-server>'], args['<remote-index>'],
                             args['<package>'], args['<version>'], args['<platform>'], args['<arch>'])
    elif args['package'] and args['push']:
        from infi.app_repo.sync import push_packages
        push_packages = console_script(name="app_repo_push")(push_packages)
        return push_packages(config, args['--index'], args['<remote-server>'], args['<remote-index>'],
                             args.get('<package>'), args.get('<version>'), args.get('<platform>'), args.get('<arch>'))
    elif args['package'] and args['delete']:
        with script_logging_context(syslog=False, logfile=False, stderr=True):
            return delete_packages(config, build_regex_predicate(args['<regex>']), args['<index>'], args['<index-type>'],
                                   args['--dry-run'], args['--yes'], args['--no-rebuild'], args['--async'])
    elif args['package'] and args['cleanup']:
        return delete_old_packages(config, args['<index>'], args['--dry-run'], args['--yes'], int(args['--days']))
Esempio n. 6
0
def eapp_repo(argv=argv[1:]):
    from infi.logging.wrappers import script_logging_context
    bypass_console_script_logging()
    args = docopt(__doc__, argv)
    config = get_config(args)

    if args['counters'] and args['show']:
        return show_counters(config)
    elif args['config'] and args['show']:
        print(config.to_json())
    elif args['config'] and args['reset']:
        config.reset_to_development_defaults() if args['--development'] else config.reset_to_production_defaults()
    elif args['setup']:
        if args['--development']:
            config.reset_to_development_defaults()
        if args['--with-legacy']:
            config.webserver.support_legacy_uris = True
            config.to_disk()
        return setup(config, args['--with-mock'], args['--force-resignature'])
    elif args['destroy']:
        if args['--yes']:
            from infi.app_repo.install import destroy_all
            destroy_all(config)
        else:
            print("This command will destroy the application repository")
            print("If this is absolutely what you want, pass the --yes flag in the command-line.\nAborting.")
    elif args['web-server']:
        return web_server(config)
    elif args['ftp-server']:
        return ftp_server(config)
    elif args['rpc-server']:
        return rpc_server(config, args['--with-mock'])
    elif args['rpc-client']:
        return rpc_client(config, args['<method>'], args['<arg>'], args['--style'], args['--async'])
    elif args['service'] and args['upload-file']:
        return upload_file(config, args['--index'], args['<filepath>'])
    elif args['service'] and args['process-rejected-file']:
        return process_rejected_file(config, args['--index'], args['<filepath>'],
                                     args['<platform>'], args['<arch>'], args['--async'])
    elif args['service'] and args['process-incoming']:
        return process_incoming(config, args['<index>'], args['--async'])
    elif args['service'] and args['rebuild-index']:
        return rebuild_index(config, args['<index>'], args['<index-type>'], args['--async'])
    elif args['service'] and args['resign-packages']:
        return resign_packages(config, args['--async'])
    elif args['index'] and args['list']:
        print(' '.join(config.indexes))
    elif args['index'] and args['add']:
        return add_index(config, args['<index>'], args['--async'])
    elif args['index'] and args['remove']:
        if args['--yes']:
            return remove_index(config, args['<index>'], args['--async'])
        else:
            print(("This command will remove index \"{0}\" from the application repository".format(args['<index>'])))
            print("If this is absolutely what you want, pass the --yes flag in the command-line.\nAborting.")
    elif args['package'] and args['list']:
        return show_packages(config, args['--index'])
    elif args['package'] and args['remote-list']:
        return show_remote_packages(config, args['<remote-server>'], args['<remote-index>'])
    elif args['package'] and args['pull']:
        from infi.app_repo.sync import pull_packages
        pull_packages = console_script(name="app_repo_pull")(pull_packages)
        return pull_packages(config, args['--index'], args['<remote-server>'], args['<remote-index>'],
                             args['<package>'], args['<version>'], args['<platform>'], args['<arch>'])
    elif args['package'] and args['push']:
        from infi.app_repo.sync import push_packages
        push_packages = console_script(name="app_repo_push")(push_packages)
        return push_packages(config, args['--index'], args['<remote-server>'], args['<remote-index>'],
                             args.get('<package>'), args.get('<version>'), args.get('<platform>'), args.get('<arch>'))
    elif args['package'] and args['delete']:
        with script_logging_context(syslog=False, logfile=False, stderr=True):
            return delete_packages(config, build_regex_predicate(args['<regex>']), args['<index>'], args['<index-type>'],
                                   args['--dry-run'], args['--yes'], args['--no-rebuild'], args['--async'])
    elif args['package'] and args['cleanup']:
        with script_logging_context(syslog=False, logfile=False, stderr=True):
            return delete_old_packages(config, args['<index>'], args['--dry-run'], args['--yes'], int(args['--days']))
Esempio n. 7
0
 def test_default(self):
     from infi.logging.wrappers import script_logging_context
     with script_logging_context(logfile_path=os.devnull):
         boo = Logger("boo")
         boo.info("baah!")