Пример #1
0
def getOptions():
	""" Parse arguments and options. """
	usage = "Usage: %prog [options] <sacfile(s)>"
	parser = OptionParser(usage=usage)

	ofilename = 'sac.pkl'
	delta = -1
	parser.set_defaults(delta=delta)
	parser.set_defaults(ofilename=ofilename)
	parser.add_option('-s', '--s2p', action="store_true", dest='s2p',
		help='Convert SAC files to pickle file. Default is True.')
	parser.add_option('-p', '--p2s', action="store_true", dest='p2s',
		help='Convert pickle file (save headers) to SAC files.')
	parser.add_option('-d', '--delta',  dest='delta', type='float',
		help='Time sampling interval. Default is %f ' % delta)
	parser.add_option('-o', '--ofilename',  dest='ofilename', type='str',
		help='Output filename which works only with -s option.')
	parser.add_option('-z', '--zipmode',  dest='zipmode', type='str',
		help='Zip mode: bz2 or gz. Default is None.')

	opts, files = parser.parse_args(sys.argv[1:])
	opts.s2p = True
	if opts.p2s:
		opts.s2p = False
	if len(files) == 0:
		print parser.usage
		sys.exit()
	return opts, files
Пример #2
0
def run( arguments ):
    '''run( arguments )

    Parses and executes the given command-line `arguments`.

    Parameters:
    - arguments     A list of strings representing the command-line arguments
                    to ``restblog <command>``, e.g. ``sys.argv[2:]``
    '''

    # Parse

    usage = USAGE.strip()
    parser = OptionParser( usage=usage )
    options = dict(
        interactive=False,
    )
    parser.set_defaults( **options )
    parser.add_option( '-i', '--interactive', action='store_true', help='Prompt for missing credentials when connecting to the server.' )
    options, arguments = parser.parse_args( arguments )

    # Validate

    if not arguments:
        raise RuntimeError, 'Required arguments are missing.'
    count = len( arguments )
    if count != 1:
        raise RuntimeError, 'Unexpected arguments: %s' % ' '.join( arguments )

    # Execute

    file_name = arguments[0]
    insert( file_name, options.interactive )
Пример #3
0
def main():
	parser = OptionParser( version="%prog 1.0", usage='Usage: %prog [options]' )

	parser.set_defaults( **{
		'verbose': False,
	} )

	parser.add_option( '-v', '--verbose', action='store_true' )

	opts, args = parser.parse_args()

	pat_dot = re.compile( r'\s+\.', re.UNICODE )

	for fn in os.listdir( '.' ):

		tags, rest = path.extract_tags( fn )

		dst = pat_dot.sub( '.', ' '.join( rest ) )

		p = ''.join( map( lambda x: '[' + x + ']', tags ) )

		dst = p and p + ' ' + dst or dst

		if os.path.exists( dst ):
			print( "Existed, skiped:", dst )
		else:
			try:
				os.renames( fn , dst )
			except OSError:
				print( "Failed:", dst )
Пример #4
0
def Options():
    OptionList = [
        make_option("-f", "--offset", dest="PcdOffset", action="store", type="int",
                          help="Start offset to the image is used to store PCD value."),
        make_option("-u", "--value", dest="PcdValue", action="store",
                          help="PCD value will be updated into the image."),
        make_option("-t", "--type", dest="PcdTypeName", action="store",
                          help="The name of PCD data type may be one of VOID*,BOOLEAN, UINT8, UINT16, UINT32, UINT64."),
        make_option("-s", "--maxsize", dest="PcdMaxSize", action="store", type="int",
                          help="Max size of data buffer is taken by PCD value.It must be set when PCD type is VOID*."),
        make_option("-v", "--verbose", dest="LogLevel", action="store_const", const=EdkLogger.VERBOSE,
                          help="Run verbosely"),
        make_option("-d", "--debug", dest="LogLevel", type="int",
                          help="Run with debug information"),
        make_option("-q", "--quiet", dest="LogLevel", action="store_const", const=EdkLogger.QUIET,
                          help="Run quietly"),
        make_option("-?", action="help", help="show this help message and exit"),
    ]

    # use clearer usage to override default usage message
    UsageString = "%prog -f Offset -u Value -t Type [-s MaxSize] <input_file>"

    Parser = OptionParser(description=__copyright__, version=__version__, option_list=OptionList, usage=UsageString)
    Parser.set_defaults(LogLevel=EdkLogger.INFO)

    Options, Args = Parser.parse_args()

    # error check
    if len(Args) == 0:
        EdkLogger.error("PatchPcdValue", PARAMETER_INVALID, ExtraData=Parser.get_usage())

    InputFile = Args[len(Args) - 1]
    return Options, InputFile
Пример #5
0
def main():
    optparser = OptionParser()
    optparser.add_option(
            '-q', '--quiet',
            action='store_const', dest='verbosity', const=0,
            help="don't output anything to stderr")
    optparser.add_option(
            '-v', '--verbose',
            action='count', dest='verbosity',
            help="increase program verbosity")
    optparser.add_option(
            '-l', '--hostname',
            action='store', dest='hostname',
            help="hostname (or location) of this server")
    optparser.add_option(
            '-i', '--interface',
            action='store', dest='interface',
            help="interface (IP address) to bind to")
    optparser.add_option(
            '-p', '--port',
            action='store', dest='port', type='int',
            help="port number on which to listen")
    optparser.set_defaults(verbosity=1, hostname=None, interface='',
                           port=8000)
    (options, args) = optparser.parse_args()
    options = vars(options) # options is not a dict!?

    run(**options)
def main (args):
	# Parse arguments
	parser = OptionParser(usage = "%prog [options]...",
		description = "Generate FallbackThaiUnicodeLinebreaker data "
			"tables from Thai wrap UserJS")
	parser.add_option("-i", "--input", dest = "infile",
		help = "location of Thai wrap UserJS", metavar = "FILE")
	parser.add_option("-o", "--output", dest = "outfile",
		help = "where to put generated tables file", metavar = "FILE")
	parser.set_defaults(infile = Default_infile, outfile = Default_outfile)
	(options, args) = parser.parse_args(args)
	assert len(args) == 1 # There should be no more arguments

	if options.infile == "-":
		f = sys.stdin
	else:
		f = open(options.infile)
	p = parse_userjs(f)
	f.close()

	if options.outfile == "-":
		f = sys.stdout
	else:
		f = open(options.outfile, "w")
	write_cpp_header(f, os.path.basename(options.outfile))
	write_cpp_word_list(f, cppify_name("Wordlist"), p["Wordlist"])
	for char_list in ("LeadingChars", "FollowingChars", "EOWChars"):
		write_cpp_char_list(f, cppify_name(char_list), p[char_list])
	write_cpp_footer(f, os.path.basename(options.outfile))
	f.close()

	return 0
Пример #7
0
def get_options():
	"""
	Returns a list of two elements, the first is an instance of optparse.Values (the command line options, like -v),
	and the second is an array of the remaining command line arguments.

	Expected command line arguments:
		depFilePath: The path of the DepFile to process. Must be specified.
		execution_arguments: Zero or more key=value strings that are evaluated in processing as values for <argument> tags.
		options: Application command line options.

	Examples:
		./program_name site.dep -v title=helloworld
		./program_name site.dep title=hello [email protected] -g -v
		./program_name site.dep -v
	"""

	global __default_config_file_path__

	option_parser = OptionParser(usage = "Usage: %prog depFilePath [execution_arguments] [options]")

	option_parser.set_defaults(version = False, help = False)

	option_parser.add_option("-c", "", dest = "config", default = __default_config_file_path__,
		help = "Path to the configuration file.")
	option_parser.add_option("", "--version", dest = "version", action = "store_true", default = False,
		help = "Retrieve version information.")
	option_parser.add_option("-q", "--quiet", dest = "quiet", action = "store_true", default = False,
		help = "Supress status messages.")

	return option_parser
Пример #8
0
def get_options():
    """
    Parse the arguments
    """
    # Instance the parser and define the usage message
    optparser = OptionParser(usage="""
    %prog [-vqdsc]""", version="%prog .2")

    # Define the options and the actions of each one
    optparser.add_option("-s", "--section", help=("Process only the given "
        "section"), action="store", dest="section")
    optparser.add_option("-c", "--config", help=("Uses the given conf file "
        "inteast of the default"), action="store", dest="conffile")
    optparser.add_option("-l", "--log", help=("Uses the given log file "
        "inteast of the default"), action="store", dest="logfile")
    optparser.add_option("-v", "--verbose", action="count", dest="verbose",
        help="Increment verbosity")
    optparser.add_option("-q", "--quiet", action="count", dest="quiet",
        help="Decrement verbosity")

    # Define the default options
    optparser.set_defaults(verbose=0, quiet=0, logfile=LOG_FILE,
        conffile="")

    # Process the options
    options, args = optparser.parse_args()
    return options, args
Пример #9
0
def main():
    optparser = OptionParser("usage: %prog [options] inputdir1 inputdir2 etc")
    optparser.set_defaults(outputdir="out",
                           outputfile="parsed.json", 
                           extension=".js",
                           version=""
                           )
    optparser.add_option( "-o", "--outputdir",
                          action="store", dest="outputdir", type="string",
                          help="Directory to write the parser results" )
    optparser.add_option( "-f", "--file",
                          action="store", dest="outputfile", type="string",
                          help="The name of the file to write the JSON output" )
    optparser.add_option( "-e", "--extension",
                          action="store", dest="extension", type="string",
                          help="The extension for the files that should be parsed" )
    optparser.add_option( "-v", "--version",
                          action="store", dest="version", type="string",
                          help="The version of the project" )
    (opts, inputdirs) = optparser.parse_args()
    if len(inputdirs) > 0:
        docparser = DocParser( inputdirs, 
                            opts.outputdir, 
                            opts.outputfile, 
                            opts.extension,
                            opts.version
                            )
    else:
        optparser.error("Incorrect number of arguments")
Пример #10
0
def main():
    parser = OptionParser()
    parser.set_defaults(np=1)
    parser.add_option("--np", type=int, help="Number of Processors.")
    parser.add_option("--golden", help="Directory where golden files are stored.")
    parser.add_option("--outdir", help="Output directory.")
    parser.add_option("--nsweep", type=int, help="number of sweep")
    parser.add_option("--mesh", help="fluent case file")
    (options, args) = parser.parse_args()

    # convert path to absolute because we may cd to the test directory
    options.outdir   = os.path.abspath(options.outdir)
    options.golden   = os.path.abspath(os.path.join(options.golden,'GOLDEN'))
    options.mesh   = os.path.abspath(options.mesh)
    script = os.path.abspath('./FVMParticleMarking.py')

    if options.outdir:
        if not os.path.isdir(options.outdir):
            try:
                os.makedirs(options.outdir)
            except:
                print "error creating directory " + options.outdir
                sys.exit(1)
        os.chdir(options.outdir)

    mpi = 'mpirun -np %s %s %s %s' % (options.np, script, options.mesh, options.nsweep)    
    if os.system( mpi ):
        cleanup(-1)
    
    # OK.  Now check results.
    err = check_particles( options )
    cleanup(err)
Пример #11
0
def main():
    """Build a shell and place it in the autoBisect cache."""

    usage = 'Usage: %prog [options]'
    parser = OptionParser(usage)
    parser.disable_interspersed_args()

    parser.set_defaults(
        buildOptions="",
    )

    # Specify how the shell will be built.
    # See buildOptions.py for details.
    parser.add_option('-b', '--build',
                      dest='buildOptions',
                      help='Specify build options, e.g. -b "--disable-debug --enable-optimize" ' +
                      '(python buildOptions.py --help)')

    parser.add_option('-r', '--rev',
                      dest='revision',
                      help='Specify revision to build')

    options = parser.parse_args()[0]
    options.buildOptions = buildOptions.parseShellOptions(options.buildOptions)

    with LockDir(getLockDirPath(options.buildOptions.repoDir)):
        if options.revision:
            shell = CompiledShell(options.buildOptions, options.revision)
        else:
            localOrigHgHash = hgCmds.getRepoHashAndId(options.buildOptions.repoDir)[0]
            shell = CompiledShell(options.buildOptions, localOrigHgHash)

        obtainShell(shell, updateToRev=options.revision)
        print shell.getShellCacheFullPath()
Пример #12
0
def get_command_line_options(executable_name, arguments):
    parser = OptionParser(usage="%s options" % executable_name)
    parser.set_defaults(port = 9876)
    parser.add_option("-x", "--xmlrpc", action="store_true", dest="xml", help="Start XMLRPC StatServer")
    parser.add_option("-n", "--npipe", action="store_true", dest="pipe", help="Start named pipe StatServer")
    parser.add_option("-o", "--out", type="string", dest="output", help="Output DB File")
    
    xml_group = OptionGroup(parser, "Options for XMLRPC Server")
    xml_group.add_option("-p", "--port", type="string", dest="port", help="port to run the server")

    parser.add_option_group(xml_group)

    pipe_group = OptionGroup(parser, "Options for named pipe Server")
    pipe_group.add_option("-i", "--input", type="string", dest="pipe_name", help="Filename of the named pipe")

    parser.add_option_group(pipe_group)
    
    (options, args) = parser.parse_args()

    if (options.xml and options.pipe) or (options.xml==None and options.pipe==None):
        parser.print_help()
        parser.error("You need to provide one of the following options, --xmlrpc or --npipe")

    if not options.output:
        parser.print_help()
        parser.error("You need to provide following options, --out=OutputDB.db")

    if options.pipe and not options.pipe_name:
        parser.print_help()
        parser.error("You need to provide following options, --input=named_pipe")
        
    return options
Пример #13
0
def get_options():
	# Today's datetime
	today = dict()
	today['datetime'] = datetime.now()
	today['api_date'] = today['datetime'].strftime('%Y%m%d')

	#yesterday's datetime
	yesterday = dict()
	yesterday['datetime'] = datetime.now() - timedelta(days=1)
	yesterday['api_date'] = yesterday['datetime'].strftime('%Y%m%d')

	# Get command-line options
	parser = OptionParser()
	parser.add_option("-v", action="store_true", dest="verbose")
	parser.add_option("-q", action="store_false", dest="verbose")
	parser.add_option("--runSim", action="store_true", dest="run_sim")

	parser.set_defaults(verbose=False,
		run_sim=False)

	(options, args) = parser.parse_args()

	# Create an error list to identify errors
	errors = list()

	if errors:
	    parser.error("\n".join(errors))

	return (options,args)
Пример #14
0
def _make_optparser():
    parser = OptionParser(
        description="Dumps the NAV PostgreSQL database as plain-text SQL to "
                    "stdout, with optional data filtering.",
        version=buildconf.VERSION,
        epilog="The output of the program can be inserted into an empty "
               "PostgreSQL database using the psql program."
    )
    parser.set_defaults(
        filters={},
        exclude=[],
    )

    opt = parser.add_option
    opt("-e", "--exclude", action="append", type="string", dest="exclude",
        metavar="TABLE", help="Exclude TABLE data from dump")
    opt("-c", "--only-open-cam", action="store_true", dest="only_open_cam",
        help="Only dump open CAM records")
    opt("-a", "--only-open-arp", action="store_true", dest="only_open_arp",
        help="Only dump open ARP records")
    opt("-f", "--filter", type="string",
        action="callback", callback=_add_filter,
        metavar="FILTER", help="Filter a table's contents. "
                               "FILTER must match "
                               "<tablename>=<SQL where clause>")
    return parser
Пример #15
0
def get_options():
    """Get options for command line interface to update_cmd_states.
    """
    from optparse import OptionParser
    parser = OptionParser()
    parser.set_defaults()
    parser.add_option("--dbi",
                      default='sqlite',
                      help="Database interface (sqlite|sybase)")
    parser.add_option("--server",
                      default='db_base.db3',
                      help="DBI server (<filename>|sybase)")
    parser.add_option("--user",
                      help="sybase user (default=Ska.DBI default)")
    parser.add_option("--database",
                      help="sybase database (default=Ska.DBI default)")
    parser.add_option("--mp_dir",
                      default='/data/mpcrit1/mplogs',
                      help="MP load directory")
    parser.add_option("--h5file",
                      default='cmd_states.h5',
                      help="filename for HDF5 version of cmd_states")
    parser.add_option("--datestart",
                      help="Starting date for update (default=Now-10 days)")
    parser.add_option("--loglevel",
                      type='int',
                      default=20,
                      help='Log level (10=debug, 20=info, 30=warnings)')
    parser.add_option("--occ",
                      action='store_true',
                      help="Running on the OCC GRETA network")

    (opt, args) = parser.parse_args()
    return (opt, args)
Пример #16
0
    def commandline_options(self):
        """Set up the command line options."""
        parser = OptionParser(version="%prog " + VERSION,
            description="GUI front-end to compress png and jpg images via "
                "optipng, advpng and jpegoptim")

        parser.set_defaults(verbose=True)
        parser.add_option("-v", "--verbose", action="store_true",
            dest="verbose", help="Verbose mode (default)")
        parser.add_option("-q", "--quiet", action="store_false",
            dest="verbose", help="Quiet mode")

        parser.add_option("-f", "--file", action="store", type="string",
            dest="filename", help="compresses image and exit")
        parser.add_option("-d", "--directory", action="store", type="string",
            dest="directory", help="compresses images in directory and exit")

        options, args = parser.parse_args()

        # make sure we quit after processing finished if using cli
        if options.filename or options.directory:
            QObject.connect(self.thread, SIGNAL("finished()"), quit)

        # send to correct function
        if options.filename:
            self.file_from_cmd(options.filename.decode("utf-8"))
        if options.directory:
            self.dir_from_cmd(options.directory.decode("utf-8"))

        self.verbose = options.verbose
Пример #17
0
def ParseOptions():
  """Parse the command line options.

  @return: (options, args) as from OptionParser.parse_args()

  """
  parser = OptionParser(description="Ganeti cluster watcher",
                        usage="%prog [-d]",
                        version="%%prog (ganeti) %s" %
                        constants.RELEASE_VERSION)

  parser.add_option(cli.DEBUG_OPT)
  parser.add_option(cli.NODEGROUP_OPT)
  parser.add_option("-A", "--job-age", dest="job_age", default=6 * 3600,
                    help="Autoarchive jobs older than this age (default"
                          " 6 hours)")
  parser.add_option("--ignore-pause", dest="ignore_pause", default=False,
                    action="store_true", help="Ignore cluster pause setting")
  parser.add_option("--wait-children", dest="wait_children",
                    action="store_true", help="Wait for child processes")
  parser.add_option("--no-wait-children", dest="wait_children",
                    action="store_false",
                    help="Don't wait for child processes")
  # See optparse documentation for why default values are not set by options
  parser.set_defaults(wait_children=True)
  options, args = parser.parse_args()
  options.job_age = cli.ParseTimespec(options.job_age)

  if args:
    parser.error("No arguments expected")

  return (options, args)
Пример #18
0
def parse_options():
    parser = OptionParser(usage="""%prog [options] server TASKFILE
or
%prog [options] client (TASKFILE | SERVER_ADDRESS)""")
    parser.set_defaults(type="simple", verbose=False)
    parser.add_option("-t", "--type", help="IPC type (-t help for more info)")
    parser.add_option("-p", "--port", help="port to use", type="int")
    parser.add_option("-v", "--verbose", help="print more detailed messages",
                      action="store_true")
    options, args = parser.parse_args()
    if options.type.lower() == "help" \
            or options.type.lower() not in IPC_HANDLERS.keys():
        parser.error("Supported IPC types: " + ", ".join(IPC_HANDLERS.keys()))
    if len(args) > 2:
        parser.error('invalid number of arguments')
    args[0] = args[0].lower()
    if args[0] not in ('client', 'server'):
        parser.error('argument must be either "server" or "client"')
    else:
        mode = args[0]
    taskfile = args[1]
    extraoptions = {}
    if options.port:
        extraoptions["port"] = options.port
    return (mode, taskfile, options.type.lower(), options.verbose,
            extraoptions)
Пример #19
0
def main():
    parser = OptionParser()
    parser.add_option('-c', '--config', dest='config',
                      help='path to configuration', metavar='FILE')
    parser.add_option('-v', '--verbose',
                      action='store_true', dest='verbose', default=False,
                      help='print status messages to stdout')
    parser.add_option('-u', '--user', dest='user',
                      help='user owning database', metavar='USER')
    parser.add_option('-d', '--database', dest='database',
                      help='database to back up', metavar='DB')
    parser.add_option('--daily', dest='type',
                      action='store_const', const='daily')
    parser.add_option('--local', dest='type',
                      action='store_const', const='')
    parser.set_defaults(type='daily')
    (options, args) = parser.parse_args()

    # Uncomment this to make -v actually work
    logger.setLevel(logging.INFO if options.verbose else
                    logging.WARNING)

    logger.debug(options)

    if options.config is None:
        die('No configuration file specified')
    load_config(options.config)

    logger.debug(config)

    result_file = get_backup_file_path(database=options.database, user=options.user, backup_type=options.type)
    logger.info('Backing up to "%s"' % (result_file,))
    perform_backup(result_file, database=options.database)

    remove_old_backups(result_file)
Пример #20
0
def build_script():
    usage = """
    usage: %prog [options] module_name
    """
    parser = OptionParser(usage = usage)
    translator.add_compile_options(parser)
    # override the default because we want print
    parser.set_defaults(print_statements=True)
    linker.add_linker_options(parser)
    options, args = parser.parse_args()
    if len(args) != 1:
        parser.error("incorrect number of arguments")

    top_module = args[0]
    for d in options.library_dirs:
        pyjs.path.append(os.path.abspath(d))

    translator_arguments=dict(
        debug=options.debug,
        print_statements = options.print_statements,
        function_argument_checking=options.function_argument_checking,
        attribute_checking=options.attribute_checking,
        source_tracking=options.source_tracking,
        line_tracking=options.line_tracking,
        store_source=options.store_source
        )

    l = SpidermonkeyLinker(top_module,
                           output=options.output,
                           platforms=[PLATFORM],
                           path=pyjs.path,
                           translator_arguments=translator_arguments)
    l()
Пример #21
0
def get_options():
    """
    Parse the arguments
    """
    # Instance the parser and define the usage message
    optparser = OptionParser(usage="""
    %prog [-vqld]""", version="%prog .1")

    # Define the options and the actions of each one
    optparser.add_option("-v", "--verbose", action="count", dest="verbose",
        help="Increment verbosity")
    optparser.add_option("-q", "--quiet", action="count", dest="quiet",
        help="Decrement verbosity")
    optparser.add_option("-l", "--log", help=("Uses the given log file "
        "inteast of the default"), action="store", dest="logfile")
    optparser.add_option("-i", "--insecure", help=("Will raise exceptions."),
        action="store_true", dest="insecure")
    optparser.add_option("-d", "--dummy", help=("Will execute a dummy test."),
        action="store_true", dest="dummy")

    # Define the default options
    optparser.set_defaults(verbose=0, quiet=0, logfile=LOG_FILE,
        conffile="", dummy=False, insecure=False)

    # Process the options
    options, args = optparser.parse_args()
    return options, args
Пример #22
0
def parse_options():
    parser = OptionParser()
    parser.add_option(
        "-a", "--ampfile", dest="ampsname", metavar="AMP", help="single input .amp file (default: %default)"
    )
    parser.add_option(
        "-s", "--segfile", dest="segsname", metavar="SEG", help="single input .seg file (default: %default)"
    )
    parser.add_option(
        "-w", "--wavfile", dest="wavname", metavar="WAV", help="single input .wav file (default: %default)"
    )

    group = OptionGroup(parser, "Batch processing")
    group.add_option(
        "-i",
        "--input-dir",
        dest="indir",
        help="input directory; must contain wav/ and amps/ subdirectories" " with matching filesets.",
    )
    group.add_option("-o", "--output-dir", dest="outdir", help="output directory (will be created if it doesn't exist)")
    parser.add_option_group(group)

    parser.set_defaults(ampsname="test.amp", segsname="test.seg", wavname="test.wav")

    return parser.parse_args()
Пример #23
0
def init():
  "Get input options."
  global opts

  "Setup program input options."
  parser = OptionParser(version = "%prog 1.0.0")
  parser.add_option("-v", "--verbose", action="store_true", dest = "verbose",
    help = "verbose mode [%default]")
  parser.add_option("-g", "--debug", action="store_true", dest = "debug",
    help = "debug mode [%default]")
  parser.add_option("-F", "--foreground", action="store_true",
    dest = "foreground", help = "run in foreground [%default]")
  parser.add_option("-r", "--disable-raid", action="store_false",
    dest = "raid", help = "disable RAID monitoring")
  parser.add_option("-n", "--disable-nagios", action="store_false",
    dest = "nagios", help = "disable nagios monitoring")
  parser.add_option("-H", "--host", dest = "host",
    help = "LCD daemon hostname or IP address [%default]")
  parser.add_option("-p", "--port", dest = "port",
    help = "LCD daemon port number [%default]")
  parser.add_option("-i", "--interval", dest = "interval",
    help = "refresh value in seconds [%default]")
  parser.add_option("-N", "--nagiostats", dest = "nagiostats",
    help = "full path to nagiostats binary [%default]")
  parser.set_defaults(help = False, verbose = False, debug = False,
    foreground = False, raid = True, nagios = True,
    host = "localhost", port = 13666, interval = 1,
    nagiostats = "/usr/sbin/nagiostats")
  (opts, args) = parser.parse_args()
  if not opts.raid and not opts.nagios:
    err("cannot disable both raid and nagios, something's gotta' give'")
Пример #24
0
def parse_options(args):
    from optparse import OptionParser

    description = ("Merge peak calls from BED regions")
    usage = '%prog [options] BEDFILES...'
    version = '%%prog %s' % __version__

    parser = OptionParser(usage=usage, version=version,
                          description=description)

    parser.add_option("-m", "--minimum-replicated",
        action="store", type='int', dest="min_rep",
        help="minimum times a base is in a peak [default: %default]")

    parser.add_option("-v", "--verbose",
        action="store_true", dest="verbose",
        help="maximum verbosity [default: %default]")

    parser.set_defaults(min_rep=2,
                        verbose=False)

    options, args = parser.parse_args()

    if len(args) < 2:
        parser.error('specify at least 2 BEDFILES')

    return options, args
Пример #25
0
def parse_options():
    from optparse import OptionParser
    opt_parser = OptionParser(usage=usage)
    opt_parser.add_option("-l", "--list",
                          action="store", type="string", dest="list",
                          help="Target list to which all specified tasks will be moved.")
    opt_parser.add_option("-f", "--filter",
                          action="store", type="string", dest="filter",
                          help="Data filter (RTM query syntax)")
    opt_parser.add_option("-v", "--verbose",
                          action="store_true", dest="verbose",
                          help="Print diagnostic messages")
    opt_parser.add_option("-d", "--dry-run",
                          action="store_true", dest="dry_run",
                          help="Don't execute any updates, just check input and (if verbose) print planned actions")
    opt_parser.add_option("-g", "--debug",
                          action="store_true", dest="debug",
                          help="Print debugging information")
                          
    opt_parser.set_defaults(verbose = False, dry_run = False, debug=False,
                            add =[], remove =[])
    (opts, args) = opt_parser.parse_args()

    if not opts.filter:
        opt_parser.error("--filter not specified")
    if not opts.list:
        opt_parser.error("--list not specified")

    if opts.debug:
        import logging
        logging.basicConfig(level = logging.DEBUG)

    return opts
Пример #26
0
def main(argv):
    op = OptionParser(usage=USAGE, description=DESCRIPTION)
    op.disable_interspersed_args()
    op.add_option(
        "--ccache",
        help="location of ccache (default: %s)" % DEFAULT_CCACHE)
    op.add_option(
        "--compression",
        help="use compression",
        action="store_true")
    op.add_option(
        "-d", "--directory",
        help="where to create the temporary directory with the cache and" \
             " other files (default: %s)" \
            % DEFAULT_DIRECTORY)
    op.add_option(
        "--hardlink",
        help="use hard links",
        action="store_true")
    op.add_option(
        "-n", "--times",
        help="number of times to compile the file (default: %d)" \
            % DEFAULT_TIMES,
        type="int")
    op.add_option(
        "-v", "--verbose",
        help="print progress messages",
        action="store_true")
    op.set_defaults(
        ccache=DEFAULT_CCACHE,
        directory=DEFAULT_DIRECTORY,
        times=DEFAULT_TIMES)
    (options, args) = op.parse_args(argv[1:])
    if len(args) < 2:
        op.error("Missing arguments; pass -h/--help for help")

    global verbose
    verbose = options.verbose

    options.ccache = abspath(options.ccache)

    compiler = find_in_path(args[0])
    if compiler is None:
        op.error("Could not find %s in PATH" % args[0])
    if "ccache" in basename(realpath(compiler)):
        op.error(
            "%s seems to be a symlink to ccache; please specify the path to"
            " the real compiler instead" % compiler)

    print "Compilation command: %s -c -o %s.o" % (
        " ".join(args),
        splitext(argv[-1])[0])
    print "Compression:", on_off(options.compression)
    print "Hardlink:", on_off(options.hardlink)

    tmp_dir = "%s/perfdir.%d" % (abspath(options.directory), getpid())
    recreate_dir(tmp_dir)
    result = test(tmp_dir, options, args[:-1], args[-1])
    rmtree(tmp_dir)
    print_result(result)
Пример #27
0
def run( arguments ):
    usage = USAGE.strip()
    parser = OptionParser( usage=usage )
    options = dict(
        count=10,
        header=False,
        interactive=False,
        user='',
        password='',
    )
    parser.set_defaults( **options )
    parser.add_option( '-l', '--last', dest='count', help='Show only the last number of posts.' )
    parser.add_option( '-e', '--header', action='store_true', help='Show column headers. Hidden by default.' )
    parser.add_option( '-i', '--interactive', action='store_true', help='Prompt for missing credentials when connecting to the server.' )
    parser.add_option( '-u', '--user' )
    parser.add_option( '-p', '--password' )
    options, arguments = parser.parse_args( arguments )
    if len( arguments ) > 1:
        raise RuntimeError, 'Unexpected arguments: %s' % ' '.join( arguments )
    url = arguments[0] if arguments else ''
    listPosts(
        url,
        count=int( options.count or 0 ),
        header=options.header,
        user=options.user,
        password=options.password,
        interactive=options.interactive,
    )
Пример #28
0
def _parse_options():
    usage = "Usage: %prog [options]"
    parser = OptionParser(usage)
    parser.set_defaults(debug=False)
    parser.add_option("-d", "--debug", action="store_true", dest="debug")
    global options
    (options, args) = parser.parse_args()
Пример #29
0
def get_parser_instance(defaults=None):
    p = OptionParser()
    unimp_group=OptionGroup(p, "Unimplimented options",
        "These options do NOT work yet, they will be accepted and ignored.")

    p.add_option("--outputdir", "-d", dest="outputdir", type="string",
                help="Directory to put the encoded file in")
    p.add_option("--config", "-c", dest="configfile", type="string")
    p.add_option("--audiobitrate", "-a", dest="abr", type="string")
    unimp_group.add_option("--hostname", "-H", dest="hostname", type="string",
                help="hostname for the backend to connect to. This is"+
                     " being ignored for the moment")
    unimp_group.add_option("--port", "-p", dest="portnumber", type="int",
                help="Port to connect or listen on")
    unimp_group.add_option("--debug", "-D", dest="debug", action="count")
    #long only options
    #p.add_option("--ignore-defaults", dest="config", type="string")
    p.add_option("--crf", dest="crf", type="string",
                 help="which x264 CRF number to use. default:22")
    unimp_group.add_option("--threads", dest="threads", type="string",
                           help="number of threads to use. default auto")
    p.add_option_group(unimp_group)
    if not defaults is None:
        if type(defaults) == type(dict()):
            p.set_defaults(**defaults)
    return p
Пример #30
0
def parseArgs():
    """Parse command-line args and return options object.
    returns: opts parse options dict"""
    desc = ( 'Pyretic runtime' )
    usage = ( '%prog [options]\n'
              '(type %prog -h for details)' )
    
    end_args = 0
    for arg in sys.argv[1:]:
        if not re.match('-',arg):
            end_args = sys.argv.index(arg)
    kwargs_to_pass = None
    if end_args > 0:
        kwargs_to_pass = sys.argv[end_args+1:]
        sys.argv = sys.argv[:end_args+1]

    op = OptionParser( description=desc, usage=usage )
    op.add_option( '--frontend-only', '-f', action="store_true", 
                     dest="frontend_only", help = 'only start the frontend'  )
    op.add_option( '--mode', '-m', type='choice',
                     choices=['interpreted','i','reactive0','r0'], 
                     help = '|'.join( ['interpreted/i','reactive0/r0'] )  )
    op.add_option( '--verbosity', '-v', type='choice',
                     choices=['low','normal','high'], default = 'low',
                     help = '|'.join( ['quiet','high'] )  )

    op.set_defaults(frontend_only=False,mode='reactive0')
    options, args = op.parse_args()

    return (op, options, args, kwargs_to_pass)
Пример #31
0
    help="port number for server to listen on")
parser.add_option("--zlib", action="store_true", dest="zlib",
    help="use zlib wrapper for compressed transport")
parser.add_option("--ssl", action="store_true", dest="ssl",
    help="use SSL for encrypted transport")
parser.add_option('-v', '--verbose', action="store_const",
    dest="verbose", const=2,
    help="verbose output")
parser.add_option('-q', '--quiet', action="store_const",
    dest="verbose", const=0,
    help="minimal output")
parser.add_option('--protocol',  dest="proto", type="string",
    help="protocol to use, one of: accel, binary, compact, json")
parser.add_option('--transport',  dest="trans", type="string",
    help="transport to use, one of: buffered, framed")
parser.set_defaults(port=9090, verbose=1, proto='binary')
options, args = parser.parse_args()

script_dir = os.path.realpath(os.path.dirname(__file__))  # <-- absolute dir the script is in
lib_dir = os.path.join(os.path.dirname(os.path.dirname(script_dir)), 'lib', 'py', 'build', 'lib.*')

sys.path.insert(0, os.path.join(script_dir, options.genpydir))
sys.path.insert(0, glob.glob(lib_dir)[0])

from ThriftTest import ThriftTest
from ThriftTest.ttypes import *
from thrift.Thrift import TException
from thrift.transport import TTransport
from thrift.transport import TSocket
from thrift.transport import TZlibTransport
from thrift.protocol import TBinaryProtocol
Пример #32
0
def parseOptions(commandLine=None):
    '''Parse command line for options'''

    desc = ' '.join([
        'This script runs the SuperFine algorithm on a set of input trees',
        'given in a file, in Newick format.'
    ])

    parser = OptionParser(
        usage="usage: %prog [options] input_trees_file > output",
        version="%prog 1.1",
        description=desc)

    parser.set_defaults(reconciler="tnt", numIters=100, outputSCM=None)

    group4InfoString = ' '.join([
        "These options enable selection of the supertree",
        "algorithm to be used as a subroutine within",
        "SuperFine for resolving polytomies.  The 'qmc'",
        "option requires that Quartets MaxCut be",
        "installed; the 'gmrp' (greedy consensus of MP",
        "trees) and 'rmrp' (random MP tree) options",
        "require that PAUP* be installed, the 'tnt' (MRP(TNT)) option requires TNT be installed;  and the 'rml' (MRL(RAxML)) option",
        "requires that RAxML be installed.  Note that",
        "the selected subroutine's binary must be in",
        "the system's executable search path."
    ])
    #group4InfoString = ' '.join(["These options enable selection of the supertree",
    #"algorithm to be used as a subroutine within",
    #"SuperFine for resolving polytomies.  The 'qmc'",
    #"option requires that Quartets MaxCut be",
    #"installed; the 'gmrp' (greedy consensus of MP",
    #"trees) and 'rmrp' (random MP tree) options",
    #"require that PAUP* be installed, the 'tnt' (MRP(TNT)) option requires TNT be installed; the 'fml' option",
    #"requires that FastTree be installed; and the 'rml' option",
    #"requires that RAxML be installed.  Note that",
    #"the selected subroutine's binary must be in",
    #"the system's executable search path."])

    group5InfoString = ' '.join(
        ["This option causes the SCM tree", "to be written to disk."])

    group6DirectoryString = ' '.join([
        "This option allows the user to set the 					temporary",
        "working directory."
    ])

    group7LogString = ' '.join(
        ["This option allows the user to set the log output file."])

    group8SCMString = ' '.join(
        ["This option allows the user give the SCM tree."])

    group4 = OptionGroup(parser, "Tree Reconciliation Options".upper(),
                         group4InfoString)
    group5 = OptionGroup(parser, "Data Output Options".upper(),
                         group5InfoString)
    group6 = OptionGroup(parser, "Working Directory Options".upper(),
                         group6DirectoryString)
    group7 = OptionGroup(parser, "Log Output File".upper(), group7LogString)
    group8 = OptionGroup(parser, "SCM Tree File".upper(), group8SCMString)

    group4.add_option("-r",
                      "--reconcile",
                      choices=("qmc", "gmrp", "rmrp", "rml", "tnt", "none"),
                      dest="reconciler",
                      metavar="ALG",
                      help="use ALG to reconcile relabeled trees, "
                      "where ALG is one of {gmrp, rml, tnt} "
                      "[default: %default]")

    group4.add_option("-n",
                      "--numIters",
                      type="int",
                      dest="numIters",
                      metavar="N",
                      help="use N ratchet iterations when resolving with MRP "
                      "[default: %default]")

    group5.add_option("-w",
                      "--write",
                      dest="writeData",
                      metavar="SUFFIX",
                      help="write merger tree and final tree to disk in same "
                      "directory as source trees file, append .SUFFIX "
                      "to written file names "
                      "[default: %default]")

    group5.add_option("-s",
                      "--scmFile",
                      dest="outputSCM",
                      help="write merger tree to outputSCM file"
                      "[default: %default]")

    group5.add_option("-o",
                      "--output",
                      dest="outputFile",
                      metavar="OUTPUT",
                      help="write final tree to disk to OUTPUT file"
                      "[default: %default]")

    group6.add_option("-d",
                      "--directory",
                      dest="tempDirectory",
                      help="write files to temporary directory"
                      "[default: %default]")

    group7.add_option("-l",
                      "--log",
                      dest="logFile",
                      help="write to log file"
                      "[default: %default]")

    group8.add_option("-t",
                      "--tree",
                      dest="treeFile",
                      help="SCM Tree"
                      "[default: %default]")

    parser.add_option_group(group4)
    parser.add_option_group(group5)
    parser.add_option_group(group6)
    parser.add_option_group(group7)
    parser.add_option_group(group8)

    if commandLine:
        (options, args) = parser.parse_args(commandLine)
    else:
        (options, args) = parser.parse_args()

    if len(args) != 1:
        parser.error(
            "Incorrect number of arguments. Try the -h flag for help.")

    input = args[0]

    return (input, options)
Пример #33
0
        if not callable(getattr(config['otherReposToTag'], 'iteritems')):
            err = True
            log.info("otherReposToTag exists in config but is not a dict")
    if err:
        sys.exit(1)
    return config


if __name__ == '__main__':
    from optparse import OptionParser
    import os

    parser = OptionParser(__doc__)
    parser.set_defaults(
        attempts=os.environ.get('MAX_PUSH_ATTEMPTS',
                                DEFAULT_MAX_PUSH_ATTEMPTS),
        buildbot_configs=os.environ.get('BUILDBOT_CONFIGS_REPO',
                                        DEFAULT_BUILDBOT_CONFIGS_REPO),
    )
    parser.add_option("-a",
                      "--push-attempts",
                      dest="attempts",
                      help="Number of attempts before giving up on pushing")
    parser.add_option("-c",
                      "--configfile",
                      dest="configfile",
                      help="The release config file to use.")
    parser.add_option("-b",
                      "--buildbot-configs",
                      dest="buildbot_configs",
                      help="The place to clone buildbot-configs from")
    parser.add_option("-t",
Пример #34
0
            f.write(str(cellCentroids[n][i][1]) + "    ")
            if (i % 5 == 4):
                f.write("\n")
        f.write("\n")

        #connectivity
        for i in range(0, ncell):
            nnodes_per_cell = cellNodes[n].getCount(i)
            for node in range(0, nnodes_per_cell):
                f.write(str(cellNodes[n](i, node) + 1) + "     ")
            f.write("\n")
        f.write("\n")
    f.close()

parser = OptionParser()
parser.set_defaults(type='quad')
parser.add_option("--type", help="'quad'[default], 'tri', 'hexa', or 'tetra'")
parser.add_option("--xdmf", action='store_true', help="Dump data in xdmf")
parser.add_option("--time",
                  "-t",
                  action='store_true',
                  help="Print timing information.")
(options, args) = parser.parse_args()

nmesh = 1
fileBase0 = "plate_transient_"
reader0 = FluentCase(sys.argv[1])

#import debug
reader0.read()
Пример #35
0
                      help="Source file path, required",
                      metavar="FILE")
    parser.add_option("-d",
                      "--dest",
                      dest="dest",
                      help="Destination file path, required",
                      metavar="FILE")
    parser.add_option("-t",
                      "--tag",
                      dest="tag",
                      help="Version tag, required",
                      metavar="VERSION")
    ## util_path default is set up such that we assume this is being run out of trunk/Python/versioned_store
    parser.add_option("-u",
                      "--utils",
                      dest="util_path",
                      help="Path to Python/util",
                      metavar="DIR",
                      default=os.path.join(os.path.dirname(sys.argv[0]), '..',
                                           'util'))
    parser.set_defaults()
    (options, args) = parser.parse_args()
    ## optparse doesn't believe in the notion of 'required options' so check these manually
    if len([t for t in [options.src, options.dest, options.tag] if t is None
            ]) > 0:
        raise Exception("src, dest and tag arguments are required")
    ## Take the util path and dynamically add in the cga_util library.
    #sys.path.append(options.util_path)
    #import cga_util
    verstore(options.src, options.dest, options.tag)
Пример #36
0
def main():

    #progStartTime = datetime.now()
    # print "program launch at "+progStartTime.strftime("%b %d %H:%M %Z")

    # parse the command line option
    usage = "usage: %prog [options] Convert CTest like XML into a webpage"
    epilog = "Author: Win-Lime Kevin <*****@*****.**> (22/08/13)."
    parser = OptionParser(usage=usage, epilog=epilog)
    parser.add_option("-i",
                      "--inputFile",
                      action="store",
                      metavar="FILE",
                      help="read the inputFile")
    parser.add_option("-d",
                      "--inputDirectory",
                      action="store",
                      metavar="DIRECTORY",
                      help="read all files ended by Test.xml in the input "
                      "directory. The default value is the active "
                      "directory")
    parser.add_option("-o",
                      "--outputDirectory",
                      action="store",
                      metavar="DIRECTORY",
                      help="Write the result to the output directory. The "
                      "default value is ./html/")
    parser.add_option("-s",
                      "--skeleton",
                      action="store",
                      metavar="SKELETON",
                      help="HTML report skeleton")
    parser.add_option("-q",
                      "--quiet",
                      action="store_true",
                      metavar="QUIET",
                      help="don't print warnings")

    parser.set_defaults(inputDirectory='.',
                        outputDirectory='html',
                        quiet=False)
    (options, args) = parser.parse_args()

    # verify the input file
    inputs = []
    if options.inputFile is not None:
        if not os.path.isfile(options.inputFile):
            print(" The input file is not a valid file")
            exit(1)
        else:
            inputs.append(options.inputFile)
    # verify the input directory and search in it for Test.xml file.
    # only if there is no filename specified. by default, the program search all the file in its (sub)directirie
    if not inputs:
        for r, d, f in os.walk(options.inputDirectory):
            for files in f:
                if files.endswith(
                        "Test.xml") and not files.endswith("PyTest.xml"):
                    inputs.append(os.path.join(r, files))

    # close the program if there is no file found
    if inputs == []:
        print(" No file found \n")
        exit()

    print("Converting *Test.xml files from %s to HTML format in %s" %
          (options.inputDirectory, options.outputDirectory))
    # verify or create the output directory
    output = options.outputDirectory
    if not os.path.isdir(output):
        os.makedirs(output)

    # Copy the project build manifest, if present.
    manifest_file = os.path.join(options.inputDirectory, 'config',
                                 'manifest.xml')
    if os.path.exists(manifest_file):
        shutil.copy(manifest_file, output)

    # Initialise the annotations
    annotations = [{}]
    # create the summary file
    globalSummaryFile = open(os.path.join(output, "summary.json"), "w")
    globalSummaryFile.write("[]")
    globalSummaryFile.close()

    # Initialisation of the test organizer
    organizer_all = TestOrganizer("index.html?test=all_results",
                                  os.path.join(output, "all_results"))
    organizer_failed = TestOrganizer("index.html?test=results",
                                     os.path.join(output, "results"))
    failures_count = {'FAIL': 0, 'ERROR': 0}

    # process each file
    for fileName in inputs:
        print("Process the file : " + fileName)
        # read and parse the xml file
        try:
            tree = ET.parse(fileName)
        except:
            cleanXml(fileName)
            tree = ET.parse(fileName)

        newdataset = tree.getroot()

        # Look for all the sites ( there is one site per default but
        # as in the specification it can be more, we consider them
        if newdataset.tag == "Site":
            sites = [newdataset]
        else:
            sites = newdataset.getchildren()
        for site in sites:
            # print "    -> Process the site : "+site.get("BuildStamp")
            Testing = site.find("Testing")
            tests = Testing.findall('Test')
            if not tests:
                # no tests in this "site", let's ignore it
                continue

            # create a directory containing the html file for each site
            # os.path.join(output,os.path.split(fileName)[1][:-8]+str(site.get("BuildStamp")))
            outputTemp = output
            if not os.path.isdir(outputTemp):
                os.makedirs(outputTemp)

            updateAnnotations(site, Testing, outputTemp, annotations)
            """ If the generator is CTest add datetime element to the XML"""
            if "ctest" in site.get("Generator"):
                testStartTime = int(Testing.find("StartTestTime").text)
                # for test in Testing.findall("Test"):

            # find the skeleton directory
            try:
                if options.skeleton is not None:
                    skel = options.skeleton
                else:
                    skel = [
                        os.path.join(d, 'HTMLTestReportSkel')
                        for d in os.environ.get('ELEMENTS_AUX_PATH', '').split(
                            os.pathsep)
                        if os.path.isdir(os.path.join(d, 'HTMLTestReportSkel'))
                    ][0]
            except IndexError:
                print("Cannot find skeleton directory in ${ELEMENTS_AUX_PATH}")
                exit(1)

            # Copy the template directory (do not overwrite)
            for dirpath, dirnames, filenames in os.walk(skel):
                destpath = os.path.join(outputTemp,
                                        os.path.relpath(dirpath, skel))
                for d in dirnames:
                    if d in ('.svn', '.git'):
                        continue
                    d = os.path.join(destpath, d)
                    if not os.path.exists(d):
                        os.mkdir(d)
                for f in filenames:
                    src = os.path.join(dirpath, f)
                    dst = os.path.join(destpath, f)
                    if not os.path.exists(dst):
                        shutil.copy(src, dst)

            # process each test case
            for Test in tests:
                labels = [l.text for l in Test.findall('Labels/Label')]

                Results = Test.find("Results")
                """___ create the local summary   ___"""

                summary = {
                    "id": cleanSpace(cleanWebChar(Test.find("Name").text)),
                    # some interface specific field
                    "fields": ["end_time", "start_time", "stdout"],
                    "cause": ""
                }
                status = Test.get("Status")
                summary["outcome"] = TestOrganizer.status.get(
                    status, cleanSpace(cleanWebChar(status)))

                if 'test-wrapper' in labels and summary["outcome"] == 'PASS':
                    # we should not report the results of test wrappers (like
                    # QMTest) if they are successful
                    continue

                organizer_all.classify(Test)
                if summary["outcome"] != "PASS":
                    organizer_failed.classify(Test)
                if summary['outcome'] in failures_count:
                    failures_count[summary['outcome']] += 1

                # Fill the summary fields
                for NamedMeasurement in Results.iter("NamedMeasurement"):

                    # remove the space character
                    summary["fields"].append(
                        cleanSpace(cleanWebChar(NamedMeasurement.get("name"))))
                    # or NamedMeasurement.get("name") == "Pass Reason" :
                    if NamedMeasurement.get("name") == "Causes":
                        if NamedMeasurement.find(
                                "Value") is not None and NamedMeasurement.find(
                                    "Value").text is not None:
                            summary["cause"] = cleanWebChar(
                                NamedMeasurement.find("Value").text)

                # update the global summary file
                globalSummaryFile = open(
                    os.path.join(outputTemp, "summary.json"), "r")
                globalSummary = json.loads(globalSummaryFile.read())
                globalSummaryFile.close()
                globalSummary.append(summary)
                globalSummaryFile = open(
                    os.path.join(outputTemp, "summary.json"), "w")
                globalSummaryFile.write(
                    json.dumps(globalSummary, sort_keys=True, indent=4))
                globalSummaryFile.close()
                """___ Create and fill the test directory ___"""
                # create the dir
                testCaseDir = os.path.join(outputTemp, summary["id"])
                if not os.path.isdir(testCaseDir):
                    os.mkdir(testCaseDir)
                # write the local summary
                summaryFile = open(os.path.join(testCaseDir, "summary.json"),
                                   "w")
                summaryFile.write(json.dumps(summary, sort_keys=True,
                                             indent=4))
                summaryFile.close()

                # write the stdout
                try:
                    value = Results.find("Measurement").find("Value")
                    text = value.text
                    if 'encoding' in value.attrib:
                        text = VALUE_DECODE[value.attrib['encoding']](text)
                    if 'compression' in value.attrib:
                        text = VALUE_DECOMP[value.attrib['compression']](text)
                    # In Python3 the methods in VALUE_DECOMP return a bytes object, which has to be decoded
                    if hasattr(text, 'decode'):
                        text = text.decode('utf-8')
                    text = dropCustomMeasurements(text)
                    text = formatMeasurementText(text, escape=True)
                    # no "Measurement" or no "Value" or no text
                except AttributeError as x:
                    if not options.quiet:
                        print('WARNING: {0[id]}: AttributeError: {1}'.format(
                            summary, x))
                    text = '<i>no stdout</i>'
                except KeyError as x:
                    if not options.quiet:
                        print('WARNING: {0[id]}: KeyError: {1}'.format(
                            summary, x))
                    # encoding or compressions unknown, keep original text
                    text = formatMeasurementText(value=text, escape=True)
                with open(os.path.join(testCaseDir, "stdout"), "wb") as stdout:
                    stdout.write(text.encode('utf-8'))

                if "ctest" not in site.get("Generator"):
                    # write the other files
                    for NamedMeasurement in Results.getiterator(
                            "NamedMeasurement"):
                        value = NamedMeasurement.find("Value")
                        cleanName = cleanSpace(
                            cleanWebChar(
                                NamedMeasurement.get("name"))).lower()
                        NamedMeasurementFile = open(
                            os.path.join(testCaseDir, cleanName), "w")

                        # Consider the void measurment
                        if value is not None and value.text is not None:
                            NamedMeasurementFile.write(
                                formatMeasurementText(value.text))
                        else:
                            NamedMeasurementFile.write("<pre></pre>")
                        NamedMeasurementFile.close()
                else:
                    executionTime = float(0)
                    # write the other files
                    for NamedMeasurement in Results.iter("NamedMeasurement"):
                        value = NamedMeasurement.find("Value")
                        cleanName = cleanSpace(
                            cleanWebChar(
                                NamedMeasurement.get("name"))).lower()
                        if cleanName == "execution_time":
                            executionTime = float(value.text)
                        NamedMeasurementFile = open(
                            os.path.join(testCaseDir, cleanName), "w")

                        # Consider the void measurment
                        if value is not None and value.text is not None:
                            NamedMeasurementFile.write(
                                formatMeasurementText(value.text))
                        else:
                            NamedMeasurementFile.write("<pre></pre>")
                        NamedMeasurementFile.close()
                    # write the interface specific files
                    #!! The start_time and the end time are computed for the cTest generator.
                    # These values are only an aproximation.
                    startTimeFile = open(
                        os.path.join(testCaseDir, "start_time"), "w")
                    startTimeFile.write(
                        time.strftime("%b %d %H:%M %Z",
                                      time.localtime(testStartTime)))
                    startTimeFile.close()
                    testEndTime = testStartTime + executionTime
                    endTimeFile = open(os.path.join(testCaseDir, "end_time"),
                                       "w")
                    endTimeFile.write(
                        time.strftime("%b %d %H:%M %Z",
                                      time.localtime(testEndTime)))
                    endTimeFile.close()
                    testStartTime = testEndTime
            organizer_all.write()
            organizer_failed.write()

    if sum(failures_count.values()):
        print('Some tests failed:')
        print('\n'.join('  %s: %s' % i for i in failures_count.items()))
        sys.exit(1)
Пример #37
0
def main():

    # setup the command line parser options
    parser = OptionParser()
    parser.add_option("-s", "--skip", dest="skip", type="int",\
            help="how many input lines should we skip?")
    parser.set_defaults(skip=0)

    # parse the command line options and get the file name
    (options, args) = parser.parse_args()
    if len(args) < 1:
        parser.error("need a file name")

    fileNames = args

    for fileName in fileNames:
        normalize = False

        # We check to see if we are dealing with the one body density matrix
        if fileName.find('obdm') != -1:
            normalize = True

        # We count the number of lines in the estimator file to make sure we
        # have some data and grab the headers
        estFile = open(fileName, 'r')
        estLines = estFile.readlines()
        numLines = len(estLines) - 2  # We expect two comment lines
        pimcid = estLines[0]
        headers = estLines[1].split()
        estFile.close()

        # If we have data, compute averages and error
        if numLines - options.skip > 0:
            estData = pyutils.loadFile(fileName)

            # Now we skip data rows to test for convergence
            for n in range(options.skip):
                estData.pop(0)

            estAve = pyutils.average(estData, 1)
            bins = MCstat.bin(np.array(estData))
            estErr = bins[-1, :]
            numData = len(estData)

            print pimcid, '# Number Samples %6d' % numData
            if not normalize:
                for n, ave in enumerate(estAve):
                    if len(headers) - 1 == len(estAve):
                        label = headers[n + 1]
                    else:
                        label = 'Col #%02d:' % n
                    print '%-16s%12.5f\t%12.5f' % (label, estAve[n], estErr[n])
            else:
                for n, ave in enumerate(estAve):
                    normAve = estAve[n] / estAve[0]
                    if abs(estAve[n]) > 1E-10:
                        normErr = (estErr[n] / estAve[n]) * normAve
                    else:
                        normErr = 0.0

                    if len(headers) - 1 == len(estAve):
                        label = headers[n + 1]
                    else:
                        label = 'Col #%02d:' % n
                    print '%-16s%12.5f\t%12.5f' % (label, normAve, normErr)
Пример #38
0
def get_option_parser(defaults):
  """Creates OptionParser and adds shell options (flags)

  Default values are loaded in initially
  """

  parser = OptionParser()
  parser.add_option("-i", "--impalad", dest="impalad",
                    help="<host:port> of impalad to connect to \t\t")
  parser.add_option("-b", "--kerberos_host_fqdn", dest="kerberos_host_fqdn",
                    help="If set, overrides the expected hostname of the Impalad's "
                         "kerberos service principal. impala-shell will check that "
                         "the server's principal matches this hostname. This may be "
                         "used when impalad is configured to be accessed via a "
                         "load-balancer, but it is desired for impala-shell to talk "
                         "to a specific impalad directly.")
  parser.add_option("-q", "--query", dest="query",
                    help="Execute a query without the shell")
  parser.add_option("-f", "--query_file", dest="query_file",
                    help="Execute the queries in the query file, delimited by ;."
                         " If the argument to -f is \"-\", then queries are read from"
                         " stdin and terminated with ctrl-d.")
  parser.add_option("-k", "--kerberos", dest="use_kerberos",
                    action="store_true", help="Connect to a kerberized impalad")
  parser.add_option("-o", "--output_file", dest="output_file",
                    help=("If set, query results are written to the "
                          "given file. Results from multiple semicolon-terminated "
                          "queries will be appended to the same file"))
  parser.add_option("-B", "--delimited", dest="write_delimited",
                    action="store_true",
                    help="Output rows in delimited mode")
  parser.add_option("--print_header", dest="print_header",
                    action="store_true",
                    help="Print column names in delimited mode"
                         " when pretty-printed.")
  parser.add_option("--output_delimiter", dest="output_delimiter",
                    help="Field delimiter to use for output in delimited mode")
  parser.add_option("-s", "--kerberos_service_name",
                    dest="kerberos_service_name",
                    help="Service name of a kerberized impalad")
  parser.add_option("-V", "--verbose", dest="verbose",
                    action="store_true",
                    help="Verbose output")
  parser.add_option("-p", "--show_profiles", dest="show_profiles",
                    action="store_true",
                    help="Always display query profiles after execution")
  parser.add_option("--quiet", dest="verbose",
                    action="store_false",
                    help="Disable verbose output")
  parser.add_option("-v", "--version", dest="version",
                    action="store_true",
                    help="Print version information")
  parser.add_option("-c", "--ignore_query_failure", dest="ignore_query_failure",
                    action="store_true", help="Continue on query failure")
  parser.add_option("-d", "--database", dest="default_db",
                    help="Issues a use database command on startup \t")
  parser.add_option("-l", "--ldap", dest="use_ldap",
                    action="store_true",
                    help="Use LDAP to authenticate with Impala. Impala must be configured"
                    " to allow LDAP authentication. \t\t")
  parser.add_option("-u", "--user", dest="user",
                    help="User to authenticate with.")
  parser.add_option("--ssl", dest="ssl",
                    action="store_true",
                    help="Connect to Impala via SSL-secured connection \t")
  parser.add_option("--ca_cert", dest="ca_cert",
                    help=("Full path to "
                    "certificate file used to authenticate Impala's SSL certificate."
                    " May either be a copy of Impala's certificate (for self-signed "
                    "certs) or the certificate of a trusted third-party CA. If not set, "
                    "but SSL is enabled, the shell will NOT verify Impala's server "
                    "certificate"))
  parser.add_option("--config_file", dest="config_file",
                    help=("Specify the configuration file to load options. "
                          "The following sections are used: [impala], "
                          "[impala.query_options]. Section names are case sensitive. "
                          "Specifying this option within a config file will have "
                          "no effect. Only specify this as an option in the commandline."
                          ))
  parser.add_option("--history_file", dest="history_file",
                    help=("The file in which to store shell history. This may also be "
                          "configured using the IMPALA_HISTFILE environment variable."))
  parser.add_option("--live_summary", dest="live_summary", action="store_true",
                    help="Print a query summary every 1s while the query is running.")
  parser.add_option("--live_progress", dest="live_progress", action="store_true",
                    help="Print a query progress every 1s while the query is running."
                         " The default value of the flag is True in the interactive mode."
                         " If live_progress is set to False in a config file, this flag"
                         " will override it")
  parser.add_option("--disable_live_progress", dest="live_progress", action="store_false",
                    help="A command line flag allows users to disable live_progress in"
                         " the interactive mode.")
  parser.add_option("--auth_creds_ok_in_clear", dest="creds_ok_in_clear",
                    action="store_true", help="If set, LDAP authentication " +
                    "may be used with an insecure connection to Impala. " +
                    "WARNING: Authentication credentials will therefore be sent " +
                    "unencrypted, and may be vulnerable to attack.")
  parser.add_option("--ldap_password_cmd", dest="ldap_password_cmd",
                    help="Shell command to run to retrieve the LDAP password")
  parser.add_option("--var", dest="keyval", action="append",
                    help="Defines a variable to be used within the Impala session."
                         " Can be used multiple times to set different variables."
                         " It must follow the pattern \"KEY=VALUE\","
                         " KEY starts with an alphabetic character and"
                         " contains alphanumeric characters or underscores.")
  parser.add_option("-Q", "--query_option", dest="query_options", action="append",
                    help="Sets the default for a query option."
                         " Can be used multiple times to set different query options."
                         " It must follow the pattern \"KEY=VALUE\","
                         " KEY must be a valid query option. Valid query options "
                         " can be listed by command 'set'.")
  parser.add_option("-t", "--client_connect_timeout_ms",
                    help="Timeout in milliseconds after which impala-shell will time out"
                    " if it fails to connect to Impala server. Set to 0 to disable any"
                    " timeout.")
  parser.add_option("--protocol", dest="protocol", default="beeswax",
                    help="Protocol to use for client/server connection. Valid inputs are "
                         "['hs2', 'hs2-http', 'beeswax']. 'hs2-http' uses HTTP transport "
                         "to speak to the coordinator while 'hs2' and 'beeswax' use the "
                         "binary TCP based transport. Beeswax support is deprecated "
                         "and will be removed in the future.")
  parser.add_option("--http_path", dest="http_path", default="cliservice",
                    help="Default http path on the coordinator to connect to. The final "
                    "connection URL looks like <http(s)>://<coordinator-host>:<port>/"
                    "<http_path>. While the coordinator server implementation does not "
                    "enforce any http path for the incoming requests, deployments could "
                    "still put it behind a loadbalancer that can expect the traffic at a "
                    "certain path.")
  parser.add_option("--fetch_size", type="int", dest="fetch_size", default=10240,
                    help="The fetch size when fetching rows from the Impala coordinator. "
                    "The fetch size controls how many rows a single fetch RPC request "
                    "(RPC from the Impala shell to the Impala coordinator) reads at a "
                    "time. This option is most effective when result spooling is enabled "
                    "('spool_query_results'=true). When result spooling is enabled "
                    "values over the batch_size are honored. When result spooling is "
                    "disabled, values over the batch_size have no affect. By default, "
                    "the fetch_size is set to 10240 which is equivalent to 10 row "
                    "batches (assuming the default batch size). Note that if result "
                    "spooling is disabled only a single row batch can be fetched at a "
                    "time regardless of the specified fetch_size.")


  # add default values to the help text
  for option in parser.option_list:
    if option.dest is not None:
      # option._short_opts returns a list of short options, e.g. ["-Q"].
      # option._long_opts returns a list of long options, e.g. ["--query_option"].
      # The code below removes the - from the short option and -- from the long option.
      short_opt = option._short_opts[0][1:] if len(option._short_opts) > 0 else None
      long_opt = option._long_opts[0][2:] if len(option._long_opts) > 0 else None
      # In order to set the default flag values, optparse requires the keys to be the
      # dest names. The default flag values are set in impala_shell_config_defaults.py and
      # the default flag values may contain default values that are not for flags.
      if short_opt in defaults:
        if option.dest not in defaults:
          defaults[option.dest] = defaults[short_opt]
        elif type(defaults[option.dest]) == list:
          defaults[option.dest].extend(defaults[short_opt])
      elif long_opt in defaults:
        if option.dest not in defaults:
          defaults[option.dest] = defaults[long_opt]
        elif type(defaults[option.dest]) == list:
          defaults[option.dest].extend(defaults[long_opt])

    # since the quiet flag is the same as the verbose flag
    # we need to make sure to print the opposite value for it
    # (print quiet is false since verbose is true)
    if option == parser.get_option('--quiet'):
      option.help += " [default: %s]" % (not defaults['verbose'])
    # print default value of disable_live_progress in the help messages as opposite
    # value for default value of live_progress
    # (print disable_live_progress is false since live_progress is true)
    elif option == parser.get_option('--disable_live_progress'):
      option.help += " [default: %s]" % (not defaults['live_progress'])
    elif option != parser.get_option('--help') and option.help is not SUPPRESS_HELP:
      # don't want to print default value for help or options without help text
      option.help += " [default: %default]"

  # mutually exclusive flags should not be used in the same time
  if '--live_progress' in sys.argv and '--disable_live_progress' in sys.argv:
    parser.error("options --live_progress and --disable_live_progress are mutually "
                 "exclusive")
  if '--verbose' in sys.argv and '--quiet' in sys.argv:
    parser.error("options --verbose and --quiet are mutually exclusive")

  parser.set_defaults(**defaults)

  return parser
Пример #39
0
def iostat_command(name):
    """iostat-like command for NFS mount points
    """
    mountstats = parse_stats_file('/proc/self/mountstats')
    devices = []
    origdevices = []
    interval_seen = False
    count_seen = False

    mydescription= """
Sample iostat-like program to display NFS client per-mount'
statistics.  The <interval> parameter specifies the amount of time in seconds
between each report.  The first report contains statistics for the time since
each file system was mounted.  Each subsequent report contains statistics
collected during the interval since the previous report.  If the <count>
parameter is specified, the value of <count> determines the number of reports
generated at <interval> seconds apart.  If the interval parameter is specified
without the <count> parameter, the command generates reports continuously.
If one or more <mount point> names are specified, statistics for only these
mount points will be displayed.  Otherwise, all NFS mount points on the
client are listed.
"""
    parser = OptionParser(
        usage="usage: %prog [ <interval> [ <count> ] ] [ <options> ] [ <mount point> ]",
        description=mydescription,
        version='version %s' % Iostats_version)
    parser.set_defaults(which=0, sort=False, list=sys.maxint)

    statgroup = OptionGroup(parser, "Statistics Options",
                            'File I/O is displayed unless one of the following is specified:')
    statgroup.add_option('-a', '--attr',
                            action="store_const",
                            dest="which",
                            const=1,
                            help='displays statistics related to the attribute cache')
    statgroup.add_option('-d', '--dir',
                            action="store_const",
                            dest="which",
                            const=2,
                            help='displays statistics related to directory operations')
    statgroup.add_option('-p', '--page',
                            action="store_const",
                            dest="which",
                            const=3,
                            help='displays statistics related to the page cache')
    parser.add_option_group(statgroup)
    displaygroup = OptionGroup(parser, "Display Options",
                               'Options affecting display format:')
    displaygroup.add_option('-s', '--sort',
                            action="store_true",
                            dest="sort",
                            help="Sort NFS mount points by ops/second")
    displaygroup.add_option('-l','--list',
                            action="store",
                            type="int",
                            dest="list",
                            help="only print stats for first LIST mount points")
    parser.add_option_group(displaygroup)

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

    for arg in args:

        if arg == sys.argv[0]:
            continue

        if arg in mountstats:
            origdevices += [arg]
        elif not interval_seen:
            try:
                interval = int(arg)
            except:
                print 'Illegal <interval> value %s' % arg
                return
            if interval > 0:
                interval_seen = True
            else:
                print 'Illegal <interval> value %s' % arg
                return
        elif not count_seen:
            try:
                count = int(arg)
            except:
                print 'Ilegal <count> value %s' % arg
                return
            if count > 0:
                count_seen = True
            else:
                print 'Illegal <count> value %s' % arg
                return

    # make certain devices contains only NFS mount points
    devices = list_nfs_mounts(origdevices, mountstats)
    if len(devices) == 0:
        print 'No NFS mount points were found'
        return


    old_mountstats = None
    sample_time = 0.0

    if not interval_seen:
        print_iostat_summary(old_mountstats, mountstats, devices, sample_time, options)
        return

    if count_seen:
        while count != 0:
            print_iostat_summary(old_mountstats, mountstats, devices, sample_time, options)
            old_mountstats = mountstats
            time.sleep(interval)
            sample_time = interval
            mountstats = parse_stats_file('/proc/self/mountstats')
            # automount mountpoints add and drop, if automount is involved
            # we need to recheck the devices list when reparsing
            devices = list_nfs_mounts(origdevices,mountstats)
            if len(devices) == 0:
                print 'No NFS mount points were found'
                return
            count -= 1
    else: 
        while True:
            print_iostat_summary(old_mountstats, mountstats, devices, sample_time, options)
            old_mountstats = mountstats
            time.sleep(interval)
            sample_time = interval
            mountstats = parse_stats_file('/proc/self/mountstats')
            # automount mountpoints add and drop, if automount is involved
            # we need to recheck the devices list when reparsing
            devices = list_nfs_mounts(origdevices,mountstats)
            if len(devices) == 0:
                print 'No NFS mount points were found'
                return
Пример #40
0
import os
import sys

import sys
import os.path
from cStringIO import StringIO

from optparse import OptionParser
from contextlib import closing

from .warctools import WarcRecord
from .httptools import RequestMessage, ResponseMessage

parser = OptionParser(usage="%prog warc:offset")

parser.set_defaults(output_directory=None, limit=None, log_level="info")


def main(argv):
    (options, args) = parser.parse_args(args=argv[1:])

    out = sys.stdout

    filename, offset = args[0].rsplit(':', 1)
    if ',' in offset:
        offset, length = [int(n) for n in offset.split(',', 1)]
    else:
        offset = int(offset)
        length = None  # unknown

    payload = extract_payload_from_file(filename, offset, length)
Пример #41
0
    help="address is used as a header, this option defines header number h1 -> h6"
)
parser.add_option(
    "--rc",
    "--row-cells",
    default="[port.number]/[port.protocol],[state],[service.name],[service.product] [service.version]",
    help="define rows which will report certain data. Those rows: [port.number], [port.protocol], [state], "
         "[service.name], [service.product], [service.version] "
)
parser.add_option(
    "--print-empty",
    dest="print_empty",
    action="store_true",
    help="should addresses with no opened ports to be printed"
)
parser.set_defaults(print_empty=False)

(options, args) = parser.parse_args()

def fileCheck():
    f = (args[0])
    kind = magic.from_file(f)
    if ('XML'.casefold() in kind.casefold()) == False:
        print("File supplied is not a valid XML file")
        print()
        parser.print_help()
        sys.exit()

try:
    fileCheck()
Пример #42
0
def main():
    parser = OptionParser()
    parser.add_option('--all', action="store_true", dest='all')
    parser.add_option(
        '--genpydirs',
        type='string',
        dest='genpydirs',
        default='default,slots,oldstyle,no_utf8strings,dynamic,dynamicslots',
        help=
        'directory extensions for generated code, used as suffixes for \"gen-py-*\" added sys.path for individual tests'
    )
    parser.add_option("--port",
                      type="int",
                      dest="port",
                      default=9090,
                      help="port number for server to listen on")
    parser.add_option('-v',
                      '--verbose',
                      action="store_const",
                      dest="verbose",
                      const=2,
                      help="verbose output")
    parser.add_option('-q',
                      '--quiet',
                      action="store_const",
                      dest="verbose",
                      const=0,
                      help="minimal output")
    parser.add_option(
        '-L',
        '--libdir',
        dest="libdir",
        default=default_libdir(),
        help="directory path that contains Thrift Python library")
    parser.add_option(
        '--gen-base',
        dest="gen_base",
        default=SCRIPT_DIR,
        help="directory path that contains Thrift Python library")
    parser.set_defaults(verbose=1)
    options, args = parser.parse_args()

    generated_dirs = []
    for gp_dir in options.genpydirs.split(','):
        generated_dirs.append('gen-py-%s' % (gp_dir))

    # commandline permits a single class name to be specified to override SERVERS=[...]
    servers = SERVERS
    if len(args) == 1:
        if args[0] in SERVERS:
            servers = args
        else:
            print('Unavailable server type "%s", please choose one of: %s' %
                  (args[0], servers))
            sys.exit(0)

    tests = TestCases(options.gen_base, options.libdir, options.port,
                      generated_dirs, servers, options.verbose)

    # run tests without a client/server first
    print('----------------')
    print(
        ' Executing individual test scripts with various generated code directories'
    )
    print(' Directories to be tested: ' + ', '.join(generated_dirs))
    print(' Scripts to be tested: ' + ', '.join(SCRIPTS))
    print('----------------')
    for genpydir in generated_dirs:
        for script in SCRIPTS:
            runScriptTest(options.libdir, options.gen_base, genpydir, script)

    print('----------------')
    print(
        ' Executing Client/Server tests with various generated code directories'
    )
    print(' Servers to be tested: ' + ', '.join(servers))
    print(' Directories to be tested: ' + ', '.join(generated_dirs))
    print(' Protocols to be tested: ' + ', '.join(PROTOS))
    print(' Options to be tested: ZLIB(yes/no), SSL(yes/no)')
    print('----------------')

    if options.all:
        tests.run_all_tests()
    else:
        tests.test_feature('gendir', generated_dirs)
        tests.test_feature('server', servers)
        tests.test_feature('proto', PROTOS)
        tests.test_feature('zlib', [False, True])
        tests.test_feature('ssl', [False, True])
Пример #43
0
def parseOpts():  # pylint: disable=invalid-name,missing-docstring,missing-return-doc,missing-return-type-doc
    parser = OptionParser()
    parser.set_defaults(
        repoName="mozilla-central",
        targetTime=15 * 60,  # 15 minutes
        existingBuildDir=None,
        timeout=0,
        build_options=None,
        useTreeherderBuilds=False,
    )

    parser.add_option("--build",
                      dest="existingBuildDir",
                      help="Use an existing build directory.")

    parser.add_option(
        "--repotype",
        dest="repoName",
        help='Sets the repository to be fuzzed. Defaults to "%default".')

    parser.add_option("--target-time",
                      dest="targetTime",
                      type="int",
                      help="Nominal amount of time to run, in seconds")

    parser.add_option(
        "-T",
        "--use-treeherder-builds",
        dest="useTreeherderBuilds",
        action="store_true",
        help="Download builds from treeherder instead of compiling our own.")

    # Specify how the shell will be built.
    parser.add_option(
        "-b",
        "--build-options",
        dest="build_options",
        help='Specify build options, e.g. -b "-c opt --arch=32" for js '
        "(python -m funfuzz.js.build_options --help)")

    parser.add_option(
        "--timeout",
        type="int",
        dest="timeout",
        help="Sets the timeout for loop. "
        "Defaults to taking into account the speed of the computer and debugger (if any)."
    )

    options, args = parser.parse_args()
    if args:
        print("Warning: bot does not use positional arguments")

    # pylint: disable=no-member
    if not options.useTreeherderBuilds and not build_options.DEFAULT_TREES_LOCATION.is_dir(
    ):
        # We don't have trees, so we must use treeherder builds.
        options.useTreeherderBuilds = True
        print()
        print("Trees were absent from default location: %s" %
              build_options.DEFAULT_TREES_LOCATION)
        print("Using treeherder builds instead...")
        print()
        sys.exit(
            "Fuzzing downloaded builds is disabled for now, until tooltool is removed. Exiting..."
        )

    if options.build_options is None:
        options.build_options = ""
    if options.useTreeherderBuilds and options.build_options != "":
        raise Exception(
            "Do not use treeherder builds if one specifies build parameters")

    return options
Пример #44
0
fileHandler = logging.FileHandler(logfile)
fileHandler.setLevel(logging.INFO)
fileHandler.setFormatter(logging.Formatter("%(asctime)s\tpid#%(process)d\t%(levelname)s - %(message)s"))
logger.addHandler(fileHandler)
consoleHandler = logging.StreamHandler()
consoleHandler.setLevel(logging.INFO)
consoleHandler.setFormatter(logging.Formatter("%(asctime)s\tpid#%(process)d\t%(filename)s\n%(message)s"))
logger.addHandler(consoleHandler)

logger.info("begin execute... %s" % str(sys.argv))

#参数解析
usageinfo = "%prog [--date=statisdate] [-v]"
verinfo = "%prog v0.0.1"
parser = OptionParser(usage=usageinfo, version=verinfo)
parser.set_defaults(statisdate=(datetime.datetime.strptime(rundate,"%Y%m%d")+datetime.timedelta(days=-1)).strftime("%Y%m%d"))
parser.add_option("-d", "--date", dest="statisdate", help="statis date, yyyy-mm-dd or yyyymmdd", metavar="DATE")
parser.add_option("-a", "--action", dest="actioncode", help="action code. AAAAA[,BBBBB[,...]]", metavar="STRING")
parser.add_option("-v", "--verbose", action="store_true", dest="verbosemode", default=False, help="verbose mode", metavar="MODE")

(options, args) = parser.parse_args()
statisdate = options.statisdate.replace('-','')
actioncode = options.actioncode
verbosemode = options.verbosemode

if isdate(statisdate)==False:
  logger.error("unconverted date %s" % statisdate)
  sys.exit(-101)

if actioncode==None:
  logger.error("Action code is missing.")
Пример #45
0
def main(args=None):

    # dechrau
    log.info('peiriant: dechrau')

    # parser = OptionParser(usage="%prog [-v] [-q] [-d] [llinyn] [-i infile] [-o outfile]", version="%prog: fersiwn 1.0", add_help_option=False)
    parser = OptionParser(
        usage="%prog [-v] [-q] [-d] [-p] [-r] [llinyn] [-i infile]",
        version="%prog: fersiwn 0.1",
        add_help_option=False)

    parser.add_option("-d",
                      "--demo",
                      action="store_true",
                      dest="demo",
                      help="showan off")
    parser.add_option("-p",
                      "--penillion",
                      action="store_true",
                      dest="demo_penillion",
                      help="mwy o showan off")
    parser.add_option("-v",
                      "--verbose",
                      action="store_true",
                      dest="verbose",
                      help="allbwn amleiriog")
    parser.add_option("-q",
                      "--quiet",
                      action="store_false",
                      dest="verbose",
                      help="allbwn cryno")
    parser.add_option("-r",
                      "--rhyddiaith",
                      action="store_true",
                      dest="rhyddiaith",
                      help="mewnbwn rhyddiaith")
    parser.add_option("-i", "--input", dest="infile", help="ffeil mewnbwn")
    parser.add_option("-h", "--help", action="help", help="cymorth")
    parser.set_defaults(verbose=True, demo=False, rhyddiaith=False)

    (options, args) = parser.parse_args()

    # dosrannu'r dewisiadau
    llinyn = ''
    if not args:
        args = sys.argv[1:]
    else:
        llinyn = args[0]

    # 1. llinyn unigol neu demos
    if llinyn:
        dad = Dadansoddwr()
        adro = dad.oes_cynghanedd(Llinell(llinyn))
        if options.verbose:
            print adro
        else:
            print lliw.magenta(adro.cynghanedd) + ': ' + llinyn.strip()
        return

    # 2. demos
    if options.demo:
        import demo
        demo.run_demo(verbose=options.verbose)
        return

    if options.demo_penillion:
        import demo_penillion
        demo_penillion.run_demo(verbose=options.verbose)
        return

    # 3. darllen o ffeil
    if options.infile:

        # rhyddiaith (hac, ond ok)
        if options.rhyddiaith:
            with codecs.open(options.infile, "r", "utf-8") as f:
                s = f.read()
            br = s.split('.')
            br = [b.strip() for b in br]
            brawddegau = []
            for b in br:
                if len(b) > 0:
                    brawddegau.append(b + u'.')
            print('----------------------------------------')

            dad = Dadansoddwr()

            for b in brawddegau:
                geiriau = [Gair(s) for s in b.split(' ')]
                ns = 0
                idx_ch = 0
                idx_dd = 1
                rhestr = []
                llinellau = []
                while idx_dd < len(geiriau):
                    while idx_dd < len(geiriau) and sum(
                        [g.nifer_sillau()
                         for g in geiriau[idx_ch:idx_dd]]) < 7:
                        rhestr.append(geiriau[idx_dd])
                        idx_dd = idx_dd + 1
                    while sum(
                        [g.nifer_sillau()
                         for g in geiriau[idx_ch:idx_dd]]) > 7:
                        rhestr.reverse()
                        rhestr.pop()
                        rhestr.reverse()
                        idx_ch = idx_ch + 1
                    if geiriau[idx_dd - 1].llinyn() not in cy.geiriau_gwan:
                        llinellau.append(Llinell(geiriau[idx_ch:idx_dd]))
                    idx_ch = idx_ch + 1
                for llinell in llinellau:
                    adro = dad.oes_cynghanedd(llinell)
                    if not adro.cynghanedd in ['DIM', 'SAL']:
                        if options.verbose:
                            print adro
                        else:
                            print lliw.magenta(
                                adro.cynghanedd) + '\t' + adro.llinell.llinyn(
                                )
            print('----------------------------------------')
            return

        # cerdd
        with open(options.infile) as f:
            rhestr_llinynnau = f.readlines()

        # creu rhestr llinellau
        llinellau = []
        for s in rhestr_llinynnau:
            s.strip()
            if re.search(r'^#', s) or re.search(r'^\s*$', s):
                continue
            llinellau.append(Llinell(s))

        # allbwn
        # if options.verbose:
        # 	print('========================================')
        # 	for llinell in llinellau:
        # 		print llinell.llinyn()
        # 	print('========================================')

        # dadansoddi pob llinell yn unigol (beth am doddeidiau? Mae angen darganfod cysylltnod)
        dad = Dadansoddwr()
        adro_llinellau_unigol = []
        for llinell in llinellau:
            adro = dad.oes_cynghanedd(llinell)
            adro_llinellau_unigol.append(adro)

        # profi mesurau
        dad = DadansoddwrPennill()
        pennill = Pennill(llinellau)
        cyw = dad.oes_cywydd(pennill)
        eng = dad.oes_englyn(pennill)
        cyh = dad.oes_cyhydedd_nawban(pennill)
        hat = dad.oes_hir_a_thoddaid(pennill)

        dosb = None
        if cyw[0]:
            dosb = 'CYW'
            adro = cyw[1]
        elif eng[0]:
            dosb = 'ENG'
            adro = eng[1]
        elif cyh[0]:
            dosb = 'CYH'
            adro = cyh[1]
        elif hat[0]:
            dosb = 'HAT'
            adro = hat[1]
        else:
            dosb = 'DIM'
            adro = adro_llinellau_unigol

        # allbwn
        print('----------------------------------------')
        if dosb:
            print lliw.cyan(dosb)
        if adro:
            for ad in adro:
                if options.verbose:
                    if ad.cynghanedd == 'DIM':
                        print lliw.magenta(ad.cynghanedd)
                        print ad.llinyn_acenion()
                        print ad.llinell.llinyn()
                    else:
                        print ad
                else:
                    ss = ad.cynghanedd + ': ' + ad.llinell.llinyn().strip()
                    if ad.cynghanedd == 'DIM':
                        print lliw.magenta(ss)
                    else:
                        print ss
        print('----------------------------------------')

    # diwedd
    print "hwyl fawr...\n"
    time_str = time.strftime("%Y.%m.%d.%H.%M.%S")
    log.info('peiriant: diwedd')
Пример #46
0
def parse_options(args):
    parser = OptionParser(usage=USAGE, version=VERSION)

    parser.set_defaults(colors = sys.stdout.isatty())
    parser.add_option('-d', '--disable-colors',
                        action = 'store_false', dest = 'colors',
                        help = 'Disable colors even when printing to terminal')
    parser.add_option('-c', '--enable-colors',
                        action = 'store_true', dest = 'colors',
                        help = 'Enable colors even when not printing to terminal')
    parser.add_option('-w', '--write-changes',
                        action = 'store_true', default = False,
                        help = 'write changes in place if possible')
    parser.add_option('-D', '--dictionary',
                        action = 'store', metavar='FILE',
                        default = default_dictionary,
                        help = 'Custom dictionary file that contains spelling '\
                               'corrections. If this flag is not specified '\
                               'then default dictionary "%s" is used.' %
                            default_dictionary)

    parser.add_option('-s', '--summary',
                        action = 'store_true', default = False,
                        help = 'print summary of fixes')

    parser.add_option('-S', '--skip',
                        help = 'Comma-separated list of files to skip. It '\
                               'accepts globs as well. E.g.: if you want '\
                               'codespell to skip .eps and .txt files, '\
                               'you\'d give "*.eps,*.txt" to this option.')

    parser.add_option('-x', '--exclude-file',
                        help = 'FILE with lines that should not be changed',
                        metavar='FILE')

    parser.add_option('-i', '--interactive',
                        action='store', type='int', default=0,
                        help = 'Set interactive mode when writing changes. '  \
                                '0 is the same of no interactivity; 1 makes ' \
                                'codespell ask confirmation; 2 ask user to '  \
                                'choose one fix when more than one is ' \
                                'available; 3 applies both 1 and 2')

    parser.add_option('-q', '--quiet-level',
                        action='store', type='int', default=0,
                        help = 'Bitmask that allows codespell to run quietly. '\
                                '0: the default, in which all messages are '\
                                'printed. 1: disable warnings about wrong '\
                                'encoding. 2: disable warnings about binary '\
                                'file. 4: shut down warnings about automatic '\
                                'fixes that were disabled in dictionary. '\
                                '8: don\'t print anything for non-automatic '\
                                'fixes. 16: don\'t print fixed files.')

    parser.add_option('-e', '--hard-encoding-detection',
                        action='store_true', default = False,
                        help = 'Use chardet to detect the encoding of each '\
                        'file. This can slow down codespell, but is more '\
                        'reliable in detecting encodings other than utf-8, '\
                        'iso8859-1 and ascii.')


    (o, args) = parser.parse_args()

    if not os.path.exists(o.dictionary):
        print('ERROR: cannot find dictionary file!', file=sys.stderr)
        parser.print_help()
        sys.exit(1)

    if not args:
        args.append('.')

    return o, args
Пример #47
0
def checkCommandLineOptions():
    global isQuickMake, QuickMakeParameters, myArgvs, parser, optionList
    myArgvs = sys.argv
    isDontRun = False
    optionList = []
    parser = OptionParser(usage="%prog [options] [<arg1>...]",
                          version="HamsiManager " + uni.version,
                          epilog="""\
Copyright (c) 2010 - 2015 Murat Demir <*****@*****.**> ,
HamsiManager is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.""")
    parser.add_option('-d',
                      '--debug',
                      help='Enable debugging output. '
                      'Chatty',
                      action='store_const',
                      const=logging.DEBUG,
                      dest='loggingLevel')
    optionList.append("d")
    optionList.append("debug")
    parser.add_option('-v',
                      '--verbose',
                      help='Enable informative output',
                      action='store_const',
                      const=logging.INFO,
                      dest='loggingLevel')
    optionList.append("v")
    optionList.append("verbose")
    parser.add_option('--directory',
                      help='The current directory path. '
                      'Example : /home/yourname/someDirectory ')
    optionList.append("directory <directory>")
    parser.add_option(
        '-s',
        '--sFileName',
        help='The setting file name(or path). '
        '"The settings directory path" + "/" + "YourEnteredName" '
        'Example : enteredName.ini ')
    optionList.append("s <settingFile>")
    optionList.append("sFileName <settingFile>")
    parser.add_option('--sDirectoryPath',
                      help='The settings directory path. '
                      'Example : /home/yourname/.HamsiApps/HamsiManager ')
    optionList.append("sDirectoryPath <settingDirectory>")
    parser.add_option('-t',
                      '--tableType',
                      help='Table Type Name. '
                      'Example : "0" for Folder Table '
                      'Example : "1" for File Table '
                      'Example : "2" for Music Table '
                      'Example : "3" for Subfolder Table '
                      'Example : "4" for Cover Table ')
    optionList.append("t <tableTypeNo>")
    optionList.append("tableType <tableTypeNo>")
    parser.add_option('-f',
                      '--fileReNamerType',
                      help='File Renamer Type. '
                      'Example : "Personal Computer" '
                      'Example : "Web Server" '
                      'Example : "Removable Media" ')
    optionList.append("f <fileReNamerTypeNo>")
    optionList.append("fileReNamerType <fileReNamerTypeNo>")
    qmgroup = OptionGroup(parser, "Quick Make Options",
                          "You can make quickly what are you want.")
    qmgroup.add_option('--qmw',
                       help='Are you want to show Quick Make Window. '
                       'Example : "1" or "True" for Yes '
                       'Example : "0" or "False" for No ')
    optionList.append("qmw <o>")
    qmgroup.add_option(
        '--qm',
        help='Are you want to run Quick Make by some parameters?',
        action='store_const',
        const=True)
    optionList.append("qm")
    qmgroup.add_option('--configurator',
                       help='Open Hamsi Manager Configurator',
                       action='store_const',
                       const=True)
    optionList.append("configurator")
    qmgroup.add_option('--plugins',
                       help='Show plugins',
                       action='store_const',
                       const=True)
    optionList.append("plugins")
    qmgroup.add_option('--pack',
                       help='The directory path. '
                       'Example : /home/yourname/someDirectory')
    optionList.append("pack <directory>")
    qmgroup.add_option('--hash',
                       help='The file path. '
                       'Example : /home/yourname/someFile')
    optionList.append("hash <file>")
    qmgroup.add_option('--checkIcon',
                       help='The directory path. '
                       'Example : /home/yourname/someDirectory')
    optionList.append("checkIcon <directory>")
    qmgroup.add_option('--clearEmptyDirectories',
                       help='The directory path. '
                       'Example : /home/yourname/someDirectory')
    optionList.append("clearEmptyDirectories <directory>")
    qmgroup.add_option('--clearUnneededs',
                       help='The directory path. '
                       'Example : /home/yourname/someDirectory')
    optionList.append("clearUnneededs <directory>")
    qmgroup.add_option('--clearIgnoreds',
                       help='The directory path. '
                       'Example : /home/yourname/someDirectory')
    optionList.append("clearIgnoreds <directory>")
    qmgroup.add_option('--emendFile',
                       help='The file path. '
                       'Example : /home/yourname/someFile')
    optionList.append("emendFile <file>")
    qmgroup.add_option('--emendDirectory',
                       help='The directory path. '
                       'Example : /home/yourname/someDirectory')
    optionList.append("emendDirectory <directory>")
    qmgroup.add_option('--emendDirectoryWithContents',
                       help='The directory path. '
                       'Example : /home/yourname/someDirectory')
    optionList.append("emendDirectoryWithContents <directory>")
    qmgroup.add_option('--copyPath',
                       help='The file/directory path. '
                       'Example : /home/yourname/somePath')
    optionList.append("copyPath <fileOrDirectory>")
    qmgroup.add_option('--fileTree',
                       help='The directory path. '
                       'Example : /home/yourname/someDirectory')
    optionList.append("fileTree <directory>")
    qmgroup.add_option('--removeOnlySubFiles',
                       help='The directory path. '
                       'Example : /home/yourname/someDirectory')
    optionList.append("removeOnlySubFiles <directory>")
    qmgroup.add_option('--clear',
                       help='The directory path. '
                       'Example : /home/yourname/someDirectory')
    optionList.append("clear <directory>")
    qmgroup.add_option('--textCorrector',
                       help='The file path. '
                       'Example : /home/yourname/someFile')
    optionList.append("textCorrector <file>")
    qmgroup.add_option('--search',
                       help='The file/directory path. '
                       'Example : /home/yourname/somePath')
    optionList.append("search <fileOrDirectory>")
    dgroup = OptionGroup(
        parser, "Dangerous Options",
        "Caution: use these options at your own risk.  "
        "It is believed that some of them bite.")
    dgroup.add_option('--runAsRoot',
                      help='Are you want to run as root?',
                      action='store_const',
                      const=True)
    optionList.append("runAsRoot")
    optionList.append("+[optionalFileOrDirectory]")
    parser.add_option_group(qmgroup)
    parser.add_option_group(dgroup)
    parser.set_defaults(loggingLevel=logging.WARNING,
                        runAsRoot=False,
                        qm=False,
                        plugins=False)
    options, remainderParameters = parser.parse_args()
    if len(remainderParameters) == 1:
        try:
            uni.setMySetting(
                "lastDirectory",
                uni.trDecode(str(remainderParameters[0]),
                             fu.defaultFileSystemEncoding))
        except:
            uni.setMySetting("lastDirectory", str(remainderParameters[0]))
    if options.directory:
        try:
            uni.setMySetting(
                "lastDirectory",
                uni.trDecode(str(options.directory),
                             fu.defaultFileSystemEncoding))
        except:
            uni.setMySetting("lastDirectory", str(options.directory))
    if options.loggingLevel:
        uni.loggingLevel = options.loggingLevel
    if options.sFileName:
        uni.fileOfSettings = options.sFileName
    if options.sDirectoryPath:
        uni.setPathOfSettingsDirectory(options.sDirectoryPath)
    if options.tableType:
        import Tables

        uni.setMySetting("tableType",
                         Tables.Tables.getThisTableType(options.tableType))
    if options.fileReNamerType:
        uni.setMySetting("fileReNamerType", options.fileReNamerType)
    if options.qm:
        if options.qmw:
            if options.qmw.lower() == "false" or options.qmw == "0":
                uni.setMySetting("isShowQuickMakeWindow", False)
            else:
                uni.setMySetting("isShowQuickMakeWindow", True)
        if options.configurator:
            QuickMakeParameters.append("configurator")
            isQuickMake = True
        elif options.plugins:
            QuickMakeParameters.append("plugins")
            isQuickMake = True
        elif options.pack:
            QuickMakeParameters.append("pack")
            QuickMakeParameters.append(options.pack)
            isQuickMake = True
        elif options.hash:
            QuickMakeParameters.append("hash")
            QuickMakeParameters.append(options.hash)
            isQuickMake = True
        elif options.checkIcon:
            QuickMakeParameters.append("checkIcon")
            QuickMakeParameters.append(options.checkIcon)
            isQuickMake = True
        elif options.clearEmptyDirectories:
            QuickMakeParameters.append("clearEmptyDirectories")
            QuickMakeParameters.append(options.clearEmptyDirectories)
            isQuickMake = True
        elif options.clearUnneededs:
            QuickMakeParameters.append("clearUnneededs")
            QuickMakeParameters.append(options.clearUnneededs)
            isQuickMake = True
        elif options.clearIgnoreds:
            QuickMakeParameters.append("clearIgnoreds")
            QuickMakeParameters.append(options.clearIgnoreds)
            isQuickMake = True
        elif options.emendFile:
            QuickMakeParameters.append("emendFile")
            QuickMakeParameters.append(options.emendFile)
            isQuickMake = True
        elif options.emendDirectory:
            QuickMakeParameters.append("emendDirectory")
            QuickMakeParameters.append(options.emendDirectory)
            isQuickMake = True
        elif options.emendDirectoryWithContents:
            QuickMakeParameters.append("emendDirectoryWithContents")
            QuickMakeParameters.append(options.emendDirectoryWithContents)
            isQuickMake = True
        elif options.copyPath:
            QuickMakeParameters.append("copyPath")
            QuickMakeParameters.append(options.copyPath)
            isQuickMake = True
        elif options.fileTree:
            QuickMakeParameters.append("fileTree")
            QuickMakeParameters.append(options.fileTree)
            isQuickMake = True
        elif options.removeOnlySubFiles:
            QuickMakeParameters.append("removeOnlySubFiles")
            QuickMakeParameters.append(options.removeOnlySubFiles)
            isQuickMake = True
        elif options.clear:
            QuickMakeParameters.append("clear")
            QuickMakeParameters.append(options.clear)
            isQuickMake = True
        elif options.textCorrector:
            QuickMakeParameters.append("textCorrector")
            QuickMakeParameters.append(options.textCorrector)
            isQuickMake = True
        elif options.search:
            QuickMakeParameters.append("search")
            QuickMakeParameters.append(options.search)
            isQuickMake = True
        QuickMakeParameters.append(remainderParameters)
    if options.runAsRoot:
        from Core import Execute

        if uni.isRunningAsRoot() is False:
            strArgvs = []
            for tempArg in sys.argv:
                if (tempArg.find("-runAsRoot") == -1 and tempArg.find(
                        Execute.findExecutablePath("HamsiManager")) == -1
                        and tempArg !=
                        "./" + Execute.findExecutableBaseName("HamsiManager")
                        and tempArg !=
                        Execute.findExecutableBaseName("HamsiManager")):
                    strArgvs.append(tempArg)
            if Execute.executeAsRootWithThread(strArgvs, "HamsiManager"):
                isDontRun = True
    if isDontRun:
        return False
    return True
Пример #48
0
        if cfatnum == topatnum:
            pass
        else:
            raise pymsmtError(
                'The atnum are not consistent between the com file '
                'and toplogy file.')


#==============================================================================
# Setting the variables
#==============================================================================
parser = OptionParser("Usage: AFQMMM_NMR.py -p toplogy_file "
                      "-r coordinate_file -m amber_mask [-w (0 to 3)]")

parser.set_defaults(water=1)

parser.add_option("-p", dest="pfile", help="topology file name")
parser.add_option("-c", dest="cfile", help="coordinate file name")
parser.add_option("-m", dest="mask", help="amber mask of the core residue")
parser.add_option("-w",
                  type='int',
                  dest="water",
                  help="whether delete "
                  "water and ion. 0: no, 1: delete water and ions, 2: "
                  "delete water, 3: delete ions. [default: 1]")
(options, args) = parser.parse_args()

#==============================================================================
# Get the molecule information
#==============================================================================
Пример #49
0
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options ', description = """
Creates unit cell including slip planes and directions for visualization

""", version = scriptID)

parser.add_option('-r', '--radians',
                  dest = 'degrees',
                  action = 'store_true',
                  help = 'angles are given in degrees [%default]')
parser.add_option('-e', '--eulers',
                  dest='eulers',
                  type = 'float', nargs = 3, metavar = ' '.join(['float']*3),
                  help = 'crystallographic orientation as euler angles')

parser.set_defaults(eulers  = (0.,0.,0.),                                                   # no rotation about 1,1,1
                    radians = False)

(options, filenames) = parser.parse_args()

eulers=np.array(options.eulers)
if not options.radians: eulers*=(np.pi/180.)

ori = damask.Orientation(matrix=np.dot(np.array([[0.0,-1.0,0.0],[-1.0,0.0,0.0],[0.0,0.0,-1.0]]),
                                       damask.Orientation(Eulers=eulers).asMatrix()))
ori=damask.Orientation()
coordinates=[]
for x in np.linspace(-0.5,0.5,3):
  for y in np.linspace(-0.5,0.5,3):
    for z in np.linspace(-0.5,0.5,3):
      coordinates.append([x,y,z])
coordinates=np.array(coordinates)
Пример #50
0
        a for a in actions
        if not action_module.__dict__['action_%s' % a].__doc__
    ])
    action_help = actions_with_help
    if action_without_help:
        action_help += "\nOther supported actions:\n" + \
            textwrap.TextWrapper(initial_indent='  ', subsequent_indent='    ').fill(action_without_help)
    parser = OptionParser("""%%prog [options] action [action ...]

Supported actions:
%s""" % action_help)

    parser.set_defaults(
        hosts=[],
        roles=[],
        concurrency=1,
        show_list=False,
        all_masters=False,
        ignored_roles=[],
    )
    parser.add_option("-f",
                      "--master-file",
                      dest="master_file",
                      help="list/url of masters")
    parser.add_option("-H", "--host", dest="hosts", action="append")
    parser.add_option("-R", "--role", dest="roles", action="append")
    parser.add_option("-M",
                      "--match",
                      dest="match",
                      action="append",
                      help="masters that match the term")
    parser.add_option("-j", dest="concurrency", type="int")
Пример #51
0
        f.write("  <Attribute Name='cellCentroids' Center='Cell'>\n")
        f.write("    <DataItem Dimensions='%s'>" % ncell)
        for i in range(0,ncell):
            if ( i % 5  == 0 ):
                f.write("\n      ")
            f.write("%s " % cellCentroids[n][i][1])
        f.write("\n")
        f.write("    </DataItem>\n")     
        f.write("  </Attribute>\n")

        f.write("</Grid>\n")
    f.close()


parser = OptionParser()
parser.set_defaults(type='tri')
parser.add_option("--type", help="'tri'[default], 'quad', 'hexa', or 'tetra'")
parser.add_option("--xdmf", action='store_true', help="Dump data in xdmf")
parser.add_option("--time","-t",action='store_true',help="Print timing information.")
(options, args) = parser.parse_args()
if len(args) != 1:
    usage()

numIterations = 10
#import ddd
reader = FluentCase(args[0])
reader.read()
fluent_meshes = reader.getMeshList()

#assembling meshes
mesh_assembler = fvmbaseExt.MeshAssembler( fluent_meshes )
Пример #52
0
""",
                      version=scriptID)

parser.add_option('-l',
                  '--label',
                  dest='keys',
                  action='extend',
                  metavar='<string LIST>',
                  help='list of column labels (a,b,c,...)')
parser.add_option('-r',
                  '--reverse',
                  dest='reverse',
                  action='store_true',
                  help='sort in reverse')

parser.set_defaults(reverse=False, )

(options, filenames) = parser.parse_args()

# --- loop over input files -------------------------------------------------------------------------

if filenames == []: filenames = [None]

for name in filenames:
    try:
        table = damask.ASCIItable(name=name, buffered=False)
    except:
        continue
    damask.util.report(scriptName, name)

    # ------------------------------------------ assemble header ---------------------------------------
Пример #53
0
def parse_arguments(argv):
    """
    Parse arguments for script input

    Args:
      argv (list): List of strings giving command line arguments
    """
    # Setup options
    parser = OptionParser(usage="%prog [options] TARGET")
    parser.add_option(
        "-b",
        "--basedir",
        dest="basedir",
        metavar="BASEDIR",
        help="If provided, use this as the base for all relative paths."
        "The default is the current working directory.")
    parser.add_option("-e",
                      "--exe",
                      dest="exe",
                      metavar="EXEPATH",
                      help="If provided, use this as the executable path."
                      "Default is to simply call 'pylint'")
    parser.add_option("-f", "--format", dest="format", metavar = "FORMAT",
                      help="If provided, use the given format type "\
                           "[default=%s]. Options are: text, html, msvs, "\
                           "parseable" % DEFAULT_PYLINT_FORMAT)
    parser.add_option(
        "-m",
        "--mantidpath",
        dest="mantidpath",
        metavar="MANTIDPATH",
        help="If provided, use this as the MANTIDPATH, overriding"
        "anything that is currently set.")
    parser.add_option(
        "-n",
        "--nofail",
        action="store_true",
        dest="nofail",
        help="If specified, then script will always return an exit status of 0."
    )
    parser.add_option("-r",
                      "--rcfile",
                      dest="rcfile",
                      metavar="CFG_FILE",
                      help="If provided, use this configuration file "
                      "instead of the default one")
    parser.add_option("-o",
                      "--output",
                      dest="output",
                      metavar="FILE",
                      help="If provided, store the output in the given file.")
    parser.add_option("-x",
                      "--exclude",
                      dest="exclude",
                      metavar="EXCLUDES",
                      help="If provided, a space-separated list of "
                      "files/directories to exclude. Relative paths are "
                      "taken as relative to --basedir")

    parser.set_defaults(format=DEFAULT_PYLINT_FORMAT,
                        exe=DEFAULT_PYLINT_EXE,
                        nofail=False,
                        basedir=os.getcwd(),
                        rcfile=DEFAULT_RCFILE,
                        exclude="")

    options, args = parser.parse_args(argv)
    if len(args) < 1:
        print("ERROR: Incorrect number of arguments '%s'" % args)
        print()
        parser.print_help()
        sys.exit(1)

    # rcfile needs to be absolute
    if options.rcfile is not None and not os.path.isabs(options.rcfile):
        options.rcfile = os.path.join(os.getcwd(), options.rcfile)
    # exclude option is more helpful as a list
    options.exclude = options.exclude.split()

    return options, args
Пример #54
0
                      "--start-time",
                      dest="start_time",
                      type="int",
                      help="timestamp for when we start looking at data")
    parser.add_option("",
                      "--catchup",
                      dest="catchup",
                      action="store_true",
                      help="Don't output any warnings, just process data")

    parser.set_defaults(
        branches=[],
        tests=[],
        start_time=time.time() - 30 * 24 * 3600,
        verbosity=log.INFO,
        output=None,
        json=None,
        addresses=[],
        machine_addresses=[],
        config="analysis.cfg",
        catchup=False,
    )

    options, args = parser.parse_args()

    config = RawConfigParser()
    config.add_section('main')
    config.add_section('cache')
    # Set some defaults
    config.set('cache', 'warning_history', 'warning_history.json')
    config.set('cache', 'pushlog', 'pushlog.json')
    config.set('cache', 'last_run_file', 'lastrun.txt')
Пример #55
0
parser.add_option(
    '-p',
    '--stress',
    dest='stress',
    type='string',
    metavar='string',
    help=
    'heading of columns containing first Piola--Kirchhoff stress [%default]')
parser.add_option('--compress',
                  action='store_false',
                  dest='compress',
                  help='compress the presion of the output data [%default]')

parser.set_defaults(
    defgrad='f',
    stress='p',
    compress=True,
)

(options, filenames) = parser.parse_args()

# --- loop over input files -------------------------------------------------------------------------

if filenames == []: filenames = [None]

for name in filenames:
    try:
        table = damask.ASCIItable(name=name, buffered=False)
    except:
        continue
    damask.util.report(scriptName, name)
Пример #56
0
#!/usr/bin/evn python

import sys
from optparse import OptionParser
from atoms import Atoms
from vasp import read_vasp
from pyspglib import spglib
import numpy as np

parser = OptionParser()
parser.set_defaults(mesh=None, qpoints=None)
parser.add_option("-m",
                  "--mesh",
                  dest="mesh",
                  type="string",
                  help="Mesh numbers")
parser.add_option("-q",
                  "--qpoints",
                  dest="qpoints",
                  type="string",
                  help="Stabilizers")
(options, args) = parser.parse_args()

if options.mesh == None:
    mesh = [4, 4, 4]
else:
    mesh = [int(x) for x in options.mesh.split()]

if options.qpoints == None:
    qpoints = np.array([[0, 0, 0]], dtype=float)
else:
Пример #57
0
def main():
    '''asxxxx to gb map file converter'''
    usage = "usage: %prog [options] [<input_asxxxx_map_file> [<output_gb_file>]]"
    parser = OptionParser(usage=usage, version="1.0")
    parser.set_defaults(no_gmb=False)
    parser.add_option("-j",
                      "--no$gmb",
                      action="store_true",
                      dest="no_gmb",
                      help="generate no$gmb symbol file (default: rrgb)")
    (options, args) = parser.parse_args()

    if len(args) > 0 and args[0] != "-":
        try:
            fin = open(args[0], "r")
        except IOError as xxx_todo_changeme:
            (errno, strerror) = xxx_todo_changeme.args
            print("%s: can't open %s: %s" %
                  (os.path.basename(sys.argv[0]), args[0], strerror),
                  file=sys.stderr)
            return 1
    else:
        fin = sys.stdin

    if len(args) > 1 and args[1] != "-":
        try:
            fout = open(args[1], "w")
        except IOError as xxx_todo_changeme1:
            (errno, strerror) = xxx_todo_changeme1.args
            print("%s: can't create %s: %s" %
                  (os.path.basename(sys.argv[1]), args[1], strerror),
                  file=sys.stderr)
            return 1
    else:
        fout = sys.stdout

    areas = []
    modules = []
    libraries = []
    ubads = []

    radix = 'HEX'
    state = None
    area = None

    # process asxxxx map file
    for line in fin:
        if re.match(r"^Hexadecimal$", line):
            radix = 'HEX'
            continue

        if re.match(r"^Area +Addr +Size +Decimal +Bytes +\(Attributes\)$",
                    line):
            line = next(fin)
            if re.match(r"^[- ]+$", line):
                line = next(fin)
                m = re.match(
                    r"^([^ ]+) +([0-9A-Fa-f]{4}) +([0-9A-Fa-f]{4}) += +\d+\. +\w+ +\(([^\)]+)\)$",
                    line)
                if m:
                    if area:
                        if m.group(1) != area['area']:
                            areas.append(area)
                            area = {
                                'area': m.group(1),
                                'radix': radix,
                                'base': int(m.group(2), 16),
                                'size': int(m.group(3), 16),
                                'attrib': m.group(4).replace(',', ' '),
                                'globals': []
                            }
                    else:
                        area = {
                            'area': m.group(1),
                            'radix': radix,
                            'base': int(m.group(2), 16),
                            'size': int(m.group(3), 16),
                            'attrib': m.group(4).replace(',', ' '),
                            'globals': []
                        }
                    state = 'IN_AREA'
            continue

        m = re.match(r"^ +([0-9A-Fa-f]{4}) +([^ ]+) +$", line)
        if state == 'IN_AREA' and m:
            area['globals'].append({
                'value': int(m.group(1), 16),
                'global': m.group(2)
            })
            continue

        m = re.match(r"Files Linked +\[ module\(s\) \]$", line)
        if m:
            state = 'IN_MODULES'
            continue

        m = re.match(r"Libraries Linked +\[ object file \]$", line)
        if m:
            state = 'IN_LIBRARIES'
            continue

        m = re.match(r"User Base Address Definitions$", line)
        if m:
            state = 'IN_UBAD'
            continue

        m = re.match(r"^([^ ]+) +\[ ([^ ]*) \]$", line)
        if m:
            if state == 'IN_MODULES':
                modules.append({'file': m.group(1), 'name': m.group(2)})
                continue

            if state == 'IN_LIBRARIES':
                libraries.append({'library': m.group(1), 'module': m.group(2)})
                continue

        m = re.match(r"^([^ ]+) += +0x([0-9A-Fa-f]{4})$", line)
        if state == 'IN_UBAD' and m:
            ubads.append({'symbol': m.group(1), 'value': m.group(2)})
            continue

    if area:
        areas.append(area)

    if options.no_gmb:
        # generate no$gmp map file
        print('; no$gmb format .sym file', file=fout)
        print('; Generated automagically by %s' %
              os.path.basename(sys.argv[0]),
              file=fout)
        for e in areas:
            print('; Area: %s' % e['area'], file=fout)
            if e['globals']:
                e['globals'].sort(key=operator.itemgetter('value'))
                for g in e['globals']:
                    if g['global'][0:3] != 'l__':
                        if g['value'] > 0x7FFF:
                            print('00:%04X %s' % (g['value'], g['global']),
                                  file=fout)
                        else:
                            print(
                                '%02X:%04X %s' %
                                (g['value'] // 16384, g['value'], g['global']),
                                file=fout)
    else:
        # generate rrgb map file
        for e in areas:
            print('AREA %s' % e['area'], file=fout)
            print('\tRADIX %s' % e['radix'], file=fout)
            print('\tBASE %04X' % e['base'], file=fout)
            print('\tSIZE %04X' % e['size'], file=fout)
            print('\tATTRIB %s' % e['attrib'], file=fout)
            if e['globals']:
                e['globals'].sort(key=operator.itemgetter('value'))
                print('\tGLOBALS', file=fout)
                for g in e['globals']:
                    print('\t\t%s\t%04X' % (g['global'], g['value']),
                          file=fout)

        if modules:
            print('MODULES', file=fout)
            for m in modules:
                print('\tFILE %s' % m['file'], file=fout)
                if m['name']:
                    print('\t\tNAME %s' % m['name'], file=fout)

        if libraries:
            print('LIBRARIES', file=fout)
            for m in libraries:
                print('\tLIBRARY %s' % m['library'], file=fout)
                print('\t\tMODULE %s' % m['module'], file=fout)

        if ubads:
            print('USERBASEDEF', file=fout)
            for m in ubads:
                print('\t%s = 0x%04X' % (m['symbol'], int(m['value'], 16)),
                      file=fout)
        return 0
Пример #58
0
                     number_h + 8)
            ctx.set_source_rgb(1, 1, 1)
            ctx.fill()

            ctx.set_source_rgb(0, 0, 0)
            ctx.move_to(offset_x, offset_y)
            ctx.show_text(number)

    ctx.show_page()


parser = OptionParser()

parser.set_defaults(bounds=(37.81211263, -122.26755482, 37.80641650,
                            -122.25725514),
                    zoom=16,
                    paper_size='letter',
                    orientation='landscape',
                    provider='http://tile.openstreetmap.org/{Z}/{X}/{Y}.png')

papers = 'a3 a4 letter'.split()
orientations = 'landscape portrait'.split()

parser.add_option('-s',
                  '--paper-size',
                  dest='paper_size',
                  help='Choice of papers: %s.' % ', '.join(papers),
                  choices=papers)

parser.add_option('-o',
                  '--orientation',
                  dest='orientation',
Пример #59
0
def main():
    usage = "usage: %prog [ options ] COMMAND product [ filename ... ]"
    description = "Operate on artifacts stored in a product bucket.  " + \
        "Valid commands are 'get', 'put' and 'list'.  You may optionally " + \
        "store the objects in a separate section of the bucket for " + \
        "classification (e.g. for different environments)."
    parser = OptionParser(usage=usage,
                          description=description,
                          version=None,
                          target=None)
    parser.set_defaults(quiet=False, prefix='', section='')
    parser.add_option("-c",
                      "--config",
                      dest="config",
                      default="artifacts.ini",
                      metavar="FILE",
                      help="read config from FILE")
    parser.add_option("-b",
                      "--bucket",
                      dest="bucket",
                      metavar="BUCKET",
                      help="use S3 bucket BUCKET")
    parser.add_option("-p",
                      "--prefix",
                      dest="prefix",
                      metavar="PREFIX",
                      help="Store artifacts prefixed with path PREFIX")
    parser.add_option("",
                      "--access-key",
                      dest="access_key",
                      help="S3 access key")
    parser.add_option("",
                      "--secret-key",
                      dest="secret_key",
                      help="S3 secret key")
    parser.add_option("-v",
                      "--version",
                      dest="version",
                      help="specify artifact version")
    parser.add_option(
        "-s",
        "--section",
        dest="section",
        metavar="SECTION",
        help="Store objects in subsection SECTION of the product bucket.")
    parser.add_option("-t",
                      "--target",
                      dest="target",
                      metavar="FILENAME",
                      help="Use FILENAME for destination")
    parser.add_option("-q",
                      "--quiet",
                      dest="quiet",
                      action="store_true",
                      help="execute quietly")

    (options, args) = parser.parse_args()

    config = configobj.ConfigObj(options.config)

    for option in parser.defaults.keys():
        if getattr(options, option):
            config[option] = getattr(options, option)

    missing_opts = []
    for option in ['bucket', 'access_key', 'secret_key', 'product']:
        if not option in config:
            missing_opts.append(option)
    if missing_opts:
        log.error("Missing configuration: %s", ", ".join(missing_opts))
        sys.exit(1)

    if len(args) < 1:
        log.error("No product specified.  A product is a grouping of " +
                  "artifacts in your artifact store.")
        sys.exit(1)

    config['product'] = args[0]
    args = args[1:]

    if len(args) < 1:
        log.error("Must specify a command: get, put or list")
        sys.exit(1)

    command = args[0].lower()
    args = args[1:]

    if command != 'list':
        if len(args) < 1:
            log.error("You must specify filenames for 'get' or 'put'")
            sys.exit(1)
        if config.get('target') and len(args) > 1:
            log.error(
                "Cannot specify a target filename when %sting " +
                "multiple files", command)
            sys.exit(1)

    if not config['quiet']:
        log.setLevel(logging.INFO)

    a = artifacts.S3Artifacts(config['bucket'], config['access_key'],
                              config['secret_key'], config['prefix'])
    if command == 'put':
        for f in args:
            log.info("Uploading %s.", f)
            a.upload(f, config['product'], config['section'],
                     config['version'], config['target'], config['quiet'])

    if command == 'list':
        for f in args:
            vs = a.get_versions(f, config['product'], config['section'])
            for v in vs:
                print "%s : %s (external version %s) at %s" % (
                    base64.b64encode(v.version_id + " " *
                                     ((3 - len(v.version_id) % 3) % 3)),
                    v.name, v.get_metadata('version'), v.last_modified)

    if command == 'put':
        for f in args:
            log.info("Downloading %s.", f)
            a.download(f, config['product'], config['section'],
                       config['version'], config['target'], config['quiet'])
Пример #60
0
parser.add_option('-c','--coordinates',
                  dest = 'pos', metavar = 'string',
                  help = 'column label of coordinates [%default]')
parser.add_option('-p','--packing',
                  dest = 'packing', type = 'int', nargs = 3, metavar = 'int int int',
                  help = 'dimension of packed group [%default]')
parser.add_option('-g','--grid',
                  dest = 'resolution', type = 'int', nargs = 3, metavar = 'int int int',
                  help = 'resolution in x,y,z [autodetect]')
parser.add_option('-s','--size',
                  dest = 'dimension', type = 'float', nargs = 3, metavar = 'int int int',
                  help = 'dimension in x,y,z [autodetect]')
parser.set_defaults(pos  = 'pos',
                    packing = (2,2,2),
                    grid    = (0,0,0),
                    size    = (0.0,0.0,0.0),
                   )

(options,filenames) = parser.parse_args()

options.packing = np.array(options.packing)
prefix = 'blowUp{}x{}x{}_'.format(*options.packing)

# --- loop over input files -------------------------------------------------------------------------

if filenames == []: filenames = [None]

for name in filenames:
  try:    table = damask.ASCIItable(name = name,
                                    outname = os.path.join(os.path.dirname(name),