Ejemplo n.º 1
0
 def parse_cmdline(self, args):
     usage = u"""
     pssh [options]
     pssh [user@site [cmd]]
     """
     parser = OptionParser(self.chan, usage=usage)
     # add options from a mapping or a Registry callback
     self.add_cmdline_options(parser)
     return parser.parse_args(args)
Ejemplo n.º 2
0
    def __new__(cls, name, bases, attrs):
        attrs = attrs if attrs else {}

        # Set the options on the plugin by finding all the Options and
        # setting them. This also removes the original Option attributes.
        global_options = []
        groups = []

        option_parser = OptionParser()

        for key,val in attrs.items():
            if key == "_usage":
                option_parser.set_usage(val)
                del attrs[key]
            elif isinstance(val, Option):
                # We set the destination of the Option to always be the
                # attribute key...
                val.dest = key

                # Append it to the list of options and delete it from
                # the original attributes list
                global_options.append(val)
                del attrs[key]
            elif isinstance(val, OptionGroup):
                groups.append(val.get_option_group(option_parser))

        # Need to iterate through the bases in order to extract the
        # list of parent options, so we can inherit those.
        for base in bases:
            if hasattr(base, "_options"):
                global_options.extend(getattr(base, "_options"))

        for option in global_options:
            try:
                option_parser.add_option(option)
            except OptionConflictError:
                pass
        for group in groups:
            option_parser.add_option_group(group)

        # Store the option list and create the option parser
        attrs["_option_parser"] = option_parser
        attrs["_options"] = global_options

        # Create the class
        return super(PluginMeta, cls).__new__(cls, name, bases, attrs)
Ejemplo n.º 3
0
def parse_options():
    import config
    from options import OptionParser

    options = OptionParser(usage=usage, version=version,
                           description=brief_copyright)
    option = options.add_option
    group = options.set_group

    # Help options
    option('-B', "--build-info", action="store_true", default=False,
        help="Show build information")
    option('-C', "--copyright", action="store_true", default=False,
        help="Show full copyright information")
    option('-R', "--readme", action="store_true", default=False,
        help="Show the readme")

    # Options for configuring the base simulator
    option('-d', "--outdir", metavar="DIR", default="m5out",
        help="Set the output directory to DIR [Default: %default]")
    option('-r', "--redirect-stdout", action="store_true", default=False,
        help="Redirect stdout (& stderr, without -e) to file")
    option('-e', "--redirect-stderr", action="store_true", default=False,
        help="Redirect stderr to file")
    option("--stdout-file", metavar="FILE", default="simout",
        help="Filename for -r redirection [Default: %default]")
    option("--stderr-file", metavar="FILE", default="simerr",
        help="Filename for -e redirection [Default: %default]")
    option('-i', "--interactive", action="store_true", default=False,
        help="Invoke the interactive interpreter after running the script")
    option("--pdb", action="store_true", default=False,
        help="Invoke the python debugger before running the script")
    option('-p', "--path", metavar="PATH[:PATH]", action='append', split=':',
        help="Prepend PATH to the system path when invoking the script")
    option('-q', "--quiet", action="count", default=0,
        help="Reduce verbosity")
    option('-v', "--verbose", action="count", default=0,
        help="Increase verbosity")

    # Statistics options
    group("Statistics Options")
    option("--stats-file", metavar="FILE", default="stats.txt",
        help="Sets the output file for statistics [Default: %default]")

    # Configuration Options
    group("Configuration Options")
    option("--dump-config", metavar="FILE", default="config.ini",
        help="Dump configuration output file [Default: %default]")

    # Debugging options
    group("Debugging Options")
    option("--debug-break", metavar="TIME[,TIME]", action='append', split=',',
        help="Cycle to create a breakpoint")
    option("--debug-help", action='store_true',
        help="Print help on trace flags")
    option("--debug-flags", metavar="FLAG[,FLAG]", action='append', split=',',
        help="Sets the flags for tracing (-FLAG disables a flag)")
    option("--remote-gdb-port", type='int', default=7000,
        help="Remote gdb base port (set to 0 to disable listening)")

    # Tracing options
    group("Trace Options")
    option("--trace-start", metavar="TIME", type='int',
        help="Start tracing at TIME (must be in ticks)")
    option("--trace-file", metavar="FILE", default="cout",
        help="Sets the output file for tracing [Default: %default]")
    option("--trace-ignore", metavar="EXPR", action='append', split=':',
        help="Ignore EXPR sim objects")

    # Help options
    group("Help Options")
    option("--list-sim-objects", action='store_true', default=False,
        help="List all built-in SimObjects, their params and default values")

    # load the options.py config file to allow people to set their own
    # default options
    options_file = config.get('options.py')
    if options_file:
        scope = { 'options' : options }
        execfile(options_file, scope)

    arguments = options.parse_args()

    return options,arguments
Ejemplo n.º 4
0
def parse_options():
    import config
    from options import OptionParser

    options = OptionParser(usage=usage,
                           version=version,
                           description=brief_copyright)
    option = options.add_option
    group = options.set_group

    listener_modes = ("on", "off", "auto")

    # Help options
    option('-B',
           "--build-info",
           action="store_true",
           default=False,
           help="Show build information")
    option('-C',
           "--copyright",
           action="store_true",
           default=False,
           help="Show full copyright information")
    option('-R',
           "--readme",
           action="store_true",
           default=False,
           help="Show the readme")

    # Options for configuring the base simulator
    option('-d',
           "--outdir",
           metavar="DIR",
           default="m5out",
           help="Set the output directory to DIR [Default: %default]")
    option('-r',
           "--redirect-stdout",
           action="store_true",
           default=False,
           help="Redirect stdout (& stderr, without -e) to file")
    option('-e',
           "--redirect-stderr",
           action="store_true",
           default=False,
           help="Redirect stderr to file")
    option("--stdout-file",
           metavar="FILE",
           default="simout",
           help="Filename for -r redirection [Default: %default]")
    option("--stderr-file",
           metavar="FILE",
           default="simerr",
           help="Filename for -e redirection [Default: %default]")
    option("--listener-mode", metavar="{on,off,auto}",
        choices=listener_modes, default="auto",
        help="Port (e.g., gdb) listener mode (auto: Enable if running " \
        "interactively) [Default: %default]")
    option("--listener-loopback-only", action="store_true", default=False,
        help="Port listeners will only accept connections over the " \
        "loopback device")
    option('-i',
           "--interactive",
           action="store_true",
           default=False,
           help="Invoke the interactive interpreter after running the script")
    option("--pdb",
           action="store_true",
           default=False,
           help="Invoke the python debugger before running the script")
    option('-p',
           "--path",
           metavar="PATH[:PATH]",
           action='append',
           split=':',
           help="Prepend PATH to the system path when invoking the script")
    option('-q', "--quiet", action="count", default=0, help="Reduce verbosity")
    option('-v',
           "--verbose",
           action="count",
           default=0,
           help="Increase verbosity")

    # Statistics options
    group("Statistics Options")
    option("--stats-file",
           metavar="FILE",
           default="stats.txt",
           help="Sets the output file for statistics [Default: %default]")

    # Configuration Options
    group("Configuration Options")
    option("--dump-config",
           metavar="FILE",
           default="config.ini",
           help="Dump configuration output file [Default: %default]")
    option("--json-config",
           metavar="FILE",
           default="config.json",
           help="Create JSON output of the configuration [Default: %default]")
    option(
        "--dot-config",
        metavar="FILE",
        default="config.dot",
        help="Create DOT & pdf outputs of the configuration [Default: %default]"
    )
    option("--dot-dvfs-config", metavar="FILE", default=None,
        help="Create DOT & pdf outputs of the DVFS configuration" + \
             " [Default: %default]")

    # Debugging options
    group("Debugging Options")
    option("--debug-break", metavar="TICK[,TICK]", action='append', split=',',
        help="Create breakpoint(s) at TICK(s) " \
             "(kills process if no debugger attached)")
    option("--debug-help",
           action='store_true',
           help="Print help on debug flags")
    option("--debug-flags",
           metavar="FLAG[,FLAG]",
           action='append',
           split=',',
           help="Sets the flags for debug output (-FLAG disables a flag)")
    option("--debug-start",
           metavar="TICK",
           type='int',
           help="Start debug output at TICK")
    option("--debug-end",
           metavar="TICK",
           type='int',
           help="End debug output at TICK")
    option("--debug-file",
           metavar="FILE",
           default="cout",
           help="Sets the output file for debug [Default: %default]")
    option("--debug-ignore",
           metavar="EXPR",
           action='append',
           split=':',
           help="Ignore EXPR sim objects")
    option("--remote-gdb-port",
           type='int',
           default=7000,
           help="Remote gdb base port (set to 0 to disable listening)")

    # Help options
    group("Help Options")
    option(
        "--list-sim-objects",
        action='store_true',
        default=False,
        help="List all built-in SimObjects, their params and default values")

    # load the options.py config file to allow people to set their own
    # default options
    options_file = config.get('options.py')
    if options_file:
        scope = {'options': options}
        execfile(options_file, scope)

    arguments = options.parse_args()
    return options, arguments
Ejemplo n.º 5
0
from util import attrdict, fatal
import config
from options import OptionParser

__all__ = [ 'options', 'arguments', 'main' ]

usage="%prog [m5 options] script.py [script options]"
version="%prog 2.0"
brief_copyright='''
Copyright (c) 2001-2008
The Regents of The University of Michigan
All Rights Reserved
'''

options = OptionParser(usage=usage, version=version,
                       description=brief_copyright)
add_option = options.add_option
set_group = options.set_group
usage = options.usage

# Help options
add_option('-A', "--authors", action="store_true", default=False,
    help="Show author information")
add_option('-B', "--build-info", action="store_true", default=False,
    help="Show build information")
add_option('-C', "--copyright", action="store_true", default=False,
    help="Show full copyright information")
add_option('-R', "--readme", action="store_true", default=False,
    help="Show the readme")
add_option('-N', "--release-notes", action="store_true", default=False,
    help="Show the release notes")
Ejemplo n.º 6
0
def parse_options():
    import config
    from options import OptionParser

    options = OptionParser(usage=usage,
                           version=version,
                           description=brief_copyright)
    option = options.add_option
    group = options.set_group

    # Help options
    option('-B',
           "--build-info",
           action="store_true",
           default=False,
           help="Show build information")
    option('-C',
           "--copyright",
           action="store_true",
           default=False,
           help="Show full copyright information")
    option('-R',
           "--readme",
           action="store_true",
           default=False,
           help="Show the readme")

    # Options for configuring the base simulator
    option('-d',
           "--outdir",
           metavar="DIR",
           default="m5out",
           help="Set the output directory to DIR [Default: %default]")
    option('-r',
           "--redirect-stdout",
           action="store_true",
           default=False,
           help="Redirect stdout (& stderr, without -e) to file")
    option('-e',
           "--redirect-stderr",
           action="store_true",
           default=False,
           help="Redirect stderr to file")
    option("--stdout-file",
           metavar="FILE",
           default="simout",
           help="Filename for -r redirection [Default: %default]")
    option("--stderr-file",
           metavar="FILE",
           default="simerr",
           help="Filename for -e redirection [Default: %default]")
    option('-i',
           "--interactive",
           action="store_true",
           default=False,
           help="Invoke the interactive interpreter after running the script")
    option("--pdb",
           action="store_true",
           default=False,
           help="Invoke the python debugger before running the script")
    option('-p',
           "--path",
           metavar="PATH[:PATH]",
           action='append',
           split=':',
           help="Prepend PATH to the system path when invoking the script")
    option('-q', "--quiet", action="count", default=0, help="Reduce verbosity")
    option('-v',
           "--verbose",
           action="count",
           default=0,
           help="Increase verbosity")

    # Statistics options
    group("Statistics Options")
    option("--stats-file",
           metavar="FILE",
           default="stats.txt",
           help="Sets the output file for statistics [Default: %default]")

    # Configuration Options
    group("Configuration Options")
    option("--dump-config",
           metavar="FILE",
           default="config.ini",
           help="Dump configuration output file [Default: %default]")
    option("--json-config",
           metavar="FILE",
           default="config.json",
           help="Create JSON output of the configuration [Default: %default]")
    option(
        "--dot-config",
        metavar="FILE",
        default="config.dot",
        help="Create DOT & pdf outputs of the configuration [Default: %default]"
    )

    # Debugging options
    group("Debugging Options")
    option("--debug-break",
           metavar="TIME[,TIME]",
           action='append',
           split=',',
           help="Cycle to create a breakpoint")
    option("--debug-help",
           action='store_true',
           help="Print help on trace flags")
    option("--debug-flags",
           metavar="FLAG[,FLAG]",
           action='append',
           split=',',
           help="Sets the flags for tracing (-FLAG disables a flag)")
    option("--remote-gdb-port",
           type='int',
           default=7000,
           help="Remote gdb base port (set to 0 to disable listening)")

    # Tracing options
    group("Trace Options")
    option("--trace-start",
           metavar="TIME",
           type='int',
           help="Start tracing at TIME (must be in ticks)")
    option("--trace-file",
           metavar="FILE",
           default="cout",
           help="Sets the output file for tracing [Default: %default]")
    option("--trace-ignore",
           metavar="EXPR",
           action='append',
           split=':',
           help="Ignore EXPR sim objects")

    # Help options
    group("Help Options")
    option(
        "--list-sim-objects",
        action='store_true',
        default=False,
        help="List all built-in SimObjects, their params and default values")

    # load the options.py config file to allow people to set their own
    # default options
    options_file = config.get('options.py')
    if options_file:
        scope = {'options': options}
        execfile(options_file, scope)

    arguments = options.parse_args()
    return options, arguments
Ejemplo n.º 7
0
def parse_options():
    import config
    from options import OptionParser

    options = OptionParser(usage=usage, version=version,
                           description=brief_copyright)
    option = options.add_option
    group = options.set_group

    listener_modes = ( "on", "off", "auto" )

    # Help options
    option('-B', "--build-info", action="store_true", default=False,
        help="Show build information")
    option('-C', "--copyright", action="store_true", default=False,
        help="Show full copyright information")
    option('-R', "--readme", action="store_true", default=False,
        help="Show the readme")

    # Options for configuring the base simulator
    option('-d', "--outdir", metavar="DIR", default="m5out",
        help="Set the output directory to DIR [Default: %default]")
    option('-r', "--redirect-stdout", action="store_true", default=False,
        help="Redirect stdout (& stderr, without -e) to file")
    option('-e', "--redirect-stderr", action="store_true", default=False,
        help="Redirect stderr to file")
    option("--stdout-file", metavar="FILE", default="simout",
        help="Filename for -r redirection [Default: %default]")
    option("--stderr-file", metavar="FILE", default="simerr",
        help="Filename for -e redirection [Default: %default]")
    option("--listener-mode", metavar="{on,off,auto}",
        choices=listener_modes, default="auto",
        help="Port (e.g., gdb) listener mode (auto: Enable if running " \
        "interactively) [Default: %default]")
    option("--listener-loopback-only", action="store_true", default=False,
        help="Port listeners will only accept connections over the " \
        "loopback device")
    option('-i', "--interactive", action="store_true", default=False,
        help="Invoke the interactive interpreter after running the script")
    option("--pdb", action="store_true", default=False,
        help="Invoke the python debugger before running the script")
    option('-p', "--path", metavar="PATH[:PATH]", action='append', split=':',
        help="Prepend PATH to the system path when invoking the script")
    option('-q', "--quiet", action="count", default=0,
        help="Reduce verbosity")
    option('-v', "--verbose", action="count", default=0,
        help="Increase verbosity")

    # Statistics options
    group("Statistics Options")
    option("--stats-file", metavar="FILE", default="stats.txt",
        help="Sets the output file for statistics [Default: %default]")

    # Configuration Options
    group("Configuration Options")
    option("--dump-config", metavar="FILE", default="config.ini",
        help="Dump configuration output file [Default: %default]")
    option("--json-config", metavar="FILE", default="config.json",
        help="Create JSON output of the configuration [Default: %default]")
    option("--dot-config", metavar="FILE", default="config.dot",
        help="Create DOT & pdf outputs of the configuration [Default: %default]")
    option("--dot-dvfs-config", metavar="FILE", default=None,
        help="Create DOT & pdf outputs of the DVFS configuration" + \
             " [Default: %default]")

    # Debugging options
    group("Debugging Options")
    option("--debug-break", metavar="TICK[,TICK]", action='append', split=',',
        help="Create breakpoint(s) at TICK(s) " \
             "(kills process if no debugger attached)")
    option("--debug-help", action='store_true',
        help="Print help on debug flags")
    option("--debug-flags", metavar="FLAG[,FLAG]", action='append', split=',',
        help="Sets the flags for debug output (-FLAG disables a flag)")
    option("--debug-start", metavar="TICK", type='int',
        help="Start debug output at TICK")
    option("--debug-end", metavar="TICK", type='int',
        help="End debug output at TICK")
    option("--debug-file", metavar="FILE", default="cout",
        help="Sets the output file for debug [Default: %default]")
    option("--debug-ignore", metavar="EXPR", action='append', split=':',
        help="Ignore EXPR sim objects")
    option("--remote-gdb-port", type='int', default=7000,
        help="Remote gdb base port (set to 0 to disable listening)")

    # Help options
    group("Help Options")
    option("--list-sim-objects", action='store_true', default=False,
        help="List all built-in SimObjects, their params and default values")

    # load the options.py config file to allow people to set their own
    # default options
    options_file = config.get('options.py')
    if options_file:
        scope = { 'options' : options }
        execfile(options_file, scope)

    arguments = options.parse_args()
    return options,arguments
Ejemplo n.º 8
0
        evaluator = WEREvaluator()
    elif args.evaluator == "cer":
        evaluator = CEREvaluator()
    else:
        raise RuntimeError("Unkonwn evaluation metric {}".format(
            args.evaluator))

    ref_corpus = read_data(args.ref_file)
    hyp_corpus = read_data(args.hyp_file)
    len_before = len(hyp_corpus)
    ref_corpus, hyp_corpus = zip(
        *filter(lambda x: NO_DECODING_ATTEMPTED not in x[1],
                zip(ref_corpus, hyp_corpus)))
    if len(ref_corpus) < len_before:
        print("> ignoring %s out of %s test sentences." %
              (len_before - len(ref_corpus), len_before))

    eval_score = evaluator.evaluate(ref_corpus, hyp_corpus)

    return eval_score


if __name__ == "__main__":

    parser = OptionParser()
    parser.add_task("evaluate", options)
    args = parser.args_from_command_line("evaluate", sys.argv[1:])

    score = xnmt_evaluate(args)
    print("{} Score = {}".format(args.evaluator, score))
Ejemplo n.º 9
0
                    self.model_serializer.save_to_file(self.args.model_file,
                                                       self.model_params,
                                                       self.model)
                else:
                    # otherwise: learning rate decay / early stopping
                    if self.args.lr_decay < 1.0:
                        self.learning_scale *= self.args.lr_decay
                        print('new learning rate: %s' %
                              (self.learning_scale * self.args.learning_rate))
                    if self.learning_scale * self.args.learning_rate < self.args.lr_threshold:
                        print('Early stopping')
                        self.early_stopping_reached = True

                self.trainer.update_epoch()
                self.translator.set_train(True)

        return math.exp(self.logger.epoch_loss / self.logger.epoch_words), \
               math.exp(self.logger.dev_loss / self.logger.dev_words)


if __name__ == "__main__":
    parser = OptionParser()
    parser.add_task("train", general_options + options)
    args = parser.args_from_command_line("train", sys.argv[1:])
    print("Starting xnmt-train:\nArguments: %r" % (args))

    xnmt_trainer = XnmtTrainer(args)

    while not xnmt_trainer.early_stopping_reached:
        xnmt_trainer.run_epoch()
Ejemplo n.º 10
0
                           help="use visualization")
    argparser.add_argument("--dynet-gpu",
                           action='store_true',
                           help="use GPU acceleration")
    argparser.add_argument("--dynet-gpu-ids", type=int)
    argparser.add_argument("--generate-doc",
                           action='store_true',
                           help="Do not run, output documentation instead")
    argparser.add_argument("experiments_file")
    argparser.add_argument("experiment_name",
                           nargs='*',
                           help="Run only the specified experiments")
    argparser.set_defaults(generate_doc=False)
    args = argparser.parse_args()

    config_parser = OptionParser()
    config_parser.add_task("preproc", xnmt_preproc.options)
    config_parser.add_task("train", xnmt_train.options)
    config_parser.add_task("decode", xnmt_decode.options)
    config_parser.add_task("evaluate", xnmt_evaluate.options)

    # Tweak the options to make config files less repetitive:
    # - Delete evaluate:evaluator, replace with exp:eval_metrics
    # - Delete decode:hyp_file, evaluate:hyp_file, replace with exp:hyp_file
    # - Delete train:model, decode:model_file, replace with exp:model_file
    config_parser.remove_option("evaluate", "evaluator")
    config_parser.remove_option("decode", "trg_file")
    config_parser.remove_option("evaluate", "hyp_file")
    config_parser.remove_option("train", "model_file")
    config_parser.remove_option("decode", "model_file")
Ejemplo n.º 11
0
def parse_options():
    import config
    from options import OptionParser

    options = OptionParser(usage=usage, version=version,
                           description=brief_copyright)
    option = options.add_option
    group = options.set_group

    # Help options
    option('-B', "--build-info", action="store_true", default=False,
        help="Show build information")
    option('-C', "--copyright", action="store_true", default=False,
        help="Show full copyright information")
    option('-R', "--readme", action="store_true", default=False,
        help="Show the readme")

    # Options for configuring the base simulator
    option('-d', "--outdir", metavar="DIR", default="m5out",
        help="Set the output directory to DIR [Default: %default]")
    option('-r', "--redirect-stdout", action="store_true", default=False,
        help="Redirect stdout (& stderr, without -e) to file")
    option('-e', "--redirect-stderr", action="store_true", default=False,
        help="Redirect stderr to file")
    option("--stdout-file", metavar="FILE", default="simout",
        help="Filename for -r redirection [Default: %default]")
    option("--stderr-file", metavar="FILE", default="simerr",
        help="Filename for -e redirection [Default: %default]")
    option('-i', "--interactive", action="store_true", default=False,
        help="Invoke the interactive interpreter after running the script")
    option("--pdb", action="store_true", default=False,
        help="Invoke the python debugger before running the script")
    option('-p', "--path", metavar="PATH[:PATH]", action='append', split=':',
        help="Prepend PATH to the system path when invoking the script")
    option('-q', "--quiet", action="count", default=0,
        help="Reduce verbosity")
    option('-v', "--verbose", action="count", default=0,
        help="Increase verbosity")

    # Statistics options
    group("Statistics Options")
    option("--stats-file", metavar="FILE", default="stats.txt",
        help="Sets the output file for statistics [Default: %default]")
    option("--carbon-server", action="store", default="127.0.0.1",
        help="Set the carbon server ip for carbon statistics [Default: %default]")
    option("--carbon-catalog", action="store", default="gem5test",
        help="Set the catalog for carbon statistics [Default: %default]")
    option("--carbon-regex", action="store", default="^[A-Za-z_]*\.\(\(switch_\)*cpu[s]*[0-9]*\.ipc\)*\(l2\.\([A-Za-z_]*\.\)*guestCapacity\)*\(mem_ctrls[0-9]*\.\([A-Za-z_]*\.\)*bw_total\)*$",
        help="Set the filter regex for carbon statistics [Default: %default]")
    #"(\w+\.)((\w*cpu\d*\.ipc)|(l2\.(\w+\.)*guestCapacity)|(mem_ctrls\d*\.(\w+\.)*bw_total))"

    # Configuration Options
    group("Configuration Options")
    option("--dump-config", metavar="FILE", default="config.ini",
        help="Dump configuration output file [Default: %default]")
    option("--json-config", metavar="FILE", default="config.json",
        help="Create JSON output of the configuration [Default: %default]")
    option("--dot-config", metavar="FILE", default="config.dot",
        help="Create DOT & pdf outputs of the configuration [Default: %default]")

    # Debugging options
    group("Debugging Options")
    option("--debug-break", metavar="TIME[,TIME]", action='append', split=',',
        help="Tick to create a breakpoint")
    option("--debug-help", action='store_true',
        help="Print help on debug flags")
    option("--debug-flags", metavar="FLAG[,FLAG]", action='append', split=',',
        help="Sets the flags for debug output (-FLAG disables a flag)")
    option("--debug-start", metavar="TIME", type='int',
        help="Start debug output at TIME (must be in ticks)")
    option("--debug-file", metavar="FILE", default="cout",
        help="Sets the output file for debug [Default: %default]")
    option("--debug-ignore", metavar="EXPR", action='append', split=':',
        help="Ignore EXPR sim objects")
    option("--remote-gdb-port", type='int', default=7000,
        help="Remote gdb base port (set to 0 to disable listening)")

    # Help options
    group("Help Options")
    option("--list-sim-objects", action='store_true', default=False,
        help="List all built-in SimObjects, their params and default values")

    # load the options.py config file to allow people to set their own
    # default options
    options_file = config.get('options.py')
    if options_file:
        scope = { 'options' : options }
        execfile(options_file, scope)

    arguments = options.parse_args()
    return options,arguments
Ejemplo n.º 12
0
Archivo: main.py Proyecto: liangwang/m5
from util import attrdict, fatal
import config
from options import OptionParser

__all__ = [ 'options', 'arguments', 'main' ]

usage="%prog [m5 options] script.py [script options]"
version="%prog 2.0"
brief_copyright='''
Copyright (c) 2001-2008
The Regents of The University of Michigan
All Rights Reserved
'''

options = OptionParser(usage=usage, version=version,
                       description=brief_copyright)
add_option = options.add_option
set_group = options.set_group
usage = options.usage

# Help options
add_option('-A', "--authors", action="store_true", default=False,
    help="Show author information")
add_option('-B', "--build-info", action="store_true", default=False,
    help="Show build information")
add_option('-C', "--copyright", action="store_true", default=False,
    help="Show full copyright information")
add_option('-R', "--readme", action="store_true", default=False,
    help="Show the readme")
add_option('-N', "--release-notes", action="store_true", default=False,
    help="Show the release notes")
Ejemplo n.º 13
0
import logging
import os
import sys

from __init__ import get_version
from config import Config
from episode import Episode
from errors import *
from logs import start_logging
from main import TvRenamr
from options import OptionParser

log = logging.getLogger("Core")

parser = OptionParser(usage="tvr [options] <file/folder>", version="Tv Renamr %s" % get_version())
options, args = parser.parse_args()


class FrontEnd:
    def __init__(self, path):
        # start logging
        if options.debug:
            options.log_level = 10
        start_logging(options.log_file, options.log_level, options.quiet)

        possible_config = (
            options.config,
            os.path.expanduser("~/.tvrenamr/config.yml"),
            os.path.join(sys.path[0], "config.yml"),
        )
Ejemplo n.º 14
0
def parse_options():
    import config
    from options import OptionParser

    options = OptionParser(usage=usage, version=version,
                           description=brief_copyright)
    option = options.add_option
    group = options.set_group

    # Help options
    option('-B', "--build-info", action="store_true", default=False,
        help="Show build information")
    option('-C', "--copyright", action="store_true", default=False,
        help="Show full copyright information")
    option('-R', "--readme", action="store_true", default=False,
        help="Show the readme")

    # Options for configuring the base simulator
    option('-d', "--outdir", metavar="DIR", default="m5out",
        help="Set the output directory to DIR [Default: %default]")
    option('-r', "--redirect-stdout", action="store_true", default=False,
        help="Redirect stdout (& stderr, without -e) to file")
    option('-e', "--redirect-stderr", action="store_true", default=False,
        help="Redirect stderr to file")
    option("--stdout-file", metavar="FILE", default="simout",
        help="Filename for -r redirection [Default: %default]")
    option("--stderr-file", metavar="FILE", default="simerr",
        help="Filename for -e redirection [Default: %default]")
    option('-i', "--interactive", action="store_true", default=False,
        help="Invoke the interactive interpreter after running the script")
    option("--pdb", action="store_true", default=False,
        help="Invoke the python debugger before running the script")
    option('-p', "--path", metavar="PATH[:PATH]", action='append', split=':',
        help="Prepend PATH to the system path when invoking the script")
    option('-q', "--quiet", action="count", default=0,
        help="Reduce verbosity")
    option('-v', "--verbose", action="count", default=0,
        help="Increase verbosity")
    option('-m', "--m5mbridge", "--mcpat", metavar="[ARG,...]", action="append", split=',', dest="m5mbridge",
        help="Load the M5M-bridge module. See its documentation for details. Optionally you can pass arguments to the m5mbridge. To do this you have to use either -m'key1=val1,key2=val2 or --m5mbridge='key1=val1,key2=val2' notation. The key and value are standard optional arguments in standard UNIX notation. Only the comma is special, because it's use to split the optional arguments.")

    # optparse does not support optional arguments to parameters. To make the
    # common case easier where one does not need to pass any arguments to the
    # m5mbridge, we change the commands to the correct syntax here:
    if '--m5mbridge' in sys.argv or '--mcpat' in sys.argv:
        idx = sys.argv.index('--m5mbridge')
        sys.argv[idx] = '--m5mbridge='
    if '-m' in sys.argv:
        idx = sys.argv.index('-m')
        sys.argv.insert(idx+1, '')

    # Statistics options
    group("Statistics Options")
    option("--stats-file", metavar="FILE", default="stats.txt",
        help="Sets the output file for statistics [Default: %default]")

    # Configuration Options
    group("Configuration Options")
    option("--dump-config", metavar="FILE", default="config.ini",
        help="Dump configuration output file [Default: %default]")
    option("--json-config", metavar="FILE", default="config.json",
        help="Create JSON output of the configuration [Default: %default]")
    option("--dot-config", metavar="FILE", default="config.dot",
        help="Create DOT & pdf outputs of the configuration [Default: %default]")

    # Debugging options
    group("Debugging Options")
    option("--debug-break", metavar="TIME[,TIME]", action='append', split=',',
        help="Cycle to create a breakpoint")
    option("--debug-help", action='store_true',
        help="Print help on trace flags")
    option("--debug-flags", metavar="FLAG[,FLAG]", action='append', split=',',
        help="Sets the flags for tracing (-FLAG disables a flag)")
    option("--remote-gdb-port", type='int', default=7000,
        help="Remote gdb base port (set to 0 to disable listening)")

    # Tracing options
    group("Trace Options")
    option("--trace-start", metavar="TIME", type='int',
        help="Start tracing at TIME (must be in ticks)")
    option("--trace-file", metavar="FILE", default="cout",
        help="Sets the output file for tracing [Default: %default]")
    option("--trace-ignore", metavar="EXPR", action='append', split=':',
        help="Ignore EXPR sim objects")

    # Help options
    group("Help Options")
    option("--list-sim-objects", action='store_true', default=False,
        help="List all built-in SimObjects, their params and default values")

    # load the options.py config file to allow people to set their own
    # default options
    options_file = config.get('options.py')
    if options_file:
        scope = { 'options' : options }
        execfile(options_file, scope)

    arguments = options.parse_args()
    return options,arguments