Пример #1
0
def _parse_raw_args(parser, args):
    """Simulate parsing by *parser*, return a list of tuples of
    (dest, option_string, args).

    If *args* contains unknown args or is otherwise malformed, we don't
    raise an error (we leave this to the actual argument parser).
    """
    results = []

    class RawArgAction(Action):
        def __call__(self, parser, namespace, values, option_string=None):
            # ignore *namespace*, append to *results*
            results.append((self.dest, option_string, values))

    def error(msg):
        raise ValueError(msg)

    raw_parser = ArgumentParser(add_help=False)
    raw_parser.error = error

    for action in parser._actions:
        # single args become single item lists
        nargs = 1 if action.nargs is None else action.nargs

        raw_parser.add_argument(*action.option_strings,
                                action=RawArgAction,
                                dest=action.dest,
                                nargs=nargs)

    # leave errors to the real parser
    raw_parser.parse_known_args(args)

    return results
Пример #2
0
def main():
    parser = ArgumentParser(description="A command line tool that converts magnet links in to .torrent files")
    parser.add_argument('-m','--magnet', help='The magnet url')
    parser.add_argument('-o','--output', help='The output torrent file name')

    #
    # This second parser is created to force the user to provide
    # the 'output' arg if they provide the 'magnet' arg.
    #
    # The current version of argparse does not have support
    # for conditionally required arguments. That is the reason
    # for creating the second parser
    #
    # Side note: one should look into forking argparse and adding this
    # feature.
    #
    conditionally_required_arg_parser = ArgumentParser(description="A command line tool that converts magnet links in to .torrent files")
    conditionally_required_arg_parser.add_argument('-m','--magnet', help='The magnet url')
    conditionally_required_arg_parser.add_argument('-o','--output', help='The output torrent file name', required=True)

    magnet = None
    output_name = None

    #
    # Attempting to retrieve args using the new method
    #
    args = vars(parser.parse_known_args()[0])
    if args['magnet'] is not None:
        magnet = args['magnet']
        argsHack = vars(conditionally_required_arg_parser.parse_known_args()[0])
        output_name = argsHack['output']
    if args['output'] is not None and output_name is None:
        output_name = args['output']
        if magnet is None:
            #
            # This is a special case.
            # This is when the user provides only the "output" args.
            # We're forcing him to provide the 'magnet' args in the new method
            #
            print ('usage: {0} [-h] [-m MAGNET] -o OUTPUT'.format(sys.argv[0]))
            print ('{0}: error: argument -m/--magnet is required'.format(sys.argv[0]))
            sys.exit()
    #
    # Defaulting to the old of doing things
    # 
    if output_name is None and magnet is None:
        if len(sys.argv) >= 2:
            magnet = sys.argv[1]
        if len(sys.argv) >= 3:
            output_name = sys.argv[2]

    print magnet, output_name

    magnet2torrent(magnet, output_name)
Пример #3
0
def main():
    """Main method in CLI method."""
    parser = ArgumentParser()
    parser.add_argument('-a', '--address', dest='address',
                        help='address of Locust Agent')
    parser.add_argument('-k', '--key', dest='key',
                        help='secret key for particular node')
    options, args = parser.parse_known_args()
    for arg in args:
        if arg.startswith('--'):
            option = arg[:arg.index('=')] if '=' in arg else arg
            parser.add_argument(option)
    all_options, args = parser.parse_known_args()
    command_options = dict((k, v) for k, v in all_options.__dict__.items() if
                           k not in options.__dict__)
    if not options.address:
        if environ.get('LOCUST_AGENT'):
            options.address = environ['LOCUST_AGENT']
        else:
            parser.error('Agent address is not specified. '
                         'Please provide -a|--address option '
                         'or set environment variable LOCUST_AGENT.')
    if not options.key:
        if environ.get('LOCUST_KEY'):
            options.key = environ['LOCUST_KEY']
        else:
            parser.error('Secret key is not specified. '
                         'Please provide -k | --key option '
                         'or set environment variable LOCUST_KEY.')

    if 'http' not in options.address:
        options.address = 'http://' + options.address
    command = []
    arguments = {}
    arguments.update(command_options)
    for arg in args:
        if '=' in arg:
            option, value = arg.split('=')
            arguments[option] = value
        else:
            command.append(arg)
    data = {}
    if command:
        data['command'] = '_'.join(command)
        if arguments:
            data['arguments'] = arguments
        data['key'] = options.key
    try:
        data = dumps(data) if data else None
        print urlopen(options.address, data).read()
    except HTTPError as error:
        print error
        print error.read()
Пример #4
0
class AvocadoApp(object):

    """
    Avocado application.
    """

    def __init__(self, external_plugins=None):
        # Catch all libc runtime errors to STDERR
        os.environ['LIBC_FATAL_STDERR_'] = '1'
        self.external_plugins = external_plugins
        self.plugin_manager = None
        self.app_parser = ArgumentParser(prog='avocado',
                                         version=VERSION,
                                         description='Avocado Test Runner')
        self.app_parser.add_argument('-V', '--verbose', action='store_true',
                                     help='print extra debug messages',
                                     dest='verbose')
        self.app_parser.add_argument('--logdir', action='store',
                                     help='Alternate logs directory',
                                     dest='logdir', default='')
        self.app_parser.add_argument('--loglevel', action='store',
                                     help='Debug Level',
                                     dest='log_level', default='')
        self.app_parser.add_argument('--plugins', action='store',
                                     help='Load extra plugins from directory',
                                     dest='plugins_dir', default='')

        args, _ = self.app_parser.parse_known_args()
        self.cmd_parser = self.app_parser.add_subparsers(title='subcommands',
                                                         description='valid subcommands',
                                                         help='subcommand help')

        self.load_plugin_manager(args.plugins_dir)
        args, _ = self.app_parser.parse_known_args()
        self.plugin_manager.activate(args)
        self.args = self.app_parser.parse_args()

    def load_plugin_manager(self, plugins_dir):
        """Load Plugin Manager.

        :param plugins_dir: Extra plugins directory.
        """
        self.plugin_manager = get_plugin_manager()
        self.plugin_manager.load_plugins(plugins_dir)
        if self.external_plugins:
            self.plugin_manager.add_plugins(self.external_plugins)
        self.plugin_manager.configure(self.app_parser, self.cmd_parser)

    def run(self):
        return self.args.func(self.args)
Пример #5
0
    def parseArgument(self):
        """Parse method specified options.There are two kinds of options.
    
        1) general options such as madlib_schema, algorithm, method, 
            target_base_name(test item name) and so on.
        2) specific options that come from algorithm, method above
        """

        #1) general options
        parser = ArgumentParser(description="MADLib Executor")
        parser.add_argument("--p"               , type=str, required = False, 
                            default = 'greenplum')
        parser.add_argument("--madlib_schema"   , type=str, required = False
                            , default = 'madlib')
        parser.add_argument("--algorithm"       , type=str, required = True)
        parser.add_argument("--method"          , type=str, required = True)
        parser.add_argument("--target_base_name", type=str, required = True)
        parser.add_argument("--run_id"          , type=str, required = False
                            , default = '0')
        parser.add_argument("--spec_file"       , type=str, required = False
                            , default = '../xml/config/' + Path.algorithmsSpecXml)
        parser.add_argument("--conn", "-C",
            metavar = "CONNSTR",
            default = '',
            dest = 'connection_string')

        parser.parse_known_args(args = self.argv, namespace = self)
        (self.logusername, self.logpassword, self.loghostname, self.logport,
            self.logdatabase, _) = parseConnectionStr(self.connection_string)

        #come out the executor specification
        self.spec = ExecutorSpec(self.spec_file, self.madlib_schema)

        #2) specific options
        parser = ArgumentParser(description="MADLib Executor")
        method = self.spec.getAlgorithm(self.algorithm).getMethod(self.method)
        paras = method.getInputParams()
        for para in paras:
            if para.getDefaultValue():
                parser.add_argument("--"+para.getName(), type=str, required = False
                    , default = para.getDefaultValue())
            else:
                parser.add_argument("--"+para.getName(), type=str, required = True)

        try:
            argument, _ = parser.parse_known_args(args = self.argv, namespace = self)
            self.argument = argument
        except Exception as e:
            print 'Error in ArgumentParser', str(e)
    def get_config_args(self, parser: argparse.ArgumentParser) -> argparse.Namespace:
        """Overrides the default CLI parsing.
        Sets the configuration parameters for what a SageMaker run should do.
        Note, this does not support the "play" mode.
        """
        # first, convert the parser to a Namespace object with all default values.
        empty_arg_list = []
        args, _ = parser.parse_known_args(args=empty_arg_list)
        parser = self.sagemaker_argparser()
        sage_args, unknown = parser.parse_known_args()
        
        # Now fill in the args that we care about.
        sagemaker_job_name = os.environ.get("sagemaker_job_name", "sagemaker-experiment")
        args.experiment_name = logger.get_experiment_name(sagemaker_job_name)
        
        # Override experiment_path used for outputs
        args.experiment_path = '/opt/ml/output/intermediate'
        rl_coach.logger.experiment_path = '/opt/ml/output/intermediate' # for gifs

        args.checkpoint_save_dir = '/opt/ml/output/data/checkpoint'
        args.checkpoint_save_secs = 10 # should avoid hardcoding
        # onnx for deployment for mxnet (not tensorflow)
        save_model = (sage_args.save_model == 1)
        backend = os.getenv('COACH_BACKEND', 'tensorflow')
        if save_model and backend == "mxnet":
            args.export_onnx_graph = True

        args.no_summary = True

        args.num_workers = sage_args.num_workers
        args.framework = Frameworks[backend]
        args.preset = sage_args.RLCOACH_PRESET
        # args.apply_stop_condition = True # uncomment for old coach behaviour

        self.hyperparameters = CoachConfigurationList()
        if len(unknown) % 2 == 1:
            raise ValueError("Odd number of command-line arguments specified. Key without value.")

        for i in range(0, len(unknown), 2):
            name = unknown[i]
            if name.startswith("--"):
                name = name[2:]
            else:
                raise ValueError("Unknown command-line argument %s" % name)
            val = unknown[i+1]
            self.map_hyperparameter(name, val)

        return args
Пример #7
0
def ctw(args, extraVMarguments=None):
    """run CompileTheWorld"""

    defaultCtwopts = '-Inline'

    parser = ArgumentParser(prog='mx ctw')
    parser.add_argument('--ctwopts', action='store', help='space separated JVMCI options used for CTW compilations (default: --ctwopts="' + defaultCtwopts + '")', default=defaultCtwopts, metavar='<options>')
    parser.add_argument('--cp', '--jar', action='store', help='jar or class path denoting classes to compile', metavar='<path>')

    args, vmargs = parser.parse_known_args(args)

    if args.ctwopts:
        # Replace spaces  with '#' since -G: options cannot contain spaces
        vmargs.append('-G:CompileTheWorldConfig=' + re.sub(r'\s+', '#', args.ctwopts))

    if args.cp:
        cp = os.path.abspath(args.cp)
    else:
        cp = join(_jdk.home, 'lib', 'modules', 'bootmodules.jimage')
        vmargs.append('-G:CompileTheWorldExcludeMethodFilter=sun.awt.X11.*.*')

    # suppress menubar and dock when running on Mac; exclude x11 classes as they may cause vm crashes (on Solaris)
    vmargs = ['-Djava.awt.headless=true'] + vmargs

    if _vm.jvmciMode == 'disabled':
        vmargs += ['-XX:+CompileTheWorld', '-Xbootclasspath/p:' + cp]
    else:
        if _vm.jvmciMode == 'jit':
            vmargs += ['-XX:+BootstrapJVMCI']
        vmargs += ['-G:CompileTheWorldClasspath=' + cp, 'com.oracle.graal.hotspot.CompileTheWorld']

    run_vm(vmargs + _noneAsEmptyList(extraVMarguments))
Пример #8
0
class Options:

    def __init__(self):
        self._init_parser()

    def _init_parser(self):
        # overrides usage that is by default something like:
        # usage: PROG [-h] [--foo [FOO]] bar [bar ...]
        usage = './bin/run_project'
        self.parser = ArgumentParser(usage=usage)
        # inits the argparser with an argument 'example' with
        # a default value 'example-value'
        self.parser.add_argument('-x',
                                 '--example',
                                 default='example-value', # specifies default value
                                 dest='example', # determines the name of the attribute that parse_args yields
                                 help='An example option') # specifies help message 

    def parse(self, args=None):
        # parse known args, returns a Namespace object
        # unknown args are ignored
        # Parse known args returns (Namespace_of_known, list_of_unknown)
        self.known, self.unknown = self.parser.parse_known_args(args)[:]
        if len(self.unknown) != 0:
            print '*WARN* Unknown args received: '+repr(self.unknown)
Пример #9
0
    def __init__(self, context,namespace = None):

        # it is either "" or the input given at creation of plugin
        self.namespace = self._parse_args(context.argv())


        super(saverPlugin, self).__init__(context)
        # Give QObjects reasonable names
        self.setObjectName('saverPlugin')

        # Process standalone plugin command-line arguments
        from argparse import ArgumentParser
        parser = ArgumentParser()
        # Add argument(s) to the parser.
        parser.add_argument("-q", "--quiet", action="store_true",
                      dest="quiet",
                      help="Put plugin in silent mode")
        args, unknowns = parser.parse_known_args(context.argv())
        if not args.quiet:
            print 'arguments: ', args
            print 'unknowns: ', unknowns
        
        
        
        # Create QWidget
        self._widget = QWidget()
        # Get path to UI file which is a sibling of this file
        # in this example the .ui and .py file are in the same folder
        ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'saver.ui')
        # Extend the widget with all attributes and children from UI file
        loadUi(ui_file, self._widget)
        # Give QObjects reasonable names
        self._widget.setObjectName('saverUi')
        # Show _widget.windowTitle on left-top of each plugin (when 
        # it's set in _widget). This is useful when you open multiple 
        # plugins at once. Also if you open multiple instances of your 
        # plugin at once, these lines add number to make it easy to 
        # tell from pane to pane.
        if context.serial_number() > 1:
            self._widget.setWindowTitle(self._widget.windowTitle() + (' (%d)' % context.serial_number()))
        # Add widget to the user interface
        context.add_widget(self._widget)

        # ---------------------------------------------- #
        # ---------------------------------------------- #

        # BUTTON TO START EXPERIMENT
        self._widget.ButtonSTART_SIM.stateChanged.connect(self.StartSimulatorService)

        # Button to Reset Simulator
        self._widget.ResetSimulator.clicked.connect(self.ResetSimulator)

        # BUTTON TO CONNECT TO QUALISYS
        self._widget.Qualisys.stateChanged.connect(self.QualisysConnect)

        # BUTTON TO CHANGE ID
        self._widget.changeID.clicked.connect(self.changeID)

        # Default Value for Id of Quad (as in QUALISYS computer)
        self._widget.ID.setValue(13)
Пример #10
0
    def __init__(self, context):
        super(utilityPlugin, self).__init__(context)
        # Give QObjects reasonable names
        self.setObjectName("utilityPlugin")

        # Process standalone plugin command-line arguments
        from argparse import ArgumentParser

        parser = ArgumentParser()
        # Add argument(s) to the parser.
        parser.add_argument("-q", "--quiet", action="store_true", dest="quiet", help="Put plugin in silent mode")
        args, unknowns = parser.parse_known_args(context.argv())
        if not args.quiet:
            print "arguments: ", args
            print "unknowns: ", unknowns

        # Create QWidget
        self._widget = QWidget()
        # Get path to UI file which is a sibling of this file
        # in this example the .ui and .py file are in the same folder
        ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "utility.ui")
        # Extend the widget with all attributes and children from UI file
        loadUi(ui_file, self._widget)
        # Give QObjects reasonable names
        self._widget.setObjectName("utilityUi")
        # Show _widget.windowTitle on left-top of each plugin (when
        # it's set in _widget). This is useful when you open multiple
        # plugins at once. Also if you open multiple instances of your
        # plugin at once, these lines add number to make it easy to
        # tell from pane to pane.
        if context.serial_number() > 1:
            self._widget.setWindowTitle(self._widget.windowTitle() + (" (%d)" % context.serial_number()))
        # Add widget to the user interface
        context.add_widget(self._widget)

        self.ID = 0

        self.State = QuadPositionDerived()
        self.Target = QuadPositionDerived()
        self.sub = ""
        self.name = ""
        self.pwd = os.environ["PWD"]

        self._widget.IrisInputBox.insertItems(0, ["iris1", "iris2", "iris3", "iris4", "iris5"])
        self._widget.bStart.clicked.connect(self.Start)
        self._widget.GravityCancelButton.clicked.connect(self.adjust_gravity_cancel)

        self._widget.XBox.setMinimum(-10.0)
        self._widget.XBox.setMaximum(10.0)
        self._widget.XBox.setSingleStep(0.1)
        self._widget.YBox.setMinimum(-10.0)
        self._widget.YBox.setMaximum(10.0)
        self._widget.YBox.setSingleStep(0.1)
        self._widget.ZBox.setMinimum(-10.0)
        self._widget.ZBox.setMaximum(10.0)
        self._widget.ZBox.setSingleStep(0.1)
        self._widget.GravitySpinBox.setMaximum(1800)
        self._widget.GravitySpinBox.setMinimum(1200)
        self._widget.GravitySpinBox.setSingleStep(10)
        self._widget.GravitySpinBox.setValue(1500)
Пример #11
0
def parse_global_args(arglist):
    """ Parse global arguments list. """

    usage = "%s [options] command [command_args]" % sys.argv[0]
    args = []

    while len(arglist) != 0 and arglist[0] not in CMDS:
        args.append(arglist[0])
        arglist.pop(0)

    parser = ArgumentParser(usage=usage)

    parser.add_argument("-a", "--hostname", dest="host", default="127.0.0.1",
                        help="Specify the EmPOWER host; default='127.0.0.1'")
    parser.add_argument("-p", "--port", dest="port", default="8888",
                        help="Specify the EmPOWER web port; default=8888")
    parser.add_argument("-u", "--user", dest="user", default="root",
                        help="EmPOWER admin user; default='root'")
    parser.add_argument("-n", "--no-passwd", action="store_true",
                        dest="no_passwd", default=False,
                        help="Run empowerctl with no password; default false")
    parser.add_argument("-f", "--passwd-file", dest="passwdfile",
                        default=None, help="Password file; default=none")
    parser.add_argument("-t", "--transport", dest="transport", default="http",
                        help="Specify the transport; default='http'")

    (args, _) = parser.parse_known_args(args)

    return args, arglist, parser
Пример #12
0
def main():
    parser = ArgumentParser()
    parser.add_argument("--dbfile", default="sums.db")
    parser.add_argument("--action", default="scan")
    parser.add_argument("--trashcan", default="trash.zip")
    parser.add_argument("--delete", action="store_true")
    parser.add_argument("--loglevel", type=int, default=10)
    parser.add_argument("--maxsize", type=int, default=(10*1024**2))
    opts,args = parser.parse_known_args()

    args = map(lambda x: unicode(x, "utf8"), args)

    if opts.delete:
        raise Exception("delete is true")

    Utils.delete = opts.delete

    if opts.loglevel:
        logging.getLogger().setLevel(opts.loglevel)

    db = Database('sqlite', os.path.abspath(opts.dbfile), create_db=True)
    init(db)
    Handlers.dispatch(opts.action, opts, args)

    pass
Пример #13
0
    def __init__(self, argv, classes, aliases):
        parser = ArgumentParser()

        self.config = Config()
        self.argv = argv
        
        all_arguments = {}
        def add_argument(name, *args, **kwargs):
            parser.add_argument(name, *args, **kwargs)
            all_arguments[name] = kwargs['dest']
        
        for cls in classes:
            for name in cls.class_traits(config=True):
                dest = cls.__name__ + '.' + name
                trait = getattr(cls, name)
                nargs = trait._metadata.get('nargs', None)
                add_argument('--' + name, type=str, dest=dest, nargs=nargs)

        for k, v in aliases.iteritems():
            try:
                add_argument('--' + k, type=str, dest=v, nargs=None)
            except ArgumentError:
                pass

        known_args, extra_args = parser.parse_known_args(argv)
        self.known_args = known_args
        self.extra_args = extra_args

        if len(extra_args) > 1:
            for item in extra_args[1:]:
                raise AliasError(item[2:], all_arguments)
Пример #14
0
def main():
    parser = ArgumentParser(add_help=False)
    appendIndependentArguments(parser)    
    args,unknown = parser.parse_known_args()
    
    parser = ArgumentParser(add_help=True,
                            description = description)
    appendIndependentArguments(parser)

    if args.manipulator.lower() == 'ln':
        parser.add_argument('-l','--axis-list',nargs='+',
                            type=int, default=[1, 2, 3],
                            help='List of axis (for use with LN manipulator)')
        parser.add_argument('-n','--axis-name',nargs='+',
                            type=str, default=['x','y','z'],
                            help='List of axis names (for use with LN manipulator)')
    args = parser.parse_args()
    # Defining it as a global so that I can close it atexit
    global manipulator
    if args.manipulator.lower() == 'ln':
        manipulator = LNmanipulator(port=args.device_port,
                            axislist=args.axis_list,
                            axisname=args.axis_name)
    mainApp = QtGui.QApplication(sys.argv)
    app = manipulator_control(opts = args)
    sys.exit(mainApp.exec_())
Пример #15
0
    def parse_args(self, argv):
        """Custom and check param list.
        """
        parser = ArgumentParser(prog="cocos %s" % self.__class__.plugin_name(),
                                description=self.__class__.brief_description())
        parser.add_argument('-c', dest='clean', action="store_true",
                            help=MultiLanguage.get_string('GEN_LIBS_ARG_CLEAN'))
        parser.add_argument('-e', dest='engine_path', help=MultiLanguage.get_string('GEN_LIBS_ARG_ENGINE'))
        parser.add_argument('-p', dest='platform', action="append", choices=['ios', 'mac', 'android', 'win32'],
                            help=MultiLanguage.get_string('GEN_LIBS_ARG_PLATFORM'))
        parser.add_argument('-m', "--mode", dest='compile_mode', default='release', choices=['debug', 'release'],
                            help=MultiLanguage.get_string('GEN_LIBS_ARG_MODE'))
        parser.add_argument('--dis-strip', dest='disable_strip', action="store_true",
                            help=MultiLanguage.get_string('GEN_LIBS_ARG_DISABLE_STRIP'))
        group = parser.add_argument_group(MultiLanguage.get_string('GEN_LIBS_GROUP_WIN'))
        group.add_argument('--vs', dest='vs_version', type=int, default=None,
                           help=MultiLanguage.get_string('GEN_LIBS_ARG_VS'))
        group = parser.add_argument_group(MultiLanguage.get_string('GEN_LIBS_GROUP_ANDROID'))
        group.add_argument("--app-abi", dest="app_abi",
                            help=MultiLanguage.get_string('GEN_LIBS_ARG_ABI'))
        group.add_argument("--ap", dest="android_platform",
                            help=MultiLanguage.get_string('COMPILE_ARG_AP'))

        (args, unknown) = parser.parse_known_args(argv)
        self.init(args)

        return args
Пример #16
0
    def __init__(self, context):
        super(ThrusterControl, self).__init__(context)
        # Give QObjects reasonable names
        self.setObjectName('ThrusterControl')

        # Process standalone plugin command-line arguments
        from argparse import ArgumentParser
        parser = ArgumentParser()
        # Add argument(s) to the parser.
        parser.add_argument("-q", "--quiet", action="store_true",
                      dest="quiet",
                      help="Put plugin in silent mode")
        args, unknowns = parser.parse_known_args(context.argv())

        if not args.quiet:
            print 'arguments: ', args
            print 'unknowns: ', unknowns

        self._mainWindow = ThrusterWidget()

        self._mainWindow.setWindowTitle(self._mainWindow.windowTitle())
        if context.serial_number() > 1:
            self._mainWindow.setWindowTitle(self._mainWindow.windowTitle() + (' (%d)' % context.serial_number()))
        self._mainWindow.setPalette(context._handler._main_window.palette())
        self._mainWindow.setAutoFillBackground(True)
        # Add widget to the user interface
        context.add_widget(self._mainWindow)
Пример #17
0
    def __init__(self, context):
        super(ReconfClientPlugin, self).__init__(context)
        # Give QObjects reasonable names
        self.setObjectName('ReconfClientPlugin')

        # Process standalone plugin command-line arguments
        from argparse import ArgumentParser
        parser = ArgumentParser()
        # Add argument(s) to the parser.
        parser.add_argument("-q", "--quiet", action="store_true",
                      dest="quiet",
                      help="Put plugin in silent mode")
        args, unknowns = parser.parse_known_args(context.argv())
        if not args.quiet:
            print 'arguments: ', args
            print 'unknowns: ', unknowns

        # Create QWidget
        self._widget = tiny_ref_gui.ReconfigureWidget()
        # Show _widget.windowTitle on left-top of each plugin (when 
        # it's set in _widget). This is useful when you open multiple 
        # plugins at once. Also if you open multiple instances of your 
        # plugin at once, these lines add number to make it easy to 
        # tell from pane to pane.
        if context.serial_number() > 1:
            self._widget.setWindowTitle(self._widget.windowTitle() + (' (%d)' % context.serial_number()))
        # Add widget to the user interface
        #parent = QTreeWidgetItem(self._widget.parameterTree)
        #parent.setText(0, "Name {}".format(2))
        #parent.setText(1, "Type")
        #parent.setText(2, "Value")
        #parent.setFlags(parent.flags() | Qt.ItemIsTristate | Qt.ItemIsUserCheckable | Qt.ItemIsEditable)
        context.add_widget(self._widget)
Пример #18
0
    def _cmd_parse(self):
        """Add command options, add options whthin this method."""
        blade_cmd_help = 'blade <subcommand> [options...] [targets...]'
        arg_parser = ArgumentParser(prog='blade', description=blade_cmd_help)

        sub_parser = arg_parser.add_subparsers(dest="command",
                        help="Available subcommands")

        build_parser = sub_parser.add_parser("build",
                        help="Build specified targets")

        run_parser = sub_parser.add_parser("run",
                        help="Build and runs a single target")

        test_parser = sub_parser.add_parser("test",
                        help="Build the specified targets and runs tests")

        clean_parser = sub_parser.add_parser("clean",
                        help="Remove all Blade-created output")

        query_parser = sub_parser.add_parser("query",
                        help="Execute a dependency graph query")

        self._add_build_arguments(build_parser)
        self._add_build_arguments(run_parser)
        self._add_build_arguments(test_parser)

        self._add_run_arguments(run_parser)
        self._add_test_arguments(test_parser)
        self._add_clean_arguments(clean_parser)
        self._add_query_arguments(query_parser)

        return arg_parser.parse_known_args()
Пример #19
0
    def __init__(self, context):
        super(MyPlugin, self).__init__(context)
        # Give QObjects reasonable names
        self.setObjectName('MyPlugin')

        # Process standalone plugin command-line arguments
        from argparse import ArgumentParser
        parser = ArgumentParser()
        # Add argument(s) to the parser
        parser.add_argument("-q", "--quiet", action="store_true",
                            dest="quiet",
                            help="Put plugin in silent mode")
        args, unknowns = parser.parse_known_args(context.argv())
        if not args.quiet:
            print 'arguments: ', args
            print 'unknowns: ', unknowns

        # Create QWidget
        self._widget = QWidget()
        # Get path to UI file which should be in the "resource" folder of this package
        ui_file = os.path.join(rospkg.RosPack().get_path('rqt_mypkg'), 'resource', 'MyPlugin.ui')
        # Extend the widget with all atrributes and children from UI File
        loadUi(ui_file, self._widget)
        # Give QObjects reasonable names
        self._widget.setObjectName('MyPluginUi')
        # Show _widget.windowTitle on left-top of each plugin(when it's set in _widget).
        # This is useful when you open multiple plugins aat once. Also if you open multiple
        # instances of your plugin at once, these lines add number to make it easy to
        # tell from pane to pane.
        if context.serial_number() > 1:
            self._widget.setWindowTitle(self._widget.windowTitle() + (' %d' % context.serial_number()))
        # Add widget to the user interface
        context.add_widget(self._widget)
        self._widget.cancelButton.clicked[bool].connect(self._handle_cancel_clicked)
        self._widget.okButton.clicked[bool].connect(self._handle_ok_clicked)
Пример #20
0
def parse_args(mode=True, name=None):
    mname = name
    if not name:
        mname = 'burp-ui'
    parser = ArgumentParser(prog=mname)
    parser.add_argument('-v', '--verbose', dest='log', help='increase output verbosity (e.g., -vv is more verbose than -v)', action='count')
    parser.add_argument('-d', '--debug', dest='debug', help='enable debug mode', action='store_true')
    parser.add_argument('-V', '--version', dest='version', help='print version and exit', action='store_true')
    parser.add_argument('-c', '--config', dest='config', help='burp-ui configuration file', metavar='<CONFIG>')
    parser.add_argument('-l', '--logfile', dest='logfile', help='output logs in defined file', metavar='<FILE>')
    parser.add_argument('-i', '--migrations', dest='migrations', help='migrations directory', metavar='<MIGRATIONSDIR>')
    parser.add_argument('remaining', nargs=REMAINDER)
    if mode:
        parser.add_argument('-m', '--mode', dest='mode', help='application mode', metavar='<agent|server|celery|manage|monitor|legacy>')

    options, unknown = parser.parse_known_args()
    if mode and options.mode and options.mode not in ['celery', 'manage', 'server']:
        options = parser.parse_args()
        unknown = []

    if options.version:
        from burpui.desc import __title__, __version__, __release__
        ver = '{}: v{}'.format(mname or __title__, __version__)
        if options.log:
            ver = '{} ({})'.format(ver, __release__)
        print(ver)
        sys.exit(0)

    return options, unknown
Пример #21
0
	def __init__(self, context):
		super(Dashboard, self).__init__(context)
		# Give QObjects reasonable names
		self.setObjectName('Dashboard')

		# Process standalone plugin command-line arguments
		from argparse import ArgumentParser
		parser = ArgumentParser()
		# Add argument(s) to the parser.
		parser.add_argument("-q", "--quiet", action="store_true",
			dest="quiet", help="Put plugin in silent mode")
		args, unknowns = parser.parse_known_args(context.argv())
		if not args.quiet:
			print 'arguments: ', args
			print 'unknowns: ', unknowns

			rospy.sleep(2.)
			self._layout = DashboardGrid()

		# Get path to UI file which is a sibling of this file
		# in this example the .ui and .py file are in the same folder
		##ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'MyPlugin.ui')
		# Extend the widget with all attributes and children from UI file
		##loadUi(ui_file, self._widget)
		# Give QObjects reasonable names
		self._layout.setObjectName('MyPluginUi')
		# Show _widget.windowTitle on left-top of each plugin (when
		# it's set in _widget). This is useful when you open multiple
		# plugins at once. Also if you open multiple instances of your
		# plugin at once, these lines add number to make it easy to
		# tell from pane to pane.
		if context.serial_number() > 1:
			self._layout.setWindowTitle(self._layout.windowTitle() + (' (%d)' % context.serial_number()))
		# Add widget to the user interface
		context.add_widget(self._layout)
Пример #22
0
    def __init__(self, context):
        name = "SimMan"
        resource = os.path.join(os.path.dirname(
                        os.path.realpath(__file__)), 
                        "resource/" + name + ".ui")
        GuiT = SimManGui
        RosT = SimManROS
        
        super(SimManRqt, self).__init__(context)
        self.setObjectName(name)

        from argparse import ArgumentParser
        parser = ArgumentParser()
        parser.add_argument("-q", "--quiet", action="store_true",
                      dest="quiet",
                      help="Put plugin in silent mode")
        args, unknowns = parser.parse_known_args(context.argv())
        if not args.quiet:
            print "arguments: ", args
            print "unknowns: ", unknowns

        # Create QWidget
        self._gui = GuiT()
        self._ros = RosT()

        loadUi(resource, self._gui)
        self._ros.setup(self._gui)
        self._gui.setup(name + "Rqt", self._ros)

        if context.serial_number() > 1:
            self._widget.setWindowTitle(self._widget.windowTitle() + 
                                        (" (%d)" % context.serial_number()))
        context.add_widget(self._gui) 
Пример #23
0
def main():
    """                                   /// WARNING ///
    The ThreatButt API tool embarks on a high speed, turbulent voyage with sudden turns and sharp drops.
    This tool employs safety restraints which may restrict certain guests from using due to their mental shape and size.
    You must posses the ability to remain in an upright position at all times while laying down.
    Persons with the following conditions should not use this tool:
    - Heart Condition or Abnormal Blood Pressure
    - Back, Neck or Similar Physical Condition
    - Expectant Parents
    - Motion Sickness or Dizziness
    - Media Sensitivity to Strobe Effects
    - Claustrophobia
    - Recent Surgery or Other Conditions That May Be Aggravated By This Tool
    """

    parser = ArgumentParser()
    parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + __version__)
    parser.add_argument('-i', '--ioc', dest='ioc', default=None,
                        help='[OPTIONAL] An IoC to attribute.')
    parser.add_argument('-m', '--md5', dest='md5', default=None,
                        help='[OPTIONAL] An MD5 hash.')
    parser.add_argument('--maltego', dest='maltego', default=False, action='store_true',
                        help='[OPTIONAL] Run in Maltego compatibility mode.')
    args, _ = parser.parse_known_args()

    tb = ThreatButt(args.maltego)

    if args.ioc:
        tb.clown_strike_ioc(args.ioc)

    elif args.md5:
        tb.bespoke_md5(args.md5)

    else:
        parser.print_help()
    def __init__(self, context):
        super(NodeManager, self).__init__(context)
        # Give QObjects reasonable names
        self.setObjectName('NodeManagerFKIE')

        # Process standalone plugin command-line arguments
        from argparse import ArgumentParser
        parser = ArgumentParser()
        # Add argument(s) to the parser.
        parser.add_argument("-q", "--quiet", action="store_true",
                      dest="quiet",
                      help="Put plugin in silent mode")
        args, unknowns = parser.parse_known_args(context.argv())
        if not args.quiet:
            print 'arguments: ', args
            print 'unknowns: ', unknowns
        node_manager_fkie.init_settings()
        masteruri = node_manager_fkie.settings().masteruri()
        node_manager_fkie.init_globals(masteruri)
        # Create QWidget
        try:
          self._widget = MainWindow()
#          self._widget.read_view_history()
        except Exception, e:
          msgBox = QMessageBox()
          msgBox.setText(str(e))
          msgBox.exec_()
          raise
Пример #25
0
def parse_arguments():
    usage = "python benchrun.py -f <list of test files> -t <list of thread configurations>"
    parser = ArgumentParser(description="Performance testing script framework thing.", usage=usage)

    parser.add_argument('-f', '--testfiles', dest='testfiles', nargs="+",
                        help='Provide a list of js test files to run',
                        default=None)
    parser.add_argument('-t', '--threads', dest='threads', nargs="+",
                        help='Specify which thread configuration to use',
                        type=int, default=[1, 2, 4, 8, 12, 16])
    parser.add_argument('-m', '--multidb', dest='multidb',
                        help='Specify how many databases the test should use',
                        type=int, default=1)
    parser.add_argument('-l', '--label', dest='reportlabel',
                        help='Specify the label for the report stats saved to bench_results db',
                        default='')
    parser.add_argument('--rhost', '--reporthost', dest='reporthost',
                        help='Host name of the mongod where the results will be saved',
                        default='localhost')
    parser.add_argument('--rport', '--reportport', dest='reportport',
                        help='Port of the mongod where the results will be saved',
                        default='27017')
    parser.add_argument('-s', '--shell', dest='shellpath',
                        help="Path to the mongo shell executable to use.",
                        default='mongo')

    return parser.parse_known_args()
Пример #26
0
    def __init__(self, context):
        super(TriangleGUI, self).__init__(context)
        # Give QObjects reasonable names
        self.setObjectName('TriangleGUI')
        
        # Process standalone plugin command-line arguments
        from argparse import ArgumentParser
        parser = ArgumentParser()
        # Add argument(s) to the parser.
        parser.add_argument("-q", "--quiet", action="store_true",
                            dest="quiet",
                            help="Put plugin in silent mode")
        args, unknowns = parser.parse_known_args(context.argv())
        self._toolbar = QToolBar()
        self._toolbar.addWidget(QLabel('Triangle'))
        
                                                                
        # Create a container widget and give it a layout
        self._container = QWidget()
        self._layout    = QVBoxLayout()
        self._container.setLayout(self._layout)
        
        self._layout.addWidget(self._toolbar)

        # Add a button for killing nodes
        self._go_button = QPushButton('Go')
        self._go_button.clicked.connect(self._go)
        self._layout.addWidget(self._go_button)
        
        self._clear_button = QPushButton('Clear')
        self._clear_button.clicked.connect(self._clear)
        self._layout.addWidget(self._clear_button)
        # self._step_run_button.setStyleSheet('QPushButton {color: black}')
        
        context.add_widget(self._container)
Пример #27
0
    def __init__(self, context):
        super(ToolBar, self).__init__(context)


        # Give QObjects reasonable names
        self.setObjectName('EnableAxis')

        # Process standalone plugin command-line arguments
        from argparse import ArgumentParser
        parser = ArgumentParser()
        # Add argument(s) to the parser.
        parser.add_argument("-q", "--quiet", action="store_true",
                      dest="quiet",
                      help="Put plugin in silent mode")
        args, unknowns = parser.parse_known_args(context.argv())

        if not args.quiet:
            print 'arguments: ', args
            print 'unknowns: ', unknowns

        self._toolbar = QToolBar()
        self._palette = Palette()
        self._enableAxisWidget = EnableAxisWidget()
        context._handler._main_window.setPalette(self._palette.palette())
        self._batteryWidget = BatteryWidget()

        # Add widget to the user interface
        self._toolbar.addWidget(self._enableAxisWidget)
        self._toolbar.addWidget(self._batteryWidget)
        context.add_toolbar(self._toolbar)
    def __init__(self, context):
        super(CalibrationControl, self).__init__(context)
        self.setObjectName('CalibrationControl')
        
        
        # Argument parsing
        from argparse import ArgumentParser
        parser = ArgumentParser()
        # Add argument(s) to the parser.
        parser.add_argument("-q", "--quiet", action="store_true",
                      dest="quiet",
                      help="Put plugin in silent mode")
        args, unknowns = parser.parse_known_args(context.argv())
        if not args.quiet:
            print 'arguments: ', args
            print 'unknowns: ', unknowns

        # Create QWidget
        self._widget = QWidget()
        # Get path to UI file which is a sibling of this file
        rp = rospkg.RosPack()
        ui_file = os.path.join(rp.get_path('industrial_calibration_gui'), 'resource', 'calibration_control.ui')
        loadUi(ui_file, self._widget)
        # Give QObjects reasonable names
        self._widget.setObjectName('calibration_control_Ui')
        
        # Custom code begins here
        self._widget.cal_button.clicked[bool].connect(self.__handle_cal_clicked)
        
        self.cal_service = rospy.ServiceProxy('calibration_service', Empty)
        
        # Add widget to the user interface
        context.add_widget(self._widget)
Пример #29
0
    def _launch_mpisub(self, args, site_dir):

        # extract the mpirun run argument
        parser = ArgumentParser(add_help=False)
        # these values are ignored. This is a hack to filter out unused argv.
        parser.add_argument("--single", default=False, action='store_true')
        parser.add_argument("--mpirun", default=None)
        parser.add_argument("--xterm", default=False, action='store_true')
        _args, additional = parser.parse_known_args()

        # now call with mpirun
        mpirun = args.mpirun.split()
        if args.xterm:
            mpirun.extend(['xterm', '-hold', '-e'])

        cmdargs = [sys.executable, '-u', sys.argv[0], '--mpisub']

        if site_dir is not None:
            # mpi subs will use system version of package
            cmdargs.extend(['--mpisub-site-dir=' + site_dir])

        # workaround the strict openmpi oversubscribe policy
        # the parameter is found from
        # https://github.com/open-mpi/ompi/blob/ba47f738871ff06b8e8f34b8e18282b9fe479586/orte/mca/rmaps/base/rmaps_base_frame.c#L169
        # see the faq:
        #   https://www.open-mpi.org/faq/?category=running#oversubscribing
        os.environ['OMPI_MCA_rmaps_base_oversubscribe'] = '1'

        os.execvp(mpirun[0], mpirun + cmdargs + additional)

        # if we are here os.execvp has failed; bail
        sys.exit(1)
Пример #30
0
def main():
    parser = ArgumentParser(
        description='compare the results of two benchmarks')
    parser.add_argument(
        'test1', metavar='test1', type=str, nargs=1,
        help='A benchmark executable or JSON output file')
    parser.add_argument(
        'test2', metavar='test2', type=str, nargs=1,
        help='A benchmark executable or JSON output file')
    # FIXME this is a dummy argument which will never actually match
    # any --benchmark flags but it helps generate a better usage message
    parser.add_argument(
        'benchmark_options', metavar='benchmark_option', nargs='*',
        help='Arguments to pass when running benchmark executables'
    )
    args, unknown_args = parser.parse_known_args()
    # Parse the command line flags
    test1 = args.test1[0]
    test2 = args.test2[0]
    if args.benchmark_options:
        print("Unrecognized positional argument arguments: '%s'"
              % args.benchmark_options)
        exit(1)
    benchmark_options = unknown_args
    check_inputs(test1, test2, benchmark_options)
    # Run the benchmarks and report the results
    json1 = gbench.util.run_or_load_benchmark(test1, benchmark_options)
    json2 = gbench.util.run_or_load_benchmark(test2, benchmark_options)
    output_lines = gbench.report.generate_difference_report(json1, json2)
    print 'Comparing %s to %s' % (test1, test2)
    for ln in output_lines:
        print(ln)
Пример #31
0
    def __init__(self, argv):
        """
        Initialize Eddy.
        :type argv: list
        """
        super().__init__(argv)

        parser = ArgumentParser()
        parser.add_argument('--nosplash', dest='nosplash', action='store_true')
        parser.add_argument('--tests', dest='tests', action='store_true')

        options, args = parser.parse_known_args(args=argv)

        self.inSocket = None
        self.inStream = None
        self.outSocket = QLocalSocket()
        self.outSocket.connectToServer(APPID)
        self.outStream = None
        self.isRunning = self.outSocket.waitForConnected()
        self.mainwindow = None
        self.pendingOpen = []
        self.server = None

        # We do not initialize a new instance of Eddy if there is a process running
        # and we are not executing the tests suite: we'll create a socket instead so we can
        # exchange messages between the 2 processes (this one and the already running one).
        if self.isRunning and not options.tests:
            self.outStream = QTextStream(self.outSocket)
            self.outStream.setCodec('UTF-8')
        else:
            self.server = QLocalServer()
            self.server.listen(APPID)
            self.outSocket = None
            self.outStream = None

            connect(self.server.newConnection, self.newConnection)
            connect(self.messageReceived, self.readMessage)

            ############################################################################################################
            #                                                                                                          #
            #   PERFORM EDDY INITIALIZATION                                                                            #
            #                                                                                                          #
            ############################################################################################################

            # Draw the splashscreen.
            self.splashscreen = None
            if not options.nosplash:
                self.splashscreen = SplashScreen(min_splash_time=4)
                self.splashscreen.show()

            # Setup layout.
            self.setStyle(Clean('Fusion'))
            with open(expandPath('@eddy/ui/clean.qss')) as sheet:
                self.setStyleSheet(sheet.read())

            # Create the main window.
            self.mainwindow = MainWindow()

            # Close the splashscreen.
            if self.splashscreen:
                self.splashscreen.wait(self.splashscreen.remaining)
                self.splashscreen.close()

            # Display the mainwindow.
            self.mainwindow.show()

            if Platform.identify() is Platform.Darwin:
                # On MacOS files being opened are handled as a QFileOpenEvent but since we don't
                # have a Main Window initialized we store them locally and we open them here.
                for filepath in self.pendingOpen:
                    self.openFile(filepath)
                self.pendingOpen = []
            else:
                # Perform document opening if files have been added to sys.argv. This is not
                # executed on Mac OS since this is already handled as a QFileOpenEvent instance.
                for filepath in argv:
                    self.openFile(filepath)
Пример #32
0
        "--end_learning_rate",
        default=2e-6,
        type=float,
        help="The ending learning rate when `--use_scheduler` is poly.",
    )
    parser.add_argument("--weight_decay", default=1e-2, type=float)
    parser.add_argument(
        "-l",
        "--log",
        dest="logLevel",
        default="INFO",
        choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
        help="Set the logging level (default: 'Info').",
    )

    main_args = parser.parse_known_args()

    if main_args[0].mode == "abstractive":
        parser = AbstractiveSummarizer.add_model_specific_args(parser)
    else:
        parser = ExtractiveSummarizer.add_model_specific_args(parser)

    main_args = parser.parse_args()

    # Setup logging config
    logging.basicConfig(
        format="%(asctime)s|%(name)s|%(levelname)s> %(message)s",
        level=logging.getLevelName(main_args.logLevel),
    )

    # Set the `nlp` logging verbosity since its default is not INFO.
Пример #33
0
def main(spider_name,
         thread_number=None,
         slave=False,
         settings='settings',
         network_logs=False,
         disable_proxy=False,
         ignore_lock=False,
         *args,
         **kwargs):
    default_logging(propagate_network_logger=network_logs)

    root_config = build_root_config(settings)
    spider_class = load_spider_class(root_config, spider_name)
    spider_config = build_spider_config(spider_class, root_config)

    spider_args = None
    if hasattr(spider_class, 'setup_arg_parser'):
        parser = ArgumentParser()
        spider_class.setup_arg_parser(parser)
        opts, trash = parser.parse_known_args()
        spider_args = vars(opts)

    if thread_number is None:
        thread_number = \
            int(spider_config.get('thread_number',
                                  deprecated_key='GRAB_THREAD_NUMBER'))

    stat_task_object = kwargs.get('stat_task_object', None)

    bot = spider_class(
        thread_number=thread_number,
        slave=slave,
        config=spider_config,
        network_try_limit=int(
            spider_config.get('network_try_limit',
                              deprecated_key='GRAB_NETWORK_TRY_LIMIT')),
        task_try_limit=int(
            spider_config.get('task_try_limit',
                              deprecated_key='GRAB_TASK_TRY_LIMIT')),
        args=spider_args,
    )
    opt_queue = spider_config.get('queue', deprecated_key='GRAB_QUEUE')
    if opt_queue:
        bot.setup_queue(**opt_queue)

    opt_cache = spider_config.get('cache', deprecated_key='GRAB_CACHE')
    if opt_cache:
        bot.setup_cache(**opt_cache)

    opt_proxy_list = spider_config.get('proxy_list',
                                       deprecated_key='GRAB_PROXY_LIST')
    if opt_proxy_list:
        if disable_proxy:
            logger.debug('Proxy servers disabled via command line')
        else:
            bot.load_proxylist(**opt_proxy_list)

    opt_ifaces = spider_config.get('command_interfaces',
                                   deprecated_key='GRAB_COMMAND_INTERFACES')
    if opt_ifaces:
        for iface_config in opt_ifaces:
            bot.controller.add_interface(**iface_config)

    # Dirty hack
    # FIXIT: REMOVE
    bot.dump_spider_stats = kwargs.get('dump_spider_stats')
    bot.stats_object = kwargs.get('stats_object')

    try:
        bot.run()
    except KeyboardInterrupt:
        pass

    stats = bot.render_stats(timing=spider_config.get(
        'display_timing', deprecated_key='GRAB_DISPLAY_TIMING'))

    if spider_config.get('display_stats', deprecated_key='GRAB_DISPLAY_STATS'):
        logger.debug(stats)

    pid = os.getpid()
    logger.debug('Spider pid is %d' % pid)

    if spider_config.get('save_report', deprecated_key='GRAB_SAVE_REPORT'):
        for subdir in (str(pid), 'last'):
            dir_ = 'var/%s' % subdir
            if not os.path.exists(dir_):
                os.mkdir(dir_)
            else:
                clear_directory(dir_)
            for key, lst in bot.items.iteritems():
                fname_key = key.replace('-', '_')
                bot.save_list(key, '%s/%s.txt' % (dir_, fname_key))
            with open('%s/report.txt' % dir_, 'wb') as out:
                out.write(stats)

    return {
        'spider_stats': bot.render_stats(timing=False),
        'spider_timing': bot.render_timing(),
    }
Пример #34
0
def parse_args_and_arch(
    parser: argparse.ArgumentParser,
    input_args: List[str] = None,
    parse_known: bool = False,
    suppress_defaults: bool = False,
    modify_parser: Optional[Callable[[argparse.ArgumentParser], None]] = None,
):
    """
    Args:
        parser (ArgumentParser): the parser
        input_args (List[str]): strings to parse, defaults to sys.argv
        parse_known (bool): only parse known arguments, similar to
            `ArgumentParser.parse_known_args`
        suppress_defaults (bool): parse while ignoring all default values
        modify_parser (Optional[Callable[[ArgumentParser], None]]):
            function to modify the parser, e.g., to set default values
    """
    if suppress_defaults:
        # Parse args without any default values. This requires us to parse
        # twice, once to identify all the necessary task/model args, and a second
        # time with all defaults set to None.
        args = parse_args_and_arch(
            parser,
            input_args=input_args,
            parse_known=parse_known,
            suppress_defaults=False,
        )
        suppressed_parser = argparse.ArgumentParser(add_help=False,
                                                    parents=[parser])
        suppressed_parser.set_defaults(
            **{k: None
               for k, v in vars(args).items()})
        args = suppressed_parser.parse_args(input_args)
        return argparse.Namespace(
            **{k: v
               for k, v in vars(args).items() if v is not None})

    from fairseq.models import ARCH_MODEL_REGISTRY, ARCH_CONFIG_REGISTRY

    # Before creating the true parser, we need to import optional user module
    # in order to eagerly import custom tasks, optimizers, architectures, etc.
    usr_parser = argparse.ArgumentParser(add_help=False, allow_abbrev=False)
    usr_parser.add_argument("--user-dir", default=None)
    usr_args, _ = usr_parser.parse_known_args(input_args)
    utils.import_user_module(usr_args)

    if modify_parser is not None:
        modify_parser(parser)

    # The parser doesn't know about model/criterion/optimizer-specific args, so
    # we parse twice. First we parse the model/criterion/optimizer, then we
    # parse a second time after adding the *-specific arguments.
    # If input_args is given, we will parse those args instead of sys.argv.
    args, _ = parser.parse_known_args(input_args)

    # Add model-specific args to parser.
    if hasattr(args, "arch"):
        model_specific_group = parser.add_argument_group(
            "Model-specific configuration",
            # Only include attributes which are explicitly given as command-line
            # arguments or which have default values.
            argument_default=argparse.SUPPRESS,
        )
        ARCH_MODEL_REGISTRY[args.arch].add_args(model_specific_group)

    # Add *-specific args to parser.
    from fairseq.registry import REGISTRIES

    for registry_name, REGISTRY in REGISTRIES.items():
        choice = getattr(args, registry_name, None)
        if choice is not None:
            cls = REGISTRY["registry"][choice]
            if hasattr(cls, "add_args"):
                cls.add_args(parser)
    if hasattr(args, "task"):
        from fairseq.tasks import TASK_REGISTRY

        TASK_REGISTRY[args.task].add_args(parser)
    if getattr(args, "use_bmuf", False):
        # hack to support extra args for block distributed data parallelism
        from fairseq.optim.bmuf import FairseqBMUF

        FairseqBMUF.add_args(parser)

    # Modify the parser a second time, since defaults may have been reset
    if modify_parser is not None:
        modify_parser(parser)

    # Parse a second time.
    if parse_known:
        args, extra = parser.parse_known_args(input_args)
    else:
        args = parser.parse_args(input_args)
        extra = None

    # Post-process args.
    if hasattr(args,
               "max_sentences_valid") and args.max_sentences_valid is None:
        args.max_sentences_valid = args.max_sentences
    if hasattr(args, "max_tokens_valid") and args.max_tokens_valid is None:
        args.max_tokens_valid = args.max_tokens
    if getattr(args, "memory_efficient_fp16", False):
        args.fp16 = True
    if getattr(args, "memory_efficient_bf16", False):
        args.bf16 = True
    args.tpu = getattr(args, "tpu", False)
    args.bf16 = getattr(args, "bf16", False)
    if args.bf16:
        args.tpu = True
    if args.tpu and args.fp16:
        raise ValueError("Cannot combine --fp16 and --tpu, use --bf16 on TPUs")

    if getattr(args, "seed", None) is None:
        args.seed = 1  # default seed for training
        args.no_seed_provided = True
    else:
        args.no_seed_provided = False

    # Apply architecture configuration.
    if hasattr(args, "arch"):
        ARCH_CONFIG_REGISTRY[args.arch](args)

    if parse_known:
        return args, extra
    else:
        return args
Пример #35
0
def main():
    prog = "python statistics.py WhatIsThis <manyPickles> WhatIsThis <manyPickles> [WhatIsThis <manyPickles>]"
    description = "Return some statistical information"

    parser = ArgumentParser(description=description, prog=prog)

    parser.add_argument("-p",
                        "--space",
                        dest="spaceFile",
                        help="Where is the space.py located?")
    parser.add_argument("-m",
                        "--maxEvals",
                        dest="maxEvals",
                        help="How many evaluations?")
    parser.add_argument("-s",
                        "--seed",
                        default="1",
                        dest="seed",
                        type=int,
                        help="Seed for the TPE algorithm")
    parser.add_argument(
        "-r",
        "--restore",
        action="store_true",
        dest="restore",
        help="When this flag is set state.pkl is restored in " +
        "the current working directory")
    parser.add_argument("--random",
                        default=False,
                        action="store_true",
                        dest="random",
                        help="Use a random search")
    parser.add_argument("--cwd",
                        help="Change the working directory before "
                        "optimizing.")

    args, unknown = parser.parse_known_args()

    if args.cwd:
        os.chdir(args.cwd)

    if not os.path.exists(args.spaceFile):
        logger.critical("Search space not found: %s" % args.spaceFile)
        sys.exit(1)

    # First remove ".py"
    space, ext = os.path.splitext(os.path.basename(args.spaceFile))

    # Then load dict searchSpace and out function cv.py
    sys.path.append("./")
    sys.path.append("")

    module = import_module(space)
    search_space = module.space
    fn = cv.main  # doForTPE

    if args.random:
        # We use a random search
        tpe_with_seed = partial(hyperopt.tpe.rand.suggest, seed=int(args.seed))
        logger.info("Using Random Search")
    else:
        tpe_with_seed = partial(hyperopt.tpe.suggest, seed=int(args.seed))

    # Now run TPE, emulate fmin.fmin()
    state_filename = "state.pkl"
    if args.restore:
        # We do not need to care about the state of the trials object since it
        # is only serialized in a synchronized state, there will never be a save
        # with a running experiment
        fh = open(state_filename)
        tmp_dict = cPickle.load(fh)
        domain = tmp_dict['domain']
        trials = tmp_dict['trials']
        print trials.__dict__
    else:
        domain = hyperopt.Domain(fn, search_space, rseed=int(args.seed))
        print(search_space)
        trials = hyperopt.Trials()
        fh = open(state_filename, "w")
        # By this we probably loose the seed; not too critical for a restart
        cPickle.dump({"trials": trials, "domain": domain}, fh)
        fh.close()

    for i in range(int(args.maxEvals) + 1):
        # in exhaust, the number of evaluations is max_evals - num_done
        rval = hyperopt.FMinIter(tpe_with_seed, domain, trials, max_evals=i)
        rval.exhaust()
        fh = open(state_filename, "w")
        cPickle.dump({"trials": trials, "domain": domain}, fh)
        fh.close()

    best = trials.argmin
    print "Best Value found for params:", best
Пример #36
0
def parse_known_args_and_warn(
    parser: argparse.ArgumentParser,
    other_args: List[str],
    export_allowed: int = NO_EXPORT,
    raw: bool = False,
    limit: int = 0,
):
    """Parses list of arguments into the supplied parser

    Parameters
    ----------
    parser: argparse.ArgumentParser
        Parser with predefined arguments
    other_args: List[str]
        List of arguments to parse
    export_allowed: int
        Choose from NO_EXPORT, EXPORT_ONLY_RAW_DATA_ALLOWED,
        EXPORT_ONLY_FIGURES_ALLOWED and EXPORT_BOTH_RAW_DATA_AND_FIGURES
    raw: bool
        Add the --raw flag
    limit: int
        Add a --limit flag with this number default
    Returns
    -------
    ns_parser:
        Namespace with parsed arguments
    """
    parser.add_argument(
        "-h", "--help", action="store_true", help="show this help message"
    )
    if export_allowed > NO_EXPORT:
        choices_export = []
        help_export = "Does not export!"

        if export_allowed == EXPORT_ONLY_RAW_DATA_ALLOWED:
            choices_export = ["csv", "json", "xlsx"]
            help_export = "Export raw data into csv, json, xlsx"
        elif export_allowed == EXPORT_ONLY_FIGURES_ALLOWED:
            choices_export = ["png", "jpg", "pdf", "svg"]
            help_export = "Export figure into png, jpg, pdf, svg "
        else:
            choices_export = ["csv", "json", "xlsx", "png", "jpg", "pdf", "svg"]
            help_export = "Export raw data into csv, json, xlsx and figure into png, jpg, pdf, svg "

        parser.add_argument(
            "--export",
            choices=choices_export,
            default="",
            type=str,
            dest="export",
            help=help_export,
        )

    if raw:
        parser.add_argument(
            "--raw",
            dest="raw",
            action="store_true",
            default=False,
            help="Flag to display raw data",
        )
    if limit > 0:
        parser.add_argument(
            "-l",
            "--limit",
            dest="limit",
            default=limit,
            help="Number of entries to show in data.",
            type=int,
        )

    if gtff.USE_CLEAR_AFTER_CMD:
        system_clear()

    try:
        (ns_parser, l_unknown_args) = parser.parse_known_args(other_args)
    except SystemExit:
        # In case the command has required argument that isn't specified
        console.print("")
        return None

    if ns_parser.help:
        txt_help = parser.format_help()
        console.print(f"[help]{txt_help}[/help]")
        return None

    if l_unknown_args:
        console.print(f"The following args couldn't be interpreted: {l_unknown_args}")

    return ns_parser
Пример #37
0
def run(argv):
    """Run a simulation or analysis."""
    usage = "%(prog)s run [options] [arg1, ...] [param=value, ...]"
    description = dedent("""\
      The list of arguments will be passed on to the simulation/analysis script.
      It should normally contain at least the name of a parameter file, but
      can also contain input files, flags, etc.

      If the parameter file should be in a format that Sumatra understands (see
      documentation), then the parameters will be stored to allow future
      searching, comparison, etc. of records.

      For convenience, it is possible to specify a file with default parameters
      and then specify those parameters that are different from the default values
      on the command line with any number of param=value pairs (note no space
      around the equals sign).""")
    parser = ArgumentParser(usage=usage, description=description)
    parser.add_argument(
        '-v',
        '--version',
        metavar='REV',
        help=
        "use version REV of the code (if this is not the same as the working copy, it will be checked out of the repository). If this option is not specified, the most recent version in the repository will be used. If there are changes in the working copy, the user will be prompted to commit them first"
    )
    parser.add_argument(
        '-l',
        '--label',
        help=
        "specify a label for the experiment. If no label is specified, one will be generated automatically."
    )
    parser.add_argument(
        '-r',
        '--reason',
        help="explain the reason for running this simulation/analysis.")
    parser.add_argument(
        '-e',
        '--executable',
        metavar='PATH',
        help=
        "Use this executable for this run. If not specified, the project's default executable will be used."
    )
    parser.add_argument(
        '-m',
        '--main',
        help=
        "the name of the script that would be supplied on the command line if running the simulation/analysis normally, e.g. init.hoc. If not specified, the project's default will be used."
    )
    parser.add_argument(
        '-n',
        '--num_processes',
        metavar='N',
        type=int,
        help=
        "run a distributed computation on N processes using MPI. If this option is not used, or if N=0, a normal, serial simulation/analysis is run."
    )
    parser.add_argument('-t',
                        '--tag',
                        help="tag you want to add to the project")
    parser.add_argument('-D',
                        '--debug',
                        action='store_true',
                        help="print debugging information.")
    parser.add_argument(
        '-i',
        '--stdin',
        help=
        "specify the name of a file that should be connected to standard input."
    )
    parser.add_argument(
        '-o',
        '--stdout',
        help=
        "specify the name of a file that should be connected to standard output."
    )

    args, user_args = parser.parse_known_args(argv)
    user_args = [str(arg) for arg in user_args]  # unifying types for Py2/Py3

    if args.debug:
        logger.setLevel(logging.DEBUG)

    project = load_project()
    parameters, input_data, script_args = parse_arguments(
        user_args, project.input_datastore, args.stdin, args.stdout,
        project.allow_command_line_parameters)
    if len(parameters) == 0:
        parameters = {}
    elif len(parameters) == 1:
        parameters = parameters[0]
    else:
        parser.error("Only a single parameter file allowed.")  # for now

    if args.executable:
        executable_path, executable_options = parse_executable_str(
            args.executable)
        executable = get_executable(path=executable_path)
        executable.options = executable_options
    elif args.main:
        executable = get_executable(
            script_file=args.main
        )  # should we take the options from project.default_executable, if they match?
    else:
        executable = 'default'
    if args.num_processes:
        if hasattr(project.default_launch_mode, 'n'):
            project.default_launch_mode.n = args.num_processes
        else:
            parser.error(
                "Your current launch mode does not support using multiple processes."
            )
    reason = args.reason or ''
    if reason:
        reason = reason.strip('\'"')

    label = args.label
    try:
        run_label = project.launch(parameters,
                                   input_data,
                                   script_args,
                                   label=label,
                                   reason=reason,
                                   executable=executable,
                                   main_file=args.main or 'default',
                                   version=args.version or 'current')
    except (UncommittedModificationsError, MissingInformationError) as err:
        print(err)
        sys.exit(1)
    if args.tag:
        project.add_tag(run_label, args.tag)
    if os.path.exists('.smt'):
        with open('.smt/labels', 'w') as f:
            f.write('\n'.join(project.get_labels()))
Пример #38
0
 def parse_args(self):
     parser = ArgumentParser(prog="dstack run gradio")
     if not self.workflow.data.get("workflow_name"):
         parser.add_argument("file", metavar="FILE", type=str)
     parser.add_argument("-r", "--requirements", type=str, nargs="?")
     parser.add_argument('-e', '--env', action='append', nargs="?")
     parser.add_argument('-a', '--artifact', action='append', nargs="?")
     # TODO: Support depends-on
     parser.add_argument("--working-dir", type=str, nargs="?")
     # parser.add_argument('--depends-on', action='append', nargs="?")
     parser.add_argument("--cpu", type=int, nargs="?")
     parser.add_argument("--memory", type=str, nargs="?")
     parser.add_argument("--gpu", type=int, nargs="?")
     parser.add_argument("--gpu-name", type=str, nargs="?")
     parser.add_argument("--gpu-memory", type=str, nargs="?")
     parser.add_argument("--shm-size", type=str, nargs="?")
     if not self.workflow.data.get("workflow_name"):
         parser.add_argument("args",
                             metavar="ARGS",
                             nargs=argparse.ZERO_OR_MORE)
     args, unknown = parser.parse_known_args(self.provider_args)
     args.unknown = unknown
     if not self.workflow.data.get("workflow_name"):
         self.workflow.data["file"] = args.file
         _args = args.unknown + args.args
         if _args:
             self.workflow.data["args"] = _args
     if args.requirements:
         self.workflow.data["requirements"] = args.requirements
     if args.artifact:
         self.workflow.data["artifacts"] = args.artifact
     if args.working_dir:
         self.workflow.data["working_dir"] = args.working_dir
     if args.env:
         environment = self.workflow.data.get("environment") or {}
         for e in args.env:
             if "=" in e:
                 tokens = e.split("=", maxsplit=1)
                 environment[tokens[0]] = tokens[1]
             else:
                 environment[e] = ""
         self.workflow.data["environment"] = environment
     if args.cpu or args.memory or args.gpu or args.gpu_name or args.gpu_memory or args.shm_size:
         resources = self.workflow.data["resources"] or {}
         self.workflow.data["resources"] = resources
         if args.cpu:
             resources["cpu"] = args.cpu
         if args.memory:
             resources["memory"] = args.memory
         if args.gpu or args.gpu_name or args.gpu_memory:
             gpu = self.workflow.data["resources"].get(
                 "gpu") or {} if self.workflow.data.get(
                     "resources") else {}
             if type(gpu) is int:
                 gpu = {"count": gpu}
             resources["gpu"] = gpu
             if args.gpu:
                 gpu["count"] = args.gpu
             if args.gpu_memory:
                 gpu["memory"] = args.gpu_memory
             if args.gpu_name:
                 gpu["name"] = args.gpu_name
         if args.shm_size:
             resources["shm_size"] = args.shm_size
                    default=False,
                    help="Overwrite existing output?  Default is to append.")

parser.add_argument("--parameters",
                    default=None,
                    action="store",
                    help="Select specific parameter set?")

parser.add_argument("--help", action="store_true", help="Show help")
parser.add_argument("--degree",
                    action="store",
                    default=1,
                    type=int,
                    help="degree of problem")

args, _ = parser.parse_known_args()

if args.help:
    help = parser.format_help()
    PETSc.Sys.Print("%s\n" % help)

problem_cls = module.Problem

if args.parameters is not None:
    if args.parameters not in problem_cls.parameter_names:
        raise ValueError("Unrecognised parameter '%s', not in %s",
                         args.parameters, problem_cls.parameter_names)
    parameter_names = [args.parameters]
else:
    parameter_names = problem_cls.parameter_names
Пример #40
0
def check_iargs_parser(iargs):
    """[For wrapping-up SPARK] Defines the possible arguments of the program, generates help
    and usage messages, and issues errors in case of invalid arguments.
    """

    parser = ArgumentParser(prog='spark.py',
                            description=dedent('''\
        SParsity-based Analysis of Reliable K-hubness (SPARK) for brain fMRI functional
        connectivity
        ____________________________________________________________________________________
         
           8b    d8 88   88 88     888888 88     888888 88   88 88b 88 88  dP 88 8b    d8
           88b  d88 88   88 88       88   88     88__   88   88 88Yb88 88odP  88 88b  d88
           88YbdP88 Y8   8P 88  .o   88   88     88""   Y8   8P 88 Y88 88"Yb  88 88YbdP88
           88 YY 88 `YbodP' 88ood8   88   88     88     `YbodP' 88  Y8 88  Yb 88 88 YY 88
           ------------------------------------------------------------------------------
                              Multimodal Functional Imaging Laboratory
        ____________________________________________________________________________________
         
        '''),
                            add_help=False,
                            formatter_class=RawTextHelpFormatter)

    # Required
    required = parser.add_argument_group(title='  REQUIRED arguments',
                                         description=dedent('''\
        __________________________________________________________________________________
        '''))
    required.add_argument(
        '--WRAP-UP',
        action='store_true',
        required=True,
        help='\n____________________________________________________________')
    required.add_argument('--fmri',
                          nargs=1,
                          type=str,
                          required=True,
                          help=dedent('''\
                          Path (absolute or relative) to the fMRI data to analyze.
                           
                          Notes:
                          - This file should be a valid fMRI file of a BIDS dataset.
                          - The filename will be used to name the outputs, for
                            example: 'kmap_sub-01_task-rest_bold.mat'.
                           
                          (type: %(type)s)
                          ____________________________________________________________
                          '''),
                          metavar='XXX',
                          dest='fmri')
    required.add_argument('--out-dir',
                          nargs=1,
                          type=str,
                          required=True,
                          help=dedent('''\
                          Path (absolute or relative) to the output directory (old
                          files might get replaced).
                          This directory should have been previously populated with
                          --SETUP and --RUN and at least contain the pipeline '.opt'
                          file corresponding to the input --fmri.

                          (type: %(type)s)
                          ____________________________________________________________
                          '''),
                          metavar=('XXX'),
                          dest='out_dir')

    # Optional
    optional = parser.add_argument_group(title='  OPTIONAL arguments',
                                         description=dedent('''\
        __________________________________________________________________________________
        '''))
    optional.add_argument('-h',
                          '--help',
                          action='help',
                          help=dedent('''\
                          Shows this help message and exits.
                          ____________________________________________________________
                          '''))
    optional.add_argument('--move-outputs',
                          action='store_true',
                          help=dedent('''\
                          If set, all outputs for this analysis will be moved to the
                          specified output directory --out-dir.
                          This flag is useful to merge in a single directory the
                          results of different analyses where the input fMRI were
                          different.
                           
                          (default: %(default)s)
                          ____________________________________________________________
                          '''),
                          dest='move_outputs')
    optional.add_argument('-v',
                          '--verbose',
                          action='store_true',
                          help=dedent('''\
                          If set, the program will provide some additional details.
                           
                          (default: %(default)s)
                          ____________________________________________________________
                          '''),
                          dest='verbose')

    oargs = vars(parser.parse_known_args(iargs)[0])

    # Hack: when (nargs=1) a list should not be returned
    for k in ['fmri', 'out_dir', 'move_outputs', 'verbose']:
        if type(oargs[k]) is list:
            oargs[k] = oargs[k][0]

    return oargs
Пример #41
0
def pre_parse(args):
    """
	Pre-parse path to input file (or some general options).
	"""

    if not args:
        args = ['--help']

    parser = ArgumentParser(
        add_help=False,
        usage='{0:s} CONFIGFILE --help'.format(basename(__file__)),
        description=
        'Command line interface for NoTeX functionality.\n\nCommands provided by extensions will become visible if you provide an input file!',
        epilog=
        'Provide an input file to load all commands provided by it\'s extensions.'
    )

    parser.add_argument(
        dest='input',
        nargs='?',
        type=str,
        default=SUPPRESS,
        help='The main input file (you can also use --input PATH).')
    parser.add_argument('--input', dest='input', type=str, help=SUPPRESS)

    parser.add_argument(
        '--only',
        dest='only',
        type=str,
        help=
        'A regular expression, only includes and renders with matching paths will be compiled.'
    )

    parser.add_argument('-v',
                        '--verbose',
                        dest='verbosity',
                        action='count',
                        default=0,
                        help='Show more information (can be stacked, -vv).')
    parser.add_argument('--version',
                        dest='show_version',
                        action='store_true',
                        help='Show version information and exit.')
    parser.add_argument('-h',
                        '--help',
                        dest='show_help',
                        action='store_true',
                        help='Show this help and exit.')

    opts, rest = parser.parse_known_args(args)

    # this is important, without it <resource> doesn't work if it and resource are both relative
    opts.input = realpath(opts.input)

    if opts.show_help:
        parser.print_help()
        exit()

    if opts.show_version:
        try:
            version = get_distribution('notex').version  #todo package name
        except DistributionNotFound as err:
            stderr.write(
                'Unable to obtain version through PyPi. Reason: {0:s}\n'.
                format(str(err)))
        else:
            stdout.write('{0:}\n'.format(version))
        exit()

    opts.verbosity += 1

    return opts, rest
Пример #42
0
from argparse import ArgumentParser
import tibia_terminator.main as start

if __name__ == "__main__":
    parser = ArgumentParser(description='Main Tibia Terminator Entry-Point')
    subparsers = parser.add_subparsers(title="Tibia Terminator Commands",
                                       dest="command",
                                       required=True)
    run_terminator_parser = subparsers.add_parser(
        "start", help="Run the Tibia Terminator")
    known, other_args = parser.parse_known_args()

    if known.command == "start":
        main_parser = start.build_parser()
        start.main(main_parser.parse_args(other_args))
Пример #43
0
                        default=8080,
                        action='store',
                        help='port number')
    parser.add_argument('-r',
                        '--rover',
                        dest='roverMode',
                        default=False,
                        action='store_true',
                        help='rover mode, to access motes connected on rovers')


webapp = None
if __name__ == "__main__":
    parser = ArgumentParser()
    _addParserArgs(parser)
    argspace = parser.parse_known_args()[0]

    # log
    log.info('Initializing OpenVisualizerWeb with options: \n\t{0}'.format(
        '\n    '.join([
            'host = {0}'.format(argspace.host),
            'port = {0}'.format(argspace.port)
        ])))

    #===== start the app
    app = openVisualizerApp.main(parser, argspace.roverMode)

    #===== add a web interface
    websrv = bottle.Bottle()
    webapp = OpenVisualizerWeb(app, websrv, argspace.roverMode)
Пример #44
0
import sys
import traceback
from argparse import ArgumentParser
from lib.utils import save_stderr, restore_stderr
from lib import extensions


parser = ArgumentParser()
parser.add_argument("--extension")
my_args, remaining_args = parser.parse_known_args()

extension_name = my_args.extension

# example: foo_bar_baz -> FooBarBaz
extension_class_name = extension_name.title().replace("_", "")

extension_class = getattr(extensions, extension_class_name)
extension = extension_class()

exception = None

save_stderr()
try:
    extension.affect(args=remaining_args)
except (SystemExit, KeyboardInterrupt):
    raise
except Exception:
    exception = traceback.format_exc()
finally:
    restore_stderr()
Пример #45
0
def main():
    """
    Run the muddery main program.
    """

    # set up argument parser

    parser = ArgumentParser(description=configs.CMDLINE_HELP,
                            formatter_class=argparse.RawTextHelpFormatter)

    parser.add_argument(
        '--init',
        nargs='+',
        action='store',
        dest="init",
        metavar="<gamename> [template name]",
        help=
        "creates a new gamedir 'name' at current location (from optional template)."
    )
    parser.add_argument(
        '--log',
        '-l',
        action='store_true',
        dest='tail_log',
        default=False,
        help="tail the portal and server logfiles and print to stdout")
    parser.add_argument('-v',
                        '--version',
                        action='store_true',
                        dest='show_version',
                        default=False,
                        help="show version info")
    parser.add_argument(
        '--upgrade',
        nargs='?',
        const='',
        dest='upgrade',
        metavar="[template]",
        help="Upgrade a game directory 'game_name' to the latest version.")
    parser.add_argument('--loaddata',
                        action='store_true',
                        dest='loaddata',
                        default=False,
                        help="Load local data from the worlddata folder.")
    parser.add_argument('--sysdata',
                        action='store_true',
                        dest='sysdata',
                        default=False,
                        help="Load system default data.")
    parser.add_argument('--migrate',
                        action='store_true',
                        dest='migrate',
                        default=False,
                        help="Migrate databases to new version.")
    parser.add_argument(
        '--port',
        '-p',
        nargs=1,
        action='store',
        dest='port',
        metavar="<N>",
        help=
        "Set game's network ports when init the game, recommend to use ports above 10000."
    )
    parser.add_argument("operation",
                        nargs='?',
                        default="noop",
                        help=configs.ARG_OPTIONS)
    parser.epilog = (
        "Common Django-admin commands are shell, dbshell, test and migrate.\n"
        "See the Django documentation for more management commands.")

    args, unknown_args = parser.parse_known_args()

    # handle arguments
    option = args.operation

    # make sure we have everything
    check_main_dependencies()
    from muddery.launcher import manager

    if not args:
        # show help pane
        manager.print_help()
        sys.exit()

    elif args.init:
        # initialization of game directory
        game_name = args.init[0]

        template = None
        if len(args.init) > 1:
            template = args.init[1]

        port = None
        if args.port:
            try:
                port = int(args.port[0])
            except:
                print("Port must be a number.")
                sys.exit(-1)

        try:
            manager.init_game(game_name, template, port)
        except Exception as e:
            print(e)
            sys.exit(-1)
        sys.exit()

    elif args.upgrade is not None:
        template = None
        if args.upgrade:
            template = args.upgrade

        try:
            manager.upgrade_game(template)
        except Exception as e:
            print(e)
            sys.exit(-1)
        sys.exit()

    elif args.loaddata:
        try:
            manager.load_game_data()
        except Exception as e:
            print(e)
            sys.exit(-1)
        sys.exit()

    elif args.sysdata:
        try:
            manager.load_system_data()
        except Exception as e:
            print(e)
            sys.exit(-1)
        sys.exit()

    elif args.migrate:
        try:
            manager.migrate_database()
        except Exception as e:
            print(e)
            sys.exit(-1)
        sys.exit()

    if args.show_version:
        # show the version info
        manager.show_version(option == "help")
        sys.exit()

    if option != "noop":
        try:
            manager.run_evennia(option)
        except Exception as e:
            print(e)
            sys.exit(-1)
        sys.exit()
    else:
        # no input; print muddery info
        manager.print_about()
        sys.exit()
Пример #46
0
def main():
    from argparse import ArgumentParser, RawDescriptionHelpFormatter

    VERSION = None
    if "--version" in sys.argv:
        # We cannot import sympy before this is run, because flags like -C and
        # -t set environment variables that must be set before SymPy is
        # imported. The only thing we need to import it for is to get the
        # version, which only matters with the --version flag.
        import sympy

        VERSION = sympy.__version__

    usage = "isympy [options] -- [ipython options]"
    parser = ArgumentParser(
        usage=usage,
        description=__doc__,
        formatter_class=RawDescriptionHelpFormatter,
    )

    parser.add_argument("--version", action="version", version=VERSION)

    parser.add_argument(
        "-c",
        "--console",
        dest="console",
        action="store",
        default=None,
        choices=["ipython", "python"],
        metavar="CONSOLE",
        help=("select type of interactive session: ipython | python; defaults "
              "to ipython if IPython is installed, otherwise python"),
    )

    parser.add_argument(
        "-p",
        "--pretty",
        dest="pretty",
        action="store",
        default=None,
        metavar="PRETTY",
        choices=["unicode", "ascii", "no"],
        help=("setup pretty printing: unicode | ascii | no; defaults to "
              "unicode printing if the terminal supports it, otherwise ascii"),
    )

    parser.add_argument(
        "-t",
        "--types",
        dest="types",
        action="store",
        default=None,
        metavar="TYPES",
        choices=["gmpy", "gmpy1", "python"],
        help=
        ("setup ground types: gmpy | gmpy1 | python; defaults to gmpy if gmpy2 "
         "or gmpy is installed, otherwise python"),
    )

    parser.add_argument(
        "-o",
        "--order",
        dest="order",
        action="store",
        default=None,
        metavar="ORDER",
        choices=[
            "lex",
            "grlex",
            "grevlex",
            "rev-lex",
            "rev-grlex",
            "rev-grevlex",
            "old",
            "none",
        ],
        help=
        ("setup ordering of terms: [rev-]lex | [rev-]grlex | [rev-]grevlex | old |"
         " none; defaults to lex"),
    )

    parser.add_argument(
        "-q",
        "--quiet",
        dest="quiet",
        action="store_true",
        default=False,
        help="print only version information at startup",
    )

    parser.add_argument(
        "-d",
        "--doctest",
        dest="doctest",
        action="store_true",
        default=False,
        help=
        "use the doctest format for output (you can just copy and paste it)",
    )

    parser.add_argument(
        "-C",
        "--no-cache",
        dest="cache",
        action="store_false",
        default=True,
        help="disable caching mechanism",
    )

    parser.add_argument(
        "-a",
        "--auto-symbols",
        dest="auto_symbols",
        action="store_true",
        default=False,
        help="automatically construct missing symbols",
    )

    parser.add_argument(
        "-i",
        "--int-to-Integer",
        dest="auto_int_to_Integer",
        action="store_true",
        default=False,
        help="automatically wrap int literals with Integer",
    )

    parser.add_argument(
        "-I",
        "--interactive",
        dest="interactive",
        action="store_true",
        default=False,
        help="equivalent to -a -i",
    )

    parser.add_argument(
        "-D",
        "--debug",
        dest="debug",
        action="store_true",
        default=False,
        help="enable debugging output",
    )

    (options, ipy_args) = parser.parse_known_args()
    if "--" in ipy_args:
        ipy_args.remove("--")

    if not options.cache:
        os.environ["SYMPY_USE_CACHE"] = "no"

    if options.types:
        os.environ["SYMPY_GROUND_TYPES"] = options.types

    if options.debug:
        os.environ["SYMPY_DEBUG"] = str(options.debug)

    if options.doctest:
        options.pretty = "no"
        options.console = "python"

    session = options.console

    if session is not None:
        ipython = session == "ipython"
    else:
        try:
            import IPython

            ipython = True
        except ImportError:
            if not options.quiet:
                from sympy.interactive.session import no_ipython

                print(no_ipython)
            ipython = False

    args = {
        "pretty_print": True,
        "use_unicode": None,
        "use_latex": None,
        "order": None,
        "argv": ipy_args,
    }

    if options.pretty == "unicode":
        args["use_unicode"] = True
    elif options.pretty == "ascii":
        args["use_unicode"] = False
    elif options.pretty == "no":
        args["pretty_print"] = False

    if options.order is not None:
        args["order"] = options.order

    args["quiet"] = options.quiet
    args["auto_symbols"] = options.auto_symbols or options.interactive
    args[
        "auto_int_to_Integer"] = options.auto_int_to_Integer or options.interactive

    from sympy.interactive import init_session

    init_session(ipython, **args)
Пример #47
0
except ImportError:
    print(
        "ERROR: Setuptools is required to install networkit python module.\nInstall via pip3 install setuptools."
    )
    sys.exit(1)

import os
import subprocess  #calling cmake, make and cython

################################################
# get the optional arguments for the compilation
################################################
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument("-j", "--jobs", dest="jobs", help="specify number of jobs")
(options, args) = parser.parse_known_args()
if options.jobs is not None:
    jobs = options.jobs
if "NETWORKIT_PARALLEL_JOBS" in os.environ:
    jobs = int(os.environ["NETWORKIT_PARALLEL_JOBS"])
else:
    import multiprocessing
    jobs = multiprocessing.cpu_count()
# make sure sys.argv is correct for setuptools
sys.argv = [__file__] + args

################################################
# compiler identification
################################################

candidates = [
def argparse():
    parser = ArgumentParser(
        description='Convert pl checkpoint to transformers format')
    parser.add_argument('ckpt_path', type=str)
    args, _ = parser.parse_known_args()
    return args
Пример #49
0
def unittest(args):
    """run the JUnit tests"""

    parser = ArgumentParser(
        prog='mx unittest',
        description='run the JUnit tests',
        formatter_class=RawDescriptionHelpFormatter,
        epilog=unittestHelpSuffix,
    )
    parser.add_argument('--blacklist',
                        help='run all testcases not specified in <file>',
                        metavar='<file>')
    parser.add_argument('--whitelist',
                        help='run testcases specified in <file> only',
                        metavar='<file>')
    parser.add_argument('--verbose',
                        help='enable verbose JUnit output',
                        action='store_true')
    parser.add_argument('--very-verbose',
                        help='enable very verbose JUnit output',
                        action='store_true')
    parser.add_argument(
        '--fail-fast',
        help='stop after first JUnit test class that has a failure',
        action='store_true')
    parser.add_argument(
        '--enable-timing',
        help='enable JUnit test timing (requires --verbose/--very-verbose)',
        action='store_true')
    parser.add_argument(
        '--regex',
        help='run only testcases matching a regular expression',
        metavar='<regex>')
    parser.add_argument('--color',
                        help='enable color output',
                        action='store_true')
    parser.add_argument('--gc-after-test',
                        help='force a GC after each test',
                        action='store_true')
    parser.add_argument('--suite',
                        help='run only the unit tests in <suite>',
                        metavar='<suite>')
    parser.add_argument('--repeat',
                        help='run only the unit tests in <suite>',
                        type=is_strictly_positive)
    eagerStacktrace = parser.add_mutually_exclusive_group()
    eagerStacktrace.add_argument(
        '--eager-stacktrace',
        action='store_const',
        const=True,
        dest='eager_stacktrace',
        help='print test errors as they occur (default)')
    eagerStacktrace.add_argument(
        '--no-eager-stacktrace',
        action='store_const',
        const=False,
        dest='eager_stacktrace',
        help='print test errors after all tests have run')

    ut_args = []
    delimiter = False
    # check for delimiter
    while len(args) > 0:
        arg = args.pop(0)
        if arg == '--':
            delimiter = True
            break
        ut_args.append(arg)

    if delimiter:
        # all arguments before '--' must be recognized
        parsed_args = parser.parse_args(ut_args)
    else:
        # parse all know arguments
        parsed_args, args = parser.parse_known_args(ut_args)

    if parsed_args.whitelist:
        try:
            with open(parsed_args.whitelist) as fp:
                parsed_args.whitelist = [
                    re.compile(fnmatch.translate(l.rstrip()))
                    for l in fp.readlines() if not l.startswith('#')
                ]
        except IOError:
            mx.log('warning: could not read whitelist: ' +
                   parsed_args.whitelist)
    if parsed_args.blacklist:
        try:
            with open(parsed_args.blacklist) as fp:
                parsed_args.blacklist = [
                    re.compile(fnmatch.translate(l.rstrip()))
                    for l in fp.readlines() if not l.startswith('#')
                ]
        except IOError:
            mx.log('warning: could not read blacklist: ' +
                   parsed_args.blacklist)
    if parsed_args.eager_stacktrace is None:
        parsed_args.eager_stacktrace = True

    _unittest(args, ['@Test', '@Parameters'], **parsed_args.__dict__)
Пример #50
0
 def parse_known_args(self, *args, **kwargs):
     args, remainder = ArgumentParser.parse_known_args(
         self, *args, **kwargs)
     return (self.validate(args), remainder)
Пример #51
0
def create_trial_from_spec(spec: dict, output_path: str,
                           parser: argparse.ArgumentParser, **trial_kwargs):
    """Creates a Trial object from parsing the spec.

    Args:
        spec: A resolved experiment specification. Arguments should
            The args here should correspond to the command line flags
            in ray.tune.experiment.config_parser.
        output_path: A specific output path within the local_dir.
            Typically the name of the experiment.
        parser: An argument parser object from
            make_parser.
        trial_kwargs: Extra keyword arguments used in instantiating the Trial.

    Returns:
        A trial object with corresponding parameters to the specification.
    """
    global _cached_pgf

    spec = spec.copy()
    resources = spec.pop("resources_per_trial", None)

    try:
        args, _ = parser.parse_known_args(to_argv(spec))
    except SystemExit:
        raise TuneError("Error parsing args, see above message", spec)

    if resources:
        if isinstance(resources, PlacementGroupFactory):
            trial_kwargs["placement_group_factory"] = resources
        else:
            # This will be converted to a placement group factory in the
            # Trial object constructor
            try:
                trial_kwargs["resources"] = json_to_resources(resources)
            except (TuneError, ValueError) as exc:
                raise TuneError("Error parsing resources_per_trial",
                                resources) from exc

    remote_checkpoint_dir = spec.get("remote_checkpoint_dir")

    sync_config = spec.get("sync_config", SyncConfig())
    if (sync_config.syncer is None or sync_config.syncer == "auto"
            or isinstance(sync_config.syncer, Syncer)):
        custom_syncer = sync_config.syncer
    else:
        raise ValueError(
            f"Unknown syncer type passed in SyncConfig: {type(sync_config.syncer)}. "
            f"Note that custom sync functions and templates have been deprecated. "
            f"Instead you can implement you own `Syncer` class. "
            f"Please leave a comment on GitHub if you run into any issues with this: "
            f"https://github.com/ray-project/ray/issues")

    return Trial(
        # Submitting trial via server in py2.7 creates Unicode, which does not
        # convert to string in a straightforward manner.
        trainable_name=spec["run"],
        # json.load leads to str -> unicode in py2.7
        config=spec.get("config", {}),
        local_dir=os.path.join(spec["local_dir"], output_path),
        # json.load leads to str -> unicode in py2.7
        stopping_criterion=spec.get("stop", {}),
        remote_checkpoint_dir=remote_checkpoint_dir,
        custom_syncer=custom_syncer,
        checkpoint_freq=args.checkpoint_freq,
        checkpoint_at_end=args.checkpoint_at_end,
        sync_on_checkpoint=sync_config.sync_on_checkpoint,
        keep_checkpoints_num=args.keep_checkpoints_num,
        checkpoint_score_attr=args.checkpoint_score_attr,
        export_formats=spec.get("export_formats", []),
        # str(None) doesn't create None
        restore_path=spec.get("restore"),
        trial_name_creator=spec.get("trial_name_creator"),
        trial_dirname_creator=spec.get("trial_dirname_creator"),
        log_to_file=spec.get("log_to_file"),
        # str(None) doesn't create None
        max_failures=args.max_failures,
        **trial_kwargs,
    )
Пример #52
0
def parse_args(sys_args):
    parser = ArgumentParser()
    parser.add_argument("--world-size", type=int, nargs=2, default=(50, 50))
    return parser.parse_known_args(sys_args)
Пример #53
0
    # cache = "/cluster/projects/radiomics/Temp/colin/isotropic_nrrd/unpaired"
    cache = "/cluster/home/carrowsm/img-cache"
    checkpoint_path = "/cluster/home/carrowsm/logs/cycleGAN/8_256_256px/2u1-0/version_2/checkpoints/epoch=48.ckpt"

    parser = ArgumentParser()

    # Paths to data and logs
    parser.add_argument("--csv_path", type=str, default=csv_path,
        help="Path to the CSV containing all image DA statuses and DA locations")
    parser.add_argument("--in_img_dir", default=img_dir, type=str,
                        help="Path to the input image data (DICOM).")
    parser.add_argument("--cache_dir", default=cache, type=str,
                        help="Where to cache images for model input.")
    parser.add_argument("--out_img_dir", default=log_dir, type=str,
                        help='Where to save clean output images.')

    ### Hyperparams for model testing ###
    parser.add_argument("--n_gpus", type=int, default=1,
                        help="Number of GPUs to use for training")
    parser.add_argument("--n_cpus", type=int, default=1,
                        help="Number of parallel workers to use for data loading.")

    ### Model selection and training parameters ###
    parser.add_argument("--checkpoint", type=str, default=checkpoint_path,
    help="The path to a checkpoint file. If 'None', training will start from scratch.")

    args, unparsed = parser.parse_known_args()


    main(args)
Пример #54
0
    def configure(self):
        defaults = {}
        defaults["message"] = "UNCLASSIFIED"
        defaults["fgcolor"] = "#FFFFFF"
        defaults["bgcolor"] = "#007A33"
        defaults["face"] = "liberation-sans"
        defaults["size"] = "small"
        defaults["weight"] = "bold"
        defaults["show_top"] = True
        defaults["show_bottom"] = True
        defaults["hres"] = 0
        defaults["vres"] = 0
        defaults["sys_info"] = False
        defaults["opacity"] = 0.75
        defaults["esc"] = True
        defaults["spanning"] = False

        # Check if a configuration file was passed in from the command line
        default_heading = DEFAULTSECT
        conf_parser = ArgumentParser(
            formatter_class=RawDescriptionHelpFormatter, add_help=False)
        conf_parser.add_argument("-c",
                                 "--config",
                                 help="Specify the configuration file",
                                 metavar="FILE")
        conf_parser.add_argument("--heading",
                                 help="Specify the config. section to use.",
                                 default=default_heading)
        options, args = conf_parser.parse_known_args()

        config_file = None
        if options.config:
            config_file = os.path.abspath(options.config)
            if not os.path.isfile(config_file):
                print("ERROR: Specified configuration file does not exist.")
                sys.exit(1)
        else:
            config_file = os.path.abspath(CONF_FILE)
            if not os.path.isfile(config_file):
                config_file = None

        # In order to maintain backwards compatibility with the way the
        # previous configuration file format, a dummy section may need
        # to be added to the configuration file.  If this is the case,
        # a temporary file is used in order to avoid overwriting the
        # user's configuration.
        config = ConfigParser()

        if config_file is not None:
            fp = open(config_file, "r")
            while True:
                try:
                    if python.major is 3:
                        config.read_file(fp, source=config_file)
                    else:
                        config.readfp(fp, config_file)
                    break
                except MissingSectionHeaderError:
                    # Recreate the file, adding a default section.
                    fp.close()
                    fp = TemporaryFile()
                    with open(config_file) as original:
                        fp.write("[%s]\n" % default_heading + original.read())
                    fp.seek(0)
            fp.close()  # If this was a temporary file it will now be deleted.

        # ConfigParser treats everything as strings and any quotation
        # marks in a setting are explicitly added to the string.
        # One way to fix this is to add everything to the defaults and
        # then strip the quotation marks off of everything.
        defaults.update(dict(config.items(options.heading)))
        for key, val in defaults.items():
            if config.has_option(options.heading, key):
                defaults[key] = val.strip("\"'")
        # TODO: This coercion section is hacky and should be fixed.
        for key in ["show_top", "show_bottom", "sys_info", "esc", "spanning"]:
            if config.has_option(options.heading, key):
                defaults[key] = config.getboolean(options.heading, key)
        for key in ["hres", "vres"]:
            if config.has_option(options.heading, key):
                defaults[key] = config.getint(options.heading, key)
        for key in ["opacity"]:
            if config.has_option(options.heading, key):
                defaults[key] = config.getfloat(options.heading, key)

        # Use the global config to set defaults for command line options
        parser = ArgumentParser(parents=[conf_parser])
        parser.add_argument("-m",
                            "--message",
                            default=defaults["message"],
                            help="Set the Classification message")
        parser.add_argument("-f",
                            "--fgcolor",
                            default=defaults["fgcolor"],
                            help="Set the Foreground (text) color")
        parser.add_argument("-b",
                            "--bgcolor",
                            default=defaults["bgcolor"],
                            help="Set the Background color")
        parser.add_argument("-x",
                            "--hres",
                            default=defaults["hres"],
                            type=int,
                            help="Set the Horizontal Screen Resolution")
        parser.add_argument("-y",
                            "--vres",
                            default=defaults["vres"],
                            type=int,
                            help="Set the Vertical Screen Resolution")
        parser.add_argument(
            "-o",
            "--opacity",
            default=defaults["opacity"],
            type=float,
            dest="opacity",
            help="Set the window opacity for composted window managers")
        parser.add_argument("--face",
                            default=defaults["face"],
                            help="Font face")
        parser.add_argument("--size",
                            default=defaults["size"],
                            help="Font size")
        parser.add_argument("--weight",
                            default=defaults["weight"],
                            help="Set the Font weight")
        parser.add_argument("--disable-esc-msg",
                            default=defaults["esc"],
                            dest="esc",
                            action="store_false",
                            help="Disable the 'ESC to hide' message")
        parser.add_argument("--hide-top",
                            default=defaults["show_top"],
                            dest="show_top",
                            action="store_false",
                            help="Disable the top banner")
        parser.add_argument("--hide-bottom",
                            default=defaults["show_bottom"],
                            dest="show_bottom",
                            action="store_false",
                            help="Disable the bottom banner")
        parser.add_argument("--system-info",
                            default=defaults["sys_info"],
                            dest="sys_info",
                            action="store_true",
                            help="Show user and hostname in the top banner")
        parser.add_argument(
            "--enable-spanning",
            default=defaults["spanning"],
            dest="spanning",
            action="store_true",
            help="Enable banner(s) to span across screens as a single banner")

        options = parser.parse_args()
        return options
Пример #55
0
def argparse():
    parser = ArgumentParser(description='Make dataset')
    parser.add_argument('--test_size', type=float, default=0.1)
    args, _ = parser.parse_known_args()
    return args
Пример #56
0
    def main(self,
             argv=None,
             standalone=None,
             plugin_argument_provider=None,
             plugin_manager_settings_prefix=''):
        if argv is None:
            argv = sys.argv

        # extract --args and everything behind manually since argparse can not handle that
        arguments = argv[1:]

        # extract plugin specific args when not being invoked in standalone mode programmatically
        if not standalone:
            plugin_args = []
            if '--args' in arguments:
                index = arguments.index('--args')
                plugin_args = arguments[index + 1:]
                arguments = arguments[0:index + 1]

        parser = ArgumentParser(os.path.basename(Main.main_filename),
                                add_help=False)
        self.add_arguments(parser,
                           standalone=bool(standalone),
                           plugin_argument_provider=plugin_argument_provider)
        self._options = parser.parse_args(arguments)

        if standalone:
            # rerun parsing to separate common arguments from plugin specific arguments
            parser = ArgumentParser(os.path.basename(Main.main_filename),
                                    add_help=False)
            self.add_arguments(parser, standalone=bool(standalone))
            self._options, plugin_args = parser.parse_known_args(arguments)
        self._options.plugin_args = plugin_args

        # set default values for options not available in standalone mode
        if standalone:
            self._options.freeze_layout = False
            self._options.lock_perspective = False
            self._options.multi_process = False
            self._options.perspective = None
            self._options.perspective_file = None
            self._options.standalone_plugin = standalone
            self._options.list_perspectives = False
            self._options.list_plugins = False
            self._options.command_pid = None
            self._options.command_start_plugin = None
            self._options.command_switch_perspective = None
            self._options.embed_plugin = None
            self._options.embed_plugin_serial = None
            self._options.embed_plugin_address = None

        # check option dependencies
        try:
            if self._options.plugin_args and not self._options.standalone_plugin and not self._options.command_start_plugin and not self._options.embed_plugin:
                raise RuntimeError(
                    'Option --args can only be used together with either --standalone, --command-start-plugin or --embed-plugin option'
                )

            if self._options.freeze_layout and not self._options.lock_perspective:
                raise RuntimeError(
                    'Option --freeze_layout can only be used together with the --lock_perspective option'
                )

            list_options = (self._options.list_perspectives,
                            self._options.list_plugins)
            list_options_set = [
                opt for opt in list_options if opt is not False
            ]
            if len(list_options_set) > 1:
                raise RuntimeError(
                    'Only one --list-* option can be used at a time')

            command_options = (self._options.command_start_plugin,
                               self._options.command_switch_perspective)
            command_options_set = [
                opt for opt in command_options if opt is not None
            ]
            if len(command_options_set) > 0 and not self._dbus_available:
                raise RuntimeError(
                    'Without DBus support the --command-* options are not available'
                )
            if len(command_options_set) > 1:
                raise RuntimeError(
                    'Only one --command-* option can be used at a time (except --command-pid which is optional)'
                )
            if len(command_options_set
                   ) == 0 and self._options.command_pid is not None:
                raise RuntimeError(
                    'Option --command_pid can only be used together with an other --command-* option'
                )

            embed_options = (self._options.embed_plugin,
                             self._options.embed_plugin_serial,
                             self._options.embed_plugin_address)
            embed_options_set = [
                opt for opt in embed_options if opt is not None
            ]
            if len(command_options_set) > 0 and not self._dbus_available:
                raise RuntimeError(
                    'Without DBus support the --embed-* options are not available'
                )
            if len(embed_options_set) > 0 and len(embed_options_set) < len(
                    embed_options):
                raise RuntimeError(
                    'Missing option(s) - all \'--embed-*\' options must be set'
                )

            if len(embed_options_set) > 0 and self._options.clear_config:
                raise RuntimeError(
                    'Option --clear-config can only be used without any --embed-* option'
                )

            groups = (list_options_set, command_options_set, embed_options_set)
            groups_set = [opt for opt in groups if len(opt) > 0]
            if len(groups_set) > 1:
                raise RuntimeError(
                    'Options from different groups (--list, --command, --embed) can not be used together'
                )

            perspective_options = (self._options.perspective,
                                   self._options.perspective_file)
            perspective_options_set = [
                opt for opt in perspective_options if opt is not None
            ]
            if len(perspective_options_set) > 1:
                raise RuntimeError(
                    'Only one --perspective-* option can be used at a time')

            if self._options.perspective_file is not None and not os.path.isfile(
                    self._options.perspective_file):
                raise RuntimeError(
                    'Option --perspective-file must reference existing file')

        except RuntimeError as e:
            print(str(e))
            #parser.parse_args(['--help'])
            # calling --help will exit
            return 1

        # set implicit option dependencies
        if self._options.standalone_plugin is not None:
            self._options.lock_perspective = True

        # create application context containing various relevant information
        from .application_context import ApplicationContext
        context = ApplicationContext()
        context.qtgui_path = self._qtgui_path
        context.options = self._options

        if self._dbus_available:
            from dbus import DBusException, Interface, SessionBus

        # non-special applications provide various dbus interfaces
        if self._dbus_available:
            context.provide_app_dbus_interfaces = len(groups_set) == 0
            context.dbus_base_bus_name = 'org.ros.qt_gui'
            if context.provide_app_dbus_interfaces:
                context.dbus_unique_bus_name = context.dbus_base_bus_name + '.pid%d' % os.getpid(
                )

                # provide pid of application via dbus
                from .application_dbus_interface import ApplicationDBusInterface
                _dbus_server = ApplicationDBusInterface(
                    context.dbus_base_bus_name)

        # determine host bus name, either based on pid given on command line or via dbus application interface if any other instance is available
        if len(command_options_set) > 0 or len(embed_options_set) > 0:
            host_pid = None
            if self._options.command_pid is not None:
                host_pid = self._options.command_pid
            else:
                try:
                    remote_object = SessionBus().get_object(
                        context.dbus_base_bus_name, '/Application')
                except DBusException:
                    pass
                else:
                    remote_interface = Interface(
                        remote_object,
                        context.dbus_base_bus_name + '.Application')
                    host_pid = remote_interface.get_pid()
            if host_pid is not None:
                context.dbus_host_bus_name = context.dbus_base_bus_name + '.pid%d' % host_pid

        # execute command on host application instance
        if len(command_options_set) > 0:
            if self._options.command_start_plugin is not None:
                try:
                    remote_object = SessionBus().get_object(
                        context.dbus_host_bus_name, '/PluginManager')
                except DBusException:
                    (rc,
                     msg) = (1,
                             'unable to communicate with GUI instance "%s"' %
                             context.dbus_host_bus_name)
                else:
                    remote_interface = Interface(
                        remote_object,
                        context.dbus_base_bus_name + '.PluginManager')
                    (rc, msg) = remote_interface.start_plugin(
                        self._options.command_start_plugin,
                        ' '.join(self._options.plugin_args))
                if rc == 0:
                    print('qt_gui_main() started plugin "%s" in GUI "%s"' %
                          (msg, context.dbus_host_bus_name))
                else:
                    print(
                        'qt_gui_main() could not start plugin "%s" in GUI "%s": %s'
                        % (self._options.command_start_plugin,
                           context.dbus_host_bus_name, msg))
                return rc
            elif self._options.command_switch_perspective is not None:
                remote_object = SessionBus().get_object(
                    context.dbus_host_bus_name, '/PerspectiveManager')
                remote_interface = Interface(
                    remote_object,
                    context.dbus_base_bus_name + '.PerspectiveManager')
                remote_interface.switch_perspective(
                    self._options.command_switch_perspective)
                print(
                    'qt_gui_main() switched to perspective "%s" in GUI "%s"' %
                    (self._options.command_switch_perspective,
                     context.dbus_host_bus_name))
                return 0
            raise RuntimeError('Unknown command not handled')

        # choose selected or default qt binding
        setattr(sys, 'SELECT_QT_BINDING', self._options.qt_binding)
        from python_qt_binding import QT_BINDING

        from python_qt_binding.QtCore import qDebug, qInstallMessageHandler, QSettings, Qt, QtCriticalMsg, QtDebugMsg, QtFatalMsg, QTimer, QtWarningMsg
        from python_qt_binding.QtGui import QIcon
        from python_qt_binding.QtWidgets import QAction, QMenuBar

        from .about_handler import AboutHandler
        from .composite_plugin_provider import CompositePluginProvider
        from .container_manager import ContainerManager
        from .help_provider import HelpProvider
        from .icon_loader import get_icon
        from .main_window import MainWindow
        from .minimized_dock_widgets_toolbar import MinimizedDockWidgetsToolbar
        from .perspective_manager import PerspectiveManager
        from .plugin_manager import PluginManager

        # TODO PySide2 segfaults when invoking this custom message handler atm
        if QT_BINDING != 'pyside':

            def message_handler(type_, context, msg):
                colored_output = 'TERM' in os.environ and 'ANSI_COLORS_DISABLED' not in os.environ
                cyan_color = '\033[36m' if colored_output else ''
                red_color = '\033[31m' if colored_output else ''
                reset_color = '\033[0m' if colored_output else ''
                if type_ == QtDebugMsg and self._options.verbose:
                    print(msg, file=sys.stderr)
                elif type_ == QtWarningMsg:
                    print(cyan_color + msg + reset_color, file=sys.stderr)
                elif type_ == QtCriticalMsg:
                    print(red_color + msg + reset_color, file=sys.stderr)
                elif type_ == QtFatalMsg:
                    print(red_color + msg + reset_color, file=sys.stderr)
                    sys.exit(1)

            qInstallMessageHandler(message_handler)

        app = self.create_application(argv)

        self._check_icon_theme_compliance()

        settings = QSettings(QSettings.IniFormat, QSettings.UserScope,
                             'ros.org', self._settings_filename)
        if len(embed_options_set) == 0:
            if self._options.clear_config:
                settings.clear()

            main_window = MainWindow()
            if self._options.on_top:
                main_window.setWindowFlags(Qt.WindowStaysOnTopHint)

            main_window.statusBar()

            def sigint_handler(*args):
                qDebug('\nsigint_handler()')
                main_window.close()

            signal.signal(signal.SIGINT, sigint_handler)
            # the timer enables triggering the sigint_handler
            timer = QTimer()
            timer.start(500)
            timer.timeout.connect(lambda: None)

            menu_bar = main_window.menuBar()
            file_menu = menu_bar.addMenu(menu_bar.tr('&File'))
            action = QAction(file_menu.tr('&Quit'), file_menu)
            action.setIcon(QIcon.fromTheme('application-exit'))
            action.triggered.connect(main_window.close)
            file_menu.addAction(action)

        else:
            app.setQuitOnLastWindowClosed(False)

            main_window = None
            menu_bar = None

        self._add_plugin_providers()

        # setup plugin manager
        plugin_provider = CompositePluginProvider(self.plugin_providers)
        plugin_manager = PluginManager(
            plugin_provider,
            settings,
            context,
            settings_prefix=plugin_manager_settings_prefix)

        if self._options.list_plugins:
            # output available plugins
            print('\n'.join(sorted(plugin_manager.get_plugins().values())))
            return 0

        help_provider = HelpProvider()
        plugin_manager.plugin_help_signal.connect(
            help_provider.plugin_help_request)

        # setup perspective manager
        if main_window is not None:
            perspective_manager = PerspectiveManager(settings, context)

            if self._options.list_perspectives:
                # output available perspectives
                print('\n'.join(sorted(perspective_manager.perspectives)))
                return 0
        else:
            perspective_manager = None

        if main_window is not None:
            container_manager = ContainerManager(main_window, plugin_manager)
            plugin_manager.set_main_window(
                main_window,
                menu_bar if not self._options.lock_perspective else None,
                container_manager)

            if not self._options.freeze_layout:
                minimized_dock_widgets_toolbar = MinimizedDockWidgetsToolbar(
                    container_manager, main_window)
                main_window.addToolBar(Qt.BottomToolBarArea,
                                       minimized_dock_widgets_toolbar)
                plugin_manager.set_minimized_dock_widgets_toolbar(
                    minimized_dock_widgets_toolbar)

        if menu_bar is not None and not self._options.lock_perspective:
            perspective_menu = menu_bar.addMenu(menu_bar.tr('P&erspectives'))
            perspective_manager.set_menu(perspective_menu)

        # connect various signals and slots
        if perspective_manager is not None and main_window is not None:
            # signal changed perspective to update window title
            perspective_manager.perspective_changed_signal.connect(
                main_window.perspective_changed)
            # signal new settings due to changed perspective
            perspective_manager.save_settings_signal.connect(
                main_window.save_settings)
            perspective_manager.restore_settings_signal.connect(
                main_window.restore_settings)
            perspective_manager.restore_settings_without_plugin_changes_signal.connect(
                main_window.restore_settings)

        if perspective_manager is not None and plugin_manager is not None:
            perspective_manager.save_settings_signal.connect(
                plugin_manager.save_settings)
            plugin_manager.save_settings_completed_signal.connect(
                perspective_manager.save_settings_completed)
            perspective_manager.restore_settings_signal.connect(
                plugin_manager.restore_settings)
            perspective_manager.restore_settings_without_plugin_changes_signal.connect(
                plugin_manager.restore_settings_without_plugins)

        if plugin_manager is not None and main_window is not None:
            # signal before changing plugins to save window state
            plugin_manager.plugins_about_to_change_signal.connect(
                main_window.save_setup)
            # signal changed plugins to restore window state
            plugin_manager.plugins_changed_signal.connect(
                main_window.restore_state)
            # signal save settings to store plugin setup on close
            main_window.save_settings_before_close_signal.connect(
                plugin_manager.close_application)
            # signal save and shutdown called for all plugins, trigger closing main window again
            plugin_manager.close_application_signal.connect(
                main_window.close, type=Qt.QueuedConnection)

        if main_window is not None and menu_bar is not None:
            about_handler = AboutHandler(context.qtgui_path, main_window)
            help_menu = menu_bar.addMenu(menu_bar.tr('&Help'))
            action = QAction(file_menu.tr('&About'), help_menu)
            action.setIcon(QIcon.fromTheme('help-about'))
            action.triggered.connect(about_handler.show)
            help_menu.addAction(action)

        # set initial size - only used without saved configuration
        if main_window is not None:
            main_window.resize(600, 450)
            main_window.move(100, 100)

        # ensure that qt_gui/src is in sys.path
        src_path = os.path.realpath(
            os.path.join(os.path.dirname(__file__), '..'))
        if src_path not in sys.path:
            sys.path.append(src_path)

        # load specific plugin
        plugin = None
        plugin_serial = None
        if self._options.embed_plugin is not None:
            plugin = self._options.embed_plugin
            plugin_serial = self._options.embed_plugin_serial
        elif self._options.standalone_plugin is not None:
            plugin = self._options.standalone_plugin
            plugin_serial = 0
        if plugin is not None:
            plugins = plugin_manager.find_plugins_by_name(plugin)
            if len(plugins) == 0:
                print('qt_gui_main() found no plugin matching "%s"' % plugin)
                return 1
            elif len(plugins) > 1:
                print(
                    'qt_gui_main() found multiple plugins matching "%s"\n%s' %
                    (plugin, '\n'.join(plugins.values())))
                return 1
            plugin = plugins.keys()[0]

        qDebug('QtBindingHelper using %s' % QT_BINDING)

        plugin_manager.discover()

        if self._options.reload_import:
            qDebug(
                'ReloadImporter() automatically reload all subsequent imports')
            from .reload_importer import ReloadImporter
            _reload_importer = ReloadImporter()
            self._add_reload_paths(_reload_importer)
            _reload_importer.enable()

        # switch perspective
        if perspective_manager is not None:
            if plugin:
                perspective_manager.set_perspective(
                    plugin, hide_and_without_plugin_changes=True)
            elif self._options.perspective_file:
                perspective_manager.import_perspective_from_file(
                    self._options.perspective_file,
                    perspective_manager.HIDDEN_PREFIX +
                    '__cli_perspective_from_file')
            else:
                perspective_manager.set_perspective(self._options.perspective)

        # load specific plugin
        if plugin:
            plugin_manager.load_plugin(plugin, plugin_serial,
                                       self._options.plugin_args)
            running = plugin_manager.is_plugin_running(plugin, plugin_serial)
            if not running:
                return 1
            if self._options.standalone_plugin:
                # use icon of standalone plugin (if available) for application
                plugin_descriptor = plugin_manager.get_plugin_descriptor(
                    plugin)
                action_attributes = plugin_descriptor.action_attributes()
                if 'icon' in action_attributes and action_attributes[
                        'icon'] is not None:
                    base_path = plugin_descriptor.attributes().get(
                        'plugin_path')
                    try:
                        icon = get_icon(
                            action_attributes['icon'],
                            action_attributes.get('icontype', None), base_path)
                    except UserWarning:
                        pass
                    else:
                        app.setWindowIcon(icon)

        if main_window is not None:
            main_window.show()
            if sys.platform == 'darwin':
                main_window.raise_()

        return app.exec_()
Пример #57
0
NAME = "Dtls"
VERSION = "1.2.3"

if __name__ == "__main__":
    # Full upload sequence for new version:
    #    1. python setup.py bdist_wheel
    #    2. python setup.py bdist_wheel -p win32
    #    3. python setup.py bdist_wheel -p win_amd64
    #    4. twine upload dist/*

    parser = ArgumentParser(add_help=False)
    parser.add_argument("-h", "--help", action="store_true")
    parser.add_argument("command", nargs="*")
    parser.add_argument("-p", "--plat-name")
    args = parser.parse_known_args()[0]
    dist = "bdist_wheel" in args.command and not args.help
    plat_dist = dist and args.plat_name
    if dist:
        from pypandoc import convert
        long_description = convert("README.md", "rst")\
                           .translate({ord("\r"): None})
        with open("README.rst", "w") as readme:
            readme.write(long_description)
    else:
        long_description = open("README.md").read()
    top_package_plat_files_file = "dtls_package_files"
    if dist:
        if plat_dist:
            prebuilt_platform_root = "dtls/prebuilt"
            if args.plat_name == "win32":
Пример #58
0
    parser.add_argument(
        '--cytomine_id_project',
        dest='id_project',
        required=False,
        help="The project to which the property will be added (optional)")
    parser.add_argument(
        '--cytomine_id_image_instance',
        dest='id_image_instance',
        required=False,
        help="The image to which the property will be added (optional)")
    parser.add_argument(
        '--cytomine_id_annotation',
        dest='id_annotation',
        required=False,
        help="The annotation to which the property will be added (optional)")
    params, other = parser.parse_known_args(sys.argv[1:])

    with Cytomine(host=params.host,
                  public_key=params.public_key,
                  private_key=params.private_key) as cytomine:

        if params.id_project:
            prop = Property(Project().fetch(params.id_project),
                            key=params.key,
                            value=params.value).save()
            print(prop)

        if params.id_image_instance:
            prop = Property(ImageInstance().fetch(params.id_image_instance),
                            key=params.key,
                            value=params.value).save()
Пример #59
0
compute_api = "https://binaries.artheriom.fr/artifactory/api/storage/"

parser = ArgumentParser()
parser.add_argument("-r",
                    "--requested",
                    help="Define requested repository.",
                    default="")
parser.add_argument("-m",
                    "--isMaven",
                    help="Define if project is Maven Project.",
                    default=False)
parser.add_argument("-o",
                    "--output",
                    help="Define artifact output",
                    default="")
args, unknown = parser.parse_known_args()

if (args.requested == "" or args.output == ""):
    print("FATAL : You must define props !")
    exit(0)

isMaven = args.isMaven
outputName = args.output
requested = args.requested

instances_rq = requests.get(url=compute_api + requested,
                            verify=False,
                            auth=HTTPBasicAuth("admin", "MDP"))
instance_file = json.loads(instances_rq.content)

found = False
Пример #60
0
    sparsity_vs_accuracy, val_vs_episodes, train_vs_episodes = dense_model.fit(
        n_epochs=FLAGS.n_epochs,
        learning_rate_schedule=simple_config.learning_rate_schedule,
        batch_size=FLAGS.batch_size,
        config=simple_config)
    fig = plot_several_graphs(data=val_vs_episodes, name='val_acc')
    _ = plot_several_graphs(data=train_vs_episodes, name='train_acc', last=1)
    plot_conv_weights(dense_model)
    dense_model.sess.close()


if __name__ == '__main__':
    parser = ArgumentParser()
    parser.add_argument('--model_path',
                        type=str,
                        default=simple_config.model_path,
                        help=' Directory where to save model checkpoint.')
    parser.add_argument('--n_epochs',
                        type=int,
                        default=simple_config.n_epochs,
                        help='number of epoches')
    parser.add_argument('--batch_size',
                        type=int,
                        default=simple_config.batch_size,
                        help='batch_size')
    parser.add_argument('--dropout',
                        type=int,
                        default=simple_config.dropout,
                        help='dropout')
    FLAGS, unparsed = parser.parse_known_args()
    main()