示例#1
0
def main():
    args = docopt(__doc__, version=_get_version(), options_first=True)

    cmd = args['COMMAND'] or 'snap'
    if cmd not in _VALID_COMMANDS:
        sys.exit('Command {!r} was not recognized'.format(cmd))

    # Default log level is INFO unless --debug is specified
    log_level = logging.INFO
    if args['--debug']:
        log_level = logging.DEBUG

    log.configure(log_level=log_level)

    common.set_enable_parallel_builds(not args['--no-parallel-build'])

    if args['--target-arch']:
        common.set_target_machine(args['--target-arch'])

    try:
        commands.load(cmd).main(argv=args['ARGS'])
    except Exception as e:
        if args['--debug']:
            raise

        sys.exit(textwrap.fill(str(e)))
示例#2
0
文件: main.py 项目: fallen/snapcraft
def main(argv=None):
    args = docopt(__doc__, version=_get_version(), argv=argv)

    # Default log level is INFO unless --debug is specified
    log_level = logging.INFO
    if args['--debug']:
        log_level = logging.DEBUG

    log.configure(log_level=log_level)

    common.set_enable_parallel_builds(not args['--no-parallel-build'])

    project_options = snapcraft.ProjectOptions()
    if args['--enable-geoip']:
        project_options.use_geoip = True

    if args['--target-arch']:
        common.set_target_machine(args['--target-arch'])

    try:
        run(args, project_options)
    except Exception as e:
        if args['--debug']:
            raise

        sys.exit(textwrap.fill(str(e)))
示例#3
0
def main():
    log.configure()
    args = docopt(__doc__, version=version, options_first=True)
    if args['COMMAND'] not in _VALID_COMMANDS:
        sys.exit('Command {!r} was not recognized'.format(args['COMMAND']))

    try:
        commands.load(args['COMMAND']).main(argv=args['ARGS'])
    except Exception as e:
        sys.exit(e)
示例#4
0
文件: main.py 项目: asac/snapcraft
def main():
    log.configure()
    args = docopt(__doc__,
                  version=version,
                  options_first=True)
    if args['COMMAND'] not in _VALID_COMMANDS:
        sys.exit('Command {!r} was not recognized'.format(args['COMMAND']))

    try:
        commands.load(args['COMMAND']).main(argv=args['ARGS'])
    except Exception as e:
        sys.exit(e)
示例#5
0
    def test_configure_must_send_errors_to_stderr(self, mock_stderr,
                                                  mock_stdout, mock_isatty):
        logger_name = self.id()
        log.configure(logger_name)
        logger = logging.getLogger(logger_name)
        # Overwrite the level to log everything.
        logger.setLevel(logging.DEBUG)

        logger.error('Test error')
        logger.critical('Test critical')

        expected_err = ('\033[1mTest error\033[0m\n'
                        '\033[1mTest critical\033[0m\n')
        self.assertEqual(expected_err, mock_stderr.getvalue())
        self.assertEqual('', mock_stdout.getvalue())
示例#6
0
    def test_configure_must_send_errors_to_stderr(
            self, mock_stderr, mock_stdout, mock_isatty):
        logger_name = self.id()
        log.configure(logger_name)
        logger = logging.getLogger(logger_name)
        # Overwrite the level to log everything.
        logger.setLevel(logging.DEBUG)

        logger.error('Test error')
        logger.critical('Test critical')

        expected_err = (
            '\033[1mTest error\033[0m\n'
            '\033[1mTest critical\033[0m\n')
        self.assertEqual(expected_err, mock_stderr.getvalue())
        self.assertEqual('', mock_stdout.getvalue())
示例#7
0
    def test_configure_must_send_messages_to_stdout(self, mock_stderr,
                                                    mock_stdout, mock_isatty):
        logger_name = self.id()
        log.configure(logger_name)
        logger = logging.getLogger(logger_name)
        # Overwrite the level to log everything.
        logger.setLevel(logging.DEBUG)

        logger.debug('Test debug')
        logger.info('Test info')
        logger.warning('Test warning')

        expected_out = ('\033[1mTest debug\033[0m\n'
                        '\033[1mTest info\033[0m\n'
                        '\033[1mTest warning\033[0m\n')
        self.assertEqual(expected_out, mock_stdout.getvalue())
        self.assertEqual('', mock_stderr.getvalue())
示例#8
0
文件: main.py 项目: morphis/snapcraft
def main(argv=None):
    args = docopt(__doc__, version=_get_version(), argv=argv)

    # Default log level is INFO unless --debug is specified
    log_level = logging.INFO
    if args['--debug']:
        log_level = logging.DEBUG

    log.configure(log_level=log_level)
    project_options = _get_project_options(args)

    try:
        return run(args, project_options)
    except Exception as e:
        if args['--debug']:
            raise

        sys.exit(textwrap.fill(str(e)))
示例#9
0
    def test_configure_must_send_messages_to_stdout(
            self, mock_stderr, mock_stdout, mock_isatty):
        logger_name = self.id()
        log.configure(logger_name)
        logger = logging.getLogger(logger_name)
        # Overwrite the level to log everything.
        logger.setLevel(logging.DEBUG)

        logger.debug('Test debug')
        logger.info('Test info')
        logger.warning('Test warning')

        expected_out = (
            '\033[1mTest debug\033[0m\n'
            '\033[1mTest info\033[0m\n'
            '\033[1mTest warning\033[0m\n')
        self.assertEqual(expected_out, mock_stdout.getvalue())
        self.assertEqual('', mock_stderr.getvalue())
示例#10
0
    def test_configure_must_log_info_and_higher(self, mock_stderr, mock_stdout,
                                                mock_isatty):
        logger_name = self.id()
        log.configure(logger_name)
        logger = logging.getLogger(logger_name)

        logger.debug('Test debug')
        logger.info('Test info')
        logger.warning('Test warning')
        logger.error('Test error')
        logger.critical('Test critical')

        expected_out = ('\033[1mTest info\033[0m\n'
                        '\033[1mTest warning\033[0m\n')
        expected_err = ('\033[1mTest error\033[0m\n'
                        '\033[1mTest critical\033[0m\n')
        self.assertEqual(expected_out, mock_stdout.getvalue())
        self.assertEqual(expected_err, mock_stderr.getvalue())
示例#11
0
    def test_configure_must_log_info_and_higher(
            self, mock_stderr, mock_stdout, mock_isatty):
        logger_name = self.id()
        log.configure(logger_name)
        logger = logging.getLogger(logger_name)

        logger.debug('Test debug')
        logger.info('Test info')
        logger.warning('Test warning')
        logger.error('Test error')
        logger.critical('Test critical')

        expected_out = (
            '\033[1mTest info\033[0m\n'
            '\033[1mTest warning\033[0m\n')
        expected_err = (
            '\033[1mTest error\033[0m\n'
            '\033[1mTest critical\033[0m\n')
        self.assertEqual(expected_out, mock_stdout.getvalue())
        self.assertEqual(expected_err, mock_stderr.getvalue())
示例#12
0
文件: main.py 项目: techraf/snapcraft
def main():
    args = docopt(__doc__, version=_get_version(), options_first=True)

    cmd = args['COMMAND'] or 'snap'
    if cmd not in _VALID_COMMANDS:
        sys.exit('Command {!r} was not recognized'.format(cmd))

    # Default log level is INFO unless --debug is specified
    log_level = logging.INFO
    if args['--debug']:
        log_level = logging.DEBUG

    log.configure(log_level=log_level)

    common.set_enable_parallel_builds(not args['--no-parallel-build'])

    try:
        commands.load(cmd).main(argv=args['ARGS'])
    except Exception as e:
        if args['--debug']:
            raise

        sys.exit(textwrap.fill(str(e)))
示例#13
0
def main():
    log.configure()
    root_parser = argparse.ArgumentParser()
    subparsers = root_parser.add_subparsers(dest="cmd")

    # Parent parsers

    force_parser = argparse.ArgumentParser(add_help=False)
    force_parser.add_argument("--force", action="store_true", help="redo all steps for all parts")

    cmd_parser = argparse.ArgumentParser(add_help=False, parents=[force_parser])
    cmd_parser.add_argument("part", nargs="*")

    root_parser.add_argument(
        "-v", "--version", action=_VersionAction, help="show the program's version number and exit"
    )

    # Command parsers

    parser = subparsers.add_parser("init", help="start a project")
    parser.set_defaults(func=snapcraft.cmds.init)

    parser = subparsers.add_parser("shell", help="enter staging environment")
    parser.add_argument(
        "userCommand",
        nargs=argparse.REMAINDER,
        metavar="cmd",
        help="optional command to run inside staging environment",
    )
    parser.set_defaults(func=snapcraft.cmds.shell)

    parser = subparsers.add_parser(
        "list-plugins", help="list the available plugins that handle different types " "of a part"
    )
    parser.set_defaults(func=snapcraft.cmds.list_plugins)

    parser = subparsers.add_parser("clean", help="clean up the environment (to start from scratch)")
    parser.set_defaults(func=snapcraft.cmds.clean)
    parser.add_argument("parts", nargs="*", metavar="PART", help="specific part to clean")

    parser = subparsers.add_parser("pull", help="get sources", parents=[cmd_parser])
    parser.set_defaults(func=snapcraft.cmds.cmd)

    parser = subparsers.add_parser("build", help="build parts", parents=[cmd_parser])
    parser.set_defaults(func=snapcraft.cmds.cmd)

    parser = subparsers.add_parser("stage", help="put parts into staging area", parents=[cmd_parser])
    parser.set_defaults(func=snapcraft.cmds.cmd)

    parser = subparsers.add_parser("snap", help="put parts into snap area", parents=[cmd_parser])
    parser.set_defaults(func=snapcraft.cmds.snap)

    parser = subparsers.add_parser("assemble", help="make snap package", parents=[force_parser], aliases=["all"])
    parser.set_defaults(func=snapcraft.cmds.assemble)

    parser = subparsers.add_parser("version", help="show the program's version number and exit")
    parser.add_argument("foo", action=_VersionAction, nargs="?", help=argparse.SUPPRESS)

    parser = subparsers.add_parser("help", usage=help.topic.__doc__, help="obtain help for plugins and specific topics")
    parser.set_defaults(func=help.topic)
    parser.add_argument("topic", help="plugin name or topic to get help from")
    parser.add_argument("--devel", action="store_true", help="show the development help")

    # Now run parser

    if len(sys.argv) < 2:
        args = root_parser.parse_args(["all"])
    else:
        args = root_parser.parse_args()

    if not hasattr(args, "func"):
        root_parser.print_help()
        sys.exit(1)

    args.func(args)
    sys.exit(0)
示例#14
0
def main():
    log.configure()
    root_parser = argparse.ArgumentParser()
    subparsers = root_parser.add_subparsers(dest='cmd')

    # Parent parsers

    force_parser = argparse.ArgumentParser(add_help=False)
    force_parser.add_argument('--force', action='store_true',
                              help='redo all steps for all parts')

    cmd_parser = argparse.ArgumentParser(add_help=False,
                                         parents=[force_parser])
    cmd_parser.add_argument('part', nargs='*')

    root_parser.add_argument('-v', '--version', action=_VersionAction,
                             help="show the program's version number and exit")

    # Command parsers

    parser = subparsers.add_parser('init', help='start a project')
    parser.add_argument('part', nargs='*', help='part to add to new project')
    parser.set_defaults(func=snapcraft.cmds.init)

    parser = subparsers.add_parser('shell', help='enter staging environment')
    parser.add_argument(
        'userCommand', nargs=argparse.REMAINDER,
        metavar='cmd',
        help='optional command to run inside staging environment')
    parser.set_defaults(func=snapcraft.cmds.shell)

    parser = subparsers.add_parser('run', help='run snap in kvm',
                                   add_help=False)
    parser.set_defaults(func=snapcraft.cmds.run)

    parser = subparsers.add_parser(
        'list-plugins',
        help='list the available plugins that handle different types '
        'of a part')
    parser.set_defaults(func=snapcraft.cmds.list_plugins)

    parser = subparsers.add_parser(
        'clean',
        help='clean up the environment (to start from scratch)')
    parser.set_defaults(func=snapcraft.cmds.clean)

    parser = subparsers.add_parser('pull', help='get sources',
                                   parents=[cmd_parser])
    parser.set_defaults(func=snapcraft.cmds.cmd)

    parser = subparsers.add_parser('build', help='build parts',
                                   parents=[cmd_parser])
    parser.set_defaults(func=snapcraft.cmds.cmd)

    parser = subparsers.add_parser(
        'stage',
        help='put parts into staging area', parents=[cmd_parser])
    parser.set_defaults(func=snapcraft.cmds.cmd)

    parser = subparsers.add_parser(
        'snap',
        help='put parts into snap area',
        parents=[cmd_parser])
    parser.set_defaults(func=snapcraft.cmds.snap)

    parser = subparsers.add_parser(
        'assemble',
        help='make snap package', parents=[force_parser],
        aliases=['all'])
    parser.set_defaults(func=snapcraft.cmds.assemble)

    parser = subparsers.add_parser(
        'version', help="show the program's version number and exit")
    parser.add_argument('foo', action=_VersionAction, nargs='?',
                        help=argparse.SUPPRESS)

    parser = subparsers.add_parser(
        'help',
        usage=help.topic.__doc__,
        help='obtain help for plugins and specific topics')
    parser.set_defaults(func=help.topic)
    parser.add_argument('topic', help='plugin name or topic to get help from')
    parser.add_argument('--devel', action='store_true',
                        help='show the development help')

    # Now run parser

    if len(sys.argv) < 2:
        args = root_parser.parse_args(['all'])
    else:
        args = root_parser.parse_args()

    if not hasattr(args, 'func'):
        root_parser.print_help()
        sys.exit(1)

    args.func(args)
    sys.exit(0)