Beispiel #1
0
def main():
    P = OptionParser(usage="%prog [-C|-S] <-v> host:port")
    P.add_option('-v','--verbose', action='count', default=0,
                 help='Print more information')
    P.add_option('-C','--client', action='store_true', default=True,
                 dest='dir', help='Act as Client to PSC')
    P.add_option('-S','--server', action='store_false', dest='dir',
                 help='Act as Server to IOC')
    vals, args = P.parse_args()

    if len(args)<1:
        P.usage()
        sys.exit(1)

    host, _, port = args[0].partition(':')
    port = int(port or '6')

    logging.basicConfig(level=_V.get(vals.verbose, 0))

    if vals.dir:
        # Client
        log.info('Connect to %s:%u', host, port)
        fact = ClientFactory()
        fact.protocol = PSCClient
        ep = reactor.connectTCP(host, port, fact)
    else:
        # Server
        log.info('Serve from %s:%u', host, port)
        fact = Factory()
        fact.protocol = PSCServer
        ep = reactor.listenTCP(port, fact, interface=host or '')

    log.info('Run')
    reactor.run()
    log.info('Done')
def parse_args():
    parser = \
        OptionParser(usage='usage: %prog [options] filenames|directory'
                     , version='%prog 1.0')
    parser.add_option(  # optional because action defaults to "store"
                        '-o',
                        '--outputdir',
                        action='store',
                        dest='outputdir',
                        default=None,
                        help='The directory to put output files',
    )
    parser.add_option(
        '-a',
        '--appledoc',
        action='store_true',
        dest='appledoc',
        default=False,
        help='Generate Appledoc output',
    )
    parser.add_option(
        '-d',
        '--doxygen',
        action='store_true',
        dest='doxygen',
        default=False,
        help='Generate Doxygen output',
    )
    parser.add_option(
        '-d',
        '--doxygen',
        action='store_true',
        dest='doxygen',
        default=False,
        help='Generate Doxygen output',
        )
    parser.add_option(
        '-v',
        '--verbose',
        action='store_true',
        dest='verbose',
        default=False,
        help='Turn on verbose output',
    )
    (options, args) = parser.parse_args()

    output_dir = options.outputdir
    if options.appledoc:
        generator = OutputGenerator.appledoc
    elif options.doxygen:
        generator = OutputGenerator.doxygen
    else:
        print('Must specify --appledoc or --doxygen')
        parser.usage()
        sys.exit(1)

    verbose = options.verbose
    return (args, output_dir, generator, verbose)
def main(args):
    optp = OptionParser(usage=usage)
    cmdcommon.opt_user(optp)
    cmdcommon.opt_outfile(optp)
    options, args = optp.parse_args(args)
    if len(args) != 1:
        optp.usage()

    report_id = cmdcommon.get_report_id(args[0]) 

    cred = cmdcommon.user_cred(options)

    params = reports.load(report_id, cred)
    cmdcommon.safe_overwrite(options, params.xmlsave, cmdcommon.OUTFILE)
Beispiel #4
0
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!')
Beispiel #5
0
Datei: plot.py Projekt: pism/pism
def process_options():
    "Process command-line options and arguments."
    parser = OptionParser()
    parser.usage = "%prog <input files> [options]"
    parser.description = "Plots the ice flux as a function of the distance from the divide."
    parser.add_option("-o", "--output", dest="output", type="string",
                      help="Output image file name (e.g. -o foo.png)")
    parser.add_option("-e", "--experiment", dest="experiment", type="string",
                      help="MISMIP experiment: 1a,1b,2a,2b,3a,3b (e.g. -e 1a)")
    parser.add_option("-s", "--step", dest="step", type="int",
                      help="MISMIP step: 1,2,3,... (e.g. -s 1)")
    parser.add_option("-m", "--model", dest="model", type="string",
                      help="MISMIP model (e.g. -M ABC1)")
    parser.add_option("-f", "--flux", dest="profile", action="store_false", default=True,
                      help="Plot ice flux only")
    parser.add_option("-p", "--profile", dest="flux", action="store_false", default=True,
                      help="Plot geometry profile only")

    opts, args = parser.parse_args()

    if len(args) == 0:
        print("ERROR: An input file is requied.")
        exit(0)

    if len(args) > 1 and opts.output:
        print("More than one input file given. Ignoring the -o option...\n")
        opts.output = None

    if opts.output and opts.profile and opts.flux:
        print("Please choose between flux (-f) and profile (-p) plots.")
        exit(0)

    return args, opts.output, opts
Beispiel #6
0
def setup():
    optparser = OptionParser()
    optparser.usage = optparser.usage+' FILE [FILE FILE ...]'
    optparser.add_option("-r","--root", dest="root", metavar="DIR",
                         help="Specify a root component that will be removed \
                         from paths before pattern matching. Default action \
                         is to use the current working directory")
    optparser.add_option("-p","--patterns", dest="patterns", metavar="FILE",
                         help="Specify a file containing filename patterns \
                         for metadata extraction")
    optparser.add_option("-t","--targets", dest="targets", metavar="FILE",
                         help="Specify a file containing target rules")
    optparser.add_option("-v","--verbose", dest="verbose", default=False, 
                         action='store_true',
                         help="Show lots of info about what is being done")
    optparser.add_option("-d","--debug", dest="debug", default=False,
                         action='store_true', help="Show debug info")

    options, filenames = optparser.parse_args()
    cfg = ConfigParser()
    cfg.read(os.path.expanduser('~/.config/determinator/determinator.rc'))

    if len(filenames) == 0:
        optparser.print_help();
        quit()

    if not options.root:
        try:
            options.root = cfg.get('Misc Options', 'root')
        finally:
            options.root = os.getcwd()

    mimetypes.init([os.path.dirname(__file__)+'/mime.types'])
    return options, filenames, cfg
Beispiel #7
0
def tunserver_mainloop():
    """Run a `TunServer` using configuration options passed through the command
    line or a config file."""
    parser = OptionParser()
    parser.usage = "Usage: %prog [OPTIONS] [CONFIG_FILE]"
    tunserver_defaults.add_options(parser)
    (options, args) = parser.parse_args()
    if len(args)>1:
        parser.print_help()
        sys.exit()

    fconf = None
    # Input configuration file
    if len(args)>0: fconf = args[0]
    _read_config_file(options, fconf)

    # attempt to create TunServer
    ts = TunServer(options=options)
    ts.start()

    print "Press (ctrl-c) to quit:"
    try:
        while 1: raw_input("")
    except KeyboardInterrupt:
        pass
def parse_arguments():
    """Parse and validate the arguments.

    This returns a tuple like ``(options, module_name, endpoint)``.

    """
    parser = OptionParser()
    parser.usage = '%prog [options] MODULE ENDPOINT'
    parser.add_option(
        '--background', action='store_true',
        help='create indexes as a non-blocking operation [default]',
    )
    parser.add_option(
        '--no-background', action='store_false', dest='background',
        help='disable background index creation',
    )
    parser.set_defaults(background=True)

    options, arguments = parser.parse_args()

    if len(arguments) != 2:
        parser.print_help()
        exit(1)

    module_name, endpoint = arguments
    return options, module_name, endpoint
Beispiel #9
0
Datei: cli.py Projekt: nagius/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
 def __init__(self):
     parser = OptionParser()
     parser.add_option('-s', '--start_time', metavar='START', action='callback', callback=self.toSeconds, type='string', default=0)
     parser.add_option('-e', '--end_time', metavar='END', action='callback', callback=self.toSeconds, type='string', default=sys.maxsize)
     parser.usage = '%prog [options] vod_id'
     self.getUsage = lambda: parser.get_usage()
     self.parseArgs = lambda: parser.parse_args()
Beispiel #11
0
def get_options():
	from optparse import OptionParser
	parser = OptionParser()
	parser.usage = "%prog [options] file_name"
	parser.add_option("-i", "--input", dest="input", 
					  help="Define one of the input files.", metavar="input files")
	parser.add_option("-o", "--output", dest="output", 
					  help="Define output directory.  Default is the script directory", metavar="output directory")
	# parser.add_option("-q", "--quiet",
	#                   action="store_false", dest="verbose", default=True,
	#                   help="don't print status messages to stdout")
	
	(options, args) = parser.parse_args()
	
	# if not (args or options.input):
	#    parser.error('Error - You must supply one of the input file names.\nThe file name can either be bare after the script name, or it can be given following an "-i"')
	
	if args:
		file_name = args[0]
	elif options.input:
		file_name = options.input
	else:
		parser.error('Error - You must supply one of the input file names.\nThe file name can either be bare after the script name, or it can be given following an "-i"')
	
	print 'The file name is:', file_name
	
	if options.output:
		output_dir = options.output
		print 'Output directory defined as', output_dir
	else:
		output_dir = ''
	
	return file_name
Beispiel #12
0
def add_reqs(argv=None, default_flink=None):
    if argv is None:
        argv = sys.argv[1:]

    parser = OptionParser()
    parser.usage = "add_reqs.py [options] <req_file1> <req_file2> ... <req_file_n>"
    parser.add_option("-f", action="store", type="string", dest='flink', 
                      help="find-links server url")
    
    (options, args) = parser.parse_args(argv)

    reqs = []
    for entry in args:
        try:
            if os.path.exists(entry):  # a local file
                reqs.extend(_get_reqs_from_file(entry))
            else:  # assume it's a url
                reqs.extend(_get_reqs_from_url(entry))
        except Exception as err:
            print "'%s' does not specify a valid requirements file or url: %s" % (entry, str(err))
            sys.exit(-1)

    for req, flink in reqs:
        if flink is None:
            if options.flink is None:
                cmd = []
            else:
                cmd = ['-f', options.flink]
        else:
            cmd = ['-f', flink]
        subprocess.check_call([os.path.join(os.path.dirname(sys.executable),
                                            'easy_install'),'-NZ'] + cmd + [req])
Beispiel #13
0
def run(args=None):
    from optparse import OptionParser

    parser = OptionParser()
    parser.usage = "%prog [options] TYPE"
    parser.description = __doc__
    parser.add_option("-b", "--batch-size", action="store", dest="batch_size", default="1024",
                      help="Number of keys in read_bulk/write_bulk batch [default: %default]")
    parser.add_option("-d", "--debug", action="store_true", dest="debug", default=False,
                      help="Enable debug output [default: %default]")
    parser.add_option("-D", "--dir", dest="tmp_dir", default='/var/tmp/dnet_recovery_%TYPE%', metavar="DIR",
                      help="Temporary directory for iterators' results [default: %default]")
    parser.add_option("-g", "--groups", action="store", dest="elliptics_groups", default=None,
                      help="Comma separated list of groups [default: all]")
    parser.add_option("-k", "--lock", dest="lock", default='dnet_recovery.lock', metavar="LOCKFILE",
                      help="Lock file used for recovery [default: %default]")
    parser.add_option("-l", "--log", dest="elliptics_log", default='dnet_recovery.log', metavar="FILE",
                      help="Output log messages from library to file [default: %default]")
    parser.add_option("-L", "--log-level", action="store", dest="elliptics_log_level",
                      default=elliptics.log_level.notice,
                      help="Elliptics client verbosity [default: %default]")
    parser.add_option("-n", "--nprocess", action="store", dest="nprocess", default="1",
                      help="Number of subprocesses [default: %default]")
    parser.add_option("-N", "--dry-run", action="store_true", dest="dry_run", default=False,
                      help="Enable test mode: only count diffs without recovering [default: %default]")
    parser.add_option("-r", "--remote", action="append", dest="remotes", default=[],
                      help="Elliptics node address")
    parser.add_option("-s", "--stat", action="store", dest="stat", default="text",
                      help="Statistics output format: {0} [default: %default]".format("/".join(ALLOWED_STAT_FORMATS)))
    parser.add_option("-S", "--safe", action="store_true", dest="safe", default=False,
                      help="Do not remove recovered keys after merge [default: %default]")
    parser.add_option("-t", "--time", action="store", dest="timestamp", default=None,
                      help="Recover keys modified since `time`. "
                           "Can be specified as timestamp or as time difference"
                           "e.g.: `1368940603`, `12h`, `1d`, or `4w` [default: %default]")
    parser.add_option("-e", "--no-exit", action="store_true", dest="no_exit", default=False,
                      help="Will be waiting for user input at the finish.")
    parser.add_option("-m", "--monitor-port", action="store", dest="monitor_port", default=0,
                      help="Enable remote monitoring on provided port [default: disabled]")
    parser.add_option("-w", "--wait-timeout", action="store", dest="wait_timeout", default="3600",
                      help="[Wait timeout for elliptics operations default: %default]")
    parser.add_option("-a", "--attemps", action="store", dest="attempts", default=1,
                      help="Number of attempts to recover one key")
    parser.add_option("-o", "--one-node", action="store", dest="one_node", default=None,
                      help="Elliptics node address that should be iterated/recovered [default: %default]")
    parser.add_option("-c", "--chunk-size", action='store', dest='chunk_size', default=1024 * 1024,
                      help="Size of chunk by which all object will be read and recovered [default: %default]")
    parser.add_option("-C", "--custom-recover", action="store", dest="custom_recover", default="",
                      help="Sets custom recover app which accepts file path and returns file path to filtered keys")
    parser.add_option("-f", '--dump-file', action='store', dest='dump_file', default='',
                      help='Sets dump file which contains hex ids of object that should be recovered')
    parser.add_option('-i', '--backend-id', action='store', dest='backend_id', default=None,
                      help='Specifies backend data on which should be recovered. IT WORKS ONLY WITH --one-node')
    parser.add_option("-u", "--dont-dump-keys", action="store_false", dest="dump_keys", default=True,
                      help="Disable dumping all iterated key [default: %default]")
    parser.add_option("-M", "--no-meta", action="store_true", dest="no_meta", default=False,
                      help="Recover data without meta. It is usefull only for services without data-rewriting because"
                      " with this option dnet_recovery will not check which replica of the key is newer"
                      " and will copy any replica of the key to missing groups.")
    return main(*parser.parse_args(args))
Beispiel #14
0
def main(args):
    parser = OptionParser(version='modifyrepo version %s' % __version__)
    # query options
    parser.add_option("--mdtype", dest='mdtype',
                      help="specific datatype of the metadata, will be derived from the filename if not specified")
    parser.add_option("--remove", action="store_true",
                      help="remove specified file from repodata")
    parser.add_option("--compress", action="store_true", default=True,
                      help="compress the new repodata before adding it to the repo (default)")
    parser.add_option("--no-compress", action="store_false", dest="compress",
                      help="do not compress the new repodata before adding it to the repo")
    parser.add_option("--compress-type", dest='compress_type',
                      help="compression format to use")
    parser.add_option("-s", "--checksum", dest='sumtype',
        help="specify the checksum type to use")
    parser.add_option("--unique-md-filenames", dest="unique_md_filenames",
        help="include the file's checksum in the filename, helps with proxies",
        action="store_true")
    parser.add_option("--simple-md-filenames", dest="unique_md_filenames",
        help="do not include the file's checksum in the filename",
        action="store_false")
    parser.usage = "modifyrepo [options] [--remove] <input_metadata> <output repodata>"
    
    (opts, argsleft) = parser.parse_args(args)
    if len(argsleft) != 2:
        parser.print_usage()
        return 0
    metadata = argsleft[0]
    repodir = argsleft[1]
    try:
        repomd = RepoMetadata(repodir)
    except MDError, e:
        print "Could not access repository: %s" % str(e)
        return 1
Beispiel #15
0
    def ParseArg(self):
        parser = OptionParser()

        parser.add_option("-b", "--bids", dest="bidsFileName",
                help="Read the bids information.", metavar="BIDSFILE")
        parser.add_option("-u", "--users", dest="usersFileName",
                help="List of users associated in case of a json bid file")
        parser.add_option("-l", "--loans", dest="loansFilename",
                help="Read the loan or mortgages information", metavar="LOANFILE")
        #TODO enable exceptions
        parser.add_option("-e", "--exceptions", dest="exceptions",
                help="List of exceptions in the calculation of the assets.",
                metavar="EXCEPTIONSFILE", default = False)
        parser.add_option("-o", "--output", dest="output",
                help="Write the Liquidity Spots for the Loans",
                metavar="OUTFILE", default = "")
        parser.add_option("-d", "--delimiter", dest="delimiter",
                help="Assigne delimiter to use in the csv format, default is ','.",
                default=',')
        parser.add_option("-v", "--verbose", dest="Verbose", action="store_true",
                help="Verbose mode",
                default=False)
        parser.add_option("-M", "--MortgageOriginator", dest="OriginatorFilename",
                default= os.path.dirname(sys.argv[0])+"/mo.csv",
                help = "Specify the Mortgage Originator, default mo.csv")
        parser.add_option("-R", "--PriorDayRateUsed", dest="PriorRate",
                default = 0, help="Prior day rate used in the Specified/Non " +
                "Comptetitive bids")
        parser.add_option("-L", "--LSSpread", dest="LSSpread",
                default = 1, help="Rate to be added to the Rate's Mortgage " +
                "Originator")
        parser.usage = "usage: %prog [options arg] [-v]"
        return parser
Beispiel #16
0
 def setup_parser(self):
     """ Init the option parser. If derived classes need to add options,
     override this and call the parent function. """
     parser = OptionParser(add_help_option=False)
     parser.usage = '%prog ' + self.name + ' [options] <PATTERN> \n' + \
                    ' Call "%prog ' + self.name + '" without any options to run it interactively.'
     ogroup = OptionGroup(parser, "General options")
     ogroup.add_option("-h", "--help", action="help", help="Displays this help message.")
     ogroup.add_option("-d", "--directory", type="string", default=".",
             help="Base directory of the module. Defaults to the cwd.")
     ogroup.add_option("-n", "--module-name", type="string", default=None,
             help="Use this to override the current module's name (is normally autodetected).")
     ogroup.add_option("-N", "--block-name", type="string", default=None,
             help="Name of the block, where applicable.")
     ogroup.add_option("--skip-lib", action="store_true", default=False,
             help="Don't do anything in the lib/ subdirectory.")
     ogroup.add_option("--skip-swig", action="store_true", default=False,
             help="Don't do anything in the swig/ subdirectory.")
     ogroup.add_option("--skip-python", action="store_true", default=False,
             help="Don't do anything in the python/ subdirectory.")
     ogroup.add_option("--skip-occ", action="store_true", default=False,
             help="Don't do anything in the occ/ subdirectory.")
     ogroup.add_option("-y", "--yes", action="store_true", default=False,
             help="Answer all questions with 'yes'. This can overwrite and delete your files, so be careful.")
     parser.add_option_group(ogroup)
     return parser
def makeParser():
 usage="""
 restrictVocabOfPronPdf [--help] [options]  <inGMTKParamFile> <outGMTKParamFile>
 Finds the pronunciation densePDF matrix, in inGMTKParamFile, with each 
 ith row corresponding to the ith row in inSortedVocabFile , trims it so
 that the only the rows remaining are the ones in outSortedVocabFile, 
 sorted as in outSortedVocabFile.
 if UNK is missing from the in-words, it is added to the in-words, and a 
 corresponding pronunciation line [1 0 0 ...] is added to the incoming pronMatrix.
 """

 parser = OptionParser()
 parser.usage=usage
 
 parser.add_option("-i", "--inGMTKParamFile", type="string", 
                  help="<REQUIRED>")
 parser.add_option("-o", "--outGMTKParamFile", type="string", 
                  help="<REQUIRED>")
 parser.add_option("-v", "--inOrderedVocabFile", type="string", 
                  help="<REQUIRED>")
 parser.add_option("-w", "--outOrderedVocabFile", type="string", 
                  help="<REQUIRED>  This file is read to determine the order of the words in the pronunciation matrix of outGMTKParamFile")
 parser.add_option("-m", "--minPronProbThreshold", type="float", default="0.0001",
                  help="If a pronunciation variant's probability is below this threshold, it gets floored to 0, with the probability being equaly distributed to the remaining pronunciation variants [default: %default]")
 return parser
Beispiel #18
0
    def main(argv):
        """
        Converts LCOV coverage data to Cobertura-compatible XML for reporting.

        Usage:
            lcov_cobertura.py lcov-file.dat
            lcov_cobertura.py lcov-file.dat -b src/dir -e test.lib -o path/out.xml

        By default, XML output will be written to ./coverage.xml
        """

        parser = OptionParser()
        parser.usage = 'lcov_cobertura.py lcov-file.dat [-b source/dir] [-e <exclude packages regex>] [-o output.xml]'
        parser.description = 'Converts lcov output to cobertura-compatible XML'
        parser.add_option('-b', '--base-dir', action='store',
                          help='Directory where source files are located',
                          dest='base_dir', default='.')
        parser.add_option('-o', '--output',
                          help='Path to store cobertura xml file',
                          action='store', dest='output', default='coverage.xml')
        (options, args) = parser.parse_args(args=argv)

        if len(args) != 2:
            print((main.__doc__))
            sys.exit(1)

        try:
            vs_cobertura = VSCobertura("c:\\myworkspace\\wx2\\latest\\wme\\")
            vs_cobertura.addCoverage(args[1], ["wme\\mediasession", "wme\\mediaengine"], 
                                     ["include", "unittest"])
            cobertura_xml = vs_cobertura.convert()
            with open(options.output, mode='wt') as output_file:
                output_file.write(cobertura_xml)
        except IOError:
            sys.stderr.write("Unable to convert %s to Cobertura XML" % args[1])
Beispiel #19
0
def makeParser():
 parser = OptionParser()
 parser.usage=usage()
 parser.add_option("-u", "--trackerUrl", type="string", default="http://ifp-32:7625/announce",
                  help="bittorrent tracker URL. (default: %default)")
 parser.add_option("-b", "--bitTorrentScriptsPath", type="string", default="/opt/rocks/bittorrent",
                  help="The path to bittorrent scripts. (default: %default)")
 parser.add_option("-r", "--rTorrentPath", type="string", default="/cworkspace/ifp-32-1/hasegawa/programs/bin.x86_64/rtorrent",
                  help="The path to rtorrent binary. (default: %default)")
 parser.add_option("-t", "--torrent_dir", type="string", default="/cworkspace/ifp-32-1/hasegawa/programs/scripts/cluster/torrents",
                  help="Where to store torrent files. (default: %default)")
 parser.add_option("-s", "--save_in", type="string", default="/scratch/hasegawa",
                  help="The path where to store the files downloaded from a torrent. (default: %default)")
 parser.add_option("-m", "--pathToMirror", type="string", 
                  help="The path to directory or file to mirror. Required argument.")
 parser.add_option("--parse_dir_interval", type="int", default="60",
                  help="How often to check the torrent_dir for changes, in seconds. (default: %default sec)")
 parser.add_option("--display_interval", type="int", default="60",
                  help="How often the swarm participants print status, in seconds. (default: %default sec)")
 parser.add_option("--download_rate", type="int", default="9500",
                  help="Global maximim download rate limit, in kb. Currently there seems to be a bug in rtorrent, when the download rate is too fast (faster than the disk can write?), you get a 'File chunk write error: Cannot allocate memory.' and peers get dropped, and not picked up again until the next tracker announce.  This affects performance. (default: %default kb)")
 parser.add_option("--shutdown", action="store_true", default=False,
                  help="When in node mode, shutdown btlaunchmany.py (default: %default)")
 intUse = OptionGroup(parser,"OPTIONS FOR INTERNAL USE")
 intUse.add_option("-n", "--nodeMode", action="store_true", default=False,
                  help="Run script in node mode, i.e. ensure that exactly one copy of btlaunchmany.py is running (default: False)")
 parser.add_option_group(intUse)
 
 #command to include command line help in auto-generated documentation
 
 return parser
Beispiel #20
0
def parse_source_options():
    parser = OptionParser()
    parser.usage = "usage: %prog [options] tracker_url source_type source\n" \
                   "Source Types: http, file, tcp\n" \
                   "Examples:\n" \
                   "$ %prog http://tracker.com http http://source.com:8080\n" \
                   "$ %prog http://tracker.com file /var/song.mp3\n" \
                   "$ %prog http://tracker.com tcp 192.168.1.10:30000"

    _creat_basic_options(parser)

    options, args = parser.parse_args()

    if len(args) == 0:
        parser.error('Missing tracker argument')

    if len(args) != 3:
        parser.error('Wrong number of arguments')

    tracker_url, source_type, source = args

    if source_type not in ('http', 'file', 'tcp'):
        parser.error('Invalid source type')

    return (options.ip, options.port, options.streaming_port,
            tracker_url, source_type, source)
Beispiel #21
0
def cli():
    # parse our args
    from optparse import OptionParser
    option_parser = OptionParser()
    option_parser.usage = "%prog [options] path path2 path3 ..."
    option_parser.description = "Will cascade together multiple"\
     + " (python config) ini files. Paths can be directories or files."
    option_parser.add_option('-j', '--json', dest='output_json', default=False,
                             help="output in json format", action="store_true")
    options, args = option_parser.parse_args()

    # now that we know what we're doing lets do it
    smasher = ConfigSmasher(args)
    r_dict = smasher.smash()
    # now the smasher object has the config on it, we want
    # to write it to stdout
    # do they want json?
    if options.output_json:
        import json
        print json.dumps(r_dict)
    else:
        from cStringIO import StringIO
        buffer = StringIO()
        smasher.config.write(buffer)
        print buffer.getvalue()
Beispiel #22
0
def get_parser():
    parser = OptionParser()
    parser.add_option("-d", "--dbfile", dest="dbfile", help="File with database options")
    parser.add_option("-o", "--oauth", dest="oauthfile", help="File with oauth options")
    parser.add_option("-t", "--terms", dest="termsfile", help="File with terms to search")
    parser.usage = "Incomplete command"
    return parser
Beispiel #23
0
def construct_options_parser(usage_string):

    parser = OptionParser()
    parser.add_option(
        "--verbose",
        help=("Generate verbose output for both initialization "
              "and execution. Default is False."),
        action="store_true",
        dest="verbose",
        default=False)
    parser.add_option(
        "--profile",
        help=("Enable profiling of Python code. The value of "
              "this option is the number of functions that are "
              "summarized."),
        action="store",
        dest="profile",
        type="int",
        default=0)
    parser.add_option(
        "--disable-gc",
        help=("Disable the python garbage collecter. Default "
              "is False."),
        action="store_true",
        dest="disable_gc",
        default=False)

    parser.usage=usage_string

    return parser
Beispiel #24
0
def parse_options(options=[], validators=[], usage=None):
    validators.insert(0, validate_source)
    validators.insert(0, validate_rating)
    validators.insert(0, validate_tags)
    validators.insert(0, validate_debug)

    parser = OptionParser()
    parser.add_option('-s', '--source-dir', dest='source', help='Photo directory')
    parser.add_option('-r', '--rating', dest='rating', help='Exif.Image.Rating')
    parser.add_option('--debug', action="store_true", dest='debug',
                      default=False, help='Debug information will print to the console')

    for option in options:
        parser.add_option(option)

    if usage:
        parser.usage = usage

    (options, args) = parser.parse_args()
    for validator in validators:
        if not validator(options, args):
            parser.print_help()
            sys.exit(-1)
        
    return options, args
Beispiel #25
0
def get_options():
    """
    Define and parse command line options
    """
    from optparse import OptionParser
    parser = OptionParser()
    parser.usage = "%prog [options] file_name\nor\n %prog -h"
    parser.add_option("-r", "--rate", dest="data_rate", default="0",
       help="Data rate in records per second. Defaults to the same data rate as \
the original data.", 
       metavar="data_rate")
    parser.add_option("-i", "--input", dest="input", 
       help="Define one of the input files.", metavar="input files")
    parser.add_option("-o", "--output", dest="output_dir", default="", 
       help="Define output directory.  Default is the script directory", 
       metavar="output directory")
    parser.add_option("-g", "--no_gns", action="store_false", 
       dest="gns_430_avail", default=True, help="No GNS 430 data to merge.")
    
    (options, args) = parser.parse_args()
    
    if args:
        file_name = args[0]
    elif options.input:
        file_name = options.input
    else:
        parser.error('Error - You must supply one of the input file names.\nThe\
 file name can either be bare after the script name, or it can be \
given following an "-i".  ')
    data_rate = float(options.data_rate)
    return file_name, data_rate, options.output_dir, options.gns_430_avail
def parseArgv():
    """
    Command line option parser. 
    """
    parser = OptionParser()
    parser.usage=r""" cat <TEXT> | %prog [--unit <UNIT>] [--output <SA_FILE>]

Create the suffix array of TEXT with the processing UNIT and optionally store it in SA_FILE for subsequent use.
UNIT may be set to 'byte', 'character' (given an encoding with the --encoding option) or 'word', which is the default.
"""


    parser.add_option("-i", "--input",
                      action="store", type="string", dest="input",
                      default=False,
                      help="Path of the file containing the input text. When '-' is given, read the standard input (default). If the path ends with '.gz', reads the decompressed file.")
  
    parser.add_option("-o", "--output",
                      action="store", type="string", dest="output",
                      default=False,
                      help="Store the suffix array of the input to the file OUTPUT. When '-' is given, writes to the standard output. If the filename ends with '.gz', the suffix array will be stored  compressed.")

    parser.add_option("", "--load",
                      action="store", type="string", dest="SAFile",
                      default=False,
                      help="Load a suffix array from SAFILE, this option and --input are mutually exclusive.")

    parser.add_option("-u", "--unit",
                      action="store", type="string", dest="unit",
                      default=DEFAULT_UNIT_STR,
                      help="Processing unit used for the creation of the suffix array."+\
                      'Possible values are "byte", "character" and "word". Default is "%s".'%DEFAULT_UNIT_STR+\
                      "This option is ignored when the suffix array is loaded from SAFILE."+\
                      'For characters, the input is decoded according to the encoding set via the option --encoding.')

    parser.add_option("-e", "--encoding",
                      action="store", type="string", dest="encoding",
                      default=DEFAULT_ENCODING,
                      help="Encoding of the input. This information is required only when processing characters. Default is '%s'."%DEFAULT_ENCODING)
                       
    parser.add_option("-p", "--print",
                      action="store_true", dest="printSA",
                      default=False,
                      help="Prints the suffix array in a human readable format to the standard error output.")
  

    parser.add_option("", "--verbose",
                      action="store_true", dest="verbose",
                      default=False,
                      help="Prints more information.")

    parser.add_option("", "--no-lcps",
                      action="store_true", dest="noLCPs",
                      default=False,
                      help="Switch off the computation of LCPs. By doing so, the find functions are unusable.")
                    
    (options, args) = parser.parse_args(_argv)
    strings=args[1:]
    return (options, strings)
def get_parser():
    parser = OptionParser()
    parser.add_option("-d", "--database", dest="database", help="mongodb database name")
    parser.add_option("-s", "--server", dest="server", help="mongodb host")
    parser.add_option("-o", "--oauth", dest="oauthfile", help="file with oauth options")
    parser.add_option("-f", "--file", dest="file", help="terms file")
    parser.usage = "bad parametres"
    return parser
Beispiel #28
0
def main(args):
	parser = OptionParser(description="Print a hexadecimal string.")
	parser.usage="%prog [options]"
	parser.add_option('-s', '--size', dest='str_size', default=32, help="string size ( Default: 32 )")

	options, parsed_args = parser.parse_args(args)

	print ''.join(random.choice(string.hexdigits) for n in xrange(int(options.str_size))).lower()
Beispiel #29
0
def setup_parser():
    """ Init the option parser. If derived classes need to add options,
    override this and call the parent function. """
    parser = OptionParser(add_help_option=False)
    parser.usage = '%prog ' + "random name" + ' [options] <PATTERN> \n' + \
                   ' Call "%prog ' + "random name" + '" without any options to run it interactively.'
    ogroup = OptionGroup(parser, "General options")
    ogroup.add_option("-h", "--help", action="help", help="Displays this help message.")
    return parser
Beispiel #30
0
def createHfccaCommandLineParser():
    from optparse import OptionParser
    parser = OptionParser(version=VERSION)
    parser.add_option("-v", "--verbose",
            help="Output in verbose mode (long function name)",
            action="store_true",
            dest="verbose",
            default=False)
    parser.add_option("-C", "--CCN",
            help =  "Threshold for cyclomatic complexity number warning. "+
                    "The default value is %d. Functions with CCN bigger than this number will generate warning" % DEFAULT_CCN_THRESHOLD,
            action="store",
            type="int",
            dest="CCN",
            default=DEFAULT_CCN_THRESHOLD)
    parser.add_option("-a", "--arguments",
            help="Limit for number of parameters",
            action="store",
            type="int",
            dest="arguments",
            default=100)
    parser.add_option("-w", "--warnings_only",
            help="Show warnings only, using clang/gcc's warning format for printing warnings. http://clang.llvm.org/docs/UsersManual.html#cmdoption-fdiagnostics-format",
            action="store_true",
            dest="warnings_only",
            default=False)
    parser.add_option("-i", "--ignore_warnings",
            help="If the number of warnings is equal or less than the number, the tool will exit normally, otherwize it will generate error. Useful in makefile when improving legacy code.",
            action="store",
            type="int",
            dest="number",
            default=0)
    parser.add_option("-x", "--exclude",
            help="Exclude files that match this pattern. * matches everything, ? matches any single characoter, \"./folder/*\" exclude everything in the folder, recursively. Multiple patterns can be specified. Don't forget to add \"\" around the pattern.",
            action="append",
            dest="exclude",
            default=[])
    parser.add_option("-X", "--xml",
            help="Generate XML in cppncss style instead of the normal tabular output. Useful to generate report in Jenkins server",
            action="store_true",
            dest="xml",
            default=None)
    parser.add_option("-P", "--no_preprocessor_count",
            help="By default, a #if will also increase the complexity. Adding this option to ignore them",
            action="store_true",
            dest="no_preprocessor_count",
            default=False)
    parser.add_option("-t", "--working_threads",
            help="number of working threads. The default value is 1.",
            action="store",
            type="int",
            dest="working_threads",
            default=1)

    parser.usage = "hfcca [options] [PATH or FILE] [PATH] ... "
    parser.description = __doc__
    return parser
Beispiel #31
0
                    self.pattern,
                    useCache=self.cache)
                print 'attached files to %s' % (single_mc_list[0].name)
                print 'files %s' % (
                    '/'.join(single_mc_list[0].files[0].split('/')[:-1] +
                             [self.pattern]))

    def pruneSampleList_(self):
        self.MC_list = [m for m in self.MC_list if m.files]


if __name__ == '__main__':

    from optparse import OptionParser
    parser = OptionParser()
    parser.usage = ''' To be written '''

    parser.add_option(
        '-T',
        '--tier',
        dest='tier',
        help='Tier. Search samples on eos that end with this tier')
    parser.add_option(
        '-U',
        '--user',
        dest='user',
        help='User. User or group that owns the samples. Default htautau_group',
        default='htautau_group')
    parser.add_option(
        '-P',
        '--pattern',
Beispiel #32
0
        "resolution": 2
    },
    "widescreen": {
        "width": 1920,
        "height": 1080,
        "resolution": 2
    }
}

DEFAULT_RESOLUTION = 3.6

if __name__ == '__main__':
    option_parser = OptionParser()

    option_parser.description = "Export a Sozi presentation to PDF"
    option_parser.usage = "sozi2pdf.py [options] url.svg"

    option_parser.add_option(
        "-f",
        "--format",
        type="string",
        dest="format",
        default="a4",
        help=
        "Page format: 'a3' | 'a4' | 'letter' | 'screen' | 'widescreen' (default is 'a4')"
    )
    option_parser.add_option(
        "-l",
        "--landscape",
        action="store_true",
        dest="landscape",
Beispiel #33
0
if __name__ == "__main__":
    usage = """
	[%prog] [options] casestring directory

	"""
    from optparse import OptionParser
    parser = OptionParser()
    parser.add_option("-v",
                      "--verbose",
                      default=0,
                      action="store",
                      type="int",
                      dest="verbose",
                      help="Verbose level")
    # parser.add_option("-d", "--dir", default="data/", action="store", type="string", dest="dir", help="Input directory containing subdirectories with server.csv files [default: %default]")
    parser.usage = usage
    (options, args) = parser.parse_args()

    ## Check arguments
    if len(args) < 2 or not os.path.isdir(args[1]):
        parser.print_help()
        exit(-1)

    case = args[0]
    config = getConfig(case)
    directory = args[1]
    if not directory.endswith('/'): directory += '/'

    ## Extract the data
    data = {}
    sizes = set()
Beispiel #34
0
#!/usr/bin/env python

import os

from CMGTools.Production.logger import *

if __name__ == '__main__':

    from optparse import OptionParser

    parser = OptionParser()

    parser.usage = """setLogger.py 
    """
    parser.add_option("-n",
                      "--number_of_jobs",
                      dest="number_of_jobs",
                      help="Specify original number of jobs",
                      default=0)

    (options, args) = parser.parse_args()

    if len(args) != 0:
        parser.print_help()
        sys.exit(1)

    dir = 'Logger'
    if not os.path.isdir(dir):
        os.mkdir(dir)
    log = logger(dir)
    log.logCMSSW()
Beispiel #35
0
            steamids.append(row['steamid'])
        url = 'https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v2/?key=' + api_key + '&steamids=' + ','.join(steamids) + '&format=xml'
        new_thread = Thread(target = lookup_group, args = (table, url))
        new_thread.start()
        threads.append(new_thread)
    for thread in threads:
        thread.join()
    return table

# ==================
# MAIN program logic is here
# ==================

# Option parsing
parser = OptionParser()
parser.usage = "%prog level [level2 [...]] [options] (level is a regular expression)"
parser.add_option("-m", "--mode", action="store", default=".", dest="mode", help="Mode to lookup. Searches all by default")
# parser.add_option("-g","--game-id", action="store", default='233610', dest="appid", help="Game id to be used. Defaults to Distance. (You can try if you want.)")
parser.add_option("-n", "--number", action="store", default=15, dest="count", help="Number of places to print. Views top 15 by default")
parser.add_option("-s", "--simple", action="count", default=0, dest="strip", help="Disable pretty box drawings.  Repeat to strip column headings")
parser.add_option("-f", "--key-file", action="store", dest="api_key_path", help="Path to Steam API key. $XDG_DATA_HOME/steamapi/apikey by default")
parser.add_option("-p", "--plot", action="store_true", dest="plot", help="Plot the board instead.")
parser.add_option("-k", "--key", action="store", dest="api_key", help="Steam API key.  Overrides -f/--key-file")
(opts, args) = parser.parse_args()

# Get API key
api_key = opts.api_key
if not api_key:
    if opts.api_key_path:
        api_key = get_api_key(opts.api_key_path)
    else:
Beispiel #36
0
        bucket_min = bucket_max
        bucket_max = boundaries[bucket]
        bucket_count = bucket_counts[bucket]
        star_count = 0
        if bucket_count:
            star_count = bucket_count / bucket_scale
        if options.percentage:
            percentage = " (%0.2f%%)" % (100 * Decimal(bucket_count) /
                                         Decimal(samples))
        print format_string % (bucket_min, bucket_max, bucket_count,
                               options.dot * star_count, percentage)


if __name__ == "__main__":
    parser = OptionParser()
    parser.usage = "cat data | %prog [options]"
    parser.add_option("-a",
                      "--agg",
                      dest="agg_value_key",
                      default=False,
                      action="store_true",
                      help="Two column input format, " +
                      "space seperated with value<space>key")
    parser.add_option("-A",
                      "--agg-key-value",
                      dest="agg_key_value",
                      default=False,
                      action="store_true",
                      help="Two column " +
                      "input format, space seperated with key<space>value")
    parser.add_option("-m",
Beispiel #37
0
def main():
    # Parse command line arguments
    parser = OptionParser()
    parser.usage = "%prog [options] map_file"
    parser.add_option('-l',
                      '--logscale',
                      dest='logscale',
                      action='store_true',
                      help='use log color scaling',
                      default=False)
    parser.add_option("-o",
                      "--output",
                      dest="outfile",
                      metavar="FILE",
                      help='output image file [default: <map_file>.png]',
                      default=None)
    parser.add_option("-m",
                      "--min",
                      dest="min",
                      metavar="VALUE",
                      help='min value',
                      default=None)
    parser.add_option("-M",
                      "--max",
                      dest="max",
                      metavar="VALUE",
                      help='max value',
                      default=None)
    parser.add_option('-a',
                      '--autorange',
                      dest='autorange',
                      action='store_true',
                      help='use automatic dynamic range (no min/max)',
                      default=False)
    parser.add_option('--big-endian',
                      dest='big_endian',
                      action='store_true',
                      help='input binary data is stored as big endian',
                      default=False)
    parser.add_option('-c',
                      '--colormap',
                      dest='cmap_str',
                      metavar='CMAP',
                      help='matplotlib color map to use',
                      default="jet")
    (opts, args) = parser.parse_args()

    # Parse input and output
    try:
        infile = args[0]
    except:
        print(parser.print_help())
        return 1

    if (opts.outfile == None):
        outfile = infile + '.tif'
    else:
        outfile = opts.outfile

    # Endianness
    if (opts.big_endian):
        endianness = ">"
    else:
        endianness = "="

    # Read image data
    #print("Reading raw Fortran data...")
    f = fortranfile.FortranFile(infile)
    [nx, ny] = f.read_fortran_record('i4', endian=endianness)
    dat = f.read_fortran_record('f4', endian=endianness)
    f.close()

    if (opts.logscale):
        dat = np.array(dat) + 1e-12

    rawmin = np.amin(dat)
    rawmax = np.amax(dat)
    #print('    Image map size  : ',(nx, ny))
    #print('    Data bounds     : ',(rawmin,rawmax))
    #print("Scaling data and processing colormap...")

    # Bounds
    if opts.min == None:
        plotmin = rawmin
    else:
        plotmin = float(opts.min)

    if opts.max == None:
        plotmax = rawmax
    else:
        plotmax = float(opts.max)

    # Log scale?
    if (opts.logscale):
        dat = np.log10(dat)
        rawmin = np.log10(rawmin)
        rawmax = np.log10(rawmax)
        plotmin = np.log10(plotmin)
        plotmax = np.log10(plotmax)

    # Auto-adjust dynamic range?
    if (opts.autorange):
        #print("Computing dynamic range...")
        # Overrides any provided bounds
        NBINS = 200
        # Compute histogram
        (hist, bins) = np.histogram(dat, NBINS, (rawmin, rawmax), normed=True)
        chist = np.cumsum(hist)
        chist = chist / np.amax(chist)
        # Compute black and white point
        clip_k = chist.searchsorted(0.05)
        plotmin = bins[clip_k]
        plotmax = rawmax

    if (plotmax - plotmin > 0):
        dat = np.clip((dat - plotmin) / (plotmax - plotmin), 0.0, 1.0)
    else:
        dat = 0.5 * dat / plotmax


#	if(opts.logscale):
#print('    Color bounds    : ',(10**plotmin,10**plotmax))
#	else:
#print('    Color bounds    : ',(plotmin,plotmax))

# Apply chosen color map
    color_map = cm.get_cmap(opts.cmap_str)
    dat = color_map(dat) * 255

    # Convert to int
    dat = np.array(dat, dtype='i')

    # Output to file
    #print("Saving image to file...")
    R_band = Image.new("L", (nx, ny))
    R_band.putdata(dat[:, 0])
    G_band = Image.new("L", (nx, ny))
    G_band.putdata(dat[:, 1])
    B_band = Image.new("L", (nx, ny))
    B_band.putdata(dat[:, 2])

    out_img = Image.merge("RGB", (R_band, G_band, B_band)).transpose(
        Image.FLIP_TOP_BOTTOM)
    out_img.save(outfile)
    print("map2img.py completed")
                  type='string',
                  action='store',
                  default=None,
                  help='Output cc list for patch file (used by git)')
parser.add_option('--no-check',
                  action='store_false',
                  dest='check_patch',
                  default=True,
                  help="Don't check for patch compliance")
parser.add_option('--no-tags',
                  action='store_false',
                  dest='process_tags',
                  default=True,
                  help="Don't process subject tags as aliaes")

parser.usage = """patman [options]

Create patches from commits in a branch, check them and email them as
specified by tags you place in the commits. Use -n to do a dry run first."""

# Parse options twice: first to get the project and second to handle
# defaults properly (which depends on project).
(options, args) = parser.parse_args()
settings.Setup(parser, options.project, '')
(options, args) = parser.parse_args()

# Run our meagre tests
if options.test:
    import doctest

    sys.argv = [sys.argv[0]]
"""
Script to create a template easyblock Python module, for a given software package.

@author: Kenneth Hoste (Ghent University)
"""

import datetime
import os
import sys
from optparse import OptionParser, OptionGroup

from easybuild.tools.filetools import encode_class_name

# parse options
parser = OptionParser()
parser.usage = "%prog <software name> [options]"
parser.description = "Generates template easyblock for given software name. " \
                     "Use -h or --help for more information."
parser.add_option("--path",
                  help="path to easyblocks repository (default: '.')",
                  default='.')
parser.add_option(
    "--parent",
    default="EasyBlock",
    help="Name of parent easyblock for this easyblock (default: 'EasyBlock').")
parser.add_option(
    "--letter-prefix",
    default=False,
    action="store_true",
    help=
    "Whether or not to prefix the easyblock path with a letter directory (default: False)"
Beispiel #40
0
def cmdLineParser():
    """
    This function parses the command line parameters and arguments
    """

    checkSystemEncoding()

    _ = getUnicode(os.path.basename(sys.argv[0]), encoding=sys.getfilesystemencoding())

    usage = "%s%s [options]" % ("python " if not IS_WIN else "", \
            "\"%s\"" % _ if " " in _ else _)

    parser = OptionParser(usage=usage)

    try:
        parser.add_option("--hh", dest="advancedHelp",
                          action="store_true",
                          help="Show advanced help message and exit")

        parser.add_option("--version", dest="showVersion",
                          action="store_true",
                          help="Show program's version number and exit")

        parser.add_option("-v", dest="verbose", type="int",
                          help="Verbosity level: 0-6 (default %d)" % defaults.verbose)

        # Target options
        target = OptionGroup(parser, "Target", "At least one of these "
                             "options has to be provided to define the target(s)")

        target.add_option("-d", dest="direct", help="Connection string "
                          "for direct database connection")

        target.add_option("-u", "--url", dest="url", help="Target URL (e.g. \"http://www.site.com/vuln.php?id=1\")")

        target.add_option("-l", dest="logFile", help="Parse target(s) from Burp "
                          "or WebScarab proxy log file")

        target.add_option("-x", dest="sitemapUrl", help="Parse target(s) from remote sitemap(.xml) file")

        target.add_option("-m", dest="bulkFile", help="Scan multiple targets given "
                          "in a textual file ")

        target.add_option("-r", dest="requestFile",
                          help="Load HTTP request from a file")

        target.add_option("-g", dest="googleDork",
                          help="Process Google dork results as target URLs")

        target.add_option("-c", dest="configFile",
                          help="Load options from a configuration INI file")

        # Request options
        request = OptionGroup(parser, "Request", "These options can be used "
                              "to specify how to connect to the target URL")

        request.add_option("--method", dest="method",
                           help="Force usage of given HTTP method (e.g. PUT)")

        request.add_option("--data", dest="data",
                           help="Data string to be sent through POST")

        request.add_option("--param-del", dest="paramDel",
                           help="Character used for splitting parameter values")

        request.add_option("--cookie", dest="cookie",
                           help="HTTP Cookie header value")

        request.add_option("--cookie-del", dest="cookieDel",
                           help="Character used for splitting cookie values")

        request.add_option("--load-cookies", dest="loadCookies",
                           help="File containing cookies in Netscape/wget format")

        request.add_option("--drop-set-cookie", dest="dropSetCookie",
                           action="store_true",
                           help="Ignore Set-Cookie header from response")

        request.add_option("--user-agent", dest="agent",
                           help="HTTP User-Agent header value")

        request.add_option("--random-agent", dest="randomAgent",
                           action="store_true",
                           help="Use randomly selected HTTP User-Agent header value")

        request.add_option("--host", dest="host",
                           help="HTTP Host header value")

        request.add_option("--referer", dest="referer",
                           help="HTTP Referer header value")

        request.add_option("--headers", dest="headers",
                           help="Extra headers (e.g. \"Accept-Language: fr\\nETag: 123\")")

        request.add_option("--auth-type", dest="authType",
                           help="HTTP authentication type "
                                "(Basic, Digest, NTLM or PKI)")

        request.add_option("--auth-cred", dest="authCred",
                           help="HTTP authentication credentials "
                                "(name:password)")

        request.add_option("--auth-private", dest="authPrivate",
                           help="HTTP authentication PEM private key file")

        request.add_option("--ignore-401", dest="ignore401", action="store_true",
                          help="Ignore HTTP Error 401 (Unauthorized)")

        request.add_option("--proxy", dest="proxy",
                           help="Use a proxy to connect to the target URL")

        request.add_option("--proxy-cred", dest="proxyCred",
                           help="Proxy authentication credentials "
                                "(name:password)")

        request.add_option("--proxy-file", dest="proxyFile",
                           help="Load proxy list from a file")

        request.add_option("--ignore-proxy", dest="ignoreProxy", action="store_true",
                           help="Ignore system default proxy settings")

        request.add_option("--tor", dest="tor",
                                  action="store_true",
                                  help="Use Tor anonymity network")

        request.add_option("--tor-port", dest="torPort",
                                  help="Set Tor proxy port other than default")

        request.add_option("--tor-type", dest="torType",
                                  help="Set Tor proxy type (HTTP (default), SOCKS4 or SOCKS5)")

        request.add_option("--check-tor", dest="checkTor",
                                  action="store_true",
                                  help="Check to see if Tor is used properly")

        request.add_option("--delay", dest="delay", type="float",
                           help="Delay in seconds between each HTTP request")

        request.add_option("--timeout", dest="timeout", type="float",
                           help="Seconds to wait before timeout connection "
                                "(default %d)" % defaults.timeout)

        request.add_option("--retries", dest="retries", type="int",
                           help="Retries when the connection timeouts "
                                "(default %d)" % defaults.retries)

        request.add_option("--randomize", dest="rParam",
                           help="Randomly change value for given parameter(s)")

        request.add_option("--safe-url", dest="safeUrl",
                           help="URL address to visit frequently during testing")

        request.add_option("--safe-post", dest="safePost",
                           help="POST data to send to a safe URL")

        request.add_option("--safe-req", dest="safeReqFile",
                           help="Load safe HTTP request from a file")

        request.add_option("--safe-freq", dest="safeFreq", type="int",
                           help="Test requests between two visits to a given safe URL")

        request.add_option("--skip-urlencode", dest="skipUrlEncode",
                           action="store_true",
                           help="Skip URL encoding of payload data")

        request.add_option("--csrf-token", dest="csrfToken",
                           help="Parameter used to hold anti-CSRF token")

        request.add_option("--csrf-url", dest="csrfUrl",
                           help="URL address to visit to extract anti-CSRF token")

        request.add_option("--force-ssl", dest="forceSSL",
                           action="store_true",
                           help="Force usage of SSL/HTTPS")

        request.add_option("--hpp", dest="hpp",
                                  action="store_true",
                                  help="Use HTTP parameter pollution method")

        request.add_option("--eval", dest="evalCode",
                           help="Evaluate provided Python code before the request (e.g. \"import hashlib;id2=hashlib.md5(id).hexdigest()\")")

        # Optimization options
        optimization = OptionGroup(parser, "Optimization", "These "
                               "options can be used to optimize the "
                               "performance of sqlmap")

        optimization.add_option("-o", dest="optimize",
                                 action="store_true",
                                 help="Turn on all optimization switches")

        optimization.add_option("--predict-output", dest="predictOutput", action="store_true",
                          help="Predict common queries output")

        optimization.add_option("--keep-alive", dest="keepAlive", action="store_true",
                           help="Use persistent HTTP(s) connections")

        optimization.add_option("--null-connection", dest="nullConnection", action="store_true",
                          help="Retrieve page length without actual HTTP response body")

        optimization.add_option("--threads", dest="threads", type="int",
                           help="Max number of concurrent HTTP(s) "
                                "requests (default %d)" % defaults.threads)

        # Injection options
        injection = OptionGroup(parser, "Injection", "These options can be "
                                "used to specify which parameters to test "
                                "for, provide custom injection payloads and "
                                "optional tampering scripts")

        injection.add_option("-p", dest="testParameter",
                             help="Testable parameter(s)")

        injection.add_option("--skip", dest="skip",
                             help="Skip testing for given parameter(s)")

        injection.add_option("--dbms", dest="dbms",
                             help="Force back-end DBMS to this value")

        injection.add_option("--dbms-cred", dest="dbmsCred",
                            help="DBMS authentication credentials (user:password)")

        injection.add_option("--os", dest="os",
                             help="Force back-end DBMS operating system "
                                  "to this value")

        injection.add_option("--invalid-bignum", dest="invalidBignum",
                             action="store_true",
                             help="Use big numbers for invalidating values")

        injection.add_option("--invalid-logical", dest="invalidLogical",
                             action="store_true",
                             help="Use logical operations for invalidating values")

        injection.add_option("--invalid-string", dest="invalidString",
                             action="store_true",
                             help="Use random strings for invalidating values")

        injection.add_option("--no-cast", dest="noCast",
                             action="store_true",
                             help="Turn off payload casting mechanism")

        injection.add_option("--no-escape", dest="noEscape",
                             action="store_true",
                             help="Turn off string escaping mechanism")

        injection.add_option("--prefix", dest="prefix",
                             help="Injection payload prefix string")

        injection.add_option("--suffix", dest="suffix",
                             help="Injection payload suffix string")

        injection.add_option("--tamper", dest="tamper",
                             help="Use given script(s) for tampering injection data")

        # Detection options
        detection = OptionGroup(parser, "Detection", "These options can be "
                                "used to customize the detection phase")

        detection.add_option("--level", dest="level", type="int",
                             help="Level of tests to perform (1-5, "
                                  "default %d)" % defaults.level)

        detection.add_option("--risk", dest="risk", type="int",
                             help="Risk of tests to perform (1-3, "
                                  "default %d)" % defaults.level)

        detection.add_option("--string", dest="string",
                             help="String to match when "
                                  "query is evaluated to True")

        detection.add_option("--not-string", dest="notString",
                             help="String to match when "
                                  "query is evaluated to False")

        detection.add_option("--regexp", dest="regexp",
                             help="Regexp to match when "
                                  "query is evaluated to True")

        detection.add_option("--code", dest="code", type="int",
                             help="HTTP code to match when "
                                  "query is evaluated to True")

        detection.add_option("--text-only", dest="textOnly",
                             action="store_true",
                             help="Compare pages based only on the textual content")

        detection.add_option("--titles", dest="titles",
                             action="store_true",
                             help="Compare pages based only on their titles")

        # Techniques options
        techniques = OptionGroup(parser, "Techniques", "These options can be "
                                 "used to tweak testing of specific SQL "
                                 "injection techniques")

        techniques.add_option("--technique", dest="tech",
                              help="SQL injection techniques to use "
                                   "(default \"%s\")" % defaults.tech)

        techniques.add_option("--time-sec", dest="timeSec",
                              type="int",
                              help="Seconds to delay the DBMS response "
                                   "(default %d)" % defaults.timeSec)

        techniques.add_option("--union-cols", dest="uCols",
                              help="Range of columns to test for UNION query SQL injection")

        techniques.add_option("--union-char", dest="uChar",
                              help="Character to use for bruteforcing number of columns")

        techniques.add_option("--union-from", dest="uFrom",
                              help="Table to use in FROM part of UNION query SQL injection")

        techniques.add_option("--dns-domain", dest="dnsName",
                              help="Domain name used for DNS exfiltration attack")

        techniques.add_option("--second-order", dest="secondOrder",
                             help="Resulting page URL searched for second-order "
                                  "response")

        # Fingerprint options
        fingerprint = OptionGroup(parser, "Fingerprint")

        fingerprint.add_option("-f", "--fingerprint", dest="extensiveFp",
                               action="store_true",
                               help="Perform an extensive DBMS version fingerprint")

        # Enumeration options
        enumeration = OptionGroup(parser, "Enumeration", "These options can "
                                  "be used to enumerate the back-end database "
                                  "management system information, structure "
                                  "and data contained in the tables. Moreover "
                                  "you can run your own SQL statements")

        enumeration.add_option("-a", "--all", dest="getAll",
                               action="store_true", help="Retrieve everything")

        enumeration.add_option("-b", "--banner", dest="getBanner",
                               action="store_true", help="Retrieve DBMS banner")

        enumeration.add_option("--current-user", dest="getCurrentUser",
                               action="store_true",
                               help="Retrieve DBMS current user")

        enumeration.add_option("--current-db", dest="getCurrentDb",
                               action="store_true",
                               help="Retrieve DBMS current database")

        enumeration.add_option("--hostname", dest="getHostname",
                               action="store_true",
                               help="Retrieve DBMS server hostname")

        enumeration.add_option("--is-dba", dest="isDba",
                               action="store_true",
                               help="Detect if the DBMS current user is DBA")

        enumeration.add_option("--users", dest="getUsers", action="store_true",
                               help="Enumerate DBMS users")

        enumeration.add_option("--passwords", dest="getPasswordHashes",
                               action="store_true",
                               help="Enumerate DBMS users password hashes")

        enumeration.add_option("--privileges", dest="getPrivileges",
                               action="store_true",
                               help="Enumerate DBMS users privileges")

        enumeration.add_option("--roles", dest="getRoles",
                               action="store_true",
                               help="Enumerate DBMS users roles")

        enumeration.add_option("--dbs", dest="getDbs", action="store_true",
                               help="Enumerate DBMS databases")

        enumeration.add_option("--tables", dest="getTables", action="store_true",
                               help="Enumerate DBMS database tables")

        enumeration.add_option("--columns", dest="getColumns", action="store_true",
                               help="Enumerate DBMS database table columns")

        enumeration.add_option("--schema", dest="getSchema", action="store_true",
                               help="Enumerate DBMS schema")

        enumeration.add_option("--count", dest="getCount", action="store_true",
                               help="Retrieve number of entries for table(s)")

        enumeration.add_option("--dump", dest="dumpTable", action="store_true",
                               help="Dump DBMS database table entries")

        enumeration.add_option("--dump-all", dest="dumpAll", action="store_true",
                               help="Dump all DBMS databases tables entries")

        enumeration.add_option("--search", dest="search", action="store_true",
                               help="Search column(s), table(s) and/or database name(s)")

        enumeration.add_option("--comments", dest="getComments", action="store_true",
                               help="Retrieve DBMS comments")

        enumeration.add_option("-D", dest="db",
                               help="DBMS database to enumerate")

        enumeration.add_option("-T", dest="tbl",
                               help="DBMS database table(s) to enumerate")

        enumeration.add_option("-C", dest="col",
                               help="DBMS database table column(s) to enumerate")

        enumeration.add_option("-X", dest="excludeCol",
                               help="DBMS database table column(s) to not enumerate")

        enumeration.add_option("-U", dest="user",
                               help="DBMS user to enumerate")

        enumeration.add_option("--exclude-sysdbs", dest="excludeSysDbs",
                               action="store_true",
                               help="Exclude DBMS system databases when "
                                    "enumerating tables")

        enumeration.add_option("--where", dest="dumpWhere",
                               help="Use WHERE condition while table dumping")

        enumeration.add_option("--start", dest="limitStart", type="int",
                               help="First query output entry to retrieve")

        enumeration.add_option("--stop", dest="limitStop", type="int",
                               help="Last query output entry to retrieve")

        enumeration.add_option("--first", dest="firstChar", type="int",
                               help="First query output word character to retrieve")

        enumeration.add_option("--last", dest="lastChar", type="int",
                               help="Last query output word character to retrieve")

        enumeration.add_option("--sql-query", dest="query",
                               help="SQL statement to be executed")

        enumeration.add_option("--sql-shell", dest="sqlShell",
                               action="store_true",
                               help="Prompt for an interactive SQL shell")

        enumeration.add_option("--sql-file", dest="sqlFile",
                               help="Execute SQL statements from given file(s)")

        # Brute force options
        brute = OptionGroup(parser, "Brute force", "These "
                          "options can be used to run brute force "
                          "checks")

        brute.add_option("--common-tables", dest="commonTables", action="store_true",
                               help="Check existence of common tables")

        brute.add_option("--common-columns", dest="commonColumns", action="store_true",
                               help="Check existence of common columns")

        # User-defined function options
        udf = OptionGroup(parser, "User-defined function injection", "These "
                          "options can be used to create custom user-defined "
                          "functions")

        udf.add_option("--udf-inject", dest="udfInject", action="store_true",
                       help="Inject custom user-defined functions")

        udf.add_option("--shared-lib", dest="shLib",
                       help="Local path of the shared library")

        # File system options
        filesystem = OptionGroup(parser, "File system access", "These options "
                                 "can be used to access the back-end database "
                                 "management system underlying file system")

        filesystem.add_option("--file-read", dest="rFile",
                              help="Read a file from the back-end DBMS "
                                   "file system")

        filesystem.add_option("--file-write", dest="wFile",
                              help="Write a local file on the back-end "
                                   "DBMS file system")

        filesystem.add_option("--file-dest", dest="dFile",
                              help="Back-end DBMS absolute filepath to "
                                   "write to")

        # Takeover options
        takeover = OptionGroup(parser, "Operating system access", "These "
                               "options can be used to access the back-end "
                               "database management system underlying "
                               "operating system")

        takeover.add_option("--os-cmd", dest="osCmd",
                            help="Execute an operating system command")

        takeover.add_option("--os-shell", dest="osShell",
                            action="store_true",
                            help="Prompt for an interactive operating "
                                 "system shell")

        takeover.add_option("--os-pwn", dest="osPwn",
                            action="store_true",
                            help="Prompt for an OOB shell, "
                                 "Meterpreter or VNC")

        takeover.add_option("--os-smbrelay", dest="osSmb",
                            action="store_true",
                            help="One click prompt for an OOB shell, "
                                 "Meterpreter or VNC")

        takeover.add_option("--os-bof", dest="osBof",
                            action="store_true",
                            help="Stored procedure buffer overflow "
                                 "exploitation")

        takeover.add_option("--priv-esc", dest="privEsc",
                            action="store_true",
                            help="Database process user privilege escalation")

        takeover.add_option("--msf-path", dest="msfPath",
                            help="Local path where Metasploit Framework "
                                 "is installed")

        takeover.add_option("--tmp-path", dest="tmpPath",
                            help="Remote absolute path of temporary files "
                                 "directory")

        # Windows registry options
        windows = OptionGroup(parser, "Windows registry access", "These "
                               "options can be used to access the back-end "
                               "database management system Windows "
                               "registry")

        windows.add_option("--reg-read", dest="regRead",
                            action="store_true",
                            help="Read a Windows registry key value")

        windows.add_option("--reg-add", dest="regAdd",
                            action="store_true",
                            help="Write a Windows registry key value data")

        windows.add_option("--reg-del", dest="regDel",
                            action="store_true",
                            help="Delete a Windows registry key value")

        windows.add_option("--reg-key", dest="regKey",
                            help="Windows registry key")

        windows.add_option("--reg-value", dest="regVal",
                            help="Windows registry key value")

        windows.add_option("--reg-data", dest="regData",
                            help="Windows registry key value data")

        windows.add_option("--reg-type", dest="regType",
                            help="Windows registry key value type")

        # General options
        general = OptionGroup(parser, "General", "These options can be used "
                             "to set some general working parameters")

        #general.add_option("-x", dest="xmlFile",
        #                    help="Dump the data into an XML file")

        general.add_option("-s", dest="sessionFile",
                            help="Load session from a stored (.sqlite) file")

        general.add_option("-t", dest="trafficFile",
                            help="Log all HTTP traffic into a "
                            "textual file")

        general.add_option("--batch", dest="batch",
                            action="store_true",
                            help="Never ask for user input, use the default behaviour")

        general.add_option("--charset", dest="charset",
                            help="Force character encoding used for data retrieval")

        general.add_option("--crawl", dest="crawlDepth", type="int",
                            help="Crawl the website starting from the target URL")

        general.add_option("--crawl-exclude", dest="crawlExclude",
                           help="Regexp to exclude pages from crawling (e.g. \"logout\")")

        general.add_option("--csv-del", dest="csvDel",
                                  help="Delimiting character used in CSV output "
                                  "(default \"%s\")" % defaults.csvDel)

        general.add_option("--dump-format", dest="dumpFormat",
                                  help="Format of dumped data (CSV (default), HTML or SQLITE)")

        general.add_option("--eta", dest="eta",
                            action="store_true",
                            help="Display for each output the "
                                 "estimated time of arrival")

        general.add_option("--flush-session", dest="flushSession",
                            action="store_true",
                            help="Flush session files for current target")

        general.add_option("--forms", dest="forms",
                                  action="store_true",
                                  help="Parse and test forms on target URL")

        general.add_option("--fresh-queries", dest="freshQueries",
                            action="store_true",
                            help="Ignore query results stored in session file")

        general.add_option("--hex", dest="hexConvert",
                            action="store_true",
                            help="Use DBMS hex function(s) for data retrieval")

        general.add_option("--output-dir", dest="outputDir",
                            action="store",
                            help="Custom output directory path")

        general.add_option("--parse-errors", dest="parseErrors",
                                  action="store_true",
                                  help="Parse and display DBMS error messages from responses")

        general.add_option("--pivot-column", dest="pivotColumn",
                               help="Pivot column name")

        general.add_option("--save", dest="saveCmdline",
                            action="store_true",
                            help="Save options to a configuration INI file")

        general.add_option("--scope", dest="scope",
                           help="Regexp to filter targets from provided proxy log")

        general.add_option("--test-filter", dest="testFilter",
                           help="Select tests by payloads and/or titles (e.g. ROW)")

        general.add_option("--update", dest="updateAll",
                            action="store_true",
                            help="Update sqlmap")

        # Miscellaneous options
        miscellaneous = OptionGroup(parser, "Miscellaneous")

        miscellaneous.add_option("-z", dest="mnemonics",
                               help="Use short mnemonics (e.g. \"flu,bat,ban,tec=EU\")")

        miscellaneous.add_option("--alert", dest="alert",
                                  help="Run host OS command(s) when SQL injection is found")

        miscellaneous.add_option("--answers", dest="answers",
                                  help="Set question answers (e.g. \"quit=N,follow=N\")")

        miscellaneous.add_option("--beep", dest="beep", action="store_true",
                                  help="Make a beep sound when SQL injection is found")

        miscellaneous.add_option("--cleanup", dest="cleanup",
                                  action="store_true",
                                  help="Clean up the DBMS from sqlmap specific "
                                  "UDF and tables")

        miscellaneous.add_option("--dependencies", dest="dependencies",
                                  action="store_true",
                                  help="Check for missing (non-core) sqlmap dependencies")

        miscellaneous.add_option("--disable-coloring", dest="disableColoring",
                                  action="store_true",
                                  help="Disable console output coloring")

        miscellaneous.add_option("--gpage", dest="googlePage", type="int",
                                  help="Use Google dork results from specified page number")

        miscellaneous.add_option("--identify-waf", dest="identifyWaf",
                                  action="store_true",
                                  help="Make a thorough testing for a WAF/IPS/IDS protection")

        miscellaneous.add_option("--mobile", dest="mobile",
                                  action="store_true",
                                  help="Imitate smartphone through HTTP User-Agent header")

        miscellaneous.add_option("--page-rank", dest="pageRank",
                                  action="store_true",
                                  help="Display page rank (PR) for Google dork results")

        miscellaneous.add_option("--purge-output", dest="purgeOutput",
                                  action="store_true",
                                  help="Safely remove all content from output directory")

        miscellaneous.add_option("--smart", dest="smart",
                                  action="store_true",
                                  help="Conduct thorough tests only if positive heuristic(s)")

        miscellaneous.add_option("--sqlmap-shell", dest="sqlmapShell", action="store_true",
                            help="Prompt for an interactive sqlmap shell")

        miscellaneous.add_option("--wizard", dest="wizard",
                                  action="store_true",
                                  help="Simple wizard interface for beginner users")

        # Hidden and/or experimental options
        parser.add_option("--dummy", dest="dummy", action="store_true",
                          help=SUPPRESS_HELP)

        parser.add_option("--pickled-options", dest="pickledOptions",
                          help=SUPPRESS_HELP)

        parser.add_option("--profile", dest="profile", action="store_true",
                          help=SUPPRESS_HELP)

        parser.add_option("--binary-fields", dest="binaryFields",
                          help=SUPPRESS_HELP)

        parser.add_option("--cpu-throttle", dest="cpuThrottle", type="int",
                          help=SUPPRESS_HELP)

        parser.add_option("--force-dns", dest="forceDns", action="store_true",
                          help=SUPPRESS_HELP)

        parser.add_option("--smoke-test", dest="smokeTest", action="store_true",
                          help=SUPPRESS_HELP)

        parser.add_option("--live-test", dest="liveTest", action="store_true",
                          help=SUPPRESS_HELP)

        parser.add_option("--stop-fail", dest="stopFail", action="store_true",
                          help=SUPPRESS_HELP)

        parser.add_option("--run-case", dest="runCase", help=SUPPRESS_HELP)

        parser.add_option_group(target)
        parser.add_option_group(request)
        parser.add_option_group(optimization)
        parser.add_option_group(injection)
        parser.add_option_group(detection)
        parser.add_option_group(techniques)
        parser.add_option_group(fingerprint)
        parser.add_option_group(enumeration)
        parser.add_option_group(brute)
        parser.add_option_group(udf)
        parser.add_option_group(filesystem)
        parser.add_option_group(takeover)
        parser.add_option_group(windows)
        parser.add_option_group(general)
        parser.add_option_group(miscellaneous)

        # Dirty hack to display longer options without breaking into two lines
        def _(self, *args):
            _ = parser.formatter._format_option_strings(*args)
            if len(_) > MAX_HELP_OPTION_LENGTH:
                _ = ("%%.%ds.." % (MAX_HELP_OPTION_LENGTH - parser.formatter.indent_increment)) % _
            return _

        parser.formatter._format_option_strings = parser.formatter.format_option_strings
        parser.formatter.format_option_strings = type(parser.formatter.format_option_strings)(_, parser, type(parser))

        # Dirty hack for making a short option -hh
        option = parser.get_option("--hh")
        option._short_opts = ["-hh"]
        option._long_opts = []

        # Dirty hack for inherent help message of switch -h
        option = parser.get_option("-h")
        option.help = option.help.capitalize().replace("this help", "basic help")

        argv = []
        prompt = False
        advancedHelp = True

        for arg in sys.argv:
            argv.append(getUnicode(arg, encoding=sys.getfilesystemencoding()))

        checkDeprecatedOptions(argv)

        prompt = "--sqlmap-shell" in argv

        if prompt:
            parser.usage = ""
            cmdLineOptions.sqlmapShell = True

            _ = ["x", "q", "exit", "quit", "clear"]

            for option in parser.option_list:
                _.extend(option._long_opts)
                _.extend(option._short_opts)

            for group in parser.option_groups:
                for option in group.option_list:
                    _.extend(option._long_opts)
                    _.extend(option._short_opts)

            autoCompletion(AUTOCOMPLETE_TYPE.SQLMAP, commands=_)

            while True:
                command = None

                try:
                    command = raw_input("sqlmap-shell> ").strip()
                    command = getUnicode(command, encoding=sys.stdin.encoding)
                except (KeyboardInterrupt, EOFError):
                    print
                    raise SqlmapShellQuitException

                if not command:
                    continue
                elif command.lower() == "clear":
                    clearHistory()                    
                    print "[i] history cleared"
                    saveHistory(AUTOCOMPLETE_TYPE.SQLMAP)
                elif command.lower() in ("x", "q", "exit", "quit"):
                    raise SqlmapShellQuitException
                elif command[0] != '-':
                    print "[!] invalid option(s) provided"
                    print "[i] proper example: '-u http://www.site.com/vuln.php?id=1 --banner'"
                else:
                    saveHistory(AUTOCOMPLETE_TYPE.SQLMAP)
                    loadHistory(AUTOCOMPLETE_TYPE.SQLMAP)
                    break

            try:
                for arg in shlex.split(command):
                    argv.append(getUnicode(arg, encoding=sys.stdin.encoding))
            except ValueError, ex:
                raise SqlmapSyntaxException, "something went wrong during command line parsing ('%s')" % ex

        # Hide non-basic options in basic help case
        for i in xrange(len(argv)):
            if argv[i] == "-hh":
                argv[i] = "-h"
            elif re.match(r"\A\d+!\Z", argv[i]) and argv[max(0, i - 1)] == "--threads" or re.match(r"\A--threads.+\d+!\Z", argv[i]):
                argv[i] = argv[i][:-1]
                conf.skipThreadCheck = True
            elif argv[i] == "--version":
                print VERSION_STRING.split('/')[-1]
                raise SystemExit
            elif argv[i] == "-h":
                advancedHelp = False
                for group in parser.option_groups[:]:
                    found = False
                    for option in group.option_list:
                        if option.dest not in BASIC_HELP_ITEMS:
                            option.help = SUPPRESS_HELP
                        else:
                            found = True
                    if not found:
                        parser.option_groups.remove(group)

        try:
            (args, _) = parser.parse_args(argv)
        except UnicodeEncodeError, ex:
            print "\n[!] %s" % ex.object.encode("unicode-escape")
            raise SystemExit
Beispiel #41
0
def ParserOpts(argv):
    '''
        '''
    parser = OptionParser()
    parser.usage = ''
    parser.description = ''
    parser.add_option('-d',
                      '--download',
                      help='Download the dependency files from CIrepo',
                      dest='download',
                      default='')
    parser.add_option('-l',
                      '--list',
                      help='List the dependency',
                      dest='list',
                      default='')
    parser.add_option('-s',
                      '--sdk',
                      help='get windowsSDK version',
                      dest='sdk',
                      default='')
    parser.add_option('-o',
                      '--os',
                      help='send os as parameter',
                      dest='myos',
                      default='')
    parser.add_option('-r',
                      '--repo',
                      help='download the repo in opts',
                      dest='repo',
                      default='')
    parser.add_option('-v',
                      '--version',
                      help='receive project version',
                      dest='version',
                      default='')
    parser.add_option('-b',
                      '--bin',
                      help='download repo bin',
                      dest='bin',
                      default='')
    parser.add_option('-g',
                      '--getdll',
                      help='download dll',
                      dest='getdll',
                      default='')
    parser.add_option('-m',
                      '--map',
                      help='download dll',
                      dest='mapcollect',
                      default='')
    parser.add_option('-t',
                      '--talist',
                      help='ta list',
                      dest='talist',
                      default='')
    parser.add_option('-u',
                      '--user/pass',
                      help='user/pass',
                      dest='userpass',
                      default='')
    parser.add_option('-p',
                      '--platform',
                      help='platform',
                      dest='platform',
                      default='')
    parser.add_option('-a',
                      '--tag',
                      help='tag',
                      dest='tag',
                      default='latest.txt')
    parser.add_option('-e',
                      '--revisions',
                      help='revisions',
                      dest='revisions',
                      default='')
    return parser.parse_args(args=argv)
Beispiel #42
0
#!/usr/bin/env python
"""
Test script. Evaluates idifference.py on a sequence of disk images.
"""

import sys, os, subprocess

if __name__ == "__main__":
    from optparse import OptionParser

    parser = OptionParser()
    parser.usage = '%prog [options] dfxml_sequence_list.txt output_zip'
    parser.add_option("-p",
                      "--prefix",
                      help="prepend prefix to every test image path",
                      dest="prefix")
    parser.add_option("-v",
                      "--verbose",
                      help="verbose output: print call to difference program",
                      dest="verbose",
                      action="store_true")
    parser.add_option("-d",
                      "--diff-program",
                      help="use this path to the diff program",
                      dest="diff_program")
    #parser.add_option("-z", "--zap", help="Zap output directory (erases if present)" dest="zap")

    (options, args) = parser.parse_args()
    if len(args) < 2:
        parser.print_help()
        sys.exit(1)
Beispiel #43
0
                  action='store_true',
                  dest='test',
                  default=False,
                  help='run tests')
parser.add_option('-T',
                  '--threads',
                  type='int',
                  default=None,
                  help='Number of builder threads to use')
parser.add_option('-u',
                  '--show_unknown',
                  action='store_true',
                  default=False,
                  help='Show boards with unknown build result')

parser.usage = """buildman -b <branch> [options]

Build U-Boot for all commits in a branch. Use -n to do a dry run"""

(options, args) = parser.parse_args()

# Run our meagre tests
if options.test:
    RunTests()
elif options.full_help:
    pager = os.getenv('PAGER')
    if not pager:
        pager = 'more'
    fname = os.path.join(os.path.dirname(sys.argv[0]), 'README')
    command.Run(pager, fname)
Beispiel #44
0
def run(args=None):
    from optparse import OptionParser

    parser = OptionParser()
    parser.usage = "%prog [options] TYPE"
    parser.description = __doc__
    parser.add_option(
        "-b",
        "--batch-size",
        action="store",
        dest="batch_size",
        default="1024",
        help="Number of keys in read_bulk/write_bulk batch [default: %default]"
    )
    parser.add_option("-d",
                      "--debug",
                      action="store_true",
                      dest="debug",
                      default=False,
                      help="Enable debug output [default: %default]")
    parser.add_option(
        "-D",
        "--dir",
        dest="tmp_dir",
        default='/var/tmp/dnet_recovery_%TYPE%',
        metavar="DIR",
        help="Temporary directory for iterators' results [default: %default]")
    parser.add_option("-g",
                      "--groups",
                      action="store",
                      dest="elliptics_groups",
                      default=None,
                      help="Comma separated list of groups [default: all]")
    parser.add_option("-k",
                      "--lock",
                      dest="lock",
                      default='dnet_recovery.lock',
                      metavar="LOCKFILE",
                      help="Lock file used for recovery [default: %default]")
    parser.add_option(
        "-l",
        "--log",
        dest="elliptics_log",
        default='dnet_recovery.log',
        metavar="FILE",
        help="Output log messages from library to file [default: %default]")
    parser.add_option("-L",
                      "--log-level",
                      action="store",
                      dest="elliptics_log_level",
                      default=elliptics.log_level.notice,
                      help="Elliptics client verbosity [default: %default]")
    parser.add_option("-n",
                      "--nprocess",
                      action="store",
                      dest="nprocess",
                      default="1",
                      help="Number of subprocesses [default: %default]")
    parser.add_option(
        "-N",
        "--dry-run",
        action="store_true",
        dest="dry_run",
        default=False,
        help=
        "Enable test mode: only count diffs without recovering [default: %default]"
    )
    parser.add_option("-r",
                      "--remote",
                      action="append",
                      dest="remotes",
                      default=[],
                      help="Elliptics node address")
    parser.add_option(
        "-s",
        "--stat",
        action="store",
        dest="stat",
        default="text",
        help="Statistics output format: {0} [default: %default]".format(
            "/".join(ALLOWED_STAT_FORMATS)))
    parser.add_option(
        "-S",
        "--safe",
        action="store_true",
        dest="safe",
        default=False,
        help="Do not remove recovered keys after merge [default: %default]")
    parser.add_option(
        "-t",
        "--time",
        action="store",
        dest="timestamp",
        default=None,
        help="Recover keys modified since `time`. "
        "Can be specified as timestamp or as time difference"
        "e.g.: `1368940603`, `12h`, `1d`, or `4w` [default: %default]")
    parser.add_option("-e",
                      "--no-exit",
                      action="store_true",
                      dest="no_exit",
                      default=False,
                      help="Will be waiting for user input at the finish.")
    parser.add_option(
        "-m",
        "--monitor-port",
        action="store",
        dest="monitor_port",
        default=0,
        help="Enable remote monitoring on provided port [default: disabled]")
    parser.add_option(
        "-w",
        "--wait-timeout",
        action="store",
        dest="wait_timeout",
        default="3600",
        help="[Wait timeout for elliptics operations default: %default]")
    parser.add_option("-a",
                      "--attemps",
                      action="store",
                      dest="attempts",
                      default=1,
                      help="Number of attempts to recover one key")
    parser.add_option(
        "-o",
        "--one-node",
        action="store",
        dest="one_node",
        default=None,
        help=
        "Elliptics node address that should be iterated/recovered [default: %default]"
    )
    parser.add_option(
        "-c",
        "--chunk-size",
        action='store',
        dest='chunk_size',
        default=1024 * 1024,
        help=
        "Size of chunk by which all object will be read and recovered [default: %default]"
    )
    parser.add_option(
        "-C",
        "--custom-recover",
        action="store",
        dest="custom_recover",
        default="",
        help=
        "Sets custom recover app which accepts file path and returns file path to filtered keys"
    )
    parser.add_option(
        "-f",
        '--dump-file',
        action='store',
        dest='dump_file',
        default='',
        help=
        'Sets dump file which contains hex ids of object that should be recovered'
    )
    parser.add_option(
        '-i',
        '--backend-id',
        action='store',
        dest='backend_id',
        default=None,
        help=
        'Specifies backend data on which should be recovered. IT WORKS ONLY WITH --one-node'
    )
    parser.add_option(
        "-u",
        "--dont-dump-keys",
        action="store_false",
        dest="dump_keys",
        default=True,
        help="Disable dumping all iterated key [default: %default]")
    parser.add_option(
        "-M",
        "--no-meta",
        action="store_true",
        dest="no_meta",
        default=False,
        help=
        "Recover data without meta. It is usefull only for services without data-rewriting because"
        " with this option dnet_recovery will not check which replica of the key is newer"
        " and will copy any replica of the key to missing groups.")
    parser.add_option(
        '-p',
        '--prepare-timeout',
        action='store',
        dest='prepare_timeout',
        default='1d',
        help='Timeout for uncommitted records (prepared, but not committed).'
        'Records that exceeded this timeout will be removed. [default: %default]'
    )
    parser.add_option(
        '-T',
        '--trace-id',
        action='store',
        dest="trace_id",
        default='0',
        help=
        'Marks all recovery commands by trace_id at both recovery and server logs. This option accepts hex strings. [default: %default]'
    )
    return main(*parser.parse_args(args))
Beispiel #45
0
                  action="store_true",
                  default=False,
                  dest="ir")
parser.add_option("-I",
                  "--irvm",
                  help="use IRVM target (default: ARM)",
                  action="store_true",
                  default=False,
                  dest="irvm")
parser.add_option("-t",
                  "--type",
                  help="invoke the typer",
                  action="store_true",
                  default=False,
                  dest="type")
parser.usage = """%prog [options] [file]"""
parser.description = "Compile a Tiger program (or standard input)"

(options, args) = parser.parse_args()
options.ir |= options.canon
options.type |= options.ir

if len(args) > 1 or (options.expression and len(args) > 0):
    parser.print_help(file=sys.stderr)
    sys.exit(1)

if options.expression:
    content = options.expression
else:
    fd = open(args[0]) if args else sys.stdin
    content = fd.read()
Beispiel #46
0
        self.end_headers()

        ## Compress the file and sent to frontend
        res = influx_resp.content
        gres = gzip.compress(res)
        self.wfile.write(gres)

        doGet_end = timeit.default_timer()
        print("Total time in middleware: ", doGet_end - doGet_start)

    do_PUT = do_POST
    do_DELETE = do_GET


def main():
    port = 8080
    print('Listening on localhost:%s' % port)
    server = HTTPServer(('', port), RequestHandler)
    server.serve_forever()


if __name__ == "__main__":
    parser = OptionParser()
    parser.usage = (
        "Creates an http-server that will echo out any GET or POST parameters\n"
        "Run:\n\n"
        "   reflect")
    (options, args) = parser.parse_args()

    main()
Beispiel #47
0
def get_args () :
    global PH5, PATH, DEBUG, EXPERIMENT_TABLE, SORT_TABLE, OFFSET_TABLE, EVENT_TABLE, \
           ARRAY_TABLE, RESPONSE_TABLE, REPORT_TABLE, RECEIVER_TABLE, DAS_TABLE, TIME_TABLE, \
           TABLE_KEY, INDEX_TABLE, M_INDEX_TABLE, ALL_ARRAYS, ALL_EVENTS
    
    from optparse import OptionParser
    
    oparser = OptionParser ()
    
    oparser.usage = "Version: {0}\ntabletokef --nickname ph5-file-prefix options".format (PROG_VERSION)
    
    oparser.description = "Dump a table to a kef file."
    
    oparser.add_option ("-n", "--nickname", dest = "ph5_file_prefix",
                        help = "The ph5 file prefix (experiment nickname).",
                        metavar = "ph5_file_prefix")
    
    oparser.add_option ("-p", "--path", dest = "ph5_path",
                        help = "Path to ph5 files. Defaults to current directory.",
                        metavar = "ph5_path")
    
    oparser.add_option ("-u", "--update_key", dest = "update_key",
                        help = "Set generated kef file to do an Update on key.",
                        metavar = "update_key", type = "string")
    
    oparser.add_option ("-d", dest = "debug", action = "store_true", default = False)
    
    oparser.add_option ("-E", "--Experiment_t", dest = "experiment_t", action = "store_true",
                        default = False,
                        help = "Dump /Experiment_g/Experiment_t to a kef file.")
    
    oparser.add_option ("-S", "--Sort_t", dest = "sort_t", action = "store_true",
                        default = False,
                        help = "Dump /Experiment_g/Sorts_g/Sort_t to a kef file.")
    
    oparser.add_option ("-O", "--Offset_t", dest = "offset_t_", metavar="a_e",
                        help = "Dump /Experiment_g/Sort_g/Offset_t_[arrayID_eventID] to a kef file.")
    
    oparser.add_option ("-V", "--Event_t_", dest = "event_t_", metavar="n",
                        type=int,
                        help = "Dump /Experiment_g/Sorts_g/Event_t_[n] to a kef file.")
    
    oparser.add_option ("--all_events", dest='all_events', action='store_true',
                        default=False,
                        help='Dump all /Experiment_g/Sorts_g/Event_t_xxx to a kef file.')
    
    oparser.add_option ("-A", "--Array_t_", dest = "array_t_", metavar = "n",
                        type=int,
                        help = "Dump /Experiment_g/Sorts_g/Array_t_[n] to a kef file.")
    
    oparser.add_option ("--all_arrays", dest = 'all_arrays', action='store_true',
                        default=False,
                        help = "Dump all /Experiment_g/Sorts_g/Array_t_xxx to a kef file.")
    
    oparser.add_option ("-R", "--Response_t", dest = "response_t", action = "store_true",
                        default = False,
                        help = "Dump /Experiment_g/Responses_g/Response_t to a kef file.")
    
    oparser.add_option ("-P", "--Report_t", dest = "report_t", action = "store_true",
                        default = False,
                        help = "Dump /Experiment_g/Reports_g/Report_t to a kef file.")
    
    oparser.add_option ("-C", "--Receiver_t", dest = "receiver_t", action = "store_true",
                        default = False,
                        help = "Dump /Experiment_g/Receivers_g/Receiver_t to a kef file.")
    
    oparser.add_option ("-I", "--Index_t", dest = "index_t", action = "store_true",
                        default = False,
                        help = "Dump /Experiment_g/Receivers_g/Index_t to a kef file.")
    
    oparser.add_option ("-M", "--M_Index_t", dest = "m_index_t", action = "store_true",
                            default = False,
                            help = "Dump /Experiment_g/Maps_g/Index_t to a kef file.")    
    
    oparser.add_option ("-D", "--Das_t", dest = "das_t_", metavar = "das",
                        help = "Dump /Experiment_g/Receivers_g/Das_g_[das]/Das_t to a kef file.")
    
    oparser.add_option ("-T", "--Time_t", dest = "time_t", action = "store_true",
                        default = False,
                        help = "Dump /Experiment_g/Receivers_g/Time_t to a kef file.")
    
    options, args = oparser.parse_args ()
    
    
    if options.ph5_file_prefix != None :
        PH5 = options.ph5_file_prefix
    else :
        PH5 = None
        
    if options.ph5_path != None :
        PATH = options.ph5_path
    else :
        PATH = "."
        
    if options.debug != None :
        DEBUG = options.debug
        
    EXPERIMENT_TABLE = options.experiment_t
    SORT_TABLE = options.sort_t
    if options.offset_t_ != None :
        try :
            OFFSET_TABLE = map (int, options.offset_t_.split ("_"))
        except Exception as e :
            sys.stderr.write ("Offset table should be entered as arrayID underscore shotLineID, eg. 1_2 or 0_0.")
            sys.stderr.write (e.message)
            sys.exit ()
    else :
        OFFSET_TABLE = None
    EVENT_TABLE = options.event_t_
    TIME_TABLE = options.time_t
    INDEX_TABLE = options.index_t
    M_INDEX_TABLE = options.m_index_t
    
    if options.update_key != None :
        TABLE_KEY = options.update_key
        
    if options.array_t_ != None :
        ARRAY_TABLE = options.array_t_
    else :
        ARRAY_TABLE = None
        
    ALL_ARRAYS = options.all_arrays
    ALL_EVENTS = options.all_events
    RESPONSE_TABLE = options.response_t
    REPORT_TABLE = options.report_t
    
    RECEIVER_TABLE = options.receiver_t
        
    if options.das_t_ != None :
        DAS_TABLE = options.das_t_
    else :
        DAS_TABLE = None
        
    if PH5 == None :
        sys.stderr.write ("Error: Missing required option. Try --help\n")
        sys.exit (-1)
Beispiel #48
0
    nc.define_2d_field('land_ice_area_fraction_retreat',
                       attrs={'units': '1',
                              'long_name': 'mask defining the maximum ice extent'})
    nc.write('land_ice_area_fraction_retreat', ice_extent)

    nc.close()


if __name__ == "__main__":

    from optparse import OptionParser

    parser = OptionParser()

    parser.usage = "%prog [options]"
    parser.description = "Creates a MISMIP boostrapping file for use with PISM."
    parser.add_option("-o", dest="output_filename",
                      help="output file")
    parser.add_option("-e", "--experiment", dest="experiment", type="string",
                      help="MISMIP experiment (one of '1a', '1b', '2a', '2b', '3a', '3b')",
                      default="1a")
    parser.add_option("-s", "--step", dest="step", type="int", default=1,
                      help="MISMIP step")
    parser.add_option("-u", "--uniform_thickness",
                      action="store_false", dest="semianalytical_profile", default=True,
                      help="Use uniform 10 m ice thickness")
    parser.add_option("-m", "--mode", dest="mode", type="int", default=2,
                      help="MISMIP grid mode")
    parser.add_option("-N", dest="N", type="int", default=3601,
                      help="Custom grid size; use with --mode=3")
Beispiel #49
0
        try:
            result = self['xep_0060'].unsubscribe(self.pubsub_server,
                                                  self.node)
            print('Unsubscribed %s from node %s' %
                  (self.boundjid.bare, self.node))
        except:
            logging.error('Could not unsubscribe %s from node %s' %
                          (self.boundjid.bare, self.node))


if __name__ == '__main__':
    # Setup the command line arguments.
    optp = OptionParser()
    optp.version = '%%prog 0.1'
    optp.usage = "Usage: %%prog [options] <jid> " + \
                             'nodes|create|delete|purge|subscribe|unsubscribe|publish|retract|get' + \
                             ' [<node> <data>]'

    optp.add_option('-q',
                    '--quiet',
                    help='set logging to ERROR',
                    action='store_const',
                    dest='loglevel',
                    const=logging.ERROR,
                    default=logging.ERROR)
    optp.add_option('-d',
                    '--debug',
                    help='set logging to DEBUG',
                    action='store_const',
                    dest='loglevel',
                    const=logging.DEBUG,
Beispiel #50
0
    if options.negate == True:
        return

    chunkDir = castortools.createSubDir(castorDir, 'Chunks')

    os.system("cmsRun tmpConfig.py")
    print 'done.'
    rfcp = "rfcp %s %s" % (tmpRootFile, chunkDir)
    print rfcp, '...'
    os.system(rfcp)
    os.system("rm %s" % tmpRootFile)
    print 'temporary files removed.'


parser = OptionParser()
parser.usage = "%prog <castor dir> <regexp pattern> <chunk size>: merge a set of CMSSW root files on castor. Temporary merged files are created on /tmp of the local machine, and are then migrated to a Chunk/ subdirectory of your input castor directory. Therefore, you need write access to the input castor directory.\n\nThe regexp pattern should contain 2 statements in parenthesis: the first one should match the file prefix, and the second one the file number. The name of the merged file will start by the file prefix. The file number is used to decide which files to take in input. The chunk size is the number of input files to be merged in a given output file.\n\nExample (just try. the -n option negates the command!):\ncastorMerge.py  /castor/cern.ch/user/c/cbern/CMSSW312/SinglePions '(.*)_(\d+)\.root' 2 -n"
parser.add_option("-n",
                  "--negate",
                  action="store_true",
                  dest="negate",
                  help="do not produce the merged files",
                  default=False)

(options, args) = parser.parse_args()

if len(args) != 3:
    parser.print_help()
    sys.exit(1)

castorDir = args[0]
regexp = args[1]
Beispiel #51
0
    (options, args) = parser.parse_args()
    if options.host_file:
        if os.path.exists(options.host_file):
            with open(options.host_file) as f:
                for line in f:
                    h = re.split('[# ]', line.rstrip())[0]
                    if h:
                        host_list.append(h)
        else:
            print "Specified host '{0}' file doesn't exist ".format(
                options.host_file)
            sys.exit(1)
    else:
        parser.error("Filename with host list not given!")
        parser.usage()

    if options.exclude_hosts:
        if os.path.exists(options.exclude_hosts):
            exclude_patterns = []
            with open(options.exclude_hosts) as f:
                for line in f:
                    exclude_patterns.append(line.rstrip())
            host_list = exclude_filter(host_list, exclude_patterns)
        else:
            print "Can't open exclude file {}".format(options.exclude_hosts)
            sys.exit(1)

    log_file = options.output_file
    credentials = []
Beispiel #52
0
                action="store_true",
                dest="json",
                default=False,
                help="Output JSON")
optp.add_option("--list-devices",
                action="store_true",
                dest="list_devices",
                default=False,
                help="Show a list of SKUs and product names")
optp.add_option("--debug",
                action="store_true",
                dest="debug",
                default=False,
                help="Dump raw server requests and replies to files")

optp.usage = """
  %prog [options] SKU1 [SKU2..SKUn]

Examples:
  %prog 3196           - Query update info for 006-B3196-00
  %prog 006-B3196-00   - Query update info for given SKU
  %prog --devicexml=~/fenix/GARMIN/GarminDevice.xml"""

(opts, device_skus) = optp.parse_args()

if opts.list_devices:
    if opts.json:
        print(json.dumps(devices.DEVICES))
    else:
        print("HWID - Device/Component")
        for hwid, name in devices.DEVICES.items():
Beispiel #53
0
# FIXME:  need to carefully set hardness

from pylab import *
import sys
import time
# try different netCDF modules
try:
    from netCDF4 import Dataset as CDF
except:
    print "netCDF4 is not installed!"
    sys.exit(1)

from optparse import OptionParser

parser = OptionParser()
parser.usage = \
    """%prog MX DURATION

where MX       is number of grid points,
      DURATION is time in years for run,

Example:  Try this diagnostic-only run:
  $ export MX=101 YY=0
  $ ./exactQ.py $MX $YY
  $ pismr -o outQ$MX.nc -y $YY -i initQ$MX.nc -bootstrap -Mx $MX -My $MX -Mz 21 -Lz 1500 -z_spacing equal -surface given -stress_balance ssa -energy none -yield_stress constant -tauc 1e6 -ssa_dirichlet_bc -cfbc -part_grid -part_redist -o_order zyx -ssa_e 1.0 -ssa_flow_law isothermal_glen
"""
parser.description = "A script which runs Test Q."
(options, args) = parser.parse_args()
if (len(args) < 2) | (len(args) > 2):
    print "ERROR; exactQ.py needs two arguments; run with --help to see usage"
    print "... EXITING"
    exit(-1)
Beispiel #54
0
    def main(self):
        """Gets video details a search term
        """
        parser = OptionParser()

        parser.add_option(
            "-d",
            "--debug",
            action="store_true",
            default=False,
            dest="debug",
            help=
            u"Show debugging info (URLs, raw XML ... etc, info varies per grabber)"
        )
        parser.add_option("-u",
                          "--usage",
                          action="store_true",
                          default=False,
                          dest="usage",
                          help=u"Display examples for executing the script")
        parser.add_option("-v",
                          "--version",
                          action="store_true",
                          default=False,
                          dest="version",
                          help=u"Display grabber name and supported options")
        parser.add_option(
            "-l",
            "--language",
            metavar="LANGUAGE",
            default=u'',
            dest="language",
            help=
            u"Select data that matches the specified language fall back to English if nothing found (e.g. 'es' Español, 'de' Deutsch ... etc).\nNot all sites or grabbers support this option."
        )
        parser.add_option(
            "-p",
            "--pagenumber",
            metavar="PAGE NUMBER",
            default=1,
            dest="pagenumber",
            help=
            u"Display specific page of the search results. Default is page 1.\nPage number is ignored with the Tree View option (-T)."
        )
        functionality = u''
        if self.grabberInfo['search']:
            parser.add_option("-S",
                              "--search",
                              action="store_true",
                              default=False,
                              dest="search",
                              help=u"Search for videos")
            functionality += 'S'

        if self.grabberInfo['tree']:
            parser.add_option("-T",
                              "--treeview",
                              action="store_true",
                              default=False,
                              dest="treeview",
                              help=u"Display a Tree View of a sites videos")
            functionality += 'T'

        if self.grabberInfo['html']:
            parser.add_option("-H",
                              "--customhtml",
                              action="store_true",
                              default=False,
                              dest="customhtml",
                              help=u"Return a custom HTML Web page")
            functionality += 'H'

        parser.usage = u"./%%prog -hduvl%s [parameters] <search text>\nVersion: %s Author: %s\n\nFor details on the MythTV Netvision plugin see the wiki page at:\nhttp://www.mythtv.org/wiki/MythNetvision" % (
            functionality, self.grabberInfo['version'],
            self.grabberInfo['author'])

        opts, args = parser.parse_args()

        # Make alls command line arguments unicode utf8
        for index in range(len(args)):
            args[index] = unicode(args[index], 'utf8')

        if opts.debug:
            sys.stdout.write("\nopts: %s\n" % opts)
            sys.stdout.write("\nargs: %s\n\n" % args)

        # Process version command line requests
        if opts.version:
            version = etree.XML(u'<grabber></grabber>')
            etree.SubElement(version, "name").text = self.grabberInfo['title']
            etree.SubElement(version,
                             "author").text = self.grabberInfo['author']
            etree.SubElement(version,
                             "thumbnail").text = self.grabberInfo['thumbnail']
            etree.SubElement(version,
                             "command").text = self.grabberInfo['command']
            for t in self.grabberInfo['type']:
                etree.SubElement(version, "type").text = t
            etree.SubElement(version,
                             "description").text = self.grabberInfo['desc']
            etree.SubElement(version,
                             "version").text = self.grabberInfo['version']
            if self.grabberInfo['search']:
                etree.SubElement(version, "search").text = 'true'
            if self.grabberInfo['tree']:
                etree.SubElement(version, "tree").text = 'true'
            sys.stdout.write(
                etree.tostring(version, encoding='UTF-8', pretty_print=True))
            sys.exit(0)

        # Process usage command line requests
        if opts.usage:
            sys.stdout.write(self.grabberInfo['usage'])
            sys.exit(0)

        if self.grabberInfo['search']:
            if opts.search and not len(args) == 1:
                sys.stderr.write(
                    "! Error: There must be one value for the search option. Your options are (%s)\n"
                    % (args))
                sys.exit(1)
            if opts.search and args[0] == u'':
                sys.stderr.write(
                    "! Error: There must be a non-empty search argument, yours is empty.\n"
                )
                sys.exit(1)

        if self.grabberInfo['html']:
            if opts.customhtml and not len(args) == 1:
                sys.stderr.write(
                    "! Error: There must be one value for the search option. Your options are (%s)\n"
                    % (args))
                sys.exit(1)
            if opts.customhtml and args[0] == u'':
                sys.stderr.write(
                    "! Error: There must be a non-empty Videocode argument, yours is empty.\n"
                )
                sys.exit(1)

        if not self.grabberInfo['search'] and not self.grabberInfo[
                'tree'] and not self.grabberInfo['html']:
            sys.stderr.write(
                "! Error: You have not selected a valid option.\n")
            sys.exit(1)

        try:
            x = int(opts.pagenumber)
        except:
            sys.stderr.write(
                "! Error: When specified the page number must be numeric. Yours was (%s)\n"
                % opts.pagenumber)
            sys.exit(1)

        Queries = siteQueries(
            self.apikey,
            self.target,
            mythtv=True,
            interactive=False,
            select_first=False,
            debug=opts.debug,
            custom_ui=None,
            language=opts.language,
            search_all_languages=False,
        )

        # Set the maximum number of items to display per Mythtvnetvision search page
        if self.grabberInfo['search']:
            if opts.search:
                if not 'SmaxPage' in self.grabberInfo.keys():
                    Queries.page_limit = 20  # Default items per page
                else:
                    Queries.page_limit = self.grabberInfo['SmaxPage']

        # Set the maximum number of items to display per Mythtvnetvision tree view page
        if self.grabberInfo['tree']:
            if opts.treeview:
                if not 'TmaxPage' in self.grabberInfo.keys():
                    Queries.page_limit = 20  # Default items per page
                else:
                    Queries.page_limit = self.grabberInfo['TmaxPage']

        # Set the grabber title
        Queries.grabber_title = self.grabberInfo['title']

        # Set the mashup title
        if not 'mashup_title' in self.grabberInfo.keys():
            Queries.mashup_title = Queries.grabber_title
        else:
            if self.grabberInfo['search']:
                if opts.search:
                    Queries.mashup_title = self.grabberInfo[
                        'mashup_title'] + "search"
            if self.grabberInfo['tree']:
                if opts.treeview:
                    Queries.mashup_title = self.grabberInfo[
                        'mashup_title'] + "treeview"
            if self.grabberInfo['html']:
                if opts.customhtml:
                    Queries.mashup_title = self.grabberInfo[
                        'mashup_title'] + "customhtml"

        # Process requested option
        if self.grabberInfo['search']:
            if opts.search:  # Video search -S
                self.page_limit = Queries.page_limit
                Queries.searchForVideos(args[0], opts.pagenumber)

        if self.grabberInfo['tree']:
            if opts.treeview:  # Video treeview -T
                self.page_limit = Queries.page_limit
                Queries.displayTreeView()

        if self.grabberInfo['html']:
            if opts.customhtml:  # Video treeview -H
                Queries.displayHTML(args[0])

        sys.exit(0)
Beispiel #55
0
def get_args():
    global PH5, PATH, DEBUG, RECEIVER_GEN, EVENT_GEN, DATA_GEN, DAS_SN, EXPERIMENT_GEN

    from optparse import OptionParser

    oparser = OptionParser()

    oparser.usage = "Version: {0}\nmeta-data-gen --nickname=ph5-file-prefix options".format(
        PROG_VERSION)

    oparser.description = "Write info about receivers, events, or data."

    oparser.add_option(
        "-E",
        "--experiment",
        dest="experiment_gen",
        help="Write info about experiment to stdout, Experiment_t.json",
        action="store_true",
        default=False)

    oparser.add_option("-n",
                       "--nickname",
                       dest="ph5_file_prefix",
                       help="The ph5 file prefix (experiment nickname).",
                       metavar="ph5_file_prefix")

    oparser.add_option(
        "-p",
        "--path",
        dest="ph5_path",
        help="Path to ph5 files. Defaults to current directory.",
        metavar="ph5_path")

    oparser.add_option(
        "-r",
        "--receivers",
        dest="receiver_gen",
        help="Write info about receivers to stdout, Array_t_all.json",
        action="store_true",
        default=False)

    oparser.add_option("-e",
                       "--events",
                       dest="event_gen",
                       help="Write info about events to stdout, Event_t.json",
                       action="store_true",
                       default=False)

    oparser.add_option("-d",
                       "--data",
                       dest="data_gen",
                       help="Write info about data to stdout, Das_t_all.json",
                       action="store_true",
                       default=False)

    #oparser.add_option ("--json", dest = "json",
    #help = "Write using JSON format.",
    #action = "store_true", default = False)

    oparser.add_option("--bug",
                       dest="debug",
                       action="store_true",
                       default=False)

    options, args = oparser.parse_args()

    if options.ph5_file_prefix != None:
        PH5 = options.ph5_file_prefix
    else:
        PH5 = None

    if options.ph5_path != None:
        PATH = options.ph5_path
    else:
        PATH = "."

    if options.debug != None:
        DEBUG = options.debug

    RECEIVER_GEN = options.receiver_gen
    EVENT_GEN = options.event_gen
    DATA_GEN = options.data_gen
    EXPERIMENT_GEN = options.experiment_gen

    if PH5 == None:
        sys.stderr.write(
            "Error: Missing required option --nickname. Try --help\n")
        sys.exit(-1)
Beispiel #56
0
def makePlot(hist, weights, box, mtregion):

    plot = H2TauTauMC(hist, anaDir, selComps,
                      '%s_OS_%s.root' % (mtregion, box), weights)
    return plot


if __name__ == '__main__':

    import copy
    from optparse import OptionParser
    from CMGTools.RootTools.RootInit import *

    parser = OptionParser()
    parser.usage = '''
    %prog <anaDir> <cfgFile>

    cfgFile: analysis configuration file, see CMGTools.H2TauTau.macros.MultiLoop
    anaDir: analysis directory containing all components, see CMGTools.H2TauTau.macros.MultiLoop.
    hist: histogram you want to plot
    '''
    parser.add_option("-B",
                      "--box",
                      dest="box",
                      help="box. Default is Inclusive",
                      default='Inclusive')
    parser.add_option("-M",
                      "--mtregion",
                      dest="mtregion",
                      help="mT region. Default is LowMT",
Beispiel #57
0
    keras.backend.clear_session()

    timer.Stop()
    realtime = timer.RealTime()
    cputime = timer.CpuTime()
    print("Real Time : {0:6.2f} seconds, CPU Time : {1:6.2f} seconds").format(
        realtime, cputime)


#Options
if __name__ == '__main__':
    from optparse import OptionParser

    parser = OptionParser()
    parser.usage = """
    %make histogram from array
    """

    parser.add_option("-t",
                      "--test",
                      dest="test",
                      action='store_true',
                      default=False,
                      help='Test single root file')

    parser.add_option("-s",
                      "--sys",
                      dest="sys",
                      action='store_true',
                      default=False,
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ray tracing map script
import pymses, os
from pymses.analysis.visualization import *
from pymses.analysis.visualization.image_plot_utils import *
from time import time
from pymses.analysis.visualization.raytracing import RayTracer, RayTracerMPI
from optparse import OptionParser
t0 = time()
parser = OptionParser()
parser.usage = "%prog ramses_directory ramses_output_number map_max_resolution=512"
(opts, args) = parser.parse_args()
try:
	fileDir = args[0]
	outNumber = int(args[1])
except:
	# "None" leads to an automatic look for 
	# RAMSES output in the current directory
	fileDir = None 
	outNumber = None
try:
	mms = int(args[2])
except:
	mms = 512
ro = pymses.RamsesOutput(fileDir, outNumber)
outNumber = ro.iout
cam = Camera(center=[ 0.5, 0.5, 0.5 ], line_of_sight_axis="z", up_vector="y", region_size=[5.0E-1, 5.0E-1], \
			distance=2.5E-1, far_cut_depth=2.5E-1, map_max_size=mms)
#import tables
#file= tables.openFile("camera2Zoom314.h5", "r")
Beispiel #59
0
#!/usr/bin/env python
# Colin
# creates new source file for a dataset on castor
# compiles the python module
# prints the line to be added to the cfg. 

import os, sys,  imp, re, pprint, string
from optparse import OptionParser

import castortools

parser = OptionParser()
parser.usage = "%prog <sampleName>\nImport a sample locally."
parser.add_option("-n", "--negate", action="store_true",
                  dest="negate",
                  help="do not proceed",
                  default=False)
parser.add_option("-c", "--castorBaseDir", 
                  dest="castorBaseDir",
                  help="Base castor directory. Subdirectories will be created automatically for each prod",
                  default="/castor/cern.ch/user/c/cbern/cmst3/SusyJetMET")
parser.add_option("-p", "--pattern", 
                  dest="pattern",
                  help="pattern for root files in castor dir",
                  default=".*root")

(options,args) = parser.parse_args()

if len(args)!=1:
    parser.print_help()
    sys.exit(1)
Beispiel #60
0
## script to generate figure: results from SeaRISE experiments
## usage:  if UAFX_G_D3_C?_??.nc are result NetCDF files then do
##   $ slr_show.py -m UAFX

# try different netCDF modules
try:
    from netCDF4 import Dataset as CDF
except:
    from netCDF3 import Dataset as CDF

from numpy import zeros
import pylab as plt
from optparse import OptionParser

parser = OptionParser()
parser.usage = "usage: %prog [options]"
parser.description = "A script for PISM output files to show time series plots using pylab."
parser.add_option("-a",
                  dest="t_a",
                  type="int",
                  help="start year, in years since 2004, default = 0",
                  default=0)
parser.add_option("-e",
                  dest="t_e",
                  type="int",
                  help="end year, in years since 2004, default = 500",
                  default=500)
parser.add_option("-m",
                  "--model",
                  dest="model",
                  help="choose experiment, default UAF1",