示例#1
0
def cmd_run_server(args):
    setup_logging('REPROZIP-JUPYTER-SERVER', args.verbosity)
    if not args.target:
        sys.stderr.write("Missing experiment directory\n")
        sys.exit(2)

    run_server(args.target, args.jupyter_args, verbosity=args.verbosity)
示例#2
0
文件: main.py 项目: ViDA-NYU/reprozip
def main():
    """Entry point when called on the command-line.
    """
    # Locale
    locale.setlocale(locale.LC_ALL, '')

    parser = argparse.ArgumentParser(
        description="Graphical user interface for reprounzip",
        epilog="Please report issues to [email protected]")
    parser.add_argument('--version', action='version',
                        version="reprounzip-qt version %s" % __version__)
    parser.add_argument('-v', '--verbose', action='count', default=1,
                        dest='verbosity', help="augments verbosity level")
    parser.add_argument('package', nargs=argparse.OPTIONAL)
    parser.add_argument('--unpacked', action='append', default=[])

    argv = sys.argv[1:]
    i = 0
    while i < len(argv):
        if argv[i].startswith('-psn'):
            del argv[i]
        else:
            i += 1
    args = parser.parse_args(argv)

    setup_logging('REPROUNZIP-QT', args.verbosity)

    from reprounzip_qt.gui import Application, ReprounzipUi

    app = Application(sys.argv)

    window_args = {}
    if args.package and args.unpacked:
        sys.stderr.write("You can't pass both a package and a unpacked "
                         "directory\n")
        sys.exit(2)
    elif args.package:
        logger.info("Got package on the command-line: %s", args.package)
        record_usage(cmdline='package')
        window_args = dict(unpack=dict(package=args.package))
    elif len(args.unpacked) == 1:
        logger.info("Got unpacked directory on the command-line: %s",
                    args.unpacked)
        record_usage(cmdline='directory')
        window_args = dict(run=dict(unpacked_directory=args.unpacked[0]),
                           tab=1)
    elif args.unpacked:
        sys.stderr.write("You may only use --unpacked once\n")
        sys.exit(2)
    else:
        record_usage(cmdline='empty')

    window = ReprounzipUi(**window_args)
    app.set_first_window(window)
    window.setVisible(True)

    app.exec_()
    submit_usage_report()
    sys.exit(0)
示例#3
0
def cmd_trace_notebook(args):
    setup_logging('REPROZIP-JUPYTER-TRACE', args.verbosity)
    if not args.notebook:
        sys.stderr.write("missing notebook\n")
        sys.exit(2)
    return trace_notebook(args.notebook,
                          save_notebook=args.save_notebook,
                          verbosity=args.verbosity, dir=args.dir,
                          identify_packages=args.identify_packages,
                          find_inputs_outputs=args.find_inputs_outputs,
                          append=args.append)
示例#4
0
def main():
    """Entry point when called on the command-line.
    """
    # Locale
    locale.setlocale(locale.LC_ALL, '')

    # Parses command-line

    # General options
    def add_options(opts):
        opts.add_argument('--version', action='version',
                          version="reprounzip version %s" % __version__)

    # Loads plugins
    for name, func, descr, descr_1 in get_plugins('reprounzip.plugins'):
        func()

    parser = RPUZArgumentParser(
        description="reprounzip is the ReproZip component responsible for "
                    "unpacking and reproducing an experiment previously "
                    "packed with reprozip",
        epilog="Please report issues to [email protected]")
    add_options(parser)
    parser.add_argument('-v', '--verbose', action='count', default=1,
                        dest='verbosity',
                        help="augments verbosity level")
    subparsers = parser.add_subparsers(title="subcommands", metavar='')

    # usage_report subcommand
    parser_stats = subparsers.add_parser(
        'usage_report',
        help="Enables or disables anonymous usage reports")
    add_options(parser_stats)
    parser_stats.add_argument('--enable', action='store_true')
    parser_stats.add_argument('--disable', action='store_true')
    parser_stats.set_defaults(func=usage_report)

    # Loads unpackers
    for name, func, descr, descr_1 in get_plugins('reprounzip.unpackers'):
        plugin_parser = subparsers.add_parser(
            name, help=descr_1, description=descr,
            formatter_class=argparse.RawDescriptionHelpFormatter)
        add_options(plugin_parser)
        info = func(plugin_parser)
        plugin_parser.set_defaults(selected_unpacker=name)
        if info is None:
            info = {}
        unpackers[name] = info

    signals.pre_parse_args(parser=parser, subparsers=subparsers)
    args = parser.parse_args()
    signals.post_parse_args(args=args)
    if getattr(args, 'func', None) is None:
        parser.print_help(sys.stderr)
        sys.exit(2)
    signals.unpacker = getattr(args, 'selected_unpacker', None)
    setup_logging('REPROUNZIP', args.verbosity)

    setup_usage_report('reprounzip', __version__)
    if hasattr(args, 'selected_unpacker'):
        record_usage(unpacker=args.selected_unpacker)
    signals.pre_setup.subscribe(lambda **kw: record_usage(setup=True))
    signals.pre_run.subscribe(lambda **kw: record_usage(run=True))

    try:
        try:
            args.func(args)
        except UsageError:
            raise
        except Exception as e:
            signals.application_finishing(reason=e)
            submit_usage_report(result=type(e).__name__)
            raise
        else:
            signals.application_finishing(reason=None)
    except UsageError:
        parser.print_help(sys.stderr)
        sys.exit(2)
    submit_usage_report(result='success')
    sys.exit(0)
示例#5
0
def run_from_vistrails():
    setup_logging('REPROUNZIP-VISTRAILS', logging.INFO)

    cli_version = 1
    if len(sys.argv) > 1:
        try:
            cli_version = int(sys.argv[1])
        except ValueError:
            logging.info("Compatibility mode: reprounzip-vistrails didn't get "
                         "a version number")
    if cli_version != 1:
        logging.critical("Unknown interface version %d; you are probably "
                         "using a version of reprounzip-vistrails too old for "
                         "your VisTrails package. Consider upgrading.",
                         cli_version)
        sys.exit(1)

    parser = argparse.ArgumentParser()
    parser.add_argument('unpacker')
    parser.add_argument('directory')
    parser.add_argument('run')
    parser.add_argument('--input-file', action='append', default=[])
    parser.add_argument('--output-file', action='append', default=[])
    parser.add_argument('--cmdline', action='store')

    args = parser.parse_args(sys.argv[2:])

    config = load_config(Path(args.directory) / 'config.yml', canonical=True)

    python = sys.executable
    rpuz = [python, '-m', 'reprounzip.main', args.unpacker]

    os.environ['REPROUNZIP_NON_INTERACTIVE'] = 'y'

    def cmd(lst, add=None):
        if add:
            logging.info("cmd: %s %s", ' '.join(lst), add)
            string = ' '.join(shell_escape(a) for a in (rpuz + lst))
            string += ' ' + add
            subprocess.check_call(string, shell=True,
                                  cwd=args.directory)
        else:
            logging.info("cmd: %s", ' '.join(lst))
            subprocess.check_call(rpuz + lst,
                                  cwd=args.directory)

    logging.info("reprounzip-vistrails calling reprounzip; dir=%s",
                 args.directory)

    # Parses input files from the command-line
    upload_command = []
    seen_input_names = set()
    for input_file in args.input_file:
        input_name, filename = input_file.split(':', 1)
        upload_command.append('%s:%s' % (filename, input_name))
        seen_input_names.add(input_name)

    # Resets the input files that are used by this run and were not given
    for name, f in iteritems(config.inputs_outputs):
        if name not in seen_input_names and int(args.run) in f.read_runs:
            upload_command.append(':%s' % name)

    # Runs the command
    cmd(['upload', '.'] + upload_command)

    # Runs the experiment
    if args.cmdline:
        cmd(['run', '.', args.run, '--cmdline'], add=args.cmdline)
    else:
        cmd(['run', '.', args.run])

    # Gets output files
    for output_file in args.output_file:
        output_name, filename = output_file.split(':', 1)
        cmd(['download', '.',
             '%s:%s' % (output_name, filename)])
示例#6
0
def run_from_vistrails():
    setup_logging('REPROUNZIP-VISTRAILS', logging.INFO)

    parser = argparse.ArgumentParser()
    parser.add_argument('unpacker')
    parser.add_argument('directory')
    parser.add_argument('run')
    parser.add_argument('--input-file', action='append', default=[])
    parser.add_argument('--output-file', action='append', default=[])
    parser.add_argument('--cmdline', action='store')

    args = parser.parse_args()

    runs, packages, other_files = load_config(Path(args.directory) /
                                              'config.yml',
                                              canonical=True)
    run = runs[int(args.run)]

    python = sys.executable
    rpuz = [python, '-m', 'reprounzip.main', args.unpacker]

    os.environ['REPROUNZIP_NON_INTERACTIVE'] = 'y'

    def cmd(lst, add=None):
        if add:
            logging.info("cmd: %s %s", ' '.join(lst), add)
            string = ' '.join(shell_escape(a) for a in (rpuz + lst))
            string += ' ' + add
            subprocess.check_call(string, shell=True, cwd=args.directory)
        else:
            logging.info("cmd: %s", ' '.join(lst))
            subprocess.check_call(rpuz + lst, cwd=args.directory)

    logging.info("reprounzip-vistrails calling reprounzip; dir=%s",
                 args.directory)

    # Parses input files from the command-line
    upload_command = []
    seen_input_names = set()
    for input_file in args.input_file:
        input_name, filename = input_file.split(':', 1)
        upload_command.append('%s:%s' % (filename, input_name))
        seen_input_names.add(input_name)

    # Resets the input files that were not given
    for input_name in run['input_files']:
        if input_name not in seen_input_names:
            upload_command.append(':%s' % input_name)

    # Runs the command
    cmd(['upload', '.'] + upload_command)

    # Runs the experiment
    if args.cmdline:
        cmd(['run', '.', '--cmdline'], add=args.cmdline)
    else:
        cmd(['run', '.'])

    # Gets output files
    for output_file in args.output_file:
        output_name, filename = output_file.split(':', 1)
        cmd(['download', '.', '%s:%s' % (output_name, filename)])
示例#7
0
def main():
    """Entry point when called on the command-line.
    """
    # Locale
    locale.setlocale(locale.LC_ALL, '')

    # Encoding for output streams
    if str == bytes:  # PY2
        writer = codecs.getwriter(locale.getpreferredencoding())
        o_stdout, o_stderr = sys.stdout, sys.stderr
        sys.stdout = writer(sys.stdout)
        sys.stdout.buffer = o_stdout
        sys.stderr = writer(sys.stderr)
        sys.stderr.buffer = o_stderr

    # http://bugs.python.org/issue13676
    # This prevents reprozip from reading argv and envp arrays from trace
    if sys.version_info < (2, 7, 3):
        sys.stderr.write("Error: your version of Python, %s, is not "
                         "supported\nVersions before 2.7.3 are affected by "
                         "bug 13676 and will not work with ReproZip\n" %
                         sys.version.split(' ', 1)[0])
        sys.exit(1)

    # Parses command-line

    # General options
    options = argparse.ArgumentParser(add_help=False)
    options.add_argument('--version',
                         action='version',
                         version="reprounzip version %s" % __version__)
    options.add_argument('-v',
                         '--verbose',
                         action='count',
                         default=1,
                         dest='verbosity',
                         help="augments verbosity level")

    parser = argparse.ArgumentParser(
        description="reprounzip is the ReproZip component responsible for "
        "unpacking and reproducing an experiment previously "
        "packed with reprozip",
        epilog="Please report issues to [email protected]",
        parents=[options])
    subparsers = parser.add_subparsers(title="formats",
                                       metavar='',
                                       dest='selected_unpacker')

    parser_info = subparsers.add_parser(
        'info',
        parents=[options],
        help="Prints out some information about a pack")
    parser_info.add_argument('pack', nargs=1, help="Pack to read")
    parser_info.set_defaults(func=lambda args: print_info(args, unpackers))

    parser_showfiles = subparsers.add_parser(
        'showfiles',
        parents=[options],
        help="Prints out input and output file names")
    parser_showfiles.add_argument('pack',
                                  nargs=1,
                                  help="Pack or directory to read from")
    parser_showfiles.set_defaults(func=showfiles)

    # Loads commands from plugins
    for entry_point in iter_entry_points('reprounzip.unpackers'):
        try:
            setup_function = entry_point.load()
        except Exception:
            print("Plugin %s from %s %s failed to initialize!" %
                  (entry_point.name, entry_point.dist.project_name,
                   entry_point.dist.version),
                  file=sys.stderr)
            traceback.print_exc(file=sys.stderr)
            continue
        name = entry_point.name
        # Docstring is used as description (used for detailed help)
        descr = setup_function.__doc__.strip()
        # First line of docstring is the help (used for general help)
        descr_1 = descr.split('\n', 1)[0]
        plugin_parser = subparsers.add_parser(
            name,
            parents=[options],
            help=descr_1,
            description=descr,
            formatter_class=argparse.RawDescriptionHelpFormatter)
        info = setup_function(plugin_parser)
        if info is None:
            info = {}
        unpackers[name] = info

    args = parser.parse_args()
    signals.unpacker = args.selected_unpacker
    setup_logging('REPROUNZIP', args.verbosity)
    try:
        args.func(args)
    except Exception as e:
        signals.application_finishing(reason=e)
        raise
    else:
        signals.application_finishing(reason=None)
    sys.exit(0)
示例#8
0
def main():
    """Entry point when called on the command-line.
    """
    # Locale
    locale.setlocale(locale.LC_ALL, '')

    # Parses command-line

    # General options
    def add_options(opts):
        opts.add_argument('--version',
                          action='version',
                          version="reprounzip version %s" % __version__)

    # Loads plugins
    for name, func, descr, descr_1 in get_plugins('reprounzip.plugins'):
        func()

    parser = RPUZArgumentParser(
        description="reprounzip is the ReproZip component responsible for "
        "unpacking and reproducing an experiment previously "
        "packed with reprozip",
        epilog="Please report issues to [email protected]")
    add_options(parser)
    parser.add_argument('-v',
                        '--verbose',
                        action='count',
                        default=1,
                        dest='verbosity',
                        help="augments verbosity level")
    subparsers = parser.add_subparsers(title="subcommands", metavar='')

    # usage_report subcommand
    parser_stats = subparsers.add_parser(
        'usage_report', help="Enables or disables anonymous usage reports")
    add_options(parser_stats)
    parser_stats.add_argument('--enable', action='store_true')
    parser_stats.add_argument('--disable', action='store_true')
    parser_stats.set_defaults(func=usage_report)

    # Loads unpackers
    for name, func, descr, descr_1 in get_plugins('reprounzip.unpackers'):
        plugin_parser = subparsers.add_parser(
            name,
            help=descr_1,
            description=descr,
            formatter_class=argparse.RawDescriptionHelpFormatter)
        add_options(plugin_parser)
        info = func(plugin_parser)
        plugin_parser.set_defaults(selected_unpacker=name)
        if info is None:
            info = {}
        unpackers[name] = info

    signals.pre_parse_args(parser=parser, subparsers=subparsers)
    args = parser.parse_args()
    signals.post_parse_args(args=args)
    if getattr(args, 'func', None) is None:
        parser.print_help(sys.stderr)
        sys.exit(2)
    signals.unpacker = getattr(args, 'selected_unpacker', None)
    setup_logging('REPROUNZIP', args.verbosity)

    setup_usage_report('reprounzip', __version__)
    if hasattr(args, 'selected_unpacker'):
        record_usage(unpacker=args.selected_unpacker)
    signals.pre_setup.subscribe(lambda **kw: record_usage(setup=True))
    signals.pre_run.subscribe(lambda **kw: record_usage(run=True))

    try:
        try:
            args.func(args)
        except UsageError:
            raise
        except Exception as e:
            signals.application_finishing(reason=e)
            submit_usage_report(result=type(e).__name__)
            raise
        else:
            signals.application_finishing(reason=None)
    except UsageError:
        parser.print_help(sys.stderr)
        sys.exit(2)
    submit_usage_report(result='success')
    sys.exit(0)
示例#9
0
        if self.testNames is None:
            self.test = self.testLoader.discover(
                    start_dir=os.path.dirname(os.path.abspath(__file__)),
                    pattern='test_*.py')
        else:
            self.test = self.testLoader.loadTestsFromNames(self.testNames)


if __name__ == '__main__':
    # Locale
    locale.setlocale(locale.LC_ALL, '')

    # Disables usage reporting
    os.environ['REPROZIP_USAGE_STATS'] = 'off'

    setup_logging('TESTSUITE', 999)

    parser = argparse.ArgumentParser(description="reprozip tests")
    parser.add_argument('--unittests', action='store_true',
                        dest='unittests', default=None)
    parser.add_argument('--no-unittests', action='store_false',
                        dest='unittests', default=None)
    parser.add_argument('--functests', action='store_true',
                        dest='functests', default=None)
    parser.add_argument('--no-functests', action='store_false',
                        dest='functests', default=None)
    parser.add_argument('--interactive', action='store_true')
    parser.add_argument('--run-vagrant', action='store_true')
    parser.add_argument('--run-docker', action='store_true')
    parser.add_argument('arg', nargs=argparse.REMAINDER)
    parser.add_argument('--no-raise-warnings', action='store_false',
示例#10
0
def main():
    """Entry point when called on the command-line.
    """
    # Locale
    locale.setlocale(locale.LC_ALL, '')

    parser = argparse.ArgumentParser(
        description="Graphical user interface for reprounzip",
        epilog="Please report issues to [email protected]")
    parser.add_argument('--version',
                        action='version',
                        version="reprounzip-qt version %s" % __version__)
    parser.add_argument('-v',
                        '--verbose',
                        action='count',
                        default=1,
                        dest='verbosity',
                        help="augments verbosity level")
    parser.add_argument('package', nargs=argparse.OPTIONAL)
    parser.add_argument('--unpacked', action='append', default=[])

    argv = sys.argv[1:]
    i = 0
    while i < len(argv):
        if argv[i].startswith('-psn'):
            del argv[i]
        else:
            i += 1
    args = parser.parse_args(argv)

    setup_logging('REPROUNZIP-QT', args.verbosity)

    from reprounzip_qt.gui import Application, ReprounzipUi

    app = Application(sys.argv)

    window_args = {}
    if args.package and args.unpacked:
        sys.stderr.write("You can't pass both a package and a unpacked "
                         "directory\n")
        sys.exit(2)
    elif args.package:
        logger.info("Got package on the command-line: %s", args.package)
        record_usage(cmdline='package')
        window_args = dict(unpack=dict(package=args.package))
    elif len(args.unpacked) == 1:
        logger.info("Got unpacked directory on the command-line: %s",
                    args.unpacked)
        record_usage(cmdline='directory')
        window_args = dict(run=dict(unpacked_directory=args.unpacked[0]),
                           tab=1)
    elif args.unpacked:
        sys.stderr.write("You may only use --unpacked once\n")
        sys.exit(2)
    else:
        record_usage(cmdline='empty')

    window = ReprounzipUi(**window_args)
    app.set_first_window(window)
    window.setVisible(True)

    app.exec_()
    submit_usage_report()
    sys.exit(0)
示例#11
0
文件: main.py 项目: Aloma/reprozip
def main():
    """Entry point when called on the command-line.
    """
    # Locale
    locale.setlocale(locale.LC_ALL, '')

    # Encoding for output streams
    if str == bytes:  # PY2
        writer = codecs.getwriter(locale.getpreferredencoding())
        o_stdout, o_stderr = sys.stdout, sys.stderr
        sys.stdout = writer(sys.stdout)
        sys.stdout.buffer = o_stdout
        sys.stderr = writer(sys.stderr)
        sys.stderr.buffer = o_stderr

    # http://bugs.python.org/issue13676
    # This prevents reprozip from reading argv and envp arrays from trace
    if sys.version_info < (2, 7, 3):
        sys.stderr.write("Error: your version of Python, %s, is not "
                         "supported\nVersions before 2.7.3 are affected by "
                         "bug 13676 and will not work with ReproZip\n" %
                         sys.version.split(' ', 1)[0])
        sys.exit(1)

    # Parses command-line

    # General options
    options = argparse.ArgumentParser(add_help=False)
    options.add_argument('--version', action='version',
                         version="reprounzip version %s" % __version__)
    options.add_argument('-v', '--verbose', action='count', default=1,
                         dest='verbosity',
                         help="augments verbosity level")

    parser = argparse.ArgumentParser(
            description="reprounzip is the ReproZip component responsible for "
                        "unpacking and reproducing an experiment previously "
                        "packed with reprozip",
            epilog="Please report issues to [email protected]",
            parents=[options])
    subparsers = parser.add_subparsers(title="formats", metavar='',
                                       dest='selected_unpacker')

    parser_info = subparsers.add_parser(
            'info', parents=[options],
            help="Prints out some information about a pack")
    parser_info.add_argument('pack', nargs=1,
                             help="Pack to read")
    parser_info.set_defaults(func=lambda args: print_info(args, unpackers))

    parser_showfiles = subparsers.add_parser(
            'showfiles', parents=[options],
            help="Prints out input and output file names")
    parser_showfiles.add_argument('pack', nargs=1,
                                  help="Pack or directory to read from")
    parser_showfiles.set_defaults(func=showfiles)

    # Loads commands from plugins
    for entry_point in iter_entry_points('reprounzip.unpackers'):
        try:
            setup_function = entry_point.load()
        except Exception:
            print("Plugin %s from %s %s failed to initialize!" % (
                  entry_point.name,
                  entry_point.dist.project_name, entry_point.dist.version),
                  file=sys.stderr)
            traceback.print_exc(file=sys.stderr)
            continue
        name = entry_point.name
        # Docstring is used as description (used for detailed help)
        descr = setup_function.__doc__.strip()
        # First line of docstring is the help (used for general help)
        descr_1 = descr.split('\n', 1)[0]
        plugin_parser = subparsers.add_parser(
                name, parents=[options],
                help=descr_1, description=descr,
                formatter_class=argparse.RawDescriptionHelpFormatter)
        info = setup_function(plugin_parser)
        if info is None:
            info = {}
        unpackers[name] = info

    args = parser.parse_args()
    signals.unpacker = args.selected_unpacker
    setup_logging('REPROUNZIP', args.verbosity)
    try:
        args.func(args)
    except Exception as e:
        signals.application_finishing(reason=e)
        raise
    else:
        signals.application_finishing(reason=None)
    sys.exit(0)
示例#12
0
def run_from_vistrails():
    setup_logging('REPROUNZIP-VISTRAILS', logging.INFO)

    parser = argparse.ArgumentParser()
    parser.add_argument('unpacker')
    parser.add_argument('directory')
    parser.add_argument('run')
    parser.add_argument('--input-file', action='append', default=[])
    parser.add_argument('--output-file', action='append', default=[])
    parser.add_argument('--cmdline', action='store')

    args = parser.parse_args()

    runs, packages, other_files = load_config(
            Path(args.directory) / 'config.yml',
            canonical=True)
    run = runs[int(args.run)]

    python = sys.executable
    rpuz = [python, '-m', 'reprounzip.main', args.unpacker]

    os.environ['REPROUNZIP_NON_INTERACTIVE'] = 'y'

    def cmd(lst, add=None):
        if add:
            logging.info("cmd: %s %s", ' '.join(lst), add)
            string = ' '.join(shell_escape(a) for a in (rpuz + lst))
            string += ' ' + add
            subprocess.check_call(string, shell=True,
                                  cwd=args.directory)
        else:
            logging.info("cmd: %s", ' '.join(lst))
            subprocess.check_call(rpuz + lst,
                                  cwd=args.directory)

    logging.info("reprounzip-vistrails calling reprounzip; dir=%s",
                 args.directory)

    # Parses input files from the command-line
    upload_command = []
    seen_input_names = set()
    for input_file in args.input_file:
        input_name, filename = input_file.split(':', 1)
        upload_command.append('%s:%s' % (filename, input_name))
        seen_input_names.add(input_name)

    # Resets the input files that were not given
    for input_name in run['input_files']:
        if input_name not in seen_input_names:
            upload_command.append(':%s' % input_name)

    # Runs the command
    cmd(['upload', '.'] + upload_command)

    # Runs the experiment
    if args.cmdline:
        cmd(['run', '.', '--cmdline'], add=args.cmdline)
    else:
        cmd(['run', '.'])

    # Gets output files
    for output_file in args.output_file:
        output_name, filename = output_file.split(':', 1)
        cmd(['download', '.',
             '%s:%s' % (output_name, filename)])