Example #1
0
def main():
    usage = "Usage: %prog [OPTIONS] [fortune_file]"
    arg_parser = OptionParser(usage=usage)
    arg_parser.add_option(
        "-V",
        "--version",
        action="store_true",
        dest="show_version",
        help="Show version and exit.",
    )
    arg_parser.epilog = ("If fortune_file is omitted, fortune looks at the "
                         "FORTUNE_FILE environment variable for the path.")

    options, args = arg_parser.parse_args(sys.argv)
    if len(args) == 2:
        fortune_file = args[1]

    else:
        try:
            fortune_file = "notes.txt"
        except KeyError:
            print("Missing fortune file.", file=sys.stderr)
            print(usage, file=sys.stderr)
            sys.exit(1)

    try:
        if options.show_version:
            print("fortune, version {}".format(__version__))
        else:
            print(get_random_fortune(fortune_file))
    except ValueError as msg:
        print(msg, file=sys.stderr)
        sys.exit(1)
Example #2
0
File: cli.py Project: sorinros/cxm
def get_parser():
	"""Parse command line options and return an OptionParser object """

	parser = OptionParser(version="%prog "+core.get_api_version())
	parser.add_option("-d", "--debug",
					  action="store_true", dest="debug", default=core.cfg['API_DEBUG'],
					  help="Enable debug mode")
	parser.add_option("-f", "--force-node", dest="node", metavar="hostname", default=None,
					  help="Specify the node to operate with")
	parser.add_option("-q", "--quiet",
					  action="store_true", dest="quiet", default=core.cfg['QUIET'],
					  help="Quiet mode: suppress extra outputs")
	parser.add_option("-n", "--no-refresh",
					  action="store_true", dest="norefresh", default=core.cfg['NOREFRESH'],
					  help="Don't refresh LVM metadatas (DANGEROUS)")
	parser.add_option("-c", "--console",
					  action="store_true", dest="console", default=False,
					  help="Attach console to the domain as soon as it has started.")

	parser.usage = "%prog <subcommand> [args] [options]\n\n"
	parser.usage += get_help()
	
	parser.epilog = "For more help on 'cxm' see the cxm(1) man page."

	return parser
Example #3
0
def parse_cmdline ():
        from optparse import OptionParser
        u = \
"""\n\tpython %prog [options] input_filename

  %prog will generate a PLY-compatible parser module from a YACC
  specification file."""

        p = OptionParser (usage=u)
        p.add_option ("-c", "--nocode",
            action="store_true", dest="nocode", default=False,
            help="Don't produce any of the semantic action code.  "\
                "Default is to write all the action code to the "\
                "output file.  ")
        p.add_option ("-t", "--tokens",
            action="store_true", dest="tokens", default=False,
            help="Generate a \"tokens\" statement in the output file.  "\
                "Default is not to generate the statement on the assumtion "\
                "that the tokens will be imported from the lexer.  ")
        p.add_option ("-d", "--debug",
            type="int", dest="debug", default=0,
            help="Set parser debug flag when parsing the input file.  ")
        p.epilog = "Arguments: input_filename  (traditionaly this will be "\
                "named with a \".y\" suffix.)"

        opts, args = p.parse_args ()
        #...arg defaults can be setup here...
        if len (args) > 1: p.error ("Expected only one argument (input file name)")
        if len (args) < 1: p.error ("Expected one argument (input file name)")
        return args, opts
Example #4
0
def main():
    """
    Main program.
    """
    usage = 'Usage: %prog [OPTIONS] [fortune_file]'
    arg_parser = OptionParser(usage=usage)
    arg_parser.add_option('-V', '--version', action='store_true',
                          dest='show_version', help='Show version and exit.')
    arg_parser.epilog = 'If fortune_file is omitted, fortune looks at the ' \
                        'FORTUNE_FILE environment variable for the path.'

    options, args = arg_parser.parse_args(sys.argv)
    if len(args) == 2:
        fortune_file = args[1]

    else:
        try:
            fortune_file = os.environ['FORTUNE_FILE']
        except KeyError:
            print('Missing fortune file.', file=sys.stderr)
            print(usage, file=sys.stderr)
            sys.exit(1)

    try:
        if options.show_version:
            print('fortune, version {}'.format(__version__))
        else:
            print(get_random_fortune(fortune_file))
    except ValueError as msg:
        print(msg, file=sys.stderr)
        sys.exit(1)
Example #5
0
def main():
    """
    Main program.
    """
    usage = 'Usage: %prog [OPTIONS] [fortune_file]'
    arg_parser = OptionParser(usage=usage)
    arg_parser.add_option('-V',
                          '--version',
                          action='store_true',
                          dest='show_version',
                          help='Show version and exit.')
    arg_parser.epilog = 'If fortune_file is omitted, fortune looks at the ' \
                        'FORTUNE_FILE environment variable for the path.'

    options, args = arg_parser.parse_args(sys.argv)
    if len(args) == 2:
        fortune_file = args[1]

    else:
        try:
            fortune_file = os.environ['FORTUNE_FILE']
        except KeyError:
            print('Missing fortune file.', file=sys.stderr)
            print(usage, file=sys.stderr)
            sys.exit(1)

    try:
        if options.show_version:
            print('fortune, version {}'.format(__version__))
        else:
            print(get_random_fortune(fortune_file))
    except ValueError as msg:
        print(msg, file=sys.stderr)
        sys.exit(1)
Example #6
0
def setup_arg_parser():
    """ Return an arg_parser, set up with all options """
    class MyIndentedHelpFormatter(IndentedHelpFormatter):
        """ Slightly modified formatter for help output: allow paragraphs """
        def format_paragraphs(self, text):
            """ wrap text per paragraph """
            result = ""
            for paragraph in text.split("\n"):
                result += self._format_text(paragraph) + "\n"
            return result
        def format_description(self, description):
            """ format description, honoring paragraphs """
            if description:
                return self.format_paragraphs(description) + "\n"
            else:
                return ""
        def format_epilog(self, epilog):
            """ format epilog, honoring paragraphs """
            if epilog:
                return "\n" + self.format_paragraphs(epilog) + "\n"
            else:
                return ""
    arg_parser = OptionParser(
        formatter=MyIndentedHelpFormatter(),
        usage = "%prog [options] CMD ARGS",
        description = __doc__)
    arg_parser.add_option(
        '--email', action='store', dest='email',
        help="Email address to use for authentification")
    arg_parser.add_option(
        '--password', action='store', dest='password',
        help="Password to use for authentification (Read warning below).")
    arg_parser.add_option(
        '--credfile', action='store', dest='credfile',
        default=os.path.join(os.environ['HOME'], '.simplenotesyncrc'),
        help="File from which to read email (first line) and "
             "password (second line). Defaults to ~/.simplenotesyncrc")
    arg_parser.add_option(
        '--cachefile', action='store', dest='cachefile',
        help="File in which to cache information about notes. "
             "Using a cachefile can dramatically speed up listing notes.")
    arg_parser.add_option(
        '--tokenfile', action='store', dest='tokenfile',
        help="File in which to cache the authentication token")
    arg_parser.add_option(
        '--results', action='store', dest='results', type="int", default=10,
        help="Maximum number of results to be returned in a search")
    arg_parser.add_option(
        '--encoding', action='store', dest='encoding', default='utf-8',
        help="Encoding for notes written to file or read from file "
             "(defaults to utf-8).")
    arg_parser.add_option(
        '--dead', action='store_true', dest='dead',
        help="When deleting a note, delete it permanently")
    arg_parser.epilog = "You are strongly advised to use the --credfile " \
                        "option instead of the --password option. Giving " \
                        "a password in cleartext on the command line will " \
                        "result in that password being visible in the "\
                        "process list and your history file."
    return arg_parser
Example #7
0
File: twi2.py Project: darkk/twi2
def main():
    parser = OptionParser()
    parser.usage = 'Usage: %prog [options] <action> <action> ...'
    parser.add_option('-d', '--database', help='Use DATABASE as sqlite db to store queue.')
    parser.add_option('-t', '--twi-name', help='Use TWI_NAME to pull data from twitter.')
    parser.add_option('-k', '--vk-client', help='Use VK_CLIENT as application `client_id` for vk.com API.')
    parser.add_option('-K', '--vk-secret', help='Use VK_SECRET as application `client_secret` for vk.com API.')
    parser.add_option('-j', '--juick-login', help='Use JUICK_LOGIN for juick.com API.')
    parser.add_option('-J', '--juick-password', help='Use JUICK_PASSWORD for juick.com API.')
    parser.add_option('-m', '--juick-msgid', help='Use JUICK_MSGID to get user `uid` for dequeue.', type=int)
    parser.add_option('-l', '--log', help='Write log to LOG')
    parser.epilog = 'Actions: ' + ', '.join(sorted(KNOWN_ARGS.keys()))
    opt, args = parser.parse_args()
    for action in args:
        if action not in KNOWN_ARGS:
            parser.error('Unknown action: <%s>' % action)

    logging_kvargs = {'level': logging.DEBUG, 'format': '%(asctime)s %(levelname)s: %(message)s'}
    if opt.log:
        logging_kvargs['filename'] = opt.log
    logging.basicConfig(**logging_kvargs)
    if callable(getattr(logging, 'captureWarnings', None)):
        logging.captureWarnings(True)
    try:
        run(opt, args)
    except Exception:
        logging.exception('FAIL!')
Example #8
0
    def handle_command_line_options(self, to_handle):
        """Handle prescribed command line options and eat them.

        Anything before first occurrence of ``--`` on the command-line is taken
        into account and removed from ``sys.argv``.

        Help messages:

        If -h or --help is specified  and -- is not, the help for the wrapper
        will be printed, and the -h/--help option kept in sys.argv.

        If -h or --help is specified before --, the help for this wrapper will
        be printed and options after -- will be kept in sys.argv.

        if -h or --help is specified after --, it will be ignored at this
        stage, and kept in sys.argv (in most cases triggering help print for
        the wrapped script).
        """

        parser = OptionParser(
            usage="%(prog)s [Odoo options] -- other arguments",
            description="This is a script rewrapped by Odoo buildout "
            "recipe to add Odoo-related options on the command "
            "line prior to other arguments.")

        if '-d' in to_handle:
            parser.add_option('-d',
                              '--db-name',
                              help="Name of the database to work on. "
                              "If not specified, the database from "
                              "configuration files will be used")

        try:
            sep = sys.argv.index('--')
        except ValueError:
            if '-h' in sys.argv or '--help' in sys.argv:
                # in case of call myscript -h --, only the wrapper help
                # will be printed
                parser.epilog = ("Help message from the wrapped script, "
                                 "if any, will follow.")
                parser.print_help()
                print
                return
            our_argv = []
            sep = None
        else:
            our_argv = sys.argv[1:sep]

        options, args = parser.parse_args(our_argv)

        if sep is not None:
            del sys.argv[1:sep + 1]

        if '-d' in to_handle:
            if options.db_name:
                logger.info("Opening database %r", options.db_name)
            else:
                logger.info("No database specified, using the one specified "
                            "in buildout configuration.")
            self.open(db=options.db_name)
Example #9
0
    def handle_command_line_options(self, to_handle):
        """Handle prescribed command line options and eat them.

        Anything before first occurrence of ``--`` on the command-line is taken
        into account and removed from ``sys.argv``.

        Help messages:

        If -h or --help is specified  and -- is not, the help for the wrapper
        will be printed, and the -h/--help option kept in sys.argv.

        If -h or --help is specified before --, the help for this wrapper will
        be printed and options after -- will be kept in sys.argv.

        if -h or --help is specified after --, it will be ignored at this
        stage, and kept in sys.argv (in most cases triggering help print for
        the wrapped script).
        """

        parser = OptionParser(
            usage="%(prog)s [Odoo options] -- other arguments",
            description="This is a script rewrapped by Odoo buildout "
                        "recipe to add Odoo-related options on the command "
                        "line prior to other arguments.")

        if '-d' in to_handle:
            parser.add_option('-d', '--db-name',
                              help="Name of the database to work on. "
                              "If not specified, the database from "
                              "configuration files will be used")

        try:
            sep = sys.argv.index('--')
        except ValueError:
            if '-h' in sys.argv or '--help' in sys.argv:
                # in case of call myscript -h --, only the wrapper help
                # will be printed
                parser.epilog = ("Help message from the wrapped script, "
                                 "if any, will follow.")
                parser.print_help()
                print
                return
            our_argv = []
            sep = None
        else:
            our_argv = sys.argv[1:sep]

        options, args = parser.parse_args(our_argv)

        if sep is not None:
            del sys.argv[1:sep+1]

        if '-d' in to_handle:
            if options.db_name:
                logger.info("Opening database %r", options.db_name)
            else:
                logger.info("No database specified, using the one specified "
                            "in buildout configuration.")
            self.open(db=options.db_name)
def main():

    usage = "%prog [options] ACTION"
    epilog = """
ACTION is one of add|modify|remove|print

  add:    add a user record
  modify: modify a user record
  remove: remove a user record
"""
    description = "Tool to manipulate CalendarServer augments XML file"
    version = "%prog v1.0"
    parser = OptionParser(usage=usage, description=description, version=version)
    parser.epilog = epilog
    parser.format_epilog = lambda _:epilog

    parser.add_option("-f", "--file", dest="configfilename",
                      help="caldavd.plist defining Augment Service", metavar="FILE")
    parser.add_option("-u", "--uid", dest="uid",
                      help="OD GUID to manipulate", metavar="UID")
    parser.add_option("-i", "--uidfile", dest="uidfile",
                      help="File containing a list of GUIDs to manipulate", metavar="UIDFILE")
    parser.add_option("-n", "--node", dest="node",
                      help="Partition node to assign to UID", metavar="NODE")
    parser.add_option("-c", "--enable-calendar", action="store_true", dest="enable_calendar",
                      default=True, help="Enable calendaring for this UID: %default")
    parser.add_option("-a", "--enable-addressbooks", action="store_true", dest="enable_addressbook",
                      default=True, help="Enable calendaring for this UID: %default")
    parser.add_option("-s", "--auto-schedule", action="store_true", dest="auto_schedule",
                      default=False, help="Enable auto-schedule for this UID: %default")

    (options, args) = parser.parse_args()

    if len(args) != 1:
        parser.error("incorrect number of arguments")

    observer = StandardIOObserver()
    observer.start()

    #
    # Get configuration
    #
    try:
        loadConfig(options.configfilename)
        setLogLevelForNamespace(None, "warn")

        # Shed privileges
        if config.UserName and config.GroupName and os.getuid() == 0:
            uid = getpwnam(config.UserName).pw_uid
            gid = getgrnam(config.GroupName).gr_gid
            switchUID(uid, uid, gid)

        os.umask(config.umask)

        config.directory = getDirectory()
        autoDisableMemcached(config)
    except ConfigurationError, e:
        usage("Unable to start: %s" % (e,))
def SEMToMediaWikiProg():
    from optparse import OptionParser
    usage = "%prog -x XMLFILE -o MEDIWIKIFILE"
    version = "%prog v0.1"
    parser = OptionParser()
    parser.add_option("-x",
                      "--xmlfile",
                      dest="xmlfilename",
                      action="store",
                      type="string",
                      metavar="XMLFILE",
                      help="The SEM formatted XMLFILE file")
    parser.add_option(
        "-o",
        "--outfile",
        dest="outfilename",
        action="store",
        type="string",
        default=None,
        metavar="MEDIAWIKIFILE",
        help="The MEDIAWIKIFILE ascii file with media-wiki formatted text.")
    parser.add_option("-p",
                      "--parts",
                      dest="parts",
                      action="store",
                      type="string",
                      default="hbf",
                      help="The parts to print out, h=Header,b=body,f=footer")
    parser.epilog = program_description
    #    print program_description
    (options, args) = parser.parse_args()

    #    It may be desirable in the future to automatically push information to the
    #    WIKI page without having to copy and paste.
    #    http://python-wikitools.googlecode.com/svn/trunk/README

    ExecutableNode = GetSEMDoc(options.xmlfilename)

    docString = ""
    for stage in options.parts:
        if stage == "h":
            docString += DumpSEMMediaWikiHeader(ExecutableNode)
        elif stage == "b":
            docString += DumpSEMMediaWikiFeatures(ExecutableNode)
        elif stage == "f":
            docString += DumpSEMMediaWikiFooter(ExecutableNode)
        else:
            parser.error(
                "The only valid options are [h|b|f]: Given {0}".format(stage))

    if options.xmlfilename is not None:
        outfile = open(options.outfilename, 'w')
        outfile.write(docString)
        outfile.close()
    else:
        sys.stdout.write(docString)
Example #12
0
def check_usage(args):
    ''' Parse command line options - yes, these aren't really "options".... deal with it '''

    parser = OptionParser()
    parser.add_option(
        '-p',
        action="store",
        dest="program_cmd_line",
        help='Program to launch, the full command line that will be executed',
        metavar="program")
    parser.add_option('-f',
                      action="store",
                      dest="original_file",
                      help='File to be mutated',
                      metavar="file")
    parser.add_option('-d',
                      action="store",
                      dest="temp_directory",
                      help='Directory for temporary files to be created',
                      metavar="temp_directory")
    parser.add_option('-t',
                      action="store",
                      dest="mutation_type",
                      help='Type of mutation ("byte", "word", "dword")',
                      metavar="mutation_type")
    parser.add_option('-l',
                      action="store",
                      dest="log_file",
                      help='Log file',
                      metavar="log")
    parser.add_option(
        '-s',
        action="store",
        dest="save_directory",
        help='Save-directory, for files to be saved that cause crashes',
        metavar="save_directory")
    parser.add_option('-m',
                      action="store",
                      dest="max_processes",
                      help='Max Processes (Default is 1)',
                      type="int",
                      default=1,
                      metavar="max_processes")
    parser.epilog = "Example:\n\n"
    parser.epilog += './fuzzer.py -p "C:\Program Files\Blah\prog.exe" -f original_file.mp3 -d temp -t dword -l log.txt -s save -m 4'
    options, args = parser.parse_args(args)

    # make sure enough args are passed
    if not all((options.program_cmd_line, options.original_file,
                options.temp_directory, options.mutation_type,
                options.log_file, options.save_directory)):
        parser.error(
            "Incorrect number of arguments - must specify program, original_file, temp_directory, mutation_type, log_file, save_directory"
        )

    return options
Example #13
0
def setup_parser_for_phase_help(phase):
  """Returns an optparse.OptionParser useful for 'goal help <phase>'.
  Used by 'goal help' and 'goal builddict'.
  :param phase: Phase object
  """
  parser = OptionParser()
  parser.set_usage('%s goal %s ([target]...)' % (sys.argv[0], phase.name))
  parser.epilog = phase.description
  add_global_options(parser)
  phase.setup_parser(parser, [], [phase])
  return parser
Example #14
0
def constructOptionParser():
    """
    returns a pre-setup optparser
    """
    parser = OptionParser(formatter=PreformattedDescriptionFormatter())

    parser.set_description('Retrieves eland config file from hts_frontend web frontend.')

    parser.epilog = """
Config File:
  * %s (System wide)
  * %s (User specific; overrides system)
  * command line overrides all config file options

  Example Config File:

    [%s]
    config_host: http://somewhere.domain:port
    genome_dir: /path to search for genomes
    post_run: runfolder -o <destdir> %%(runfolder)s

""" % (CONFIG_SYSTEM, CONFIG_USER, GERALD_CONFIG_SECTION)

    #Special formatter for allowing preformatted description.
    ##parser.format_epilog(PreformattedDescriptionFormatter())

    parser.add_option("-u", "--url",
                      action="store", type="string", dest="url")

    parser.add_option("-o", "--output-file",
                      action="store", type="string", dest="output_filepath",
                      help="config file destination. If runfolder is specified defaults "
                           "to <runfolder>/config-auto.txt" )

    parser.add_option("-f", "--flowcell",
                      action="store", type="string", dest="flowcell")

    parser.add_option("-g", "--genome_dir",
                      action="store", type="string", dest="genome_dir")

    parser.add_option("-r", "--runfolder",
                      action="store", type="string",
                      help="specify runfolder for post_run command ")

    parser.add_option("--sample-sheet", default=None,
                      help="path to save demultiplexing sample sheet")

    parser.add_option("--operator", default='', help="Name of sequencer operator")
    parser.add_option("--recipe", default="Unknown",
                      help="specify recipe name")

    parser.add_option('-v', '--verbose', action='store_true', default=False,
                       help='increase logging verbosity')
    return parser
Example #15
0
    def get_options(self):
        opts = OptionParser()
        opts.add_option('', '--start', action='store', default=None,
                         help=('The starting time (YYYY-MM-DD HH:MM:SS, '
                               'UTC time).'))
        opts.add_option('', '--end', action='store', default=None, 
                        help=('The ending time.'))
        opts.usage = '%prog --host=<host> [options]'
        opts.epilog = """Counts the number of oplog events between <start> and <end>, if provided. 
The range is open-ended if only one or zero of the <start> and <end> parameters
are provided. 
"""
        return opts
Example #16
0
def run_generator(generator: Generator, optparser: OptionParser, plugin: bool):
    """This function should be called by custom generator"""

    add_base_options(optparser)
    # Check if we are running as a plugin under protoc
    if plugin:
        main_plugin(generator, optparser)
    else:
        optparser.usage = "{} [options] file.pb ...".format(
            os.path.split(sys.argv[0])[1])
        optparser.epilog = (
            "Compile file.pb from file.proto by: 'protoc -ofile.pb file.proto'. "
        )
        main_cli(generator, optparser)
Example #17
0
  def execute(self, targets):
    goal = self.context.options.help_goal
    if goal is None:
      return self.list_goals('You must supply a goal name to provide help for.')
    phase = Phase(goal)
    if not phase.goals():
      return self.list_goals('Goal %s is unknown.' % goal)

    parser = OptionParser()
    parser.set_usage('%s goal %s ([target]...)' % (sys.argv[0], goal))
    parser.epilog = phase.description
    Goal.add_global_options(parser)
    Phase.setup_parser(parser, [], [phase])
    parser.parse_args(['--help'])
Example #18
0
  def execute(self, targets):
    goal = self.context.options.help_goal
    if goal is None:
      return self.list_goals('You must supply a goal name to provide help for.')
    phase = Phase(goal)
    if not phase.goals():
      return self.list_goals('Goal %s is unknown.' % goal)

    parser = OptionParser()
    parser.set_usage('%s goal %s ([target]...)' % (sys.argv[0], goal))
    parser.epilog = phase.description
    Goal.add_global_options(parser)
    Phase.setup_parser(parser, [], [phase])
    parser.parse_args(['--help'])
Example #19
0
def check_usage(args):
    ''' Parse command line options - yes, these aren't really "options".... deal with it '''

    parser = OptionParser()
    parser.add_option('-s', action="store", dest="host", help='Server to connect to', metavar="server")
    parser.add_option('-p', action="store", dest="port", help='Port to connect on', type='int', metavar="port")
    parser.add_option('-t', action="store", dest="temp_directory", help='Temporary directory for files to be created', metavar="temp_directory")
    parser.add_option('-g', action="store", dest="save_directory", help='Save-directory, for files to be saved that cause crashes', metavar="save_directory")
    parser.epilog = "Example:\n\n"
    parser.epilog += './client.py -s 127.0.0.1 -p 12345 -t temp -g save'
    options, args = parser.parse_args(args)

    # make sure enough args are passed
    if not all((options.temp_directory, options.save_directory, options.port, options.host)):
        parser.error("Incorrect number of arguments - must specify temp_directory, save_directory, host, port")

    return options
Example #20
0
def get_parser():
	"""Parse command line options and return an OptionParser object """

	parser = OptionParser(version="%prog "+core.get_api_version())
	parser.add_option("-p", "--ping",
						action="store_true", dest="ping", default=False,
						help="Ping local daemon.")
	parser.add_option("-l", "--list-nodes",
						action="store_true", dest="listnodes", default=False,
						help="List currents nodes in the cluster.")
	parser.add_option("-s", "--status",
						action="store_true", dest="status", default=False,
						help="Print current daemon status.")
	parser.add_option("-d", "--dump",
						action="store_true", dest="dump", default=False,
						help="Dump current internal memory (usefull for debugging).")
	parser.add_option("-e", "--force-election",
						action="store_true", dest="election", default=False,
						help="Force a new master's election.")
	parser.add_option("-q", "--quit",
						action="store_true", dest="quit", default=False,
						help="Shutdown local daemon.")

	group = OptionGroup(parser, "Dangerous Options",
						"Be sure you understand what you're doing before use.")

	group.add_option("-f", "--format",
						action="store_true", dest="format", default=False,
						help="Format the heartbeat device.")
	group.add_option("--force-panic",
						action="store_true", dest="panic", default=False,
						help="Switch master into panic mode.")
	group.add_option("-r", "--recover",
						action="store_true", dest="recover", default=False,
						help="Recover from panic mode. Should be run on the master's node.")
	group.add_option("-k", "--kill",
						action="store", type="string", dest="kill", metavar="hostname", default=False,
						help="Remove the specified node from the cluster. You can't kill the master.")

	parser.add_option_group(group)

	parser.usage = "%prog option"
	parser.epilog = "For more help on 'cxmd_ctl' see the cxmd_ctl(1) man page."

	return parser
def main():

    usage = "%prog [options] MODE"
    epilog = """
MODE is one of primary|secondary|add

  primary:   Create a new primary node (manages main DBs)
  secondary: Create a new secondary node
  add:       Add information for a new partition node on another machine
"""
    description = "Tool to setup CalendarServer partition node configuration files"
    version = "%prog v1.0"
    parser = OptionParser(usage=usage, description=description, version=version)
    parser.epilog = epilog
    parser.format_epilog = lambda _:epilog

    parser.add_option("-c", "--conf", dest="conf",
                      help="Directory where .plist files are stored", metavar="CONF")
    parser.add_option("-n", "--nodeid", dest="nodeid",
                      help="Node ID for this node", metavar="NODEID")
    parser.add_option("-u", "--url", dest="nodeurl",
                      help="URL of node being added", metavar="NODEURL")
    parser.add_option("-p", "--primary", dest="primaryurl",
                      help="URL of primary node", metavar="PRIMARYURL")

    (options, args) = parser.parse_args()

    if len(args) != 1:
        parser.error("incorrect number of arguments")

    # Make sure conf dir has the needed .plist files
    if not os.path.exists(options.conf):
        parser.error("Could not find '%s'" % (options.conf,))
    confdir = os.path.dirname(options.conf)
    if not os.path.exists(os.path.join(confdir, "caldavd-partitioning-primary.plist")):
        parser.error("Could not find caldavd-partitioning-primary.plist in '%s'" % (confdir,))
    if not os.path.exists(os.path.join(confdir, "caldavd-partitioning-secondary.plist")):
        parser.error("Could not find caldavd-partitioning-secondary.plist in '%s'" % (confdir,))

    # Handle each action
    {
        "primary"  : createPrimary,
        "secondary": createSecondary,
        "add"      : addOther,
    }[args[0]](options)
Example #22
0
def SEMToMediaWikiProg():
    from optparse import OptionParser
    usage = "%prog -x XMLFILE -o MEDIWIKIFILE"
    version = "%prog v0.1"
    parser = OptionParser()
    parser.add_option("-x", "--xmlfile", dest="xmlfilename",
        action="store", type="string",
        metavar="XMLFILE", help="The SEM formatted XMLFILE file")
    parser.add_option("-o", "--outfile", dest="outfilename",
        action="store", type="string", default=None,
        metavar="MEDIAWIKIFILE",
        help="The MEDIAWIKIFILE ascii file with media-wiki formatted text.")
    parser.add_option("-p", "--parts", dest="parts",
        action="store", type="string", default="hbf",
        help="The parts to print out, h=Header,b=body,f=footer")
    parser.epilog = program_description
#    print program_description
    (options, args) = parser.parse_args()

#    It may be desirable in the future to automatically push information to the
#    WIKI page without having to copy and paste.
#    http://python-wikitools.googlecode.com/svn/trunk/README

    ExecutableNode = GetSEMDoc(options.xmlfilename)

    docString = ""
    for stage in options.parts:
        if stage == "h":
            docString += DumpSEMMediaWikiHeader(ExecutableNode)
        elif stage == "b":
            docString += DumpSEMMediaWikiFeatures(ExecutableNode)
        elif stage == "f":
            docString += DumpSEMMediaWikiFooter(ExecutableNode)
        else:
            parser.error(
                "The only valid options are [h|b|f]: Given {0}".format(
                    stage))

    if options.xmlfilename is not None:
        outfile = open(options.outfilename, 'w')
        outfile.write(docString)
        outfile.close()
    else:
        sys.stdout.write(docString)
Example #23
0
def check_usage(args):
    ''' Parse command line - they're not really optional, shhh'''

    parser = OptionParser()
    parser.add_option('-e', action="store", dest="program_cmd_line", help='Executable program to launch, the full command line that will be executed', metavar="program")
    parser.add_option('-f', action="store", dest="original_file", help='File to be mutated', metavar="file")
    parser.add_option('-t', action="store", dest="mutation_type", help='Type of mutation ("byte", "word", "dword")', metavar="mutation_type")
    parser.add_option('-l', action="store", dest="log_file", help='Log file', metavar="log")
    parser.add_option('-p', action="store", dest="port", help='Port to listen on', type='int', metavar="port")
    parser.add_option('-d', action="store", dest="directory", help="Directory to save files that cause crashes", metavar="directory")
    parser.epilog = "Example:\n\n"
    parser.epilog += './server.py -e "C:\Program Files\Blah\prog.exe" -f original_file.mp3 -t dword -l log.txt -p 12345 -d save'
    options, args = parser.parse_args(args)

    # make sure enough args are passed
    if not all((options.program_cmd_line, options.original_file, options.mutation_type, options.log_file, options.port, options.directory)):
        parser.error("Incorrect number of arguments - must specify program, original_file, mutation_type, log_file, port, directory")

    return options
def main():

    usage = "%prog [options] ACTION"
    epilog = """
ACTION is one of init|start|stop|run

  init:   initialize databases
  start:  start postgres daemon
  stop:   stop postgres daemon
  run:    run postgres (non-daemon)
  clean:  remove databases
  
"""
    description = "Tool to manage PostgreSQL"
    version = "%prog v1.0"
    parser = OptionParser(usage=usage, description=description, version=version)
    parser.epilog = epilog
    parser.format_epilog = lambda _:epilog

    parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
                      default=True, help="Use debug logging for PostgreSQL")
    parser.add_option("-d", "--base-dir", dest="basedir",
                      default="%s/../postgresql-8.4.2/_root" % (os.getcwd(),), help="Base directory for PostgreSQL install")

    (options, args) = parser.parse_args()

    if len(args) != 1:
        parser.error("incorrect number of arguments")

    if args[0] == "init":
        doInit(options.basedir)
    elif args[0] == "start":
        doStart(options.basedir)
    elif args[0] == "stop":
        doStop(options.basedir)
    elif args[0] == "run":
        doRun(options.basedir, options.verbose)
    elif args[0] == "clean":
        doClean(options.basedir)
    else:
        parser.error("incorrect argument '%s'" % (args[0],))
Example #25
0
    def get_options(self):
        opts = OptionParser()
        opts.add_option('',
                        '--remove-after',
                        action='store',
                        default=None,
                        dest='remove_after',
                        help=('The time after which to delete oplog entries. '
                              '(YYYY-MM-DD HH:MM:SS, in UTC).'))
        opts.add_option('-y',
                        '',
                        action='store_true',
                        dest='always_yes',
                        default=None,
                        help='Answer yes for all prompts.')
        opts.usage = '%prog --host=<host> --remove-after=<date> [options]'
        opts.epilog = """
%s

""" % warning

        opts.formatter = HelpFormatter()
        return opts
Example #26
0
    def get_options(self):
        opts = OptionParser()
        opts.add_option(
            "",
            "--remove-after",
            action="store",
            default=None,
            dest="remove_after",
            help=("The time after which to delete oplog entries. " "(YYYY-MM-DD HH:MM:SS, in UTC)."),
        )
        opts.add_option(
            "-y", "", action="store_true", dest="always_yes", default=None, help="Answer yes for all prompts."
        )
        opts.usage = "%prog --host=<host> --remove-after=<date> [options]"
        opts.epilog = (
            """
%s

"""
            % warning
        )

        opts.formatter = HelpFormatter()
        return opts
Example #27
0
def main(argv, package, subpackages, filter, testdir, dirname="test"):

    parser = OptionParser()
    parser.add_option(
        "--no-xunit",
        help="Disable generation of XUnit XML summary",
        action="store_false",
        dest="xunit",
        default=True)
    parser.add_option(
        "-v",
        "--verbose",
        help="Provide verbose output",
        action="store_true",
        dest="verbose",
        default=False)
    parser.add_option(
        "-f",
        "--filter",
        help="Enable filtering of coverage tests with a customized nose installation",
        action="store_true",
        dest="filtering",
        default=False)
    parser.add_option(
        "-F",
        "--filter-all",
        help="Apply nose to all packages, filtering each coverage test",
        action="store_true",
        dest="filtering_all",
        default=False)
    parser.usage = "runtests [options] <package> [...]"
    parser.description = "A utility to run Pyomo tests.  A particular feature of this tool is the ability to filter coverage information, using a customized installation of the nose utility."
    parser.epilog = """The customized nose utility that supports filtering can be obtained from Bill Hart ([email protected])."""
    #
    # Process argv list
    #
    (options, args) = parser.parse_args(args=argv)
    #
    # Preprocess arguments, to eliminate trailing '/' or '\\' characters, which a user
    # might add using tab completion.
    #
    for i in range(0, len(args)):
        if args[i][-1] == os.sep:
            args[i] = args[i][:-1]
    #
    # Verify that the arguments are valid subpackages
    #
    unwanted = copy.copy(subpackages)
    for arg in args[1:]:
        if not arg in subpackages:
            print("ERROR: no subpackage '" + arg)
            sys.exit(1)
        unwanted.remove(arg)
    if unwanted == subpackages:
        unwanted = []
    #
    # Remove coverage files from previous 'runtests' executions
    #
    coverage_file = testdir + os.sep + dirname + os.sep + ".coverage"
    if os.path.exists(coverage_file):
        os.remove(coverage_file)
    os.environ["COVERAGE_FILE"] = coverage_file
    #for file in glob.glob("*/.coverage"):
    #os.remove(file)
    #for file in glob.glob("*/*/.coverage"):
    #os.remove(file)
    #
    # Remove XML files from previous 'runtests' executions
    #
    xunitdir = testdir + os.sep + dirname + os.sep + "xunit"
    if os.path.exists(xunitdir):
        for file in glob.glob(xunitdir + os.sep + "TEST*.xml"):
            os.remove(file)
    else:
        os.mkdir(xunitdir)

    plugins = [UnwantedPackagePlugin(unwanted)]
    #if nose_xunit_installed and options.xunit:
    #plugins.append(nosexunit.plugin.NoseXUnit())
    #if coverage_installed:
    #plugins.append(nose.plugins.cover.Coverage())
    #plugins.append(nose.plugins.xunit.Xunit())
    if not options.filtering_all:
        newargs = ['runtests'] + generate_options(
            package, args[1:], subpackages, filter, options, testdir, xunitdir,
            dirname) + args[1:]
        os.chdir(testdir)
        if options.verbose:
            print("Nose Arguments:", newargs)
            print("Test Dir:", testdir)
            if len(args) > 1:
                print("Test Packages:",)
                for arg in args[1:]:
                    print(arg,)
                print("")
            if len(unwanted) > 1:
                print("Ignored Packages:", unwanted)
        sys.argv = newargs
        nose.run(argv=newargs, addplugins=plugins)
    else:
        if len(args[1:]) == 0:
            arglist = subpackages
        else:
            arglist = args[1:]
        for arg in arglist:
            newargs = ['runtests'] + generate_options(arg, options) + [arg]
            print("Package Coverage Tests: " + arg)
            tmp = sys.stdout
            os.chdir(testdir)
            if options.verbose:
                print("Nose Arguments:", newargs)
                print("Test Dir:", testdir)
                if len(args) > 1:
                    print("Test Packages:",)
                    for arg in args[1:]:
                        print(arg,)
                    print("")
                if len(unwanted) > 1:
                    print("Ignored Packages:", unwanted)
            nose.run(argv=newargs, addplugins=plugins)
            sys.stdout = tmp
    #
    # Rename xUnit files and insert the package information
    #
    if os.path.exists(xunitdir):
        p = re.compile('^.*TEST-(.+)\.xml')
        for file in glob.glob(xunitdir + os.sep + "TEST-*.xml"):
            oldname = p.match(file).group(1)
            if oldname == "test":
                suffix = ""
            else:
                suffix = "." + oldname

            FILE = open(file, "r")
            text0 = "".join(FILE.readlines())
            FILE.close()
            ptmp = re.compile("testsuite name=\"nosetests\"")
            text1 = ptmp.sub("testsuite name=\"" + package + "\"", text0)
            #ptmp = re.compile("classname=\""+oldname)
            #text2 = ptmp.sub("classname=\""+package+suffix, text1)
            #FILE = open(xunitdir+os.sep+"TEST-"+package+suffix+".xml","w")
            FILE = open(file, "w")
            FILE.write(text1)
            FILE.close()
Example #28
0
                      metavar="FILE",
                      help="Output js version 3d file")
    parser.add_option("-c",
                      "--streamjs",
                      dest="streamjs",
                      default=False,
                      action="store_true",
                      help="Stream js to stdout")
    parser.add_option("-t",
                      "--tunnelvr",
                      dest="tunnelvr",
                      default=False,
                      action="store_true",
                      help="TunnelVR format")
    parser.description = "Analyses or processes survex 3D file to do things with the passages\n(station beginning with 'fbmap_' should be mountaintops)"
    parser.epilog = "Best way to execute: dump3d yourcave.3d | ./parse3ddmp.py -s -r \n"

    # Code is here: https://bitbucket.org/goatchurch/survexprocessing
    options, args = parser.parse_args()

    # push command line args that look like files into file options
    if len(args) >= 1 and re.search("\.js$", args[0]) and not options.js:
        options.js = args.pop(0)
    if len(args) >= 1 and re.search("\.dmp$", args[0]) and not options.dmp:
        options.dmp = args.pop(0)
    if len(args) >= 1 and re.search("\.3d$", args[0]) and not options.s3d:
        options.s3d = args.pop(0)
    if len(args) >= 1 and re.search("\.svx$", args[0]) and not options.svx:
        options.svx = args.pop(0)

    # get the input dmp stream
Example #29
0
def main():
    parser = OptionParser() # creates an instance of the parser
    parser.usage = "%prog -i input.cara [-o output.cara] [-p project-name]"
    parser.description = "%prog  reads in a CARA repository and changes the visibility of specified classes of spinlinks in specified spectra. It is recommended to run showAllSpinLinks.py before running this script."
    parser.epilog = ""
    parser.add_option("-i", "--input", dest="infile",type="string",default=None,
                      help="name of original CARA repository, required.", metavar="FILE")
    parser.add_option("-o", "--output", dest="outfile",type="string",default=None,
                      help="name of new CARA repository, defaults to stdout.", metavar="FILE")
    parser.add_option("-p", "--project", metavar="NAME", dest="project", default=None,type="string",
                      help="name of project to alter, if there is more than one project in the repository, defaults to the first project.")
    parser.add_option("-l","--log",metavar="FILE",dest="log",default=None,type="string",
                      help="name of log file.")

    # Now parse the command-line options
    (options, args) = parser.parse_args()

    infile = options.infile
    outfile = options.outfile
    projectName = options.project
    log = options.log

    if infile == None:
        parser.print_help()
        parser.error("Please specify an input cara file.")

    if outfile == None:
        outfile = stdout
    elif exists(outfile):
        print '\nOutput file \'%s\' exists. Choose a new name to avoid overwriting.\n'%outfile
        return

    if log == None:
        log = stdout
    
    # Now that we have an input file and we know where to send the output, we parse the xml.

    tree = ET.parse(infile)
    root = tree.getroot() #retrieves the whole repository
    projects = root.findall('project') #retrieves every project in the repository

# Select a project according to command-line input, defaulting to the first project

    if projectName:
        project = getProject(projectName,projects)
        if not project:
            print 'No project found with name \"%s\".'%projectName
            return
    else:
        project = projects[0]
        if not project:
            print 'No project found.'
            return

### Retrieve data from CARA repository ####################################

    spinbase = project.find('spinbase')
    spins = spinbase.findall('spin')
    spinlinks = spinbase.findall('pair')
    systems = spinbase.findall('spinsys')
    sequence = project.find('sequence')
    residues = sequence.findall('residue')

### Organize CARA repository data into dictionaries #######################
    
    spindict = {}
    #pairList = []
    sysdict = {}
    resdict = {}

    for res in residues:
        residueID = int(res.get('id'))
        residueType = res.get('type')
        resdict[residueID] = residueType

    for sys in systems:
        systemID = int(sys.get('id'))
        try:
            residueID = int(sys.get('ass'))
        except Exception, e:
            residueID = None
        sysdict[systemID] = residueID
Example #30
0
def init_host_test_cli_params():
    """! Function creates CLI parser object and returns populated options object.
    @return Function returns 'options' object returned from OptionParser class
    @details Options object later can be used to populate host test selector script.
    """
    parser = OptionParser()

    parser.add_option("-m",
                      "--micro",
                      dest="micro",
                      help="Target microcontroller name",
                      metavar="MICRO")

    parser.add_option("-p",
                      "--port",
                      dest="port",
                      help="Serial port of the target",
                      metavar="PORT")

    parser.add_option("-d",
                      "--disk",
                      dest="disk",
                      help="Target disk (mount point) path",
                      metavar="DISK_PATH")

    parser.add_option("-t",
                      "--target-id",
                      dest="target_id",
                      help="Unique Target Id or mbed platform",
                      metavar="TARGET_ID")

    parser.add_option("-f",
                      "--image-path",
                      dest="image_path",
                      help="Path with target's binary image",
                      metavar="IMAGE_PATH")

    copy_methods_str = "Plugin support: " + ', '.join(
        host_tests_plugins.get_plugin_caps('CopyMethod'))

    parser.add_option("-c",
                      "--copy",
                      dest="copy_method",
                      help="Copy (flash the target) method selector. " +
                      copy_methods_str,
                      metavar="COPY_METHOD")

    reset_methods_str = "Plugin support: " + ', '.join(
        host_tests_plugins.get_plugin_caps('ResetMethod'))

    parser.add_option("-r",
                      "--reset",
                      dest="forced_reset_type",
                      help="Forces different type of reset. " +
                      reset_methods_str)

    parser.add_option(
        "-C",
        "--program_cycle_s",
        dest="program_cycle_s",
        help=
        "Program cycle sleep. Define how many seconds you want wait after copying binary onto target",
        type="float",
        metavar="PROGRAM_CYCLE_S")

    parser.add_option(
        "-R",
        "--reset-timeout",
        dest="forced_reset_timeout",
        metavar="NUMBER",
        type="float",
        help=
        "When forcing a reset using option -r you can set up after reset idle delay in seconds"
    )

    parser.add_option("-e",
                      "--enum-host-tests",
                      dest="enum_host_tests",
                      help="Define directory with local host tests")

    parser.add_option(
        '',
        '--test-cfg',
        dest='json_test_configuration',
        help='Pass to host test class data about host test configuration')

    parser.add_option('',
                      '--list',
                      dest='list_reg_hts',
                      default=False,
                      action="store_true",
                      help='Prints registered host test and exits')

    parser.add_option('',
                      '--plugins',
                      dest='list_plugins',
                      default=False,
                      action="store_true",
                      help='Prints registered plugins and exits')

    parser.add_option(
        '',
        '--run',
        dest='run_binary',
        default=False,
        action="store_true",
        help=
        'Runs binary image on target (workflow: flash, reset, output console)')

    parser.add_option(
        '',
        '--skip-flashing',
        dest='skip_flashing',
        default=False,
        action="store_true",
        help=
        'Skips use of copy/flash plugin. Note: target will not be reflashed')

    parser.add_option(
        '',
        '--skip-reset',
        dest='skip_reset',
        default=False,
        action="store_true",
        help='Skips use of reset plugin. Note: target will not be reset')

    parser.add_option(
        '-P',
        '--pooling-timeout',
        dest='pooling_timeout',
        default=60,
        metavar="NUMBER",
        type="int",
        help=
        'Timeout in sec for mbed-ls mount point and serial port readiness. Default 60 sec'
    )

    parser.add_option(
        '-b',
        '--send-break',
        dest='send_break_cmd',
        default=False,
        action="store_true",
        help=
        'Send reset signal to board on specified port (-p PORT) and print serial output. You can combine this with (-r RESET_TYPE) switch'
    )

    parser.add_option('-v',
                      '--verbose',
                      dest='verbose',
                      default=False,
                      action="store_true",
                      help='More verbose mode')

    parser.add_option('',
                      '--version',
                      dest='version',
                      default=False,
                      action="store_true",
                      help='Prints package version and exits')

    parser.description = """Flash, reset and perform host supervised tests on mbed platforms"""
    parser.epilog = """Example: mbedhtrun -d E: -p COM5 -f "test.bin" -C 4 -c shell -m K64F"""

    (options, _) = parser.parse_args()
    return options
Example #31
0
'''
import urllib, time, sys
from urllib import urlopen, urlencode
from optparse import OptionParser

try:
    from pyparsing import *
except ImportError:
    print "pyparsing is a required module for this programs operation!"
    print "Please: $sudo apt-get install python-pyparsing"

parser = OptionParser()
parser.add_option("-i", "--input", dest="in_filename", help="File to analyze", default=None)
parser.add_option("-o", "--output", dest="out_filename", help="File to save to", default=None)
parser.add_option("-f", "--full", action="store_true", dest="full", default=False, help="Require full bib-time match")
parser.epilog = __doc__

(options, args) = parser.parse_args()


if options.in_filename == None or options.out_filename == None:
    parser.print_help()
    sys.exit(0)

# Definition of the bibitem stuff
label = Word(nums + alphas + ":.")

# This is the parser for a basic /bibitem 
bib_item_header = Literal(r"\bibitem{").suppress() + label + Literal("}").suppress()
bib_item_header.setName("Header")
Example #32
0
def init_host_test_cli_params():
    """Create CLI parser object and return populated options object.

    Options object can be used to populate host test selector script.

    Returns:
        'options' object returned from OptionParser class.
    """
    parser = OptionParser()

    parser.add_option(
        "-m",
        "--micro",
        dest="micro",
        help="Target microcontroller name",
        metavar="MICRO",
    )

    parser.add_option("-p",
                      "--port",
                      dest="port",
                      help="Serial port of the target",
                      metavar="PORT")

    parser.add_option(
        "-d",
        "--disk",
        dest="disk",
        help="Target disk (mount point) path",
        metavar="DISK_PATH",
    )

    parser.add_option(
        "-t",
        "--target-id",
        dest="target_id",
        help="Unique Target Id",
        metavar="TARGET_ID",
    )

    parser.add_option(
        "",
        "--sync",
        dest="sync_behavior",
        default=2,
        type=int,
        help=(
            "Define how many times __sync packet will be sent to device: 0: "
            "none; -1: forever; 1,2,3... - number of times (Default 2 time)"),
        metavar="SYNC_BEHAVIOR",
    )

    parser.add_option(
        "",
        "--sync-timeout",
        dest="sync_timeout",
        default=5,
        type=int,
        help=
        "Define delay in seconds between __sync packet (Default is 5 seconds)",
        metavar="SYNC_TIMEOUT",
    )

    parser.add_option(
        "-f",
        "--image-path",
        dest="image_path",
        help="Path with target's binary image",
        metavar="IMAGE_PATH",
    )

    copy_methods_str = "Plugin support: " + ", ".join(
        host_tests_plugins.get_plugin_caps("CopyMethod"))

    parser.add_option(
        "-c",
        "--copy",
        dest="copy_method",
        help="Copy (flash the target) method selector. " + copy_methods_str,
        metavar="COPY_METHOD",
    )

    parser.add_option(
        "",
        "--retry-copy",
        dest="retry_copy",
        default=3,
        type=int,
        help="Number of attempts to flash the target",
        metavar="RETRY_COPY",
    )

    parser.add_option(
        "",
        "--tag-filters",
        dest="tag_filters",
        default="",
        type=str,
        help=
        ("Comma seperated list of device tags used when allocating a target "
         "to specify required hardware or attributes [--tag-filters tag1,tag2]"
         ),
        metavar="TAG_FILTERS",
    )

    reset_methods_str = "Plugin support: " + ", ".join(
        host_tests_plugins.get_plugin_caps("ResetMethod"))

    parser.add_option(
        "-r",
        "--reset",
        dest="forced_reset_type",
        help="Forces different type of reset. " + reset_methods_str,
    )

    parser.add_option(
        "-C",
        "--program_cycle_s",
        dest="program_cycle_s",
        default=4,
        help=(
            "Program cycle sleep. Define how many seconds you want wait after "
            "copying binary onto target (Default is 4 second)"),
        type="float",
        metavar="PROGRAM_CYCLE_S",
    )

    parser.add_option(
        "-R",
        "--reset-timeout",
        dest="forced_reset_timeout",
        default=1,
        metavar="NUMBER",
        type="float",
        help=(
            "When forcing a reset using option -r you can set up after reset "
            "idle delay in seconds (Default is 1 second)"),
    )

    parser.add_option(
        "--process-start-timeout",
        dest="process_start_timeout",
        default=60,
        metavar="NUMBER",
        type="float",
        help=(
            "This sets the maximum time in seconds to wait for an internal "
            "process to start. This mostly only affects machines under heavy "
            "load (Default is 60 seconds)"),
    )

    parser.add_option(
        "-e",
        "--enum-host-tests",
        dest="enum_host_tests",
        action="append",
        default=["./test/host_tests"],
        help="Define directory with local host tests",
    )

    parser.add_option(
        "",
        "--test-cfg",
        dest="json_test_configuration",
        help="Pass to host test class data about host test configuration",
    )

    parser.add_option(
        "",
        "--list",
        dest="list_reg_hts",
        default=False,
        action="store_true",
        help="Prints registered host test and exits",
    )

    parser.add_option(
        "",
        "--plugins",
        dest="list_plugins",
        default=False,
        action="store_true",
        help="Prints registered plugins and exits",
    )

    parser.add_option(
        "-g",
        "--grm",
        dest="global_resource_mgr",
        help=
        ('Global resource manager: "<remote mgr module>:<host url or IP address>'
         '[:<port>]", Ex. "module_name:10.2.123.43:3334", '
         'module_name:https://example.com"'),
    )

    # Show --fm option only if "fm_agent" module installed
    try:
        imp.find_module("fm_agent")
    except ImportError:
        fm_help = SUPPRESS_HELP
    else:
        fm_help = (
            "Fast Model connection, This option requires mbed-fastmodel-agent "
            'module installed, list CONFIGs via "mbedfm"')
    parser.add_option(
        "",
        "--fm",
        dest="fast_model_connection",
        metavar="CONFIG",
        default=None,
        help=fm_help,
    )

    parser.add_option(
        "",
        "--run",
        dest="run_binary",
        default=False,
        action="store_true",
        help=
        "Runs binary image on target (workflow: flash, reset, output console)",
    )

    parser.add_option(
        "",
        "--skip-flashing",
        dest="skip_flashing",
        default=False,
        action="store_true",
        help=
        "Skips use of copy/flash plugin. Note: target will not be reflashed",
    )

    parser.add_option(
        "",
        "--skip-reset",
        dest="skip_reset",
        default=False,
        action="store_true",
        help="Skips use of reset plugin. Note: target will not be reset",
    )

    parser.add_option(
        "-P",
        "--polling-timeout",
        dest="polling_timeout",
        default=60,
        metavar="NUMBER",
        type="int",
        help=("Timeout in sec for readiness of mount point and serial port of "
              "local or remote device. Default 60 sec"),
    )

    parser.add_option(
        "-b",
        "--send-break",
        dest="send_break_cmd",
        default=False,
        action="store_true",
        help=(
            "Send reset signal to board on specified port (-p PORT) and print "
            "serial output. You can combine this with (-r RESET_TYPE) switch"),
    )

    parser.add_option(
        "",
        "--baud-rate",
        dest="baud_rate",
        help=(
            "Baud rate of target, overrides values from mbed-ls, disk/mount "
            "point (-d, --disk-path), and serial port -p <port>:<baud rate>"),
        metavar="BAUD_RATE",
    )

    parser.add_option(
        "-v",
        "--verbose",
        dest="verbose",
        default=False,
        action="store_true",
        help="More verbose mode",
    )

    parser.add_option(
        "",
        "--serial-output-file",
        dest="serial_output_file",
        default=None,
        help="Save target serial output to this file.",
    )

    parser.add_option(
        "",
        "--compare-log",
        dest="compare_log",
        default=None,
        help="Log file to compare with the serial output from target.",
    )

    parser.add_option(
        "",
        "--version",
        dest="version",
        default=False,
        action="store_true",
        help="Prints package version and exits",
    )

    parser.add_option(
        "",
        "--format",
        dest="format",
        help="Image file format passed to pyocd (elf, bin, hex, axf...).",
    )

    parser.description = (
        """Flash, reset and perform host supervised tests on Mbed enabled platforms"""
    )
    parser.epilog = (
        """Example: htrun -d E: -p COM5 -f "test.bin" -C 4 -c shell -m K64F""")

    (options, _) = parser.parse_args()

    if len(sys.argv) == 1:
        parser.print_help()
        sys.exit()

    return options
Example #33
0
    return keys


def format_keys(keys):
    return " ; ".join(keys)


def get_keys_from_html(html):
    keys = get_keywords(html)
    return format_keys(keys)


def main(url):
    logging.info("getting html from %s", url)
    html = get_html(url)
    logging.info("searching from keys")
    keys = get_keywords(html)
    return format_keys(keys)

if __name__ == "__main__":
    from optparse import OptionParser
    parser = OptionParser()
    parser.epilog = "example: python dump_keyword.py  http://inspirehep.net/record/1114314"
    (options, args) = parser.parse_args()

    if len(args) != 1:
        logging.error("you have to specify the arxiv url")
        exit()

    print main(args[0])


# Internal Variable initialisations
valid_xml=float(0)
invalid_xml=float(0)

opmn_cmds = ['coreapplication_obips1' ,'coreapplication_obis1','opmn']
#opmn_cmds = ['coreapplication_obips2' ,'coreapplication_obis2','coreapplication_obips1' ,'coreapplication_obis1','opmn']

# OptionParser is depreciated in Python 2.7, but used here for compatibility with Python 2.4 (the version distributed with OEL 5.5)
# NB it does not support newlines (\n) but these are included for when I figure out how to implement them
opts = OptionParser()
opts.description = "obi-metrics-agent will can extract metric data from Fusion MiddleWare (FMW) and its Dynamic Monitoring Systems (DMS).\nIt will poll at a predefined interval and parse the resulting set of metrics.\nThe metrics can be output to a variety of formats, including CSV. Sending to Carbon is also supported, from where graphs can be rendered in Graphite."
# epilog doesn't display, why?
opts.epilog = ("Developed by @rmoff / Rittman Mead (http://www.rittmanmead.com)           Absolutely no warranty, use at your own risk                                         Please include this notice in any copy or reuse of the script you make ")
opts.add_option("-o","--output",action="store",dest="outputformat",default="csv",help="The output format(s) of data, comma separated. More than one can be specified.\nUnparsed options: raw, xml\nParsed options: csv , carbon, sql")
opts.add_option("-d","--data-directory",action="store",dest="DATA",default="./data",help="The directory to which data files are written. Not needed if sole output is carbon.")
opts.add_option("-p","--parse-only",action="store_true",dest="parse_only",default=False, help="If specified, then all raw and xml files specified in the data-directory will be processed, and output to the specified format(s)\nSelecting this option will disable collection of metrics.")
opts.add_option("-v","--verbose",action="store_true",dest="debug_on",default=False, help="Verbose output")
opts.add_option("--fmw-instance",action="store",dest="FMW_INSTANCE",help="Optional. The name of a particular FMW instance. This will be prefixed to metric names.")
opts.add_option("--carbon-server",action="store",dest="CARBON_SERVER",help="The host or IP address of the Carbon server. Required if output format 'carbon' specified.")
opts.add_option("--carbon-port",action="store",dest="CARBON_PORT",default=2003,help="Alternative carbon port, if not 2003.")
opts.add_option("-i","--interval",action="store",dest="interval",default=5,help="The interval in seconds between metric samples. Specify 0 for no loop (i.e. run once and exit)")
opts.add_option("--opmnbin",action="store",dest="OPMN_BIN",help="The complete path to opmnctl. Watch out for spaces.")

input_opts , args = opts.parse_args()

try:
	interval = int(input_opts.interval)
	output=input_opts.outputformat
Example #35
0
def main():

    usage = "%prog [options] <input_dir> <output_dir>"
    parser = OptionParser(usage=usage, formatter=MyHelpFormatter())
    parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
            default=False, help="Be more verbose")
    parser.add_option('-m', '--move', dest='move', action='store_true',
            default=False, help="Instead of copying the files, the files "
            "will be moved to the destination. Default=False")
    parser.add_option('-f', '--format', dest='format', default=F_SIMPLE,
            help='Target folder format. Can be one of {0}, {1} or {2}'.format(
                   F_SIMPLE,
                   F_ASPECT,
                   F_APPROX_ASPECT))
    parser.add_option('-s', '--target-for', dest='target_for',
            metavar='SIZE', default=None,
            help='Show the target folder for a given resolution '
                 'and exit. For example: SIZE=1680x1050')
    epilog = """\

FORMATS
=======

There are three different naming options for target folders:

--format=s (the default)
    When using this format, the application will simply generate folders
    representing width and height. An image with a width of 1920 and height op
    1080 will be saved to a folder named '1920x1080'.

--format=a
    This will store the images into folders which represent the images aspect
    ratio. Note that the aspect ratios will be aggressively reduced if
    possible. So an aspect ratio of "16:10" will be reduced to "8:5".
    Additionally, while a proper display would be "16:9", the folder names
    will be named "16@9" for compatibility with Windows, as it does not allow
    ``:`` in file names.

--format=x
    This is the same as ``--format=a`` with the difference that the
    denominator will never be larger than 10. This results in an approximate
    destination for files. So the folder "16@9" might contain images which do
    not quite have this aspect ratio. But it will always be close.
"""
    parser.epilog = epilog

    (options, args) = parser.parse_args()

    if options.target_for:
        width, height = options.target_for.split('x')
        target = aspect_folder(int(width), int(height), options.format)
        print "Pictures of size %s will be moved into %s" % (
                options.target_for, target)
        sys.exit(0)

    if len(args) != 2:
        parser.print_help()
        sys.exit(9)

    if options.verbose:
        print "Being verbose"
        logging.basicConfig(level=logging.DEBUG)
    else:
        logging.basicConfig()

    input_dir, output_dir = args

    move_files(input_dir, output_dir, options.format, move=options.move)
def main():
### Parsing command-line options ##########################################
    # The OptionParser has two purposes here:
    # 1. facilitate obtaining filenames for input and output, and possibly
    #    the name of a project, in case there is more than one project in
    #    the repository
    # 2. provide help text in case the user needs to be reminded of how to
    #    invoke the script. The help text will be printed if the user
    #    invokes the script with the -h or --help option, or if the user
    #    fails to supply an input file. The help file shows the usage, then
    #    then the description, then describes the possible options, and ends
    #    with the epilog.
    # 
    # First we fill in usage, description, and epilog with the text we want
    # to show up in help. Then we define the options, including help text,
    # but also variable names for storing the input and output filenames.
    
    parser = OptionParser() # creates an instance of the parser
    parser.usage = "%prog -i input.cara -d shiftChange -t tag -s spectrumID [-o output.cara] [-p project-name]"
    parser.description = "%prog takes a cara repository file and shifts all the spin aliases with the indicated tag in the indicated spectrum by a specified amount."
    parser.epilog = ""
    parser.add_option("-d", "--shift", dest="shiftChange", type="float",
                      help="Desired change in chemical shift in ppm, required.")
    #parser.add_option("-a", "--aliases", dest="alias", action="store_true", default=False,
    #                  help="Use this flag to change aliases as well as regular spins.")
    parser.add_option("-i", "--input", dest="infile",type="string",default=None,
                      help="name of original CARA repository, required.", metavar="FILE")
    parser.add_option("-o", "--output", dest="outfile",type="string",default=None,
                      help="name of new CARA repository, defaults to stdout.", metavar="FILE")
    parser.add_option("-p", "--project", metavar="NAME", dest="project", default=None,type="string",
                      help="name of project to alter, if there is more than one project in the repository, defaults to the first project.")
    parser.add_option("-t", "--tag", metavar="TAG", dest="tagToShift", default=None,type="string",
                      help="tag of spins to shift, eg N. Required.")
    parser.add_option("-s", "--spectrum",metavar="SPECID",dest="specID",default=None,type="int",
                      help="ID of spectrum with aliases to shift")
    # Now parse the command-line options
    (options, args) = parser.parse_args()

    infile = options.infile
    outfile = options.outfile
    projectName = options.project
    shiftChange = options.shiftChange
    #alias = options.alias
    tagToShift = options.tagToShift
    specIDtoShift = str(options.specID)
    
    if tagToShift == None:
        parser.print_help()
        parser.error("Please specify an atom type tag to shift, such as \"N\".")
    
    if shiftChange == None:
        parser.print_help()
        parser.error("Please specify a chemical shift change in ppm.")

    if infile == None:
        parser.print_help()
        parser.error("Please specify an input file.")

    if outfile == None:
        outfile = stdout
    elif exists(outfile):
        print '\nOutput file \'%s\' exists. Choose a new name to avoid overwriting.\n'%outfile
        return

    alias = False
    if specIDtoShift == None:
        print '\nNo spectrum ID was indicated. All spins will be shifted.\n'
        parser.print_help()
        specIDtoShift = 0
        alias = True

    # Now that we have an input file and we know where to send the output, we parse the xml.

    tree = ET.parse(infile)
    root = tree.getroot() #retrieves the whole repository
    projects = root.findall('project') #retrieves every project in the repository

# Select a project according to command-line input, defaulting to the first project

    if projectName:
        project = getProject(projectName,projects)
        if not project:
            print 'No project found with name \"%s\".'%projectName
            return
    else:
        project = projects[0]
        if not project:
            print 'No project found.'
            return

# Convert spins

    spinbase = project.find('spinbase')
    spins = spinbase.findall('spin')


    
    for spin in spins:
        tag = spin.get('tag')
        if tag == tagToShift:
            positions = spin.findall('pos')
            spectra = [pos.get('spec') for pos in positions]
            if specIDtoShift not in spectra:
                newalias = ET.Element('pos')
                unalias = [pos for pos in positions if pos.get('spec') == '0'][0]
                for attribute in unalias.keys():
                    newalias.set(attribute,unalias.get(attribute))
                newalias.set('spec',specIDtoShift)
                spin.append(newalias)
                positions.append(newalias)
            for pos in positions:
                spec = pos.get('spec')
                shift = float(pos.get('shift'))
                if spec == specIDtoShift or alias==True:
                    newshift = str(shift+shiftChange)
                    pos.set('shift',newshift)
                
# Write out the modified xml tree

    tree.write(outfile)
Example #37
0
        dest="time_window",
        type="float",
        default=1.0,
        help="Number of seconds to sample CPU use of renderer processes.")
    op.add_option(
        "--threshold",
        action="store",
        dest="threshold",
        type="float",
        default=0.05,
        help=
        "Threshold for determining CPU \"piggyness\" of renderer processes.")

    op.disable_interspersed_args()

    op.epilog = """\
    Selectively enable or disable Chromium browser process instances.
    This is done by issuing SIGSTOP and SIGCONT signals.  This program
    only runs on Linux.

    The determination of "piggyness" is by sampling the CPU "jiffies"
    before and after a wait of "time_window" which defaults to one second.
    The threshold is the fraction of one CPU core equivalent and defaults
    to 0.05.
"""

    (opts, args) = op.parse_args()
    arg_pids = [parse_pid(arg) for arg in args]

    if opts.enable == True and opts.disable == True:
        op.error("Cannot mix --disable and --enable options.")
Example #38
0
def main():
    """
    Main program.
    """
    class MyIndentedHelpFormatter(IndentedHelpFormatter):
        """ Slightly modified formatter for help output: allow paragraphs """
        def format_paragraphs(self, text):
            """ wrap text per paragraph """
            result = ""
            for paragraph in text.split("\n"):
                result += self._format_text(paragraph) + "\n"
            return result
        def format_description(self, description):
            """ format description, honoring paragraphs """
            if description:
                return self.format_paragraphs(description) + "\n"
            else:
                return ""
        def format_epilog(self, epilog):
            """ format epilog, honoring paragraphs """
            if epilog:
                return "\n" + self.format_paragraphs(epilog) + "\n"
            else:
                return ""
    usage = 'Usage: %s [OPTIONS] fortune_path' % os.path.basename(sys.argv[0])
    arg_parser = OptionParser(usage=usage, formatter=MyIndentedHelpFormatter())
    arg_parser.description = "Print a random, hopefully interesting, adage " \
        "(\"fortune\"), selected from a collection of fortune files found " \
        "in fortune_path.\n\n" \
        "%s " % str(os.path.basename(sys.argv[0])) \
        + 'is an extended implementation of ' \
        'the classic BSD Unix fortune command. It combines the capabilities ' \
        'of the strfile command (which produces the fortune index file) and ' \
        'the fortune command (which displays a random fortune). It reads ' \
        'the traditional fortune program\'s text file format. ' \
        "For more information about the fortune files, and the accompanying " \
        "fortune index files, see below." 
    arg_parser.add_option('-u', '--update', action='store_true', dest='update',
                          help='Update the index files, instead of printing a '
                               'fortune. You must run this before you will be '
                               'able to print fortunes from the fortune files. '
                               'This option serves the same purpose as the '
                               'strfile utility for the traditional BSD '
                               'fortune command. Note that the generated '
                               'index files are not compatible with the format '
                               'of the traditional index files. The generated '
                               'index files have the %s extension.' %  INDEX_EXT
                               )
    arg_parser.add_option('-q', '--quiet', action='store_true', dest='quiet',
                          help="When updating the index file, don't emit " 
                               "messages.")
    arg_parser.add_option('-a', '--all', action='store_true', dest='use_all',
                          help="Choose from all fortune files, including "
                          "offensive ones. Don't complain if you are offended!")
    arg_parser.add_option('-o', '--offensive', action='store_true', 
                          dest='offensive',
                          help="Choose only from offensive fortunes. "
                               "Offensive fortunes are those stored in files "
                               "with filenames ending in '-o'. Make absolutely "
                               "sure that you want to be offended!")
    arg_parser.add_option('-e', '--equal', action='store_true',
                          dest='equal_size',
                          help="Consider all fortune files to be of equal " 
                               "size, making it equally likely for a "
                               "fortune to be chosen from any fortune file")
    arg_parser.add_option('-f', '--fortunefiles', action='store_true',
                          dest='list_fortunefiles',
                          help="Print out the list of files which would be " 
                               "searched, but don't print a fortune. ")
    arg_parser.add_option('-l', '--long', action='store_true', dest='use_long',
                          help="Show only long fortunes. See -n on how " 
                               "''long'' is defined in this sense.")
    arg_parser.add_option('-w', '--wait', action='store', type=int, 
                          dest='seconds_to_wait',
                          help="Wait before termination for an amount of time "
                               "calculated from the number of characters in "
                               "the message. This is useful if it is executed "
                               "as part of the logout procedure to guarantee "
                               "that the message can be read before the screen "
                               "is cleared.")
    arg_parser.add_option('-m', '--filter', action='store', dest='pattern',
                          help="Print out all fortunes which match the " 
                               "regular expression pattern.\n" 
                               "The fortunes are printed to standard output, " 
                               "while the names of the file from which each " 
                               "fortune comes are printed to standard " 
                               "error.  Either or both can be redirected; " 
                               "if standard output is redirected to a file, " 
                               "the result is a valid fortunes database " 
                               "file. If standard error is also redirected " 
                               "to this file, the result is still valid, " 
                               "but there will be ''bogus'' fortunes, i.e. " 
                               "the filenames themselves, in parentheses.\n" 
                               "You may combine this option with -o, -l, " 
                               "-s, -n, -i")
    arg_parser.add_option('-i', '--ignorecase', action='store_true', 
                          dest='ignorecase',
                          help="Ignore case for -m patterns.")
    arg_parser.add_option('-s', '--short', action='store_true', 
                          dest='use_short',
                          help="Show only short fortunes. See -n on how " 
                               "''short'' is defined in this sense.")
    arg_parser.add_option('-n', action='store', dest='max_shortlength',
                          help="Set the longest fortune length (in " 
                               "characters) considered to be ''short'' " 
                               "(the default is %s)" % DEFAULT_LENGTH)

    arg_parser.epilog = 'If <fortune_path> is omitted, fortune looks at ' \
        'the FORTUNE_PATH environment variable for the paths. Different ' \
        'paths in FORTUNE_PATH are separated by \':\'.\n' \
        'An individual item inside the fortune_path can be a direct fortune' \
        'file, or a folder, in which case all fortune files inside the ' \
        'folder will be used. Any item may be preceded by a percentage, '\
        'which is a number N between 0  and 99 inclusive, followed by a %. ' \
        'If it is, there will be a N percent probability that a fortune ' \
         'will be picked from that file or directory. For items for which ' \
         'there is a percentage, the probability of a fortune being selected ' \
         'from any one of them is based on the relative number of fortunes ' \
         'it contains.\n\n' \
         'The format of each fortune file is simple: All the fortunes appear ' \
         'in clear text, separated by a single line containing only a ' \
         '\'%\'. For example, the following is a fortune file containing two ' \
         'fortunes:\n\n' \
         '    186,282 miles per second:\n\n' \
         '    It isn\'t just a good idea, it\'s the law!\n' \
         '    %\n' \
         '    A bird in the hand makes it awfully hard to blow your nose.\n\n' \
         'Before a fortune file can be used, you must generate an index ' \
         'file for it. This is a binary file that is used to select ' \
         'fortunes with more speed and efficiency.\n\n' \
         'For more background information about the fortune utility ' \
         'look at http://en.wikipedia.org/wiki/Fortune_(Unix)'
         

    options, args = arg_parser.parse_args(sys.argv)

    if len(args) >= 2:
        fortunepaths = args[1:]
    else:
        try:
            fortunepaths = os.environ['FORTUNE_PATH'].split(':')
        except KeyError:
            print ("Missing fortune files", file=sys.stderr)
            print ("Try %s --help" % os.path.basename(sys.argv[0]), file=sys.stderr)
            sys.exit(1)

    if options.use_all:
        offensive = None
    elif options.offensive:
        offensive = True
    else:
        offensive = False

    if options.use_short:
        minlength = 0
        maxlength = DEFAULT_LENGTH 
        if not options.max_shortlength is None:
            maxlength = int(options.max_shortlength)
    elif options.use_long:
        minlength = DEFAULT_LENGTH 
        if not options.max_shortlength is None:
            minlength = int(options.max_shortlength)
        maxlength = None
    else:
        minlength = 0
        maxlength = None

    try:
        # Update Mode
        if options.update:
            make_fortune_data_file(fortunepaths)

        # Listing Fortune Files Mode
        elif options.list_fortunefiles:
            percentages, fortune_files = fortune_files_from_paths(fortunepaths,
                                                                  offensive)
            for filename in fortune_files:
                print (filename)

        # Filtering Mode
        elif not options.pattern is None:
            filter_fortunes(fortunepaths, options.pattern, 
                            ignorecase=options.ignorecase, 
                            offensive=offensive)
                
        # Printing Fortunes Mode
        else:
            sys.stdout.write(get_random_fortune(
                fortunepaths, 
                offensive=offensive,
                weighted=(not options.equal_size),
                min_length=minlength,
                max_length=maxlength) )

    except ValueError as msg:
        print(msg, file=sys.stderr)
        sys.exit(1)

    if not options.seconds_to_wait is None:
        sleep(options.seconds_to_wait)

    sys.exit(0)
Example #39
0
#!/usr/bin/env python
import os, sys

from optparse import OptionParser, Option, OptionGroup
parser = OptionParser()

parser.usage = "%s [--option [Argument]]" % os.path.basename(sys.argv[0])

parser.epilog = """
Python implementation on tests2 -- Vision's Stage 2 testbench.
"""

parser.add_option( '--s',      dest='starttime', metavar='<starttime>', help='starttime for testbench (used to sync chips)')
parser.add_option( '--sr',     dest='seed',      metavar='<seed>',      help='seed value for random number generation')
parser.add_option( '--js',     dest='speed',     metavar='<speed>',     help='set speed of JTAG interface in kHz (750, 1500, 300, 6000, 12000, 24000')
parser.add_option( '--c',      dest='filename',  metavar='<filename>',  help='specify xml-file to be loaded (default hicann_conf.xml)', default='hicann_conf.xml')
parser.add_option( '--log',    dest='loglevel',  metavar='<loglevel>',  help='specify integer log level - default is 2: INFO')
parser.add_option( '--l',      action='store_true',                     help='list testmodes')
parser.add_option( '--m',      dest='testmode',  metavar='<name>',      help='uses testmode')
parser.add_option( '--label',  dest='label',     metavar='<label>',     help='label your test')

comm_techniques = OptionGroup(parser, 'Comm. technique for: | FPGA  |  DNC   | HICANN')
comm_techniques.add_options( [
Option( '--bj',     action='store_true',                    help='  |  --   |  --    | JTAG  (e.g. I2C)'),
Option( '--bj2f',   nargs=2, type=int, metavar='<nh> <h>',   help='  | JTAG  | GBit   | GBit  (<nh> HICANNs, using <h>)'),
Option( '--bja',    nargs=2, type=int, metavar='<nh> <h>',   help='  | JTAG  | JTAG   | JTAG'),
Option( '--bjac',   nargs=2, type=int, metavar='<nh> <h>',   help='  | JTAG  |  --    | JTAG'),
Option( '--bt',     action='store_true',                    help='uses tcpip communication model'),
Option( '--btp',    action='store_true',                    help='uses tcpip communication model with playback memory'),
Option( '--bo',     action='store_true',                    help='use direct ocp communication model'),
])
Example #40
0
#TOBO:id3tag: "http://img.youtube.com/vi/"..video_id.."/default.jpg"

import urllib, webbrowser, os, tempfile, time, threading, re, sys
from optparse import OptionParser
from optparse import OptionGroup
import modules
import modules.cfg
import modules.language

#leerzeile
print ""
#Die ganzen Argumente wenn man diese Datei auf der shell verwendet (z.B. ohne X-server)
parser = OptionParser()
parser.usage = "%prog [options] YouTubeUrl [YTUrl] ..."
parser.description = _("This is a easy program to download YouTube videos and extract the audio to mp3. (with shell or gui) (for mp3 lame and faad2 is required)")
parser.epilog = _("This program is biodegradable.")

group = OptionGroup(parser, _("Normal options"), _("Example for a fullHD-download and mp3 conversion:\n'./pYtLoader.py -c --fullhd http://www.youtube.com/watch?v=uxk4hIX3Kn4'."))
advanced_group = OptionGroup(parser, _("advanced options"), _("Options, for non normal people."))
group.add_option("-c", "--convert", dest="convert", help=_("Convert video to (can be used only with mp4)."), default=False, action="store_true")
group.add_option("", "--hd", dest="usehd", help=_("Download in high quality (720p), if available."), default=False, action="store_true")
group.add_option("", "--fullhd", dest="usefullhd", help=_("Download in high quality (1080p), if available."), default=False, action="store_true")
group.add_option("-3", "--3gp", dest="use3gp", help=_("Download as 3gp for mobile phones video (MPEG-4)."), default=False, action="store_true")
group.add_option("-l", "--flv", dest="useflv", help=_("Download video as flv."), default=False, action="store_true")

advanced_group.add_option("-f", "--fmt", dest="usefmt", help=_("Download video in custom quality (-f 0 to show the fmt list; Without this option the best quality will be downloaded.)"), metavar="FMT")
advanced_group.add_option("", "--megahd", dest="usemegahd", help=_("Download in very high quality (4096x2304), if available."), default=False, action="store_true")
advanced_group.add_option("", "--3gp4", dest="use3gp4", help=_("Download as 3gp for mobile phones video (h263)."), default=False, action="store_true")
advanced_group.add_option("-w", "--webm", dest="usewebm", help=_("Download video in WebM."), default=False, action="store_true")
advanced_group.add_option("-u", "--url", dest="useurl", help=_("Only print download URL."), default=False, action="store_true")
advanced_group.add_option("-b", "--webbrowser", dest="useweb", help=_("Open downloadurl in your default webbrowser. (senseless?!)"), default=False, action="store_true")
Example #41
0
def do_parse_args():
    """Parse command line arguments."""
    parser = OptionParser()

    # Set default checks.
    parser.set_defaults(formats=False)
    parser.set_defaults(imports=False)
    parser.set_defaults(manifest=False)
    parser.set_defaults(quality=False)
    parser.set_defaults(checkers=[])
    parser.set_defaults(security=False)

    # Set default output options.
    parser.set_defaults(auto=False)
    parser.set_defaults(benchmark=False)
    parser.set_defaults(color=False)
    parser.set_defaults(report=False)
    parser.set_defaults(verbose=True)

    # Which file(s) to check.
    parser.add_option("-f",
                      "--file",
                      action='append',
                      dest="filename",
                      help="comma-separated list of files to check",
                      metavar="FILE[S]")

    # How much to poop out to the screen.
    parser.add_option("-v",
                      "--verbose",
                      action='store_true',
                      dest='verbose',
                      help="provide verbose output",
                      default=True)
    parser.add_option("-q",
                      "--quiet",
                      action='store_false',
                      dest='verbose',
                      help="provide less verbose output")

    # Which checkers to run.
    parser.add_option("--format",
                      action='store_true',
                      dest='formats',
                      help="check (and optionally fix) the formatting of the "
                      "code using yapf")
    parser.add_option("--import",
                      action='store_true',
                      dest='imports',
                      help="check (and optionally fix) the order/grouping of "
                      "imports using isort")
    parser.add_option("--manifest",
                      action='store_true',
                      dest='manifest',
                      help="check the MANIFEST.in file for proper content "
                      "using check-manifest")
    parser.add_option("--quality",
                      action='store_true',
                      dest='quality',
                      help="check the quality/style of the code using one "
                      "or more checkers from flake8, pycodestyle, "
                      "pydocstyle, pylint")
    parser.add_option("--checkers",
                      action='append',
                      dest='checkers',
                      help="comma-separated list of checkers to use for "
                      "quality checks",
                      metavar="<flake8,pycodestyle,pydocstyle,pylint>")
    parser.add_option("--security",
                      action='store_true',
                      dest='security',
                      help="check for potential security vulnerabilities "
                      "using bandit")

    # Which files to (not) check.
    parser.add_option("-i",
                      "--ignore",
                      action='append',
                      type='string',
                      dest='ignore',
                      help="comma-separated list of files or directories to "
                      "exclude (bandit, flake8, pycodestyle, pylint, "
                      "yapf)",
                      metavar="<file[,file...]> or <patterns>")

    # How to present the output.
    parser.add_option("-c",
                      "--color",
                      action='store_true',
                      dest='color',
                      help="colorize outputs if color is supported (pylint)")
    parser.add_option("-d",
                      "--diff",
                      action='store_false',
                      dest='auto',
                      help="just print a diff for the fixed source code "
                      "(flake8, isort, pycodestyle, yapf)")
    parser.add_option("--output-format",
                      action='store',
                      type='string',
                      dest='output_format',
                      help="select output format "
                      "(csv,html,json,screen,txt,xml) (bandit), "
                      "(default, pylint) (flake8), "
                      "(colorized, json, text) (pylint)",
                      metavar="<format>")

    # Where to put the output.
    parser.add_option("--files-output",
                      action='store',
                      type='string',
                      dest='files_output',
                      help="redirect report to OUTPUT_FILE (bandit, flake8) "
                      "or into files rather than stdout (pylint)",
                      default="n",
                      metavar="=<OUTPUT_FILE> or <y_or_n>")
    parser.add_option("--reports",
                      action='store_true',
                      dest='reports',
                      help="display full report or only a summary (pylint)")

    # How to run the checkers.
    parser.add_option("-a",
                      "--auto",
                      action='store_true',
                      dest='auto',
                      help="automatically (in-line) apply recommended "
                      "changes (isort, yapf)")
    parser.add_option("-b",
                      "--benchmark",
                      action='store_false',
                      dest='benchmark',
                      help="benchmark code (flake8, pycodestyle)")
    parser.add_option("--python3",
                      action='store_false',
                      dest='python3',
                      help="analyze code for python3 required fixes")
    parser.add_option("--parallel=<num>",
                      action='store',
                      type="int",
                      dest='parallel',
                      help="use <num> sub-processes (flake8, pylint, yapf)",
                      default=1)
    parser.add_option(
        "-r",
        "--recursive",
        action='store_true',
        dest='recurse',
        help="run recursively over directories (bandit, isort, pylint, yapf)")

    parser.set_usage("StaticCheck <checks> <options ...> [file(s) ...]")
    parser.epilog = """\
    <checks> are one or more of the following
        |--format|--import|--manifest|--quality|--security|
    <options ...> are one or more options above.\
    """

    options, args = parser.parse_args()

    return options, args
Example #42
0
                      help="The amount of correlation between the letters.",
                      default=2,
                      type=int)
    parser.add_option("-n",
                      "--number",
                      dest="num_words",
                      help="The number of examples.",
                      default=20,
                      type=int)
    parser.add_option("-q",
                      "--quiet",
                      dest="verbose",
                      action="store_false",
                      help=u"Don’t give any statistical information.",
                      default=True)
    parser.epilog = "If no dictionary is given, a list of possible dictionaries is produced."

    (options, args) = parser.parse_args()

    if len(args) > 1:
        parser.error("Only one dictionary file is supported.")

    if not args:
        dictionary = show_available_dicts()
    else:
        dictionary = args[0]

    if dictionary is None:
        exit

    demo = DictionaryDemo(dictionary, options.correlation, options.verbose)
Example #43
0
def init_host_test_cli_params():
    """! Function creates CLI parser object and returns populated options object.
    @return Function returns 'options' object returned from OptionParser class
    @details Options object later can be used to populate host test selector script.
    """
    parser = OptionParser()

    parser.add_option("-m",
                      "--micro",
                      dest="micro",
                      help="Target microcontroller name",
                      metavar="MICRO")

    parser.add_option("-p",
                      "--port",
                      dest="port",
                      help="Serial port of the target",
                      metavar="PORT")

    parser.add_option("-d",
                      "--disk",
                      dest="disk",
                      help="Target disk (mount point) path",
                      metavar="DISK_PATH")

    parser.add_option("-t",
                      "--target-id",
                      dest="target_id",
                      help="Unique Target Id or mbed platform",
                      metavar="TARGET_ID")

    parser.add_option(
        "",
        "--sync",
        dest="sync_behavior",
        default=2,
        type=int,
        help=
        "Define how many times __sync packet will be sent to device: 0: none; -1: forever; 1,2,3... - number of times (Default 2 time)",
        metavar="SYNC_BEHAVIOR")

    parser.add_option(
        "",
        "--sync-timeout",
        dest="sync_timeout",
        default=5,
        type=int,
        help=
        "Define delay in seconds between __sync packet (Default is 5 seconds)",
        metavar="SYNC_TIMEOUT")

    parser.add_option("-f",
                      "--image-path",
                      dest="image_path",
                      help="Path with target's binary image",
                      metavar="IMAGE_PATH")

    copy_methods_str = "Plugin support: " + ', '.join(
        host_tests_plugins.get_plugin_caps('CopyMethod'))

    parser.add_option("-c",
                      "--copy",
                      dest="copy_method",
                      help="Copy (flash the target) method selector. " +
                      copy_methods_str,
                      metavar="COPY_METHOD")

    parser.add_option("",
                      "--retry-copy",
                      dest="retry_copy",
                      default=3,
                      type=int,
                      help="Number of attempts to flash the target",
                      metavar="RETRY_COPY")

    parser.add_option(
        "",
        "--tag-filters",
        dest="tag_filters",
        default="",
        type=str,
        help=
        "Comma seperated list of device tags used when allocating a target to specify required hardware or attributes [--tag-filters tag1,tag2]",
        metavar="TAG_FILTERS")

    reset_methods_str = "Plugin support: " + ', '.join(
        host_tests_plugins.get_plugin_caps('ResetMethod'))

    parser.add_option("-r",
                      "--reset",
                      dest="forced_reset_type",
                      help="Forces different type of reset. " +
                      reset_methods_str)

    parser.add_option(
        "-C",
        "--program_cycle_s",
        dest="program_cycle_s",
        default=4,
        help=
        "Program cycle sleep. Define how many seconds you want wait after copying binary onto target (Default is 4 second)",
        type="float",
        metavar="PROGRAM_CYCLE_S")

    parser.add_option(
        "-R",
        "--reset-timeout",
        dest="forced_reset_timeout",
        default=1,
        metavar="NUMBER",
        type="float",
        help=
        "When forcing a reset using option -r you can set up after reset idle delay in seconds (Default is 1 second)"
    )

    parser.add_option(
        "--process-start-timeout",
        dest="process_start_timeout",
        default=60,
        metavar="NUMBER",
        type="float",
        help=
        "This sets the maximum time in seconds to wait for an internal process to start. This mostly only affects machines under heavy load (Default is 60 seconds)"
    )

    parser.add_option("-e",
                      "--enum-host-tests",
                      dest="enum_host_tests",
                      help="Define directory with local host tests")

    parser.add_option(
        '',
        '--test-cfg',
        dest='json_test_configuration',
        help='Pass to host test class data about host test configuration')

    parser.add_option('',
                      '--list',
                      dest='list_reg_hts',
                      default=False,
                      action="store_true",
                      help='Prints registered host test and exits')

    parser.add_option('',
                      '--plugins',
                      dest='list_plugins',
                      default=False,
                      action="store_true",
                      help='Prints registered plugins and exits')

    parser.add_option(
        '-g',
        '--grm',
        dest='global_resource_mgr',
        help=
        '[Experimental] Global resource manager service module name, IP and port, example remote_client:10.2.123.43:3334'
    )

    parser.add_option(
        '',
        '--run',
        dest='run_binary',
        default=False,
        action="store_true",
        help=
        'Runs binary image on target (workflow: flash, reset, output console)')

    parser.add_option(
        '',
        '--skip-flashing',
        dest='skip_flashing',
        default=False,
        action="store_true",
        help=
        'Skips use of copy/flash plugin. Note: target will not be reflashed')

    parser.add_option(
        '',
        '--skip-reset',
        dest='skip_reset',
        default=False,
        action="store_true",
        help='Skips use of reset plugin. Note: target will not be reset')

    parser.add_option(
        '-P',
        '--polling-timeout',
        dest='polling_timeout',
        default=60,
        metavar="NUMBER",
        type="int",
        help=
        'Timeout in sec for readiness of mount point and serial port of local or remote device. Default 60 sec'
    )

    parser.add_option(
        '-b',
        '--send-break',
        dest='send_break_cmd',
        default=False,
        action="store_true",
        help=
        'Send reset signal to board on specified port (-p PORT) and print serial output. You can combine this with (-r RESET_TYPE) switch'
    )

    parser.add_option(
        '',
        '--baud-rate',
        dest='baud_rate',
        help=
        "Baud rate of target, overrides values from mbed-ls, disk/mount point (-d, --disk-path), and serial port -p <port>:<baud rate>",
        metavar="BAUD_RATE")

    parser.add_option('-v',
                      '--verbose',
                      dest='verbose',
                      default=False,
                      action="store_true",
                      help='More verbose mode')

    parser.add_option('',
                      '--serial-output-file',
                      dest='serial_output_file',
                      default=None,
                      help='Save target serial output to this file.')

    parser.add_option(
        '',
        '--compare-log',
        dest='compare_log',
        default=None,
        help='Log file to compare with the serial output from target.')

    parser.add_option('',
                      '--version',
                      dest='version',
                      default=False,
                      action="store_true",
                      help='Prints package version and exits')

    parser.description = """Flash, reset and perform host supervised tests on mbed platforms"""
    parser.epilog = """Example: mbedhtrun -d E: -p COM5 -f "test.bin" -C 4 -c shell -m K64F"""

    (options, _) = parser.parse_args()
    return options
Example #44
0
def main():
    """
    Main program.
    """
    class MyIndentedHelpFormatter(IndentedHelpFormatter):
        """ Slightly modified formatter for help output: allow paragraphs """
        def format_paragraphs(self, text):
            """ wrap text per paragraph """
            result = ""
            for paragraph in text.split("\n"):
                result += self._format_text(paragraph) + "\n"
            return result
        def format_description(self, description):
            """ format description, honoring paragraphs """
            if description:
                return self.format_paragraphs(description) + "\n"
            else:
                return ""
        def format_epilog(self, epilog):
            """ format epilog, honoring paragraphs """
            if epilog:
                return "\n" + self.format_paragraphs(epilog) + "\n"
            else:
                return ""
    usage = 'Usage: %s [OPTIONS] fortune_path' % os.path.basename(sys.argv[0])
    arg_parser = OptionParser(usage=usage, formatter=MyIndentedHelpFormatter())
    arg_parser.description = "Print a random, hopefully interesting, adage " \
        "(\"fortune\"), selected from a collection of fortune files found " \
        "in fortune_path.\n\n" \
        "%s " % str(os.path.basename(sys.argv[0])) \
        + 'is an extended implementation of ' \
        'the classic BSD Unix fortune command. It combines the capabilities ' \
        'of the strfile command (which produces the fortune index file) and ' \
        'the fortune command (which displays a random fortune). It reads ' \
        'the traditional fortune program\'s text file format. ' \
        "For more information about the fortune files, and the accompanying " \
        "fortune index files, see below." 
    arg_parser.add_option('-u', '--update', action='store_true', dest='update',
                          help='Update the index files, instead of printing a '
                               'fortune. You must run this before you will be '
                               'able to print fortunes from the fortune files. '
                               'This option serves the same purpose as the '
                               'strfile utility for the traditional BSD '
                               'fortune command. Note that the generated '
                               'index files are not compatible with the format '
                               'of the traditional index files. The generated '
                               'index files have the %s extension.' %  INDEX_EXT
                               )
    arg_parser.add_option('-q', '--quiet', action='store_true', dest='quiet',
                          help="When updating the index file, don't emit " 
                               "messages.")
    arg_parser.add_option('-a', '--all', action='store_true', dest='use_all',
                          help="Choose from all fortune files, including "
                          "offensive ones. Don't complain if you are offended!")
    arg_parser.add_option('-o', '--offensive', action='store_true', 
                          dest='offensive',
                          help="Choose only from offensive fortunes. "
                               "Offensive fortunes are those stored in files "
                               "with filenames ending in '-o'. Make absolutely "
                               "sure that you want to be offended!")
    arg_parser.add_option('-e', '--equal', action='store_true',
                          dest='equal_size',
                          help="Consider all fortune files to be of equal " 
                               "size, making it equally likely for a "
                               "fortune to be chosen from any fortune file")
    arg_parser.add_option('-f', '--fortunefiles', action='store_true',
                          dest='list_fortunefiles',
                          help="Print out the list of files which would be " 
                               "searched, but don't print a fortune. ")
    arg_parser.add_option('-l', '--long', action='store_true', dest='use_long',
                          help="Show only long fortunes. See -n on how " 
                               "''long'' is defined in this sense.")
    arg_parser.add_option('-w', '--wait', action='store', type=int, 
                          dest='seconds_to_wait',
                          help="Wait before termination for an amount of time "
                               "calculated from the number of characters in "
                               "the message. This is useful if it is executed "
                               "as part of the logout procedure to guarantee "
                               "that the message can be read before the screen "
                               "is cleared.")
    arg_parser.add_option('-m', '--filter', action='store', dest='pattern',
                          help="Print out all fortunes which match the " 
                               "regular expression pattern.\n" 
                               "The fortunes are printed to standard output, " 
                               "while the names of the file from which each " 
                               "fortune comes are printed to standard " 
                               "error.  Either or both can be redirected; " 
                               "if standard output is redirected to a file, " 
                               "the result is a valid fortunes database " 
                               "file. If standard error is also redirected " 
                               "to this file, the result is still valid, " 
                               "but there will be ''bogus'' fortunes, i.e. " 
                               "the filenames themselves, in parentheses.\n" 
                               "You may combine this option with -o, -l, " 
                               "-s, -n, -i")
    arg_parser.add_option('-i', '--ignorecase', action='store_true', 
                          dest='ignorecase',
                          help="Ignore case for -m patterns.")
    arg_parser.add_option('-s', '--short', action='store_true', 
                          dest='use_short',
                          help="Show only short fortunes. See -n on how " 
                               "''short'' is defined in this sense.")
    arg_parser.add_option('-n', action='store', dest='max_shortlength',
                          help="Set the longest fortune length (in " 
                               "characters) considered to be ''short'' " 
                               "(the default is %s)" % DEFAULT_LENGTH)

    arg_parser.epilog = 'If <fortune_path> is omitted, fortune looks at ' \
        'the FORTUNE_PATH environment variable for the paths. Different ' \
        'paths in FORTUNE_PATH are separated by \':\'.\n' \
        'An individual item inside the fortune_path can be a direct fortune' \
        'file, or a folder, in which case all fortune files inside the ' \
        'folder will be used. Any item may be preceded by a percentage, '\
        'which is a number N between 0  and 99 inclusive, followed by a %. ' \
        'If it is, there will be a N percent probability that a fortune ' \
         'will be picked from that file or directory. For items for which ' \
         'there is a percentage, the probability of a fortune being selected ' \
         'from any one of them is based on the relative number of fortunes ' \
         'it contains.\n\n' \
         'The format of each fortune file is simple: All the fortunes appear ' \
         'in clear text, separated by a single line containing only a ' \
         '\'%\'. For example, the following is a fortune file containing two ' \
         'fortunes:\n\n' \
         '    186,282 miles per second:\n\n' \
         '    It isn\'t just a good idea, it\'s the law!\n' \
         '    %\n' \
         '    A bird in the hand makes it awfully hard to blow your nose.\n\n' \
         'Before a fortune file can be used, you must generate an index ' \
         'file for it. This is a binary file that is used to select ' \
         'fortunes with more speed and efficiency.\n\n' \
         'For more background information about the fortune utility ' \
         'look at http://en.wikipedia.org/wiki/Fortune_(Unix)'
         

    options, args = arg_parser.parse_args(sys.argv)

    if len(args) >= 2:
        fortunepaths = args[1:]
    else:
        try:
            fortunepaths = os.environ['FORTUNE_PATH'].split(':')
        except KeyError:
            print >> sys.stderr, "Missing fortune files"
            print >> sys.stderr, "Try %s --help" % os.path.basename(sys.argv[0])
            sys.exit(1)

    if options.use_all:
        offensive = None
    elif options.offensive:
        offensive = True
    else:
        offensive = False

    if options.use_short:
        minlength = 0
        maxlength = DEFAULT_LENGTH 
        if not options.max_shortlength is None:
            maxlength = int(options.max_shortlength)
    elif options.use_long:
        minlength = DEFAULT_LENGTH 
        if not options.max_shortlength is None:
            minlength = int(options.max_shortlength)
        maxlength = None
    else:
        minlength = 0
        maxlength = None

    try:
        # Update Mode
        if options.update:
            make_fortune_data_file(fortunepaths)

        # Listing Fortune Files Mode
        elif options.list_fortunefiles:
            percentages, fortune_files = fortune_files_from_paths(fortunepaths,
                                                                  offensive)
            for filename in fortune_files:
                print filename

        # Filtering Mode
        elif not options.pattern is None:
            filter_fortunes(fortunepaths, options.pattern, 
                            ignorecase=options.ignorecase, 
                            offensive=offensive)
                
        # Printing Fortunes Mode
        else:
            sys.stdout.write(get_random_fortune(
                fortunepaths, 
                offensive=offensive,
                weighted=(not options.equal_size),
                min_length=minlength,
                max_length=maxlength) )

    except ValueError, msg:
        print >> sys.stderr, msg
        sys.exit(1)
Example #45
0
    '''Attempts to get the secret from the given string - either the whole
    string itself, or the secret from within an otpauth:// URI.
    '''
    input = input.strip()
    if input.startswith("otpauth://"):
        u = urlparse(input)
        q = parse_qs(u.query)
        return (q["secret"][0], u.hostname)
    return (input, None)


if __name__ == "__main__":
    parser = OptionParser()
    parser.description = "Prints the TOTP auth code for the given secret. Can be either the raw secret string or a otpauth:// URI; the script will attempt to auto-detect which is given."
    parser.usage = "%prog [options] secret OR %prog [options] --stdin < secret.txt"
    parser.epilog = "Copyright (c) Mark Embling 2013"

    parser.add_option("--stdin", dest="stdin", 
                      action="store_true", default=False,
                      help="Read the secret (raw secret or otpauth:// URI) from stdin [default: %default]")
    parser.add_option("--type", dest="type", 
                      choices=["TOTP", "HOTP"], default="TOTP", 
                      help="Token type (HOTP or TOTP). If a URI is provided, the type will be determined from there. [default: %default]")
    parser.add_option("--count", dest="count", 
                      type="int", default=1,
                      help="Counter for HOTP [default: %default]")
    # parser.add_option("-d", "--digits", dest="digits", 
    #                   choices=['6','8'], default='6',
    #                   help="Number of digits to display (6 or 8) [default: %default]")

    (options, args) = parser.parse_args()
                  "--3d",
                  dest="s3d",
                  metavar="FILE",
                  help="Input survex 3d file")
parser.add_option("-j",
                  "--js",
                  dest="js",
                  metavar="FILE",
                  help="Output json version 3d file")
parser.add_option("-a",
                  "--align",
                  dest="alignjs",
                  metavar="FILE",
                  help="json file to align with")
parser.description = "Convert survex 3D file to do json format for tunnelvr"
parser.epilog = "python convertdmptojson.py survexfile \n"

options, args = parser.parse_args()

# push command line args that look like files into file options
if len(args) >= 1 and re.search("\.3d$", args[0]) and not options.s3d:
    options.s3d = args.pop(0)
if len(args) >= 1 and re.search("\.json$", args[0]) and not options.js:
    options.js = args.pop(0)
if not options.js:
    if not options.s3d:
        parser.print_help()
        exit(1)
    options.js = os.path.splitext(options.s3d)[0] + ".json"

#fname = "Ireby/Ireby2/Ireby2.3d"
Example #47
0
def parse_cmdline():
    u = \
"""\n\t%prog [options]

%prog will convert textual xrefs in table "xresolv", to actual
entr.id xrefs and write them to database table "xref".

Arguments: none"""

    v = sys.argv[0][max (0,sys.argv[0].rfind('\\')+1):] \
            + " Rev %s (%s)" % __version__
    p = OptionParser(usage=u,
                     version=v,
                     add_help_option=False,
                     formatter=IndentedHelpFormatterWithNL())

    p.add_option("--help", action="help", help="Print this help message.")

    p.add_option("-n",
                 "--noaction",
                 default=False,
                 action="store_true",
                 help="Resolve xrefs and generate log file but don't make "
                 "any changes to database. (This implies --keep.)")

    p.add_option("-v",
                 "--verbose",
                 default=False,
                 action="store_true",
                 help="Print a message for every successfully resolved xref.")

    p.add_option("-q",
                 "--quiet",
                 default=False,
                 action="store_true",
                 help="Do not print a warning for each unresolvable xref.")

    p.add_option("-f",
                 "--filename",
                 default=None,
                 help="Name of a file containing kanji/reading to seq# map.")

    p.add_option(
        "-k",
        "--keep",
        default=False,
        action="store_true",
        help="Do not delete unresolved xrefs after they are resolved.")

    p.add_option("-i",
                 "--ignore-nonactive",
                 default=False,
                 action="store_true",
                 help="Ignore unresolved xrefs belonging to entries with a"
                 "status of deleted or rejected or which are unapproved ")

    p.add_option(
        "-s",
        "--source-corpus",
        default=None,
        metavar='CORPORA',
        help="Limit to xrefs occuring in entries of CORPORA (a comma-"
        "separated list of corpus names or id numbers).  If preceeded "
        "by a \"-\", all corpora will be included except those listed.")

    p.add_option(
        "-t",
        "--target-corpus",
        default=None,
        metavar='CORPORA',
        help="Limit to xrefs that resolve to targets in CORPORA (a comma-"
        "separated list of corpus names or id numbers).  If preceeded "
        "by a \"-\", all corpora will be included except those listed.")

    p.add_option("-e",
                 "--encoding",
                 default="utf-8",
                 type="str",
                 dest="encoding",
                 help="Encoding for output (typically \"sjis\", \"utf8\", "
                 "or \"euc-jp\"")

    p.add_option("-d",
                 "--database",
                 type="str",
                 dest="database",
                 default="jmdict",
                 help="Name of the database to load.")
    p.add_option("-h",
                 "--host",
                 default=None,
                 type="str",
                 dest="host",
                 help="Name host machine database resides on.")
    p.add_option("-u",
                 "--user",
                 default=None,
                 type="str",
                 dest="user",
                 help="Connect to database with this username.")
    p.add_option("-p",
                 "--password",
                 default=None,
                 type="str",
                 dest="password",
                 help="Connect to database with this password.")

    p.add_option("-D",
                 "--debug",
                 default=0,
                 type="int",
                 metavar="NUM",
                 help="Print debugging output to stderr.  The number NUM "
                 "controls what is printed.  See source code.")

    p.epilog = """\
When a program such as jmparse.py or exparse.py parses
a corpus file, any xrefs in that file are in textual
form (often a kanji and/or kana text string that identifies
the target of the xref).  The database stores xrefs using
the actual entry id number of the target entry but the
textual form canot be resolved into the id form at parse
time since the target entry may not even be in the database
yet. Instead, the parser programs save the textual form of
the xref in a table, 'xresolv', and it is the job of this
program, when run later, to convert the textual 'xresolv'
table xrefs into the id form of xrefs and load them into
table 'xref'.

Each xresolv row contains the entr id and sens number
of the entry that contained the xref, the type of xref,
and the xref target entry kanji and/or reading, and
optionally, sense number.

This program searches for an entry matching the kanji
and reading and creates one or more xref records using
the target entry's id number.  The matching process is
more involved than doing a simple search because a kanji
xref may match several entries, and our job is to find
the right one.  This is currently done by a fast but
inaccurate method that does not take into account restr,
stagr, and stag restrictions which limit certain reading-
kanji combinations and thus would make unabiguous some
xrefs that this program considers ambiguous.  See the
comments in sub choose_entry() for a description of
the algorithm.

When an xref text is not found, or multiple candidate
entries still exist after applying the selection
algorithm, the fact is reported (unless the -q option
was given) and that xref skipped.

Before the program exits, it prints a summary of all
unresolvable xrefs, grouped by reason and xref text.
Following the xref text, in parenthesis, is the number
of xresolv xrefs that included that unresolvable text.
All normal (non-fatal) messages (other than debug
messages generated via the -D option) are written to
stdout.  Fatal errors and debug messages are written
to stderr."""

    opts, args = p.parse_args()
    return args, opts
Example #48
0
def generateSlices(filename, throughFace, sliceNum):
    parser = OptionParser()
    parser.add_option("-s",
                      "--stl",
                      dest="stlfiles",
                      action="append",
                      metavar="FILE",
                      help="Input STL file")
    parser.add_option(
        "-o",
        "--output",
        dest="outputfile",
        default=None,
        metavar="FILE",
        help="Output image name (can contain %d or %f) for multiple names")
    parser.add_option("-t",
                      "--transform",
                      dest="transform",
                      default="unit",
                      help="Transformation to apply to STL file")
    parser.add_option("-q",
                      "--quiet",
                      dest="verbose",
                      default=True,
                      action="store_false",
                      help="Verbose")
    parser.add_option("-w",
                      "--width",
                      dest="widthpixels",
                      default=1200,
                      type="int",
                      help="Bitmap width")
    parser.add_option("",
                      "--height",
                      dest="heightpixels",
                      default=0,
                      type="int",
                      help="Bitmap height")
    parser.add_option("",
                      "--extra",
                      dest="extra",
                      default="5%",
                      help="Extra space to leave around the model")
    parser.add_option("-p",
                      "--position",
                      dest="position",
                      default="mid",
                      help="Position")
    parser.add_option("-n",
                      "--nslices",
                      dest="nslices",
                      default=0,
                      type="int",
                      help="Number of slices to make")
    parser.add_option("-z",
                      "--zlevel",
                      dest="zlevels",
                      action="append",
                      help="Zlevel values to slice at")
    parser.add_option(
        "-i",
        "--inputs",
        dest="cinputs",
        default=False,
        action="store_true",
        help="Wait for lines from input stream of form 'zvalue [pngfile]\\n'")
    parser.description = "Slices STL files into black and white PNG bitmaps as a batch or on demand"
    parser.epilog = "For more speed try running with pypy"

    options, args = parser.parse_args()
    #options, args = parser.parse_args(args=[])  # to run within debugger
    print('args', args)
    args = []
    options.stlfiles = [filename]
    options.nslices = sliceNum
    #, 'outputfile': None, 'transform': 'unit', 'verbose': True, 'widthpixels': 1200, 'heightpixels': 0, 'extra': '5%', 'position': 'mid', 'nslices': 10, 'zlevels': None, 'cinputs': False}

    if not options.stlfiles:
        parser.print_help()
        exit(1)

    if not options.outputfile:
        rfile = re.sub("\.stl$(?i)", "", options.stlfiles[0])
        if options.nslices != 0:
            options.outputfile = rfile + "_%04d.png"
        elif options.zlevels:
            options.outputfile = rfile + "_%010f.png"
        else:
            options.outputfile = rfile + ".png"

    # load the stl files into trianglebarmeshes
    transmaps = {"unit": lambda t: t, "swapyz": lambda t: (t[0], -t[2], t[1])}

    tzs = TriZSlice(options.verbose)
    for stlfile in options.stlfiles:
        tzs.LoadSTLfile(stlfile, transmaps[options.transform])

    tzs.LoadSTLfile(stlfile, transmaps['unit'])

    # Determin the ranges from the loaded files
    tzs.SetExtents(options.extra)
    tzs.BuildPixelGridStructures(options.widthpixels, options.heightpixels)

    def pngname(optionoutputfile, i, z):
        if re.search("%.*?d(?i)", optionoutputfile):
            return optionoutputfile % i
        if re.search("%.*?f(?i)", optionoutputfile):
            return optionoutputfile % z
        return optionoutputfile

    if options.nslices != 0:
        for i in range(options.nslices):
            z = tzs.zlo + (tzs.zhi - tzs.zlo) * (i + 0.5) / options.nslices
            print('zloose', z, tzs.zlo, tzs.zhi, i, options.nslices)
            tzs.SliceToPNG(z, pngname(options.outputfile, i, z), throughFace)

    i = options.nslices
    for sz in options.zlevels or []:
        z = float(z)
        tzs.SliceToPNG(z, pngname(options.outputfile, i, z), throughFace)
        i += 1

    if options.cinputs:
        if options.verbose:
            print(
                "Give zvalue within [%.3f,%.3f] and optionally pngfile name followed by linefeed"
                % (tzs.zlo, tzs.zhi))
        while True:
            cl = sys.stdin.readline().strip()
            if cl == "":
                break
            lcl = cl.split(None, 1)
            z = float(lcl[0])
            tzs.SliceToPNG(
                z,
                pngname(lcl[1] if len(lcl) == 2 else options.outputfile, i, z),
                throughFace)
            i += 1
Example #49
0
#!/usr/bin/env python

# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
__doc__ = "Convert TMVA BDT weight files to ROOT format used by egamma::BDT"

import os

if __name__ == "__main__":

    from optparse import OptionParser
    parser = OptionParser("%prog inputXMLPath outputPath")
    parser.description = __doc__
    parser.epilog = "\n"

    parser.add_option(
        "-t",
        "--particleType",
        default='0',
        choices=['0', '1'],
        help="Type of particle (0=photon, 1=electron) (default: %default)")

    options, (inputXMLPath, outputPath) = parser.parse_args()
    options.particleType = int(options.particleType)

    if not os.path.isdir(inputXMLPath):
        raise IOError('Input path %s is not valid!' % inputXMLPath)

    if not os.path.isdir(outputPath):
        print 'Creating output path for ROOT files: %s' % outputPath
        os.mkdir(outputPath)
Example #50
0
op.add_option("--show-urlbase",
              action="store_true", dest="show_urlbase", default=False,
              help="Show the URL scheme, host and port number.")
op.add_option("--show-title",
              action="store_true", dest="show_title", default=False,
              help="Show the page title.")
op.add_option("--show-visit-count",
              action="store_true", dest="show_visit_count", default=False,
              help="Show the number of visits for the URL.")
op.add_option("--show-last-visit-time",
              action="store_true", dest="show_last_visit_time", default=False,
              help="Show the last visit time.")

op.disable_interspersed_args()

op.epilog = """\
Examine URL visit history for the Chromium browser.

BEFORE_TIME and AFTER_TIME are specified as decimal digit strings of
format  YYYY[MM[DD[HH[MM[SS]]]]]
"""

(opts, args) = op.parse_args()
if len(args) < 1:
    print("Path to history file not specified.", file=sys.stderr)
    sys.exit(3)

fname = args[0]
filters = []
if opts.order_by:
    orderings = opts.order_by.split(',')
Example #51
0
def init_host_test_cli_params():
    """! Function creates CLI parser object and returns populated options object.
    @return Function returns 'options' object returned from OptionParser class
    @details Options object later can be used to populate host test selector script.
    """
    parser = OptionParser()

    parser.add_option("-m", "--micro",
                      dest="micro",
                      help="Target microcontroller name",
                      metavar="MICRO")

    parser.add_option("-p", "--port",
                      dest="port",
                      help="Serial port of the target",
                      metavar="PORT")

    parser.add_option("-d", "--disk",
                      dest="disk",
                      help="Target disk (mount point) path",
                      metavar="DISK_PATH")

    parser.add_option("-t", "--target-id",
                      dest="target_id",
                      help="Unique Target Id or mbed platform",
                      metavar="TARGET_ID")

    parser.add_option("-f", "--image-path",
                      dest="image_path",
                      help="Path with target's binary image",
                      metavar="IMAGE_PATH")

    copy_methods_str = "Plugin support: " + ', '.join(host_tests_plugins.get_plugin_caps('CopyMethod'))

    parser.add_option("-c", "--copy",
                      dest="copy_method",
                      help="Copy (flash the target) method selector. " + copy_methods_str,
                      metavar="COPY_METHOD")

    reset_methods_str = "Plugin support: " + ', '.join(host_tests_plugins.get_plugin_caps('ResetMethod'))

    parser.add_option("-r", "--reset",
                      dest="forced_reset_type",
                      help="Forces different type of reset. " + reset_methods_str)

    parser.add_option("-C", "--program_cycle_s",
                      dest="program_cycle_s",
                      help="Program cycle sleep. Define how many seconds you want wait after copying binary onto target",
                      type="float",
                      metavar="PROGRAM_CYCLE_S")

    parser.add_option("-R", "--reset-timeout",
                      dest="forced_reset_timeout",
                      metavar="NUMBER",
                      type="float",
                      help="When forcing a reset using option -r you can set up after reset idle delay in seconds")

    parser.add_option("-e", "--enum-host-tests",
                      dest="enum_host_tests",
                      help="Define directory with local host tests")

    parser.add_option('', '--test-cfg',
                      dest='json_test_configuration',
                      help='Pass to host test class data about host test configuration')

    parser.add_option('', '--list',
                      dest='list_reg_hts',
                      default=False,
                      action="store_true",
                      help='Prints registered host test and exits')

    parser.add_option('', '--plugins',
                      dest='list_plugins',
                      default=False,
                      action="store_true",
                      help='Prints registered plugins and exits')

    parser.add_option('', '--run',
                      dest='run_binary',
                      default=False,
                      action="store_true",
                      help='Runs binary image on target (workflow: flash, reset, output console)')

    parser.add_option('', '--skip-flashing',
                      dest='skip_flashing',
                      default=False,
                      action="store_true",
                      help='Skips use of copy/flash plugin. Note: target will not be reflashed')

    parser.add_option('', '--skip-reset',
                      dest='skip_reset',
                      default=False,
                      action="store_true",
                      help='Skips use of reset plugin. Note: target will not be reset')

    parser.add_option('-P', '--pooling-timeout',
                      dest='pooling_timeout',
                      default=60,
                      metavar="NUMBER",
                      type="int",
                      help='Timeout in sec for mbed-ls mount point and serial port readiness. Default 60 sec')

    parser.add_option('-b', '--send-break',
                      dest='send_break_cmd',
                      default=False,
                      action="store_true",
                      help='Send reset signal to board on specified port (-p PORT) and print serial output. You can combine this with (-r RESET_TYPE) switch')

    parser.add_option('-v', '--verbose',
                      dest='verbose',
                      default=False,
                      action="store_true",
                      help='More verbose mode')

    parser.add_option('', '--version',
                      dest='version',
                      default=False,
                      action="store_true",
                      help='Prints package version and exits')

    parser.description = """Flash, reset and perform host supervised tests on mbed platforms"""
    parser.epilog = """Example: mbedhtrun -d E: -p COM5 -f "test.bin" -C 4 -c shell -m K64F"""

    (options, _) = parser.parse_args()
    return options
Example #52
0
def main(argv, package, subpackages, filter, testdir, dirname="test"):

    parser = OptionParser()
    parser.add_option("--no-xunit",
                      help="Disable generation of XUnit XML summary",
                      action="store_false",
                      dest="xunit",
                      default=True)
    parser.add_option("-v",
                      "--verbose",
                      help="Provide verbose output",
                      action="store_true",
                      dest="verbose",
                      default=False)
    parser.add_option(
        "-f",
        "--filter",
        help=
        "Enable filtering of coverage tests with a customized nose installation",
        action="store_true",
        dest="filtering",
        default=False)
    parser.add_option(
        "-F",
        "--filter-all",
        help="Apply nose to all packages, filtering each coverage test",
        action="store_true",
        dest="filtering_all",
        default=False)
    parser.usage = "runtests [options] <package> [...]"
    parser.description = "A utility to run Pyomo tests.  A particular feature of this tool is the ability to filter coverage information, using a customized installation of the nose utility."
    parser.epilog = """The customized nose utility that supports filtering can be obtained from Bill Hart ([email protected])."""
    #
    # Process argv list
    #
    (options, args) = parser.parse_args(args=argv)
    #
    # Preprocess arguments, to eliminate trailing '/' or '\\' characters, which a user
    # might add using tab completion.
    #
    for i in range(0, len(args)):
        if args[i][-1] == os.sep:
            args[i] = args[i][:-1]
    #
    # Verify that the arguments are valid subpackages
    #
    unwanted = copy.copy(subpackages)
    for arg in args[1:]:
        if not arg in subpackages:
            print("ERROR: no subpackage '" + arg)
            sys.exit(1)
        unwanted.remove(arg)
    if unwanted == subpackages:
        unwanted = []
    #
    # Remove coverage files from previous 'runtests' executions
    #
    coverage_file = testdir + os.sep + dirname + os.sep + ".coverage"
    if os.path.exists(coverage_file):
        os.remove(coverage_file)
    os.environ["COVERAGE_FILE"] = coverage_file
    #for file in glob.glob("*/.coverage"):
    #os.remove(file)
    #for file in glob.glob("*/*/.coverage"):
    #os.remove(file)
    #
    # Remove XML files from previous 'runtests' executions
    #
    xunitdir = testdir + os.sep + dirname + os.sep + "xunit"
    if os.path.exists(xunitdir):
        for file in glob.glob(xunitdir + os.sep + "TEST*.xml"):
            os.remove(file)
    else:
        os.mkdir(xunitdir)

    plugins = [UnwantedPackagePlugin(unwanted)]
    #if nose_xunit_installed and options.xunit:
    #plugins.append(nosexunit.plugin.NoseXUnit())
    #if coverage_installed:
    #plugins.append(nose.plugins.cover.Coverage())
    #plugins.append(nose.plugins.xunit.Xunit())
    if not options.filtering_all:
        newargs = ['runtests'] + generate_options(
            package, args[1:], subpackages, filter, options, testdir, xunitdir,
            dirname) + args[1:]
        os.chdir(testdir)
        if options.verbose:
            print("Nose Arguments:", newargs)
            print("Test Dir:", testdir)
            if len(args) > 1:
                print("Test Packages:", )
                for arg in args[1:]:
                    print(arg, )
                print("")
            if len(unwanted) > 1:
                print("Ignored Packages:", unwanted)
        sys.argv = newargs
        nose.run(argv=newargs, addplugins=plugins)
    else:
        if len(args[1:]) == 0:
            arglist = subpackages
        else:
            arglist = args[1:]
        for arg in arglist:
            newargs = ['runtests'] + generate_options(arg, options) + [arg]
            print("Package Coverage Tests: " + arg)
            tmp = sys.stdout
            os.chdir(testdir)
            if options.verbose:
                print("Nose Arguments:", newargs)
                print("Test Dir:", testdir)
                if len(args) > 1:
                    print("Test Packages:", )
                    for arg in args[1:]:
                        print(arg, )
                    print("")
                if len(unwanted) > 1:
                    print("Ignored Packages:", unwanted)
            nose.run(argv=newargs, addplugins=plugins)
            sys.stdout = tmp
    #
    # Rename xUnit files and insert the package information
    #
    if os.path.exists(xunitdir):
        p = re.compile('^.*TEST-(.+)\.xml')
        for file in glob.glob(xunitdir + os.sep + "TEST-*.xml"):
            oldname = p.match(file).group(1)
            if oldname == "test":
                suffix = ""
            else:
                suffix = "." + oldname

            FILE = open(file, "r")
            text0 = "".join(FILE.readlines())
            FILE.close()
            ptmp = re.compile("testsuite name=\"nosetests\"")
            text1 = ptmp.sub("testsuite name=\"" + package + "\"", text0)
            #ptmp = re.compile("classname=\""+oldname)
            #text2 = ptmp.sub("classname=\""+package+suffix, text1)
            #FILE = open(xunitdir+os.sep+"TEST-"+package+suffix+".xml","w")
            FILE = open(file, "w")
            FILE.write(text1)
            FILE.close()
def main():
    parser = OptionParser() # creates an instance of the parser
    parser.usage = "%prog -i input.cara -u uplfile.upl [-o output.cara] [-p project-name]"
    parser.description = "%prog  reads in a CARA repository and a UPL list, and generates spin links in the repository based on the UPL list."
    parser.epilog = ""
    parser.add_option("-i", "--input", dest="infile",type="string",default=None,
                      help="name of original CARA repository, required.", metavar="FILE")
    parser.add_option("-o", "--output", dest="outfile",type="string",default=None,
                      help="name of new CARA repository, defaults to stdout.", metavar="FILE")
    parser.add_option("-p", "--project", metavar="NAME", dest="project", default=None,type="string",
                      help="name of project to alter, if there is more than one project in the repository, defaults to the first project.")
    parser.add_option("-u", "--upl", dest="uplfile",type="string",default=None,
                      help="name of upl file, required.", metavar="FILE")

    # Now parse the command-line options
    (options, args) = parser.parse_args()

    infile = options.infile
    outfile = options.outfile
    projectName = options.project
    uplfile = options.uplfile

    if infile == None:
        parser.print_help()
        parser.error("Please specify an input cara file.")

    if uplfile == None:
        parser.print_help()
        parser.error("Please specify an input upl file.")
    
    if outfile == None:
        outfile = stdout
    elif exists(outfile):
        print '\nOutput file \'%s\' exists. Choose a new name to avoid overwriting.\n'%outfile
        return
    # Now that we have an input file and we know where to send the output, we parse the xml.

    tree = ET.parse(infile)
    root = tree.getroot() #retrieves the whole repository
    projects = root.findall('project') #retrieves every project in the repository

# Select a project according to command-line input, defaulting to the first project

    if projectName:
        project = getProject(projectName,projects)
        if not project:
            print 'No project found with name \"%s\".'%projectName
            return
    else:
        project = projects[0]
        if not project:
            print 'No project found.'
            return

    spinbase = project.find('spinbase')
    spins = spinbase.findall('spin')
    pairs = spinbase.findall('pair')
    spindict = {}
    getSpinID = {}
    pairList = []

    for spin in spins:
        atom = spin.get('atom')
        offset = spin.get('off')
        if atom == 'H1':
            spinid = spin.get('id')
            try:
                system = int(spin.get('sys'))
                tag = spin.get('tag')
                spindict[spinid] = {'tag': tag, 'sys': system}
                getSpinID[(system,tag)]=spinid
            except Exception, e:
                print "Orphan spin: ",e
Example #54
0
def setup_arg_parser():
    """ Return an arg_parser, set up with all options """
    class MyIndentedHelpFormatter(IndentedHelpFormatter):
        """ Slightly modified formatter for help output: allow paragraphs """
        def format_paragraphs(self, text):
            """ wrap text per paragraph """
            result = ""
            for paragraph in text.split("\n"):
                result += self._format_text(paragraph) + "\n"
            return result

        def format_description(self, description):
            """ format description, honoring paragraphs """
            if description:
                return self.format_paragraphs(description) + "\n"
            else:
                return ""

        def format_epilog(self, epilog):
            """ format epilog, honoring paragraphs """
            if epilog:
                return "\n" + self.format_paragraphs(epilog) + "\n"
            else:
                return ""

    arg_parser = OptionParser(formatter=MyIndentedHelpFormatter(),
                              usage="%prog [options] CMD ARGS",
                              description=__doc__)
    arg_parser.add_option('--email',
                          action='store',
                          dest='email',
                          help="Email address to use for authentification")
    arg_parser.add_option(
        '--password',
        action='store',
        dest='password',
        help="Password to use for authentification (Read warning below).")
    arg_parser.add_option(
        '--credfile',
        action='store',
        dest='credfile',
        default=os.path.join(os.environ['HOME'], '.simplenotesyncrc'),
        help="File from which to read email (first line) and "
        "password (second line). Defaults to ~/.simplenotesyncrc")
    arg_parser.add_option(
        '--cachefile',
        action='store',
        dest='cachefile',
        help="File in which to cache information about notes. "
        "Using a cachefile can dramatically speed up listing notes.")
    arg_parser.add_option(
        '--tokenfile',
        action='store',
        dest='tokenfile',
        help="File in which to cache the authentication token")
    arg_parser.add_option(
        '--results',
        action='store',
        dest='results',
        type="int",
        default=10,
        help="Maximum number of results to be returned in a search")
    arg_parser.add_option(
        '--encoding',
        action='store',
        dest='encoding',
        default='utf-8',
        help="Encoding for notes written to file or read from file "
        "(defaults to utf-8).")
    arg_parser.add_option('--dead',
                          action='store_true',
                          dest='dead',
                          help="When deleting a note, delete it permanently")
    arg_parser.epilog = "You are strongly advised to use the --credfile " \
                        "option instead of the --password option. Giving " \
                        "a password in cleartext on the command line will " \
                        "result in that password being visible in the "\
                        "process list and your history file."
    return arg_parser
Example #55
0
def handle_arguments():
	from optparse import OptionParser, OptionGroup, OptionValueError
	sys.path.append( os.path.abspath( '..' ) )

	def option_callback(option, opt_str, value, parser, *args, **kwargs):
		pass

	def parse_host(text):
		if "@" in text:
			user = text[:text.index("@")]
			if ":" in text:
				host = text[text.index("@") +1 :text.index(":")]
				port = int(text[text.index(":") +1 :])
			else:
				host = text[text.index("@") +1 :]
				port = options.socks_port
		else:
			user = None
			if ":" in text:
				host = text[:text.index(":")]
				port = int(text[text.index(":") +1 :])
			else:
				host = text
				port = options.socks_port

		return user, host, port

	def check_ssh(option, opt, value, parser):
		try:
			if option.dest == "ssh_host":
				if parser.values.use_socks:
					raise OptionValueError("Cannot use both SSH and SOCKS proxy")
	
			if option.dest == "socks_host":
				if parser.values.use_ssh:
					raise OptionValueError("Cannot use both SSH and SOCKS proxy")
		except AttributeError:
			pass

	def check_socks_host(option, opt, value, parser):
		check_ssh(option, opt, value, parser)
		try:
			u, h, p = parse_host(value)
		except ValueError:
			raise OptionValueError("socks host string is improperly formatted")
		else:
			parser.values.socks_user = u
			parser.values.socks_host = h
			parser.values.socks_port = p
			parser.values.use_socks  = True

	def check_ssh_host(option, opt, value, parser):
		check_ssh(option, opt, value, parser)
		try:
			u, h, p = parse_host(value)
		except ValueError:
			raise OptionValueError("ssh host string is improperly formatted")
		else:
			parser.values.ssh_user = u
			parser.values.ssh_host = h
			parser.values.ssh_port = p
			parser.values.use_ssh  = True
			parser.values.use_socks  = True

	# skip the formatter for the epilog....nice hack.
	def format_epilog(self, formatter):
		import textwrap
		w = ioctl_GWINSZ()[1]
		e = self.epilog.strip()
		lines = []
		[ lines.append(textwrap.fill(l,w).lstrip()) for l in e.split("%") ]
		self.epilog = "\n" + "\n".join(lines) + "\n"
		return self.epilog

	parser = OptionParser()
	ssh_opt = OptionGroup(parser, "SSH/SOCKS Options")
	debug_opt = OptionGroup(parser, "Debug Options")
	parser.add_option_group(ssh_opt)
	parser.add_option_group(debug_opt)

	# just some hack
	instancemethod = type(parser.format_epilog)
	parser.format_epilog = instancemethod(format_epilog, parser, OptionParser)

	# give some more info
	parser.epilog = epilog

	parser.add_option("-a", action="store_true",\
		help="attempt to automatically configure LAN",\
		dest="auto_config")

	parser.add_option("-w", action="store",\
		help="WAN Interface (internet)",\
		type="string", dest="wan_if")

	parser.add_option("-l", action="store",\
		help="LAN Interface (listens for xbox)",\
		type="string", dest="lan_if")

	parser.add_option("-f", action="store_true",\
		help="forward traffic from host (use with care)",\
		dest="forward_host")

	parser.add_option("-c", action="store_true",\
		help="use color for output", dest="use_color")

	parser.add_option("-q",  action="store_true",\
		help="supress output",\
		default=False, dest="quiet")

	debug_opt.add_option("--debug-supress-run",  action="store_true",\
		help="supress the running of commands",\
		default=False, dest="debug_supress_run")

	debug_opt.add_option("-v", action="count",\
		help="more v's for more output",\
		dest="verbosity")

	ssh_opt.add_option("-p", action="callback",\
		help="socks host (see below)",\
		type="string", dest="socks_host", callback=check_socks_host)

	ssh_opt.add_option("-t", action="store",\
		help="type of socks server: 4/5",\
		type="choice", dest="socks_type",\
		choices=["socks4","socks5"])

	ssh_opt.add_option("-s", action="callback",\
		help="ssh host (see below)",\
		type="string", dest="ssh_host", callback=check_ssh_host)

	opt, args = parser.parse_args()

	if opt.verbosity != None:
		opt.verbosity += 2

	if opt.quiet:
		opt.verbosity = 0

	# update the options
	for key, value in opt.__dict__.items():
		if value != None:
			#if hasattr(options, key):
			setattr(options, key, value)
Example #56
0
def get_args():
    global PH5, FILES, EVERY, NUM_MINI, TSPF, UTM, FIRST_MINI, APPEND,\
        MANUFACTURERS_CODE

    TSPF = False

    from optparse import OptionParser
    oparser = OptionParser()

    oparser.usage = "Version: {0} Usage: segdtoph5 [options]".format(
        PROG_VERSION)
    oparser.epilog = ("Notice: Data of a Das can't be stored in more than one "
                      "mini file.")

    oparser.add_option("-r",
                       "--raw",
                       dest="rawfile",
                       help="Fairfield SEG-D v1.6 file.",
                       metavar="raw_file")

    oparser.add_option("-f",
                       "--file",
                       action="store",
                       dest="infile",
                       type="string",
                       help="File containing list of Fairfield SEG-D\
                        v1.6 file names.",
                       metavar="file_list_file")

    oparser.add_option("-n",
                       "--nickname",
                       dest="outfile",
                       help="The ph5 file prefix (experiment nick name).",
                       metavar="output_file_prefix")

    oparser.add_option("-U",
                       "--UTM",
                       dest="utm_zone",
                       help="Locations in SEG-D file are UTM, --UTM=utmzone."
                       " Zone number and N or S designation"
                       " eg 13N",
                       type='str',
                       default=0,
                       metavar="utm_zone")

    oparser.add_option("-T",
                       "--TSPF",
                       dest="texas_spc",
                       help="Locations are in texas state plane coordinates.",
                       action='store_true',
                       default=False)

    oparser.add_option("-M",
                       "--num_mini",
                       help=("Create a given number of miniPH5 files."
                             " Ex: -M 38"),
                       metavar="num_mini",
                       type='int',
                       default=None)

    oparser.add_option("-S",
                       "--first_mini",
                       help=("The index of the first miniPH5_xxxxx.ph5 "
                             "file of all. Ex: -S 5"),
                       metavar="first_mini",
                       type='int',
                       default=1)

    oparser.add_option("-c",
                       "--combine",
                       dest="combine",
                       help="Combine this number if SEG-D traces to one\
                        PH5 trace.",
                       metavar="combine",
                       type='int',
                       default=APPEND)

    oparser.add_option("-E",
                       "--allevents",
                       action="store_true",
                       dest="all_events",
                       default=False,
                       metavar="all_events")

    oparser.add_option("--manufacturers_code",
                       dest="manufacturers_code",
                       help="Manufacturers code. Defaults to 20 for Fairfield.\
                        Most likely will not work for SEG-D written by other\
                         data loggers,",
                       type='int',
                       default=FAIRFIELD)

    options, args = oparser.parse_args()

    if options.rawfile and options.infile:
        oparser.error("argument -f/--file: not allowed with argument -r/--raw")

    FILES = []
    PH5 = None

    EVERY = options.all_events
    NUM_MINI = options.num_mini
    FIRST_MINI = options.first_mini
    UTM = options.utm_zone
    TSPF = options.texas_spc
    APPEND = options.combine
    MANUFACTURERS_CODE = options.manufacturers_code

    if options.infile is not None:
        read_infile(options.infile)

    elif options.rawfile is not None:
        FILES.append(options.rawfile)

    if len(FILES) == 0:
        raise Exception("No input file given.\n")

    #   Set output file
    if options.outfile is not None:
        PH5 = options.outfile
    else:
        raise Exception("No outfile (PH5) given.\n")

    setLogger()