Пример #1
0
def parse_cmdline():
    """
    parse_cmdline parses supplied options and returns them
    @return parsed options and args
    """
    parser = OptionParser(usage=USAGE)
    parser.add_option('-t', '--target', dest='target', action='store',
                      type='string', help='MDT name to monitor, \
                      <fsname>-MDT<index> default: %default',
                      default='scratch-MDT0000')
    parser.add_option('--no-header', dest='noheader', action='store_true',
                      help='Don\'t print header, default: %default',
                      default=False)
    parser.add_option('--table', dest='table', action='store_true',
                      help='Print values as a table, default: %default',
                      default=False)
    parser.add_option('--csv', dest='csv', action='store_true',
                      help='Print values in CSV format, default: %default',
                      default=False)
    parser.add_option('-i', '--intreval', dest='interval', action='store',
                      type='int', help='Statistics print interval in seconds, \
                      default: %default', default=1)
    parser.add_option('-c', '--count', dest='count', action='store', type='int',
                      help='Number of iteration', default=0)
    parser.add_option('--header-repeat', dest='hrepeat', action='store', \
                      type='int', help='Repeat header each X lines', default=0)

    (options, args) = parser.parse_args()

    if not options.interval > 0:
        parser.error("interval must be greater than 0 !")

    parser.destroy()

    return options, args
Пример #2
0
  def __init__(self):
    usage = "--user <user-name> [--host <host-name>] [--port <port>]"
    parser = OptionParser()
    parser.set_usage(usage)
    parser.add_option("-u", "--user", dest="user", help="DataHub username")
    parser.add_option("-H", "--host", dest="host", help="DataHub server hostname", default="datahub-experimental.csail.mit.edu")
    parser.add_option("-p", "--port", dest="port", help="DataHub server port", type="int", default=9000)
    (options, args) = parser.parse_args()

    if not options.user:
      parser.print_usage()
      sys.exit(1)

    parser.destroy()
    password = getpass.getpass('DataHub password for %s: ' %(options.user))
    cmd2.Cmd.__init__(self, completekey='tab')
    transport = TSocket.TSocket(options.host, options.port)
    self.transport = TTransport.TBufferedTransport(transport)
    protocol = TBinaryProtocol.TBinaryProtocol(self.transport)
    self.client = DataHub.Client(protocol)
    self.transport.open()
    try:
      self.con_params = DHConnectionParams(
          user=options.user,
          password=password)
      self.con = self.client.connect(self.con_params)
      self.prompt = "datahub> "
    except Exception, e:
      self.print_line('error: %s' % (e.message))
      sys.exit(1)
Пример #3
0
  def __init__(self):
    usage = "--user <user-name> [--database <database-name>] [--host <host-name>] [--port <port>]"
    parser = OptionParser()
    parser.set_usage(usage)
    parser.add_option("-u", "--user", dest="user", help="DataHub username")
    parser.add_option("-H", "--host", dest="host", help="DataHub server hostname", default="datahub-experimental.csail.mit.edu")
    parser.add_option("-p", "--port", dest="port", help="DataHub server port", type="int", default=9000)
    parser.add_option("-d", "--database", dest="database", help="DataHub database")
    (self.options, self.arg_values) = parser.parse_args()

    if not self.options.user:
      parser.print_usage()
      sys.exit(1)

    parser.destroy()
    self.password = getpass.getpass('DataHub password for %s: ' %(self.options.user))
    cmd2.Cmd.__init__(self, completekey='tab')
    self.client = DataHubClient(host=self.options.host, port=self.options.port)
    try:
      database = None
      if self.options.database:
        database=DHDatabase(name=self.options.database)
      con_params = DHConnectionParams(
          user=self.options.user,
          password=self.password,
          database=database)
      self.con = self.client.connect(con_params)
      self.prompt = "datahub> "
    except Exception, e:
      self.print_line('error: %s' % (e.message))
      sys.exit(1)
Пример #4
0
    def __init__(self, argv):
        parser = OptionParser(usage=PachuLog.USAGE)
        parser.add_option('-a', dest='api', type='string',
                          help='the api address, /api/1275.xml')
        parser.add_option('-k', dest='key', type='string',
                          help='personal api key')
        parser.add_option('-i', dest='interval', type='float', default=5,
                          help='update interval in minutes')
        parser.add_option('--src', dest='src', type='string', default='/dev/ttyUSB0',
                          help='the source of data')
        (options, args) = parser.parse_args(argv)        
        if len(args) != 1:
            parser.error('Exactly one argument required')
        if args[0] not in ['start', 'stop']:
            parser.error('Argument must be start/stop')
        if not options.api:
            parser.error('Api address required')
        if not options.key:
            parser.error('Api key required')
        parser.destroy()

        daemon = PachuDaemon(options.api, options.key, options.src, options.interval)
        if args[0] == 'start':
            print 'starting'
            daemon.start()
        elif args[0] == 'stop':
            print 'stopping'
            daemon.stop()
Пример #5
0
    def __init__(self):
        usage = "--user <user-name> [--host <host-name>] [--port <port>]"
        parser = OptionParser()
        parser.set_usage(usage)
        parser.add_option("-u", "--user", dest="user", help="databse username")
        parser.add_option("-H",
                          "--host",
                          dest="host",
                          help="database hostname",
                          default="localhost")
        parser.add_option("-p",
                          "--port",
                          dest="port",
                          help="database port",
                          type="int",
                          default=5432)
        (options, args) = parser.parse_args()

        if not options.user:
            parser.print_usage()
            sys.exit(1)

        parser.destroy()
        password = getpass.getpass('password: '******'tab')

        try:
            self.con = Connection(user=options.user, password=password)
            self.prompt = "datahub> "
        except Exception, e:
            self.print_line('error: %s' % (e.message))
            sys.exit(1)
Пример #6
0
def parse_options():
    parser = OptionParser(usage='usage: %prog [options] <input>',
                          version='%prog 0.0')
    parser.add_option('-y',
                      '--arch',
                      help='the CPU architecture. Default to "armv7".',
                      default="armv7")
    parser.add_option(
        '-o',
        '--output',
        help=
        'output file. If not supplied, the result will be written to "<input>.o".',
        metavar='FILE')
    parser.add_option('-a',
                      '--address',
                      help='VM address this file should map to. Default to 0',
                      default='0',
                      metavar='VMADDR')
    (options, args) = parser.parse_args()

    if not args:
        parser.error('Please supply the input filename.')

    inputfn = args[0]
    outputfn = options.output or args[0] + ".o"
    vmaddr = int(options.address, 16)

    parser.destroy()

    return (options.arch, inputfn, outputfn, vmaddr)
Пример #7
0
def ParseArgs(argv):
   _CMD_OPTIONS_LIST = [
      make_option("-h", "--host", dest="host", default="localhost",
                  help="Host name"),
      make_option("-u", "--user", dest="user", default="root",
                  help="User name"),
      make_option("-p", "--pwd", dest="pwd", default="",
                  help="Password"),
      make_option("-n", "--vmname", dest="vmname", default="QuestionTest",
                  help="Virtual machine name"),
      make_option("-v", "--verbose", dest="verbose", action="store_true",
                  default=False, help="Enable verbose logging"),
      make_option("-i", "--iterations", dest="iter", type="int",
                  default=1, help="Number of iterations"),
      make_option("-?", "--help", action="store_true", help="Help"),
   ]
   _STR_USAGE = "%prog [options]"

   # Get command line options
   cmdParser = OptionParser(option_list=_CMD_OPTIONS_LIST,
                            usage=_STR_USAGE,
                            add_help_option=False)
   cmdParser.allow_interspersed_args = False
   usage = cmdParser.format_help()

   # Parse arguments
   (options, remainingOptions) = cmdParser.parse_args(argv)
   cmdParser.destroy()

   # Print usage
   if options.help:
      print(usage)
      sys.exit(0)
   return (options, remainingOptions)
Пример #8
0
Файл: gpl.py Проект: am0d/bit
class GPL(Harbinger):
    def __init__(self):
        Harbinger.__init__(self)
        if not gc.isenabled():
            gc.enable()
        self.project_dict = {}
        self.project_list = []
        self.parser = OptionParser(conflict_handler="resolve")
        self.parser.add_option(
            "-n", "--no-color", action="store_true", dest="no_color", default=False, help="Text does not use colors"
        )
        self.parser.add_option(
            "-s",
            "--sequential",
            action="store_true",
            dest="sequential",
            default=False,
            help="Run projects one at a time",
        )
        self.parser.add_option(
            "-q", "--quiet", action="store_true", dest="quiet", default=False, help="Minimal Information Printed"
        )
        self.parser.add_option(
            "-a",
            "--hash",
            action="store",
            type="string",
            dest="hash_type",
            default="md5",
            help="Which hash algorithm to use.",
        )

    def run(self):
        self.options, self.args = self.parser.parse_args()
        self.parser.destroy()  # We don't need the actual parser anymore
        for project in self.project_list:
            if self.options.sequential:
                project.run()
            else:
                project.start()
        while threading.active_count < 1:
            time.sleep(1)

    def project(self, *instances):
        for instance in instances:
            self.project_list.append(instance)
            self.project_dict["{1}|{0}".format(instance.project_name, instance.name)] = instance

    def path(self, *directories):
        path_list = []
        directories = flatten(list(directories))
        for path in os.environ["PATH"].split(os.pathsep):
            path_list.append(path)
        for directory in directories:
            path_list.append(directory)
        path_list = os.pathsep.join(path_list)
        os.environ["PATH"] = path_list
Пример #9
0
def getOptions(arg):
    usage = 'usage: %prog [options -t=<table name>]'
    parser = OptionParser(usage)
    parser.add_option('-t', '--table', dest='table', type='string', metavar='name',
            help='Table to be extracted')
    parser.add_option('-c', '--config', dest='config', type='string', metavar='name',
            help='Config file name')
    (options, arg) = parser.parse_args(arg)
    parser.destroy()
    return (options, arg)  
Пример #10
0
def main(argv):
    parser = OptionParser(
        conflict_handler='resolve')  # Intelligently resolve switch collisions
    parser.set_defaults(verbose=False,
                        filters_to_run=[],
                        packages=BuiltInPackages)

    # If any library loading switches (-l) are given, collect their names and remove them from argv
    argv, user_defined_libraries = filter_library_switches(argv)
    argv, autoloaded_libraries = filter_autoload_paths(argv)

    # Load built-in filters (those under BuiltInPackages)
    # Load user-requested filters (passed by -l on the command line)
    all_libraries = BuiltInPackages + user_defined_libraries + autoloaded_libraries
    tracer = TraceCore(libraries=all_libraries)

    # For each available filter, allow it to be invoked with switches on the command line
    for filter in tracer.available_filters_dict.values():
        add_filter_to_optparser(parser, filter)
    # Load built-in optparse switches
    register_builtin_switches(parser)

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

    # Perform option parse, check for user-requested filter classes
    opts, remaining_args = parser.parse_args(argv)
    # Done with parser
    parser.destroy()

    if opts.debug:
        config.set(debug=True)

    # Set verbose switch if given on command line
    tracer.verbose = opts.verbose
    tracer.break_on_exception = opts.break_on_exception

    # Set override Reader if given on command line
    tracer.reader_class_name = opts.reader_class_name

    # Take remaining arguments as input file names
    files = remaining_args[1:]  # remaining_args[0] seems to be sys.argv[0]

    # If switch -L was passed, dump out all available filter names and quit
    if opts.do_list_filters:
        tracer.list_filters()
        sys.exit(0)

    # Run requested filters
    try:
        tracer.run(opts.filters_to_run, files)
    except RuntimeError, e:
        err('RuntimeError: %s', e)
        sys.exit(1)
Пример #11
0
def ParseArguments(argv):
   """ Parse arguments """

   from optparse import OptionParser, make_option

   testHelp = """ """

   # Internal cmds supported by this handler
   _CMD_OPTIONS_LIST = [
      make_option("-h", "--host", dest="host", default="localhost",
                  help="ESX host name"),
      make_option("-o", "--port", dest="port", default=443, help="Port"),
      make_option("-u", "--user", dest="user", default="root",
                  help="Host User name"),
      make_option("-p", "--pwd", dest="pwd", default="",
                  help="Host Password"),
      make_option("-k", "--key", dest="keyFile", default=None,
                  help="Key file path"),
      make_option("-c", "--cert", dest="certFile", default=None,
                  help="Cert file path"),
      make_option("-w", "--workers", dest="workers", type="int",
                  default=8, help="Num of workers"),
      make_option("-s", "--waitSec", dest="waitSec", type="int",
                  default=8, help="Num of sec to wait"),
      make_option("-n", "--numPCUpdates", dest="numWaitUpdate", type="int",
                  default=2, help="Num of pc wait for updates"),
      make_option("-v", "--verbose", action="store_true", dest="verbose_stats",
                  default=False, help="Enable verbose stats"),
      make_option("-?", "--help", action="store_true", help="Help"),
   ]
   _STR_USAGE = "%prog [options]"

   # Get command line options
   cmdParser = OptionParser(option_list=_CMD_OPTIONS_LIST,
                            usage=_STR_USAGE,
                            add_help_option=False)
   cmdParser.allow_interspersed_args = False
   usage = cmdParser.format_help()

   # Parse arguments
   (options, remainingOptions) = cmdParser.parse_args(argv)
   try:
      # optparser does not have a destroy() method in older python
      cmdParser.destroy()
   except Exception:
      pass
   del cmdParser

   # Print usage
   if options.help:
      print(usage)
      print(testHelp)
      sys.exit(0)

   return (options, remainingOptions)
Пример #12
0
def parse_cmdline():
    """
    parse_cmdline parses supplied options and returns them
    @return parsed options and args
    """
    parser = OptionParser(usage=USAGE)
    parser.add_option('-t',
                      '--target',
                      dest='target',
                      action='store',
                      type='string',
                      help='MDT name to monitor, \
                      <fsname>-MDT<index> default: %default',
                      default='scratch-MDT0000')
    parser.add_option('--no-header',
                      dest='noheader',
                      action='store_true',
                      help='Don\'t print header, default: %default',
                      default=False)
    parser.add_option('--table',
                      dest='table',
                      action='store_true',
                      help='Print values as a table, default: %default',
                      default=False)
    parser.add_option('--csv',
                      dest='csv',
                      action='store_true',
                      help='Print values in CSV format, default: %default',
                      default=False)
    parser.add_option('-i',
                      '--intreval',
                      dest='interval',
                      action='store',
                      type='int',
                      help='Statistics print interval in seconds, \
                      default: %default',
                      default=1)
    parser.add_option('-c',
                      '--count',
                      dest='count',
                      action='store',
                      type='int',
                      help='Number of iteration',
                      default=0)
    parser.add_option('--header-repeat', dest='hrepeat', action='store', \
                      type='int', help='Repeat header each X lines', default=0)

    (options, args) = parser.parse_args()

    if not options.interval > 0:
        parser.error("interval must be greater than 0 !")

    parser.destroy()

    return options, args
Пример #13
0
def main():
    parser = OptionParser(version="Hypnotoad Console")
    (options, args) = parser.parse_args()
    parser.destroy()

    command = Commands[args[0]](args[1:])

    file_server = FileServer(command)
    file_server.start()

    command.run()
Пример #14
0
def main():
    parser = OptionParser(version='Hypnotoad Console')
    (options,args) = parser.parse_args()
    parser.destroy()

    command = Commands[args[0]](args[1:])

    file_server = FileServer(command)
    file_server.start()

    command.run()    
Пример #15
0
    def __init__(self, argv):
        parser = OptionParser()
        parser.add_option("-c", "--create", dest='create',
                          help="create new RRD database", action="store_true", default=False)
        parser.add_option("--step", dest="step", 
                          help="base interval in seconds with which data will be fed into the RRD",
                          type='string', default='10')
        parser.add_option('-d', dest='daemon', action='store_true',
                          help='start daemon for reading values', default=False)
        parser.add_option('--stop', dest='stop', action='store_true',
                          help='start daemon for reading values', default=False)
        parser.add_option('--graph', dest='graph',
                          help='create graph')


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

        if options.create:
            print "creating ... "
            rrdtool.create('/tmp/temperature.rrd',
                           'DS:temperature:GAUGE:'+ str(options.step*4) +':-40:124',
                           'RRA:AVERAGE:0.5:1:1200',
                           'RRA:MIN:0.5:12:2400',
                           'RRA:MAX:0.5:12:2400',
                           'RRA:AVERAGE:0.5:12:2400',
                           '--step', options.step)
            print 'done'
            sys.exit(0)

        if options.daemon:
            print 'starting daemon'
            daemon = ThermoDaemon('/tmp/thermolog.pid', stdout='/tmp/thermolog.out')            
            daemon.start()
            sys.exit(0)
        if options.stop:
            print 'stopping daemon'
            daemon = ThermoDaemon('/tmp/thermolog.pid', stdout='/tmp/thermolog.out')            
            daemon.stop()
            sys.exit(0)
        if options.graph:
            print 'creating graph'
            now = int(time.time())
            start = now - 60*60
            rrdtool.graph(options.graph,
                          '--imgformat', 'PNG',
                          '--width', '540',
                          '--height', '100',
                          '--start', str(start),
                          '--end', str(now),
                          '--vertical-label', '°C',
                          '--title', 'Temperature',
                          'DEF:temp=/tmp/temperature.rrd:temperature:AVERAGE',
                          'AREA:temp#990033:Temperature')
Пример #16
0
def main(argv):
    parser = OptionParser(conflict_handler='resolve') # Intelligently resolve switch collisions
    parser.set_defaults(verbose=False, filters_to_run=[], packages=BuiltInPackages)

    # If any library loading switches (-l) are given, collect their names and remove them from argv
    argv, user_defined_libraries = filter_library_switches(argv)
    argv, autoloaded_libraries   = filter_autoload_paths(argv)
    
    # Load built-in filters (those under BuiltInPackages)
    # Load user-requested filters (passed by -l on the command line)
    all_libraries = BuiltInPackages + user_defined_libraries + autoloaded_libraries
    tracer = TraceCore(libraries=all_libraries)
    
    # For each available filter, allow it to be invoked with switches on the command line
    for filter in tracer.available_filters_dict.values(): add_filter_to_optparser(parser, filter)
    # Load built-in optparse switches
    register_builtin_switches(parser)

    if len(argv) <= 1:
        parser.print_help()
        sys.exit(1)
    
    # Perform option parse, check for user-requested filter classes
    opts, remaining_args = parser.parse_args(argv)
    # Done with parser
    parser.destroy()
    
    if opts.debug:
        config.set(debug=True)
            
    # Set verbose switch if given on command line
    tracer.verbose = opts.verbose
    tracer.break_on_exception = opts.break_on_exception
    
    # Set override Reader if given on command line
    tracer.reader_class_name = opts.reader_class_name
    
    # Take remaining arguments as input file names
    files = remaining_args[1:] # remaining_args[0] seems to be sys.argv[0]
    
    # If switch -L was passed, dump out all available filter names and quit
    if opts.do_list_filters:
        tracer.list_filters()
        sys.exit(0)
        
    # Run requested filters
    try:
        tracer.run(opts.filters_to_run, files)
    except RuntimeError, e:
        err('RuntimeError: %s', e)
        sys.exit(1)
Пример #17
0
def _parseCLArgs():
	"""parses the command line and returns instructions on how to go on.

	As a side effect, sys.argv is manipulated such that the program
	called thinks it was execd in the first place.
	"""
	from optparse import OptionParser
	sels = [n for n,x in functions]
	sels.sort()
	parser = OptionParser(usage="%prog {<global option>} <func>"
		" {<func option>} {<func argument>}\n"+
		textwrap.fill("<func> is a unique prefix into {%s}"%(", ".join(sels)),
		initial_indent='', subsequent_indent='  '),
		description="Try %prog <func> --help for function-specific help")
	parser.disable_interspersed_args()
	parser.add_option("--traceback", help="print a traceback on all errors.",
		action="store_true", dest="alwaysTracebacks")
	parser.add_option("--hints", help="if there are hints on an error, display"
		" them", action="store_true", dest="showHints")
	parser.add_option("--enable-pdb", help="run pdb on all errors.",
		action="store_true", dest="enablePDB")
	parser.add_option("--disable-spew", help='Ignored.',
		action="store_true", dest="disableSpew")
	parser.add_option("--profile-to", metavar="PROFILEPATH",
		help="enable profiling and write a profile to PROFILEPATH",
		action="store", dest="profilePath", default=None)
	parser.add_option("--suppress-log", help="Do not log exceptions and such"
		" to the gavo-specific log files", action="store_true",
		dest="suppressLog")
	parser.add_option("--debug", help="Produce debug info as appropirate.",
		action="callback", callback=_enableDebug)
	parser.add_option("--version", help="Write software version to stdout"
		" and exit", action="callback", callback=_printVersion)
	parser.add_option("-U", "--ui", help="use UI to show what is going on;"
		" try --ui=help to see available interfaces.",
		dest="uiName", action="store", type="str", default="module-dependent",
		metavar="UI")

	opts, args = parser.parse_args()
	if len(args)<1:
		parser.print_help(file=sys.stderr)
		sys.exit(2)

	module, funcName = common.getMatchingFunction(args[0], functions, parser)
	parser.destroy()
	args[0] = "gavo "+args[0]
	sys.argv = args
	return opts, module, funcName
Пример #18
0
def main():
    parser = OptionParser()

    version = (
        "%prog 0.2.2\n"
        "Copyright (C) 2008-2009 Guy Rutenberg <http://www.guyrutenberg.com/contact-me>"
        "Modified 2011 Mike McCabe")
    usage = ("%prog [options] TARFILE\n"
             "Print a checksum signature for every file in TARFILE.\n"
             "With no FILE, or when FILE is -, read standard input.")
    parser = OptionParser(usage=usage, version=version)
    parser.add_option(
        "-c",
        "--checksum",
        dest="checksum",
        type="string",
        help="use HASH as for caclculating the checksums. [default: %default]",
        metavar="HASH",
        default="md5")
    parser.add_option("-o",
                      "--output",
                      dest="output",
                      type="string",
                      help="save signatures to FILE.",
                      metavar="FILE")
    parser.add_option("-p",
                      "--pipe",
                      action="store_true",
                      help="copy input to output, for use in pipe.")

    (option, args) = parser.parse_args()

    if option.pipe and not option.output:
        parser.error("--pipe option requires that --output also be specified")
    parser.destroy()

    output_file = sys.stdout
    if option.output:
        output_file = open(option.output, "w")

    input_file = sys.stdin
    if len(args) == 1 and args[0] != "-":
        input_file = open(args[0], "r")

    input_file = hashing_file(input_file, option.checksum, option.pipe)

    tarsum(input_file, option.checksum, output_file)
Пример #19
0
def parseArguments( args ):
	"""Parses list of string arguments. Returns an object with the converted arguments as fields."""

	# init parser
	usage = """gsvn googleDocsUsername googleDocsPassword [svnUsername svnPassword]
     googleDocsUsername  email address of the google user account
     googleDocsPassword  password of the google user account

     svnUsername         username for svn repo authentication
     svnPassword         password for svn repo authentication"""

	parser = OptionParser( prog = 'gsvn', usage = usage )

	parser.add_option(
		"-g", "--gDocsRoot", help="name of the root of the file tree to copy fetch from google docs, default is root folder",
		type = "string", action="store", default=ROOT_FOLDER )
	parser.add_option(
		"-s", "--svnRoot", help="path to directory into which the google doc file tree shall be copied into, default is current folder",
		type = "string", action="store", default="." )
	
	parser.add_option( "-v", "--verbose", help="log messages during run of script", action="store_true", default=True )

	# parse args
	options, args = parser.parse_args( args )

	# check if there are the right number of arguments
	# put mandatory arguments into options object for simplicity
	if len( args ) == 4:
		options.gDocsUsername = args[0]
		options.gDocsPassword = args[1]
		options.svnUsername   = args[2]
		options.svnPassword   = args[3]
	elif len( args ) == 2:
		options.gDocsUsername = args[0]
		options.gDocsPassword = args[1]
		options.svnUsername   = None
		options.svnPassword   = None
	else:
		parser.print_help()
		print "error: gsvn requires exactly 2 or 4 arguments, %d given." % len( args )
		exit( 2 )

	# dispose of parser
	parser.destroy()

	return options
Пример #20
0
def prepare_app():
    parser = OptionParser(usage="usage: %prog [options]")
    parser.add_option('-1', '--config1', dest='config1', default=None,
                      help='Параметры подключения Odoo v8')
    parser.add_option('-2', '--config2', dest='config2', default=None,
                      help='Параметры подключения Odoo v10')
    (options, args) = parser.parse_args()
    parser.destroy()

    dal8 = db.DataAccessLayer()
    dal10 = db.DataAccessLayer()
    user1, pass1, address1, database1 = options.config1.split(",")
    user2, pass2, address2, database2 = options.config2.split(",")

    dal8.connect(user1, pass1, address1, database1)
    dal10.connect(user2, pass2, address2, database2)
    return dal8.session, dal10.session
Пример #21
0
    def __init__(self):
        usage = "--user <user-name> [--database <database-name>] [--host <host-name>] [--port <port>]"
        parser = OptionParser()
        parser.set_usage(usage)
        parser.add_option("-u", "--user", dest="user", help="DataHub username")
        parser.add_option("-H",
                          "--host",
                          dest="host",
                          help="DataHub server hostname",
                          default="datahub-experimental.csail.mit.edu")
        parser.add_option("-p",
                          "--port",
                          dest="port",
                          help="DataHub server port",
                          type="int",
                          default=9000)
        parser.add_option("-d",
                          "--database",
                          dest="database",
                          help="DataHub database")
        (self.options, self.arg_values) = parser.parse_args()

        if not self.options.user:
            parser.print_usage()
            sys.exit(1)

        parser.destroy()
        self.password = getpass.getpass('DataHub password for %s: ' %
                                        (self.options.user))
        cmd2.Cmd.__init__(self, completekey='tab')
        self.client = DataHubClient(host=self.options.host,
                                    port=self.options.port)
        try:
            database = None
            if self.options.database:
                database = DHDatabase(name=self.options.database)
            con_params = DHConnectionParams(user=self.options.user,
                                            password=self.password,
                                            database=database)
            self.con = self.client.connect(con_params)
            self.prompt = "datahub> "
        except Exception, e:
            self.print_line('error: %s' % (e.message))
            sys.exit(1)
Пример #22
0
def main():
    usage = 'usage: %prog [options] source_image output_image tiles_directory'
    parser = OptionParser(usage)
    parser.add_option('-p',
                      dest='ratio', type='int', default=1,
          help='ratio between tile size and subdivisions of source image [default=1]')
    parser.add_option('-m', '--method', type='choice',
                      dest='method', default='inside-out',
                      choices=['inside-out', 'top-down'],
          help='traversing method (inside-out, top-down) [default=%default]')
    parser.add_option('-r', '--repeat',
                      dest='repeat',
                      action='store_true',
                      help='allow repeating tiles')
    parser.add_option('-n', '--norepeat',
                      dest='repeat',
                      action='store_false', default=False,
                      help='do not allow repeating tiles [default]')
    parser.add_option('-t', '--threshold',
                      dest='threshold', default=0, type='int',
                      help='''threshold value for comparing colors. 
                      0 for no threshold [default=0]''')
    parser.add_option('-x', '--xStart',
                      dest='xStart', default=None,
                      help='''X position of where to start matching. For inside-out
                      only''')
    parser.add_option('-y', '--yStart',
                      dest='yStart', default=None,
                      help='''Y position of where to start matching. For inside-out
                      only''')
    parser.add_option('-v', '--verbose',
                      dest='verbose',
                      action='store_true', default=False)
    (options, args) = parser.parse_args()
    if len(args) == 3:
        create_mosaic(args[0], args[1], args[2],
                      options.ratio, options.method, options.repeat,
                     options.threshold, options.verbose)
    else:
        parser.error('Incorrect number of arguments. ')
    parser.destroy()
Пример #23
0
    def setUp(self):
        if sys.platform == "win32":
            sessionFile = "lwpCookie.txt"
        else:
            sessionFile = "/tmp/lwpCookie.txt"

        optionsList = [
            make_option("--host",
                        dest="host",
                        default="localhost",
                        help="ESX hostname"),
            make_option("-u",
                        "--user",
                        dest="user",
                        default="root",
                        help="User name"),
            make_option("-p",
                        "--pwd",
                        dest="password",
                        default="ca$hc0w",
                        help="Password"),
        ]

        cmdParser = OptionParser(option_list=optionsList)
        (options, remainingArgs) = cmdParser.parse_args(sys.argv[1:])
        try:
            # optparser does not have a destroy() method in older python
            cmdParser.destroy()
        except Exception:
            pass
        del cmdParser

        self.sessionFile = sessionFile
        self.user = options.user
        self.host = options.host
        if sys.platform == "win32":
            if options.password == "''":
                options.password = ""
        self.password = options.password
Пример #24
0
def parse_args():
    """
    parse command line arguments
    """

    parser = OptionParser(add_help_option=False)

    try:
        parser.set_defaults(verbose=True, ttl_tolerance=-1, side_by_side=False, run_tests=False)

        parser.add_option("-r", "--resolver", action="append", dest="resolvers", type="string")
        parser.add_option("-q", "--quiet", action="store_false", dest="verbose")
        parser.add_option("-y", "--side-by-side", action="store_true", dest="side_by_side")
        parser.add_option("-t", "--ttl_tolerance", action="store", dest="ttl_tolerance", type="int")
        parser.add_option("-x", "--test", action="store_true", dest="run_tests")
        parser.add_option("-h", "--help", action="callback", callback=usage_callback)

        return parser.parse_args()

    finally:
        #parser has circular references and can be large
        parser.destroy()
Пример #25
0
def command_line():
    """Handle options on the command line

    Destroy the option parser when finished
        (do not interfere with tests which use it)
    """
    from optparse import OptionParser
    parser = OptionParser()
    parser.add_option('-s', '--show', dest='show',
                      help='show files being tested', action='store_true')
    parser.add_option('-v', '--verbose', dest='verbose',
                      help='Hello World', action='store_true')
    parser.add_option('-r', '--recursive', dest='recursive',
                      help='recurse into any sub-directories found',
                      action='store_true', default=False)
    parser.add_option('-a', '--all', dest='all',
                      help="run all tests (don't stop on first FAIL)",
                      action='store_true', default=False)
    parser.add_option('-d', '--directory_all', dest='directory_all',
                      help='run all test scripts in a directory'
                      '(do not stop on first FAILing script)',
                      action='store_true', default=False)
    parser.add_option('-q', '--quiet_on_success', dest='quiet_on_success',
                      help='no output if all tests pass',
                      action='store_true', default=False)
    parser.add_option('-p', '--persist', dest='persist',
                      help='do not stop on DoctestInterrupts',
                      action='store_true', default=False)
    options, args = parser.parse_args()
    if hasattr(parser, 'destroy'):
        parser.destroy()
    del parser
    if options.recursive:
        for arg in args:
            if os.path.isfile(arg):
                raise ValueError(
                    'Do not use --recursive with files (%s)' % arg)
    return options, args
Пример #26
0
def parse_options():
    parser = OptionParser(usage="usage: %prog [options] <input>", version="%prog 0.0")
    parser.add_option("-y", "--arch", help='the CPU architecture. Default to "armv7".', default="armv7")
    parser.add_option(
        "-o",
        "--output",
        help='output file. If not supplied, the result will be written to "<input>.o".',
        metavar="FILE",
    )
    parser.add_option(
        "-a", "--address", help="VM address this file should map to. Default to 0", default="0", metavar="VMADDR"
    )
    (options, args) = parser.parse_args()

    if not args:
        parser.error("Please supply the input filename.")

    inputfn = args[0]
    outputfn = options.output or args[0] + ".o"
    vmaddr = int(options.address, 16)

    parser.destroy()

    return (options.arch, inputfn, outputfn, vmaddr)
Пример #27
0
def main():
	conf = {}
	pkgs = {}

	parser = OptionParser( version = "%prog " + __version__ )
	parser.usage = "%prog [options] [category/package] ..."
	parser.disable_interspersed_args()

	parser.add_option( "-f", "--file", dest = "filename", action = "store", type = "string",
			help = "write result into FILE [default: %default]", metavar = "FILE", default = "stdout" )
	parser.add_option( "-m", "--main", dest = "main_arch", action = "store", type = "string",
			help = "set main ARCH (e.g. your arch) [default: %default]", metavar = "ARCH", default = MAIN_ARCH )
	parser.add_option( "-t", "--target", dest = "target_arch", action = "store", type = "string",
			help = "set target ARCH (e.g. x86) [default: %default]", metavar = "ARCH", default = TARGET_ARCH )
	parser.add_option( "--mtime", dest = "mtime", action = "store", type = "int",
			help = "set minimum MTIME in days [default: %default]", metavar = "MTIME", default = 30 )

	# TODO: leave a good comment here (about True/False) :)
	parser.add_option( "-s", "--stable", dest = "stable", action = "store_true", default = False,
			help = "just show stable candidates (e.g. -s and -k is the default result) [default: True]" )
	parser.add_option( "-k", "--keyword", dest = "keyword", action = "store_true", default = False,
			help = "just show keyword candidates (e.g. -s and -k is the default result) [default: True]" )

	parser.add_option( "-M", "--maintainer", dest = "maintainer", action = "store", type = "string",
			help = "Show only packages from the specified maintainer", metavar = "MAINTAINER", default = None)

	parser.add_option( "-H", "--herd", dest = "herd", action = "store", type = "string",
			help = "Show only packages from the specified herd", metavar = "HERD", default = None)

#	# EXPERIMENTAL
#	parser.add_option( "-e", "--experimental", dest = "experimental", action = "store_true", default = False,
#			help = "enables experimental functions/features (have a look for # EXPERIMENTAL comments in the source) [default: %default]" )

	parser.add_option( "-C", "--category", "--categories", dest = "categories", action = "store", default = None,
			metavar = "CATEGORIES",
			help = "just check in the specified category/categories (comma separated) [default: %default]")

	( options, args ) = parser.parse_args()

	if len( args ) > 0:
		conf["USER_PKGS"] = args
	else:
		conf["USER_PKGS"] = []

	# cleanup optparse
	try:
		parser.destroy()
	except AttributeError:
		# to be at least python 2.4 compatible
		del parser._short_opt
		del parser._long_opt
		del parser.defaults

	# generated timestamp (UTC)
	conf["TIME"] = strftime( "%a %b %d %H:%M:%S %Z %Y", gmtime() )

	# package counter
	conf["KEYWORD_SUM"] = 0
	conf["STABLE_SUM"] = 0

	if not options.main_arch in portage.archlist and options.main_arch != "auto":
		raise ValueError("invalid MAIN ARCH defined!")
	if not options.target_arch in portage.archlist and options.target_arch != "auto":
		raise ValueError("invalid TARGET ARCH defined!")

	conf["MAIN_ARCH"] = options.main_arch
	conf["TARGET_ARCH"] = options.target_arch

	conf["FILE"] = options.filename
	conf["MTIME"] = options.mtime

	if not options.stable and not options.keyword:
		conf["STABLE"] = True
		conf["KEYWORD"] = True
	else:
		conf["STABLE"] = options.stable
		conf["KEYWORD"] = options.keyword

#	conf["EXPERIMENTAL"] = options.experimental
	conf["CATEGORIES"] = options.categories

	conf["MAINTAINER"] = options.maintainer
	conf["HERD"] = options.herd

	# append to our existing
	conf = get_settings( conf )
	pkgs = get_packages( conf )
	pkgs = get_imlate( conf, pkgs )

	show_result( conf, pkgs )
        traceback.print_exception(*exc_info)
        logger.critical("Unhandled exception", exc_info=exc_info)

    sys.excepthook = hook

    if ((options.key is not None and options.cert is None)
            or (options.key is None and options.cert is None)):
        logger.critical("An SSL certificate and private key must be provided")
        sys.exit(1)

    ssl_config = dict(
        keyfile=options.key,
        certfile=options.cert,
        server_side=True,
        cert_reqs=ssl.CERT_NONE,
        ssl_version=ssl.PROTOCOL_SSLv23,  # Maximum compatibility.
        ca_certs=None,
        do_handshake_on_connect=False,
        suppress_ragged_eofs=False,
        ciphers=None)

    def thread_factory(tasks, shutdown_event, hup_event):
        return BroccoliWorker(tasks, shutdown_event, hup_event, options.bro,
                              options.out)

    server = Server(SSHDAuditMuxClient, thread_factory, ssl_config,
                    pyev.default_loop(), (options.addr, options.port),
                    options.timeout)
    p.destroy()
    server.start()
Пример #29
0
def main(args):
    parser = OptionParser(usage='%prog [ options ... ] URI [ FILES ]',
                          description='Analyze repository modifications',
                          version=VERSION)
    parser.disable_interspersed_args()
    parser.add_option('-g',
                      '--debug',
                      dest='debug',
                      action="store_true",
                      default=False,
                      help="Run in debug mode")
    parser.add_option('-c',
                      '--config-file',
                      dest='config_file',
                      metavar='FILE',
                      help="Use a custom configuration file")
    parser.add_option('-r',
                      '--revision',
                      dest='revision',
                      metavar='REV',
                      help='Revision to analyze (HEAD)')
    parser.add_option('-f',
                      '--fast',
                      dest='fast',
                      action="store_true",
                      default=False,
                      help="Run faster but moves and copies are not detected")
    parser.add_option('-o',
                      '--output',
                      dest='output',
                      default='text',
                      help='Output type [text|db|xml|csv] (%default)')
    add_outputs_options(parser)

    # Save default values and pass an emtpy Values object to
    # parser_args, so that default values are not set. We need it
    # to know whether a value has been provided by the user or not
    # After parsing the command line we complete the config options
    # with the default values for the options that have not been set
    # by the parser or by a config file
    defaults = parser.get_default_values()
    options, args = parser.parse_args(args, values=Values())

    try:
        config = Config(options.config_file)
    except AttributeError:
        config = Config()

    config.update(options.__dict__)
    config.add(defaults.__dict__)

    if not args:
        parser.error("missing required repository URI")
        return 1

    parser.destroy()

    if config.debug:
        import repositoryhandler.backends
        repositoryhandler.backends.DEBUG = True

    uri = args[0]
    files = args[1:]
    files_from_stdin = (files and files[0] == '-')

    # Create repository
    path = uri_to_filename(uri)
    if path is not None:
        try:
            repo = create_repository_from_path(path)
        except RepositoryUnknownError:
            printerr(
                "Path %s doesn't seem to point to a repository supported by guilty",
                (path, ))
            return 1
        except Exception, e:
            printerr("Unknown error creating repository for path %s (%s)",
                     (path, str(e)))
            return 1
        uri = repo.get_uri_for_path(path)
Пример #30
0
def main(args, env, cwd, cb):
    """
    Start a single makefile execution, given a command line, working directory, and environment.

    @param cb a callback to notify with an exit code when make execution is finished.
    """

    try:
        makelevel = int(env.get('MAKELEVEL', '0'))

        op = OptionParser()
        op.add_option('-f',
                      '--file',
                      '--makefile',
                      action='append',
                      dest='makefiles',
                      default=[])
        op.add_option('-d', action="store_true", dest="verbose", default=False)
        op.add_option('-k',
                      '--keep-going',
                      action="store_true",
                      dest="keepgoing",
                      default=False)
        op.add_option('--debug-log', dest="debuglog", default=None)
        op.add_option('-C', '--directory', dest="directory", default=None)
        op.add_option('-v',
                      '--version',
                      action="store_true",
                      dest="printversion",
                      default=False)
        op.add_option('-j', '--jobs', type="int", dest="jobcount", default=1)
        op.add_option('-w',
                      '--print-directory',
                      action="store_true",
                      dest="printdir")
        op.add_option('--no-print-directory',
                      action="store_false",
                      dest="printdir",
                      default=True)
        op.add_option('-s',
                      '--silent',
                      action="store_true",
                      dest="silent",
                      default=False)
        op.add_option('-n',
                      '--just-print',
                      '--dry-run',
                      '--recon',
                      action="store_true",
                      dest="justprint",
                      default=False)

        options, arguments1 = op.parse_args(parsemakeflags(env))
        options, arguments2 = op.parse_args(args, values=options)

        op.destroy()

        arguments = arguments1 + arguments2

        if options.printversion:
            _version()
            cb(0)
            return

        shortflags = []
        longflags = []

        if options.keepgoing:
            shortflags.append('k')

        if options.printdir:
            shortflags.append('w')

        if options.silent:
            shortflags.append('s')
            options.printdir = False

        if options.justprint:
            shortflags.append('n')

        loglevel = logging.WARNING
        if options.verbose:
            loglevel = logging.DEBUG
            shortflags.append('d')

        logkwargs = {}
        if options.debuglog:
            logkwargs['filename'] = options.debuglog
            longflags.append('--debug-log=%s' % options.debuglog)

        if options.directory is None:
            workdir = cwd
        else:
            workdir = util.normaljoin(cwd, options.directory)

        if options.jobcount != 1:
            longflags.append('-j%i' % (options.jobcount, ))

        makeflags = ''.join(shortflags)
        if len(longflags):
            makeflags += ' ' + ' '.join(longflags)

        logging.basicConfig(level=loglevel, **logkwargs)

        context = process.getcontext(options.jobcount)

        if options.printdir:
            print "make.py[%i]: Entering directory '%s'" % (makelevel, workdir)
            sys.stdout.flush()

        if len(options.makefiles) == 0:
            if os.path.exists(util.normaljoin(workdir, 'Makefile')):
                options.makefiles.append('Makefile')
            else:
                print "No makefile found"
                cb(2)
                return

        ostmts, targets, overrides = parserdata.parsecommandlineargs(arguments)

        _MakeContext(makeflags, makelevel, workdir, context, env, targets,
                     options, ostmts, overrides, cb)
    except (util.MakeError), e:
        print e
        if options.printdir:
            print "make.py[%i]: Leaving directory '%s'" % (makelevel, workdir)
        sys.stdout.flush()
        cb(2)
        return
Пример #31
0
def main(args, env, cwd, cb):
    """
    Start a single makefile execution, given a command line, working directory, and environment.

    @param cb a callback to notify with an exit code when make execution is finished.
    """

    try:
        makelevel = int(env.get('MAKELEVEL', '0'))

        op = OptionParser()
        op.add_option('-f', '--file', '--makefile',
                      action='append',
                      dest='makefiles',
                      default=[])
        op.add_option('-d',
                      action="store_true",
                      dest="verbose", default=False)
        op.add_option('-k', '--keep-going',
                      action="store_true",
                      dest="keepgoing", default=False)
        op.add_option('--debug-log',
                      dest="debuglog", default=None)
        op.add_option('-C', '--directory',
                      dest="directory", default=None)
        op.add_option('-v', '--version', action="store_true",
                      dest="printversion", default=False)
        op.add_option('-j', '--jobs', type="int",
                      dest="jobcount", default=1)
        op.add_option('-w', '--print-directory', action="store_true",
                      dest="printdir")
        op.add_option('--no-print-directory', action="store_false",
                      dest="printdir", default=True)
        op.add_option('-s', '--silent', action="store_true",
                      dest="silent", default=False)
        op.add_option('-n', '--just-print', '--dry-run', '--recon',
                      action="store_true",
                      dest="justprint", default=False)

        options, arguments1 = op.parse_args(parsemakeflags(env))
        options, arguments2 = op.parse_args(args, values=options)

        op.destroy()

        arguments = arguments1 + arguments2

        if options.printversion:
            _version()
            cb(0)
            return

        shortflags = []
        longflags = []

        if options.keepgoing:
            shortflags.append('k')

        if options.printdir:
            shortflags.append('w')

        if options.silent:
            shortflags.append('s')
            options.printdir = False

        if options.justprint:
            shortflags.append('n')

        loglevel = logging.WARNING
        if options.verbose:
            loglevel = logging.DEBUG
            shortflags.append('d')

        logkwargs = {}
        if options.debuglog:
            logkwargs['filename'] = options.debuglog
            longflags.append('--debug-log=%s' % options.debuglog)

        if options.directory is None:
            workdir = cwd
        else:
            workdir = util.normaljoin(cwd, options.directory)

        if options.jobcount != 1:
            longflags.append('-j%i' % (options.jobcount,))

        makeflags = ''.join(shortflags)
        if len(longflags):
            makeflags += ' ' + ' '.join(longflags)

        logging.basicConfig(level=loglevel, **logkwargs)

        context = process.getcontext(options.jobcount)

        if options.printdir:
            print "make.py[%i]: Entering directory '%s'" % (makelevel, workdir)
            sys.stdout.flush()

        if len(options.makefiles) == 0:
            if os.path.exists(util.normaljoin(workdir, 'Makefile')):
                options.makefiles.append('Makefile')
            else:
                print "No makefile found"
                cb(2)
                return

        ostmts, targets, overrides = parserdata.parsecommandlineargs(arguments)

        _MakeContext(makeflags, makelevel, workdir, context, env, targets, options, ostmts, overrides, cb)
    except (util.MakeError), e:
        print e
        if options.printdir:
            print "make.py[%i]: Leaving directory '%s'" % (makelevel, workdir)
        sys.stdout.flush()
        cb(2)
        return
def main():
    global MONITOR_LOG
    parser = OptionParser(usage="""
    %prog [--alg=ALG] [seed]
    """)
    #     parser.add_option('--fixed', action='store_true',
    #                       help="Use a fixed generic guide function")
    parser.add_option(
        '--alg',
        action='store',
        choices=['gradient', 'fixed', 'genetic', 'd_e'],
        help=
        "Algorithm - one of gradient, fixed, genetic, d_e [default %default]",
        default="fixed")
    opts, args = parser.parse_args()
    if len(args) > 1:
        parser.error('Extra arguments found')
    if len(args) == 1:
        try:
            seed_row = int(args[0])
            seed_file = None
        except ValueError:
            if os.path.exists(args[0]):
                seed_row = None
                seed_file = args[0]
            else:
                parser.error(
                    'seed must be an integer row number or a pkl file containing one record'
                )
    else:
        parser.error('required argument is missing')
        seed_row = None
        seed_file = None

    parser.destroy()

    #     rslt_path = get_rslt_path()
    #     os.makedirs(rslt_path)

    subDF, acesL, boolColL, scalarColL, fixedL, passiveL, ageL = load_dataset()

    #print(scalarColL)
    print('ages: ', ageL)
    ageMin = int(min(ageL))
    ageMax = int(max(ageL))
    scalarColL.remove('AGE')
    print('scalar columns: ', scalarColL)
    ageDFD = {}
    range_d = None
    for age in range(ageMin, ageMax + 1):
        ageDF = subDF[subDF.AGE == age].drop(columns=['AGE', 'FIPSST'])
        ageDFD[age], _, _, _, dct = quantizeData(ageDF, acesL, boolColL,
                                                 scalarColL)
        if range_d is None:
            range_d = dct
        else:
            assert dct == range_d, 'Quantized ranges do not match?'


#    weightedSampGen = createWeightedSamplesGenerator(N_SAMP)

#    scSampGen = createWeightedSamplesGenerator(1)
#    prototype = scSampGen(pd.read_pickle(seed_file))
    prototype = weightedSampGen(pd.read_pickle(seed_file), 1)

    fixed_l = fixedL
    fixed_d = {elt: prototype.iloc[0][elt] for elt in fixed_l}
    passive_l = passiveL
    aces_l = acesL
    advancing_l = [
        elt for elt in aces_l if elt not in list(fixed_d) + passive_l
    ]
    open_l = [k for k in prototype.columns]
    for elt in list(fixed_d) + advancing_l + passive_l:
        open_l.remove(elt)
    samp_gen = weightedSampGen
    nIter = 1000
    all_col_l = open_l + advancing_l
    which_bin = createBinner(all_col_l, range_d=range_d)
    binnerParams = {}

    for age in range(ageMin, ageMax):
        transition = '%d-%d' % (age, age + 1)
        outer_cohort = select_subset(ageDFD[age], fixed_d)
        new_outer_cohort = select_subset(ageDFD[age + 1],
                                         fixed_d).drop(columns=['FWC'])
        mutator = MSTMutator(new_outer_cohort)
        mutatorParams = {'nsteps': 2}
        testSampParams = {'df': outer_cohort, 'n_samp': N_SAMP}
        genSampParams = {'df': new_outer_cohort, 'n_samp': N_SAMP}
        initial_wt_ser = createWeightSer(all_col_l, range_d=range_d)
        MONITOR_LOG = []
        rslt = differential_evolution(
            minimizeMe, [(0.5 * v, 4.0 * v) for v in initial_wt_ser.values],
            (N_SAMP, nIter, all_col_l, weightedSampGen, testSampParams,
             genSampParams, which_bin, binnerParams, mutator, mutatorParams),
            maxiter=10,
            popsize=10,
            disp=True,
            polish=False,
            callback=monitorDE)
        print(rslt)
        with open('%s_generic.pkl' % transition, 'wb') as f:
            pickle.dump([rslt, MONITOR_LOG], f)
Пример #33
0
def main():
    parser = OptionParser()
    parser.add_option('-s', '--server-host',
                      dest='server_host', type='string',
                      default='localhost', help='Server host (can be a comma-delimited list)',
                      action='callback',
                      callback_args=(str,),
                      callback=get_comma_separated_args)
    parser.add_option('-p', '--server-port',
                      dest='server_port', type='string',
                      default=8073, help='Server port, default 8073 (can be a comma delimited list)',
                      action='callback',
                      callback_args=(int,),
                      callback=get_comma_separated_args)
    parser.add_option('--pw', '--password',
                      dest='password', type='string', default='',
                      help='Kiwi login password (if required, can be a comma delimited list)',
                      action='callback',
                      callback_args=(str,),
                      callback=get_comma_separated_args)
    parser.add_option('-u', '--user',
                      dest='user', type='string', default='kiwirecorder.py',
                      help='Kiwi connection user name',
                      action='callback',
                      callback_args=(str,),
                      callback=get_comma_separated_args)
    parser.add_option('--station',
                      dest='station',
                      type='string', default=None,
                      help='Station ID to be appended to filename (can be a comma-separated list)',
                      action='callback',
                      callback_args=(str,),
                      callback=get_comma_separated_args)
    parser.add_option('--log', '--log-level', '--log_level', type='choice',
                      dest='log_level', default='warn',
                      choices=['debug', 'info', 'warn', 'error', 'critical'],
                      help='Log level: debug|info|warn(default)|error|critical')
    parser.add_option('-q', '--quiet',
                      dest='quiet',
                      default=False,
                      action='store_true',
                      help='Don\'t print progress messages')
    parser.add_option('-d', '--dir',
                      dest='dir',
                      type='string', default=None,
                      help='Optional destination directory for files')
    parser.add_option('--fn', '--filename',
                      dest='filename',
                      type='string', default='',
                      help='Use fixed filename instead of generated filenames (optional station ID(s) will apply)',
                      action='callback',
                      callback_args=(str,),
                      callback=get_comma_separated_args)
    parser.add_option('--tlimit', '--time-limit',
                      dest='tlimit',
                      type='float', default=None,
                      help='Record time limit in seconds')
    parser.add_option('--dt-sec',
                      dest='dt',
                      type='int', default=0,
                      help='Start a new file when mod(sec_of_day,dt) == 0')
    parser.add_option('--launch-delay', '--launch_delay',
                      dest='launch_delay',
                      type='int', default=0,
                      help='Delay (secs) in launching multiple connections')
    parser.add_option('-k', '--socket-timeout', '--socket_timeout',
                      dest='socket_timeout', type='int', default=10,
                      help='Timeout(sec) for sockets')
    parser.add_option('--OV',
                      dest='ADC_OV',
                      default=False,
                      action='store_true',
                      help='Print "ADC OV" message when Kiwi ADC is overloaded')
    parser.add_option('--stats',
                      dest='stats',
                      default=False,
                      action='store_true',
                      help='Print additional statistics (applies only to --S-meter mode currently)')
    parser.add_option('--no-api',
                      dest='no_api',
                      default=False,
                      action='store_true',
                      help='Simulate connection to Kiwi using improper/incomplete API')

    group = OptionGroup(parser, "Audio connection options", "")
    group.add_option('-f', '--freq',
                      dest='frequency',
                      type='string', default=1000,
                      help='Frequency to tune to, in kHz (can be a comma-separated list)',
                      action='callback',
                      callback_args=(float,),
                      callback=get_comma_separated_args)
    group.add_option('-m', '--modulation',
                      dest='modulation',
                      type='string', default='am',
                      help='Modulation; one of am, lsb, usb, cw, nbfm, iq (default passband if -L/-H not specified)')
    group.add_option('--ncomp', '--no_compression',
                      dest='compression',
                      default=True,
                      action='store_false',
                      help='Don\'t use audio compression')
    group.add_option('-L', '--lp-cutoff',
                      dest='lp_cut',
                      type='float', default=None,
                      help='Low-pass cutoff frequency, in Hz')
    group.add_option('-H', '--hp-cutoff',
                      dest='hp_cut',
                      type='float', default=None,
                      help='High-pass cutoff frequency, in Hz')
    group.add_option('-r', '--resample',
                      dest='resample',
                      type='int', default=0,
                      help='Resample output file to new sample rate in Hz. The resampling ratio has to be in the range [1/256,256]')
    group.add_option('-T', '--squelch-threshold',
                      dest='thresh',
                      type='float', default=None,
                      help='Squelch threshold, in dB.')
    group.add_option('--squelch-tail',
                      dest='squelch_tail',
                      type='float', default=1,
                      help='Time for which the squelch remains open after the signal is below threshold.')
    group.add_option('-g', '--agc-gain',
                      dest='agc_gain',
                      type='string',
                      default=None,
                      help='AGC gain; if set, AGC is turned off (can be a comma-separated list)',
                      action='callback',
                      callback_args=(float,),
                      callback=get_comma_separated_args)
    group.add_option('--nb',
                      dest='nb',
                      action='store_true', default=False,
                      help='Enable noise blanker with default parameters.')
    group.add_option('--nb-gate',
                      dest='nb_gate',
                      type='int', default=100,
                      help='Noise blanker gate time in usec (100 to 5000, default 100)')
    group.add_option('--nb-th', '--nb-thresh',
                      dest='nb_thresh',
                      type='int', default=50,
                      help='Noise blanker threshold in percent (0 to 100, default 50)')
    group.add_option('-w', '--kiwi-wav',
                      dest='is_kiwi_wav',
                      default=False,
                      action='store_true',
                      help='In the wav file include KIWI header containing GPS time-stamps (only for IQ mode)')
    group.add_option('--S-meter', '--s-meter',
                      dest='S_meter',
                      type='int', default=-1,
                      help='Report S-meter(RSSI) value after S_METER number of averages. S_METER=0 does no averaging and reports each RSSI value received. Does not write wav data to file.')
    group.add_option('--kiwi-tdoa',
                      dest='is_kiwi_tdoa',
                      default=False,
                      action='store_true',
                      help='Used when called by Kiwi TDoA extension')
    group.add_option('--test-mode',
                      dest='test_mode',
                      default=False,
                      action='store_true',
                      help='Write wav data to /dev/null (Linux) or NUL (Windows)')
    parser.add_option_group(group)

    group = OptionGroup(parser, "Waterfall connection options", "")
    group.add_option('--wf',
                      dest='waterfall',
                      default=False,
                      action='store_true',
                      help='Process waterfall data instead of audio')
    group.add_option('-z', '--zoom',
                      dest='zoom', type='int', default=0,
                      help='Zoom level 0-14')
    group.add_option('--snd',
                      dest='sound',
                      default=False,
                      action='store_true',
                      help='Also process sound data when in waterfall mode (sound connection options above apply)')
    parser.add_option_group(group)

    (options, unused_args) = parser.parse_args()

    ## clean up OptionParser which has cyclic references
    parser.destroy()

    FORMAT = '%(asctime)-15s pid %(process)5d %(message)s'
    logging.basicConfig(level=logging.getLevelName(options.log_level.upper()), format=FORMAT)
    if options.log_level.upper() == 'DEBUG':
        gc.set_debug(gc.DEBUG_SAVEALL | gc.DEBUG_LEAK | gc.DEBUG_UNCOLLECTABLE)

    run_event = threading.Event()
    run_event.set()

    if options.S_meter >= 0:
        options.quiet = True
    options.raw = False;
    gopt = options
    multiple_connections,options = options_cross_product(options)

    snd_recorders = []
    if not gopt.waterfall or (gopt.waterfall and gopt.sound):
        for i,opt in enumerate(options):
            opt.multiple_connections = multiple_connections;
            opt.idx = i
            snd_recorders.append(KiwiWorker(args=(KiwiSoundRecorder(opt),opt,run_event)))

    wf_recorders = []
    if gopt.waterfall:
        for i,opt in enumerate(options):
            opt.multiple_connections = multiple_connections;
            opt.idx = i
            wf_recorders.append(KiwiWorker(args=(KiwiWaterfallRecorder(opt),opt,run_event)))

    try:
        for i,r in enumerate(snd_recorders):
            if opt.launch_delay != 0 and i != 0 and options[i-1].server_host == options[i].server_host:
                time.sleep(opt.launch_delay)
            r.start()
            #logging.info("started sound recorder %d, tstamp=%d" % (i, options[i].tstamp))
            logging.info("started sound recorder %d" % i)

        for i,r in enumerate(wf_recorders):
            if i!=0 and options[i-1].server_host == options[i].server_host:
                time.sleep(opt.launch_delay)
            r.start()
            logging.info("started waterfall recorder %d" % i)

        while run_event.is_set():
            time.sleep(.1)

    except KeyboardInterrupt:
        run_event.clear()
        join_threads(snd_recorders, wf_recorders)
        print("KeyboardInterrupt: threads successfully closed")
    except Exception as e:
        print_exc()
        run_event.clear()
        join_threads(snd_recorders, wf_recorders)
        print("Exception: threads successfully closed")

    if gopt.is_kiwi_tdoa:
      for i,opt in enumerate(options):
          # NB: MUST be a print (i.e. not a logging.info)
          print("status=%d,%d" % (i, opt.status))

    logging.debug('gc %s' % gc.garbage)
Пример #34
0
    def cmdline(self):
        '''Parse options from the command line. For an explanation of the
        options and their usage, use:

        python master.py --help
        '''
        # This is a m-m-m-monster function, but sometimes there are just lots
        # of things to do, and that is how it is.
        self.constants()
        # we add our own help option for obscure reasons
        parser = OptionParser(add_help_option=False)
        parser.add_option('-h',
                          '--help',
                          action='store_true',
                          help='Display this help and exit')
        # options other than --help are in loose alphabetical order
        if has_ipv6:
            parser.add_option('-4',
                              '--ipv4',
                              action='store_false',
                              default=True,
                              dest='ipv6',
                              help='Only use IPv4')
            parser.add_option('-6',
                              '--ipv6',
                              action='store_false',
                              default=True,
                              dest='ipv4',
                              help='Only use IPv6')
        # a better error message here for invalid values would be nice
        parser.add_option('-d',
                          '--db',
                          help='Database backend to use, '
                          '<none|tdb|sqlite|auto>',
                          metavar='NAME',
                          default='auto',
                          choices=['none', 'tdb', 'sqlite', 'auto'])
        if has_chroot:
            parser.add_option('-j',
                              '--jail',
                              help='Path to chroot into at startup',
                              metavar='DIR')
        parser.add_option('-l',
                          '--listen-addr',
                          help='IPv4 address to listen to',
                          metavar='ADDR')
        if has_ipv6:
            # Can we put this in the conditional above without spoiling
            # the ordering?
            parser.add_option('-L',
                              '--listen6-addr',
                              help='IPv6 address to listen to',
                              metavar='ADDR')
        parser.add_option('-n',
                          '--max-servers',
                          type='int',
                          help='Maximum number of servers to track',
                          metavar='NUM')
        parser.add_option('-p',
                          '--port',
                          action='append',
                          type='int',
                          dest='ports',
                          help='Port for incoming requests. '
                          'May be specified multiple times to listen on '
                          'additional ports.',
                          metavar='NUM')
        parser.add_option('-P',
                          '--challengeport',
                          type='int',
                          help='Port for outgoing challenges',
                          metavar='NUM')
        parser.add_option('-q',
                          action='count',
                          default=0,
                          help='Decrease verbose level. Multiple -q options '
                          'may suppress logging entirely.')
        if has_setuid:
            parser.add_option('-u',
                              '--user',
                              help='User to switch to at startup')
        parser.add_option('-v',
                          action='count',
                          default=0,
                          help='Increase verbose level. Multiple -v options '
                          'increase the level further.')
        parser.add_option('--verbose',
                          type='int',
                          default=LOG_PRINT,
                          help='Set verbose level directly. Takes a single '
                          'integer argument between {0} and {1}'.format(
                              LOG_ALWAYS, LOG_LEVELS - 1),
                          metavar='LEVEL')
        parser.add_option('-V',
                          '--version',
                          action='store_true',
                          help='Show version information')
        self.options, args = parser.parse_args(argv[1:])
        if args:
            raise ConfigError('Unexpected command line arguments')

        if self.help:
            stdout.write(parser.format_help())
            exit(0)
        # don't need this anymore
        parser.destroy()
        del parser

        if self.version:
            stdout.write('{0}\n'.format(self.VERSION))
            exit(0)

        self.verbose += self.v - self.q

        if not LOG_ALWAYS <= self.verbose < LOG_LEVELS:
            raise ConfigError('Verbose level must be between', LOG_ALWAYS,
                              'and', LOG_LEVELS - 1,
                              '(not {0})'.format(self.verbose))

        self.log(LOG_VERBOSE, 'Logging:', *loglevels[:self.verbose + 1])

        if not self.ipv4 and not self.ipv6:
            raise ConfigError('Cannot specify both --ipv4 and --ipv6')

        if self.user is not None:
            try:
                pwnam = getpwnam(self.user)
                uid = pwnam.pw_uid
            except KeyError:
                try:
                    uid = int(self.user)
                    pwnam = getpwuid(uid)
                except ValueError:
                    raise ConfigError(self.user, 'no such user', sep=': ')

            if has_setgid:
                gid = pwnam.pw_gid

        if self.jail is not None:
            try:
                chdir(self.jail)
                chroot('.')
            except OSError as err:
                raise ConfigError('chroot {0}:'.format(self.jail),
                                  err.strerror)
            self.log(LOG_VERBOSE, 'Chrooted to', self.jail)

        if self.user is not None:
            # okay, probably root at this point
            if has_setgroups:
                try:
                    setgroups(())
                except OSError as err:
                    raise ConfigError('setgroups:', err.strerror)

            if has_setgid:
                try:
                    setgid(gid)
                except OSError as err:
                    raise ConfigError('setgid {0}:'.format(gid), err.strerror)

            # setuid last, so setgroups & setgid don't fail
            try:
                setuid(uid)
            except OSError as err:
                raise ConfigError('setuid {0}:'.format(uid), err.strerror)

            pwnam = None

            self.log(LOG_VERBOSE, 'UID set to', getuid())

        if self.ports is None:
            self.ports = [30710]
        else:
            self.ports = sorted(set(self.ports))

        if self.challengeport is None:
            self.challengeport = self.ports[-1] + 1
            while self.challengeport > 0xffff or \
               self.challengeport in self.ports:
                self.challengeport = (self.challengeport & 0xffff) + 1
            self.log(LOG_VERBOSE, 'Automatically set challenge port to',
                     self.challengeport)
        elif self.challengeport in self.ports:
            raise ConfigError('Challenge port cannot be the same as a request '
                              'port ({0})'.format(self.challengeport))
Пример #35
0
DDICT = defaultdict(list)
MBOX0 = mbox()
MBOX1 = mailbox.MH()
MBOX2 = mailbox.Maildir()

OP0 = OptionParser()
OP1 = Queue()
OP2 = socket.socket()
OP3 = 'abcdef'
OP4 = collections.deque()
OP5 = datetime.datetime(1976, 6, 21)
OP6 = tarfile.TarFile()
OP7 = weakref.WeakKeyDictionary()
OP8 = weakref.WeakValueDictionary()
print OP0.destroy()
print OP1.join()
print OP1.task_done()
print OP2.recv_into('')
print OP2.recvfrom_into('', '')
print OP3.partition('c')
print OP3.rpartition('c')
print OP4.remove(1)
print OP5.strptime('%p-%v')
print OP6.extractall()
print OP7.iterkeyrefs()
print OP7.keyrefs()
print OP8.itervaluerefs()
print OP8.valuerefs()

AP1 = OP0
Пример #36
0
 def destroy(self):
     del self.command_list
     OptionParser.destroy(self)
Пример #37
0
        logger.critical("Unhandled exception", exc_info=exc_info)

    sys.excepthook = hook

    if ( (options.key is not None and options.cert is None) or
         (options.key is None and options.cert is None) ):
        logger.critical("An SSL certificate and private key must be provided")
        sys.exit(1)

    ssl_config = dict(
        keyfile=options.key,
        certfile=options.cert,
        server_side=True,
        cert_reqs=ssl.CERT_NONE,
        ssl_version=ssl.PROTOCOL_SSLv23, # Maximum compatibility.
        ca_certs=None,
        do_handshake_on_connect=False,
        suppress_ragged_eofs=False,
        ciphers=None
    )

    def thread_factory(tasks, shutdown_event, hup_event):
        return BroccoliWorker(tasks, shutdown_event, hup_event,
                              options.bro, options.out)

    server = Server(SSHDAuditMuxClient, thread_factory, ssl_config,
                    pyev.default_loop(), (options.addr, options.port),
                    options.timeout)
    p.destroy()
    server.start()
Пример #38
0
def main():
    parser = OptionParser()
    parser.add_option(
        '--log',
        '--log-level',
        '--log_level',
        type='choice',
        dest='log_level',
        default='warn',
        choices=['debug', 'info', 'warn', 'error', 'critical'],
        help='Log level: debug|info|warn(default)|error|critical')
    parser.add_option('-q',
                      '--quiet',
                      dest='quiet',
                      default=False,
                      action='store_true',
                      help='Don\'t print progress messages')
    parser.add_option('-k',
                      '--socket-timeout',
                      '--socket_timeout',
                      dest='socket_timeout',
                      type='int',
                      default=10,
                      help='Timeout(sec) for sockets')
    parser.add_option('-s',
                      '--server-host',
                      dest='server_host',
                      type='string',
                      default='localhost',
                      help='Server host (can be a comma-delimited list)',
                      action='callback',
                      callback_args=(str, ),
                      callback=get_comma_separated_args)
    parser.add_option(
        '-p',
        '--server-port',
        dest='server_port',
        type='string',
        default=8073,
        help='Server port, default 8073 (can be a comma delimited list)',
        action='callback',
        callback_args=(int, ),
        callback=get_comma_separated_args)
    parser.add_option(
        '--pw',
        '--password',
        dest='password',
        type='string',
        default='',
        help='Kiwi login password (if required, can be a comma delimited list)',
        action='callback',
        callback_args=(str, ),
        callback=get_comma_separated_args)
    parser.add_option('-u',
                      '--user',
                      dest='user',
                      type='string',
                      default='kiwirecorder.py',
                      help='Kiwi connection user name',
                      action='callback',
                      callback_args=(str, ),
                      callback=get_comma_separated_args)
    parser.add_option('--launch-delay',
                      '--launch_delay',
                      dest='launch_delay',
                      type='int',
                      default=0,
                      help='Delay (secs) in launching multiple connections')
    parser.add_option(
        '-f',
        '--freq',
        dest='frequency',
        type='string',
        default=1000,
        help='Frequency to tune to, in kHz (can be a comma-separated list)',
        action='callback',
        callback_args=(float, ),
        callback=get_comma_separated_args)
    parser.add_option('-m',
                      '--modulation',
                      dest='modulation',
                      type='string',
                      default='am',
                      help='Modulation; one of am, lsb, usb, cw, nbfm, iq')
    parser.add_option('--ncomp',
                      '--no_compression',
                      dest='compression',
                      default=True,
                      action='store_false',
                      help='Don\'t use audio compression')
    parser.add_option('--dt-sec',
                      dest='dt',
                      type='int',
                      default=0,
                      help='Start a new file when mod(sec_of_day,dt) == 0')
    parser.add_option('-L',
                      '--lp-cutoff',
                      dest='lp_cut',
                      type='float',
                      default=100,
                      help='Low-pass cutoff frequency, in Hz')
    parser.add_option('-H',
                      '--hp-cutoff',
                      dest='hp_cut',
                      type='float',
                      default=2600,
                      help='Low-pass cutoff frequency, in Hz')
    parser.add_option(
        '--fn',
        '--filename',
        dest='filename',
        type='string',
        default='',
        help=
        'Use fixed filename instead of generated filenames (optional station ID(s) will apply)',
        action='callback',
        callback_args=(str, ),
        callback=get_comma_separated_args)
    parser.add_option(
        '--station',
        dest='station',
        type='string',
        default=None,
        help='Station ID to be appended (can be a comma-separated list)',
        action='callback',
        callback_args=(str, ),
        callback=get_comma_separated_args)
    parser.add_option('-d',
                      '--dir',
                      dest='dir',
                      type='string',
                      default=None,
                      help='Optional destination directory for files')
    parser.add_option(
        '-w',
        '--kiwi-wav',
        dest='is_kiwi_wav',
        default=False,
        action='store_true',
        help=
        'Use wav file format including KIWI header (GPS time-stamps) only for IQ mode'
    )
    parser.add_option('--kiwi-tdoa',
                      dest='is_kiwi_tdoa',
                      default=False,
                      action='store_true',
                      help='Used when called by Kiwi TDoA extension')
    parser.add_option('--tlimit',
                      '--time-limit',
                      dest='tlimit',
                      type='float',
                      default=None,
                      help='Record time limit in seconds')
    parser.add_option('-T',
                      '--squelch-threshold',
                      dest='thresh',
                      type='float',
                      default=None,
                      help='Squelch threshold, in dB.')
    parser.add_option(
        '--squelch-tail',
        dest='squelch_tail',
        type='float',
        default=1,
        help=
        'Time for which the squelch remains open after the signal is below threshold.'
    )
    parser.add_option(
        '-g',
        '--agc-gain',
        dest='agc_gain',
        type='string',
        default=None,
        help=
        'AGC gain; if set, AGC is turned off (can be a comma-separated list)',
        action='callback',
        callback_args=(float, ),
        callback=get_comma_separated_args)
    parser.add_option('-z',
                      '--zoom',
                      dest='zoom',
                      type='int',
                      default=0,
                      help='Zoom level 0-14')
    parser.add_option('--wf',
                      dest='waterfall',
                      default=False,
                      action='store_true',
                      help='Process waterfall data instead of audio')
    parser.add_option('--snd',
                      dest='sound',
                      default=False,
                      action='store_true',
                      help='Also process sound data when in waterfall mode')
    parser.add_option('--test-mode',
                      dest='test_mode',
                      default=False,
                      action='store_true',
                      help='write wav data to /dev/null')

    (options, unused_args) = parser.parse_args()

    ## clean up OptionParser which has cyclic references
    parser.destroy()

    FORMAT = '%(asctime)-15s pid %(process)5d %(message)s'
    logging.basicConfig(level=logging.getLevelName(options.log_level.upper()),
                        format=FORMAT)
    if options.log_level.upper() == 'DEBUG':
        gc.set_debug(gc.DEBUG_SAVEALL | gc.DEBUG_LEAK | gc.DEBUG_UNCOLLECTABLE)

    run_event = threading.Event()
    run_event.set()

    gopt = options
    multiple_connections, options = options_cross_product(options)

    snd_recorders = []
    if not gopt.waterfall or (gopt.waterfall and gopt.sound):
        for i, opt in enumerate(options):
            opt.multiple_connections = multiple_connections
            opt.idx = i
            snd_recorders.append(
                KiwiWorker(args=(KiwiSoundRecorder(opt), opt, run_event)))

    wf_recorders = []
    if gopt.waterfall:
        for i, opt in enumerate(options):
            opt.multiple_connections = multiple_connections
            opt.idx = i
            wf_recorders.append(
                KiwiWorker(args=(KiwiWaterfallRecorder(opt), opt, run_event)))

    try:
        for i, r in enumerate(snd_recorders):
            if opt.launch_delay != 0 and i != 0 and options[
                    i - 1].server_host == options[i].server_host:
                time.sleep(opt.launch_delay)
            r.start()
            #logging.info("started sound recorder %d, tstamp=%d" % (i, options[i].tstamp))
            logging.info("started sound recorder %d" % i)

        for i, r in enumerate(wf_recorders):
            if i != 0 and options[i - 1].server_host == options[i].server_host:
                time.sleep(opt.launch_delay)
            r.start()
            logging.info("started waterfall recorder %d" % i)

        while run_event.is_set():
            time.sleep(.1)

    except KeyboardInterrupt:
        run_event.clear()
        join_threads(snd_recorders, wf_recorders)
        print("KeyboardInterrupt: threads successfully closed")
    except Exception as e:
        print_exc()
        run_event.clear()
        join_threads(snd_recorders, wf_recorders)
        print("Exception: threads successfully closed")

    if gopt.is_kiwi_tdoa:
        for i, opt in enumerate(options):
            # NB: MUST be a print (i.e. not a logging.info)
            print("status=%d,%d" % (i, opt.status))

    logging.debug('gc %s' % gc.garbage)
Пример #39
0
def main():
    parser = OptionParser()
    parser.add_option('-s',
                      '--server-host',
                      dest='server_host',
                      type='string',
                      default='localhost',
                      help='Server host')
    parser.add_option('-p',
                      '--server-port',
                      dest='server_port',
                      type='string',
                      default="8073",
                      help='Server port, default 8073')
    parser.add_option('--pw',
                      '--password',
                      dest='password',
                      type='string',
                      default='',
                      help='Kiwi login password')
    parser.add_option('-u',
                      '--user',
                      dest='user',
                      type='string',
                      default='kiwirecorder.py',
                      help='Kiwi connection user name')
    parser.add_option('-f',
                      '--freq',
                      dest='frequency',
                      type='float',
                      default=1000,
                      help='Frequency to tune to, in kHz')
    parser.add_option('-z',
                      '--zoom',
                      dest='zoom',
                      type='int',
                      default=0,
                      help='Zoom level 0-14')
    parser.add_option(
        '--station',
        dest='station',
        type='string',
        default=None,
        help='Station ID to be appended to filename',
    )
    parser.add_option(
        '--log',
        '--log-level',
        '--log_level',
        type='choice',
        dest='log_level',
        default='warn',
        choices=['debug', 'info', 'warn', 'error', 'critical'],
        help='Log level: debug|info|warn(default)|error|critical')
    (opt, unused_args) = parser.parse_args()

    ## clean up OptionParser which has cyclic references
    parser.destroy()

    opt.is_kiwi_tdoa = False
    opt.socket_timeout = 10
    opt.tlimit = None
    opt.no_api = True
    opt.raw = False
    opt.S_meter = -1
    opt.ADC_OV = None

    FORMAT = '%(asctime)-15s pid %(process)5d %(message)s'
    logging.basicConfig(level=logging.getLevelName(opt.log_level.upper()),
                        format=FORMAT)
    if opt.log_level.upper() == 'DEBUG':
        gc.set_debug(gc.DEBUG_SAVEALL | gc.DEBUG_LEAK | gc.DEBUG_UNCOLLECTABLE)

    run_event = threading.Event()
    run_event.set()

    snd_queue, wf_queue = [Queue(), Queue()]
    snd_recorder = KiwiWorker(args=(KiwiSoundRecorder(opt, snd_queue), opt,
                                    run_event))
    wf_recorder = KiwiWorker(args=(KiwiWaterfallRecorder(opt, wf_queue), opt,
                                   run_event))
    consumer = Consumer(args=(opt, snd_queue, wf_queue, run_event))

    threads = [snd_recorder, wf_recorder, consumer]

    try:
        opt.start_time = time.time()
        opt.tstamp = int(time.time() + os.getpid()) & 0xffffffff
        opt.idx = 0
        snd_recorder.start()

        opt.start_time = time.time()
        opt.tstamp = int(time.time() + os.getpid() + 1) & 0xffffffff
        opt.idx = 1
        wf_recorder.start()

        consumer.start()

        while run_event.is_set():
            time.sleep(.5)

    except KeyboardInterrupt:
        run_event.clear()
        join_threads(threads)
        print("KeyboardInterrupt: threads successfully closed")
    except Exception:
        print_exc()
        run_event.clear()
        join_threads(threads)
        print("Exception: threads successfully closed")

    logging.debug('gc %s' % gc.garbage)
Пример #40
0
def main():
    parser = OptionParser()
    parser.add_option(
        '--log',
        '--log-level',
        '--log_level',
        type='choice',
        dest='log_level',
        default='warn',
        choices=['debug', 'info', 'warn', 'error', 'critical'],
        help='Log level: debug|info|warn(default)|error|critical')
    parser.add_option(
        '--progress',
        dest='progress',
        default=False,
        action='store_true',
        help='Print progress messages instead of output of binary data')
    parser.add_option('-k',
                      '--socket-timeout',
                      '--socket_timeout',
                      dest='socket_timeout',
                      type='int',
                      default=10,
                      help='Timeout(sec) for sockets')
    parser.add_option('-s',
                      '--server-host',
                      dest='server_host',
                      type='string',
                      default='localhost',
                      help='Server host (can be a comma-delimited list)',
                      action='callback',
                      callback_args=(str, ),
                      callback=get_comma_separated_args)
    parser.add_option(
        '-p',
        '--server-port',
        dest='server_port',
        type='string',
        default=8073,
        help='Server port, default 8073 (can be a comma delimited list)',
        action='callback',
        callback_args=(int, ),
        callback=get_comma_separated_args)
    parser.add_option(
        '--pw',
        '--password',
        dest='password',
        type='string',
        default='',
        help='Kiwi login password (if required, can be a comma delimited list)',
        action='callback',
        callback_args=(str, ),
        callback=get_comma_separated_args)
    parser.add_option(
        '--tlimit-pw',
        '--tlimit-password',
        dest='tlimit_password',
        type='string',
        default='',
        help=
        'Connect time limit exemption password (if required, can be a comma-separated list)',
        action='callback',
        callback_args=(str, ),
        callback=get_comma_separated_args)
    parser.add_option('-u',
                      '--user',
                      dest='user',
                      type='string',
                      default='kiwi_nc.py',
                      help='Kiwi connection user name',
                      action='callback',
                      callback_args=(str, ),
                      callback=get_comma_separated_args)
    parser.add_option('--launch-delay',
                      '--launch_delay',
                      dest='launch_delay',
                      type='int',
                      default=0,
                      help='Delay (secs) in launching multiple connections')
    parser.add_option(
        '-f',
        '--freq',
        dest='frequency',
        type='string',
        default=1000,
        help='Frequency to tune to, in kHz (can be a comma-separated list). '
        'For sideband modes (lsb/lsn/usb/usn/cw/cwn) this is the carrier frequency. See --pbc option below.',
        action='callback',
        callback_args=(float, ),
        callback=get_comma_separated_args)
    parser.add_option(
        '--pbc',
        '--freq-pbc',
        dest='freq_pbc',
        action='store_true',
        default=False,
        help=
        'For sideband modes (lsb/lsn/usb/usn/cw/cwn) interpret -f/--freq frequency as the passband center frequency.'
    )
    parser.add_option(
        '-m',
        '--modulation',
        dest='modulation',
        type='string',
        default='am',
        help=
        'Modulation; one of am/amn, sam/sau/sal/sas/qam, lsb/lsn, usb/usn, cw/cwn, nbfm, iq (default passband if -L/-H not specified)'
    )
    parser.add_option(
        '--ncomp',
        '--no_compression',
        dest='compression',
        default=True,
        action='store_false',
        help='Don\'t use audio compression (IQ mode never uses compression)')
    parser.add_option('-L',
                      '--lp-cutoff',
                      dest='lp_cut',
                      type='float',
                      default=100,
                      help='Low-pass cutoff frequency, in Hz')
    parser.add_option('-H',
                      '--hp-cutoff',
                      dest='hp_cut',
                      type='float',
                      default=2600,
                      help='Low-pass cutoff frequency, in Hz')
    parser.add_option('--tlimit',
                      '--time-limit',
                      dest='tlimit',
                      type='float',
                      default=None,
                      help='Record time limit in seconds')
    parser.add_option('-T',
                      '--squelch-threshold',
                      dest='thresh',
                      type='float',
                      default=None,
                      help='Squelch threshold, in dB.')
    parser.add_option(
        '--squelch-tail',
        dest='squelch_tail',
        type='float',
        default=1,
        help=
        'Time for which the squelch remains open after the signal is below threshold.'
    )
    parser.add_option(
        '-g',
        '--agc-gain',
        dest='agc_gain',
        type='string',
        default=None,
        help=
        'AGC gain; if set, AGC is turned off (can be a comma-separated list)',
        action='callback',
        callback_args=(float, ),
        callback=get_comma_separated_args)
    parser.add_option('--agc-decay',
                      dest='agc_decay',
                      type='int',
                      default=1000,
                      help='AGC decay (msec); if set, AGC is turned on')
    parser.add_option('--agc-yaml',
                      dest='agc_yaml_file',
                      type='string',
                      default=None,
                      help='AGC options provided in a YAML-formatted file')
    parser.add_option('--de-emp',
                      dest='de_emp',
                      action='store_true',
                      default=False,
                      help='Enable de-emphasis.')
    parser.add_option('--wf',
                      '--waterfall',
                      dest='waterfall',
                      default=False,
                      action='store_true',
                      help='Process waterfall data instead of audio')

    group = OptionGroup(parser, "KiwiSDR development options", "")
    group.add_option('--gc-stats',
                     dest='gc_stats',
                     default=False,
                     action='store_true',
                     help='Print garbage collection stats')
    group.add_option(
        '--admin',
        dest='admin',
        default=False,
        action='store_true',
        help='Kiwi connection: admin instead of default audio stream.')
    parser.add_option_group(group)

    (options, unused_args) = parser.parse_args()

    ## clean up OptionParser which has cyclic references
    parser.destroy()

    FORMAT = '%(asctime)-15s pid %(process)5d %(message)s'
    logging.basicConfig(level=logging.getLevelName(options.log_level.upper()),
                        format=FORMAT)
    if options.gc_stats:
        gc.set_debug(gc.DEBUG_SAVEALL | gc.DEBUG_LEAK | gc.DEBUG_UNCOLLECTABLE)

    run_event = threading.Event()
    run_event.set()

    ### decode AGC YAML file options
    options.agc_yaml = None
    if options.agc_yaml_file:
        try:
            if not HAS_PyYAML:
                raise Exception(
                    'PyYAML not installed: sudo apt install python-yaml / sudo apt install python3-yaml / pip install pyyaml / pip3 install pyyaml'
                )
            with open(options.agc_yaml_file) as yaml_file:
                documents = yaml.full_load(yaml_file)
                logging.debug('AGC file %s: %s' %
                              (options.agc_yaml_file, documents))
                logging.debug('Got AGC parameters from file %s: %s' %
                              (options.agc_yaml_file, documents['AGC']))
                options.agc_yaml = documents['AGC']
        except KeyError:
            logging.fatal('The YAML file does not contain AGC options')
            return
        except Exception as e:
            logging.fatal(e)
            return

    options.raw = True
    options.S_meter = -1
    options.ADC_OV = None
    options.is_kiwi_tdoa = False
    options.no_api = False
    options.connect_retries = 0
    options.connect_timeout = 3
    options.rigctl_enabled = False
    gopt = options
    multiple_connections, options = options_cross_product(options)

    nc_inst = []
    for i, opt in enumerate(options):
        opt.multiple_connections = multiple_connections
        opt.idx = 0
        nc_inst.append(KiwiWorker(args=(KiwiNetcat(opt, True), opt,
                                        run_event)))
        if gopt.admin:
            opt.writer_init = False
            opt.idx = 1
            nc_inst.append(
                KiwiWorker(args=(KiwiNetcat(opt, False), opt, run_event)))

    try:
        for i, r in enumerate(nc_inst):
            if opt.launch_delay != 0 and i != 0 and options[
                    i - 1].server_host == options[i].server_host:
                time.sleep(opt.launch_delay)
            r.start()
            #logging.info("started sound recorder %d, timestamp=%d" % (i, options[i].timestamp))
            logging.info("started sound recorder %d" % i)

        while run_event.is_set():
            time.sleep(.1)

    except KeyboardInterrupt:
        run_event.clear()
        join_threads(nc_inst)
        print("KeyboardInterrupt: threads successfully closed")
    except Exception as e:
        print_exc()
        run_event.clear()
        join_threads(nc_inst)
        print("Exception: threads successfully closed")

    if gopt.gc_stats:
        logging.debug('gc %s' % gc.garbage)
Пример #41
0
def main (args):
    parser = OptionParser (usage='%prog [ options ... ] URI [ FILES ]',
                           description='Analyze repository modifications',
                           version=VERSION)
    parser.disable_interspersed_args()
    parser.add_option ('-g', '--debug', dest='debug',
                       action="store_true", default=False,
                       help="Run in debug mode")
    parser.add_option ('-c', '--config-file', dest='config_file',
                       metavar='FILE',
                       help="Use a custom configuration file")
    parser.add_option ('-r', '--revision', dest='revision',
                       metavar='REV',
                       help='Revision to analyze (HEAD)')
    parser.add_option ('-f', '--fast', dest='fast',
                       action="store_true", default=False,
                       help="Run faster but moves and copies are not detected")
    parser.add_option ('-o', '--output', dest='output',
                       default = 'text',
                       help='Output type [text|db|xml|csv] (%default)')
    add_outputs_options (parser)

    # Save default values and pass an emtpy Values object to
    # parser_args, so that default values are not set. We need it
    # to know whether a value has been provided by the user or not
    # After parsing the command line we complete the config options
    # with the default values for the options that have not been set
    # by the parser or by a config file
    defaults = parser.get_default_values ()
    options, args = parser.parse_args (args, values = Values())

    try:
        config = Config (options.config_file)
    except AttributeError:
        config = Config ()

    config.update (options.__dict__)
    config.add (defaults.__dict__)

    if not args:
        parser.error("missing required repository URI")
        return 1

    parser.destroy ()

    if config.debug:
        import repositoryhandler.backends
        repositoryhandler.backends.DEBUG = True

    uri = args[0]
    files = args[1:]
    files_from_stdin = (files and files[0] == '-')

    # Create repository
    path = uri_to_filename (uri)
    if path is not None:
        try:
            repo = create_repository_from_path (path)
        except RepositoryUnknownError:
            printerr ("Path %s doesn't seem to point to a repository supported by guilty", (path,))
            return 1
        except Exception, e:
            printerr ("Unknown error creating repository for path %s (%s)", (path, str (e)))
            return 1
        uri = repo.get_uri_for_path (path)
Пример #42
0
def main():
    def ensure_dir(path):
        """Ensure that path is a directory creating it if necessary.

        If path already exists and is not a directory, print an error
        message and quit with sys.exit().

        Parameters:
          path   String specifying the path to ensure

        Return value:
          path

        """
        if not os.path.exists(path):
            os.makedirs(path)
        elif not os.path.isdir(path):
            print("error: '%s' is not a directory" % path)
            sys.exit(1)
        return path


    def config_default(config, section, option, default):
        """Set default values for options that do not have a value."""
        try:
            config.get(section, option)
        except NoSectionError:
            config.add_section(section)
            config.set(section, option, default)
        except NoOptionError:
            config.set(section, option, default)


    config_dir = ensure_dir(os.path.expanduser("~/.diceware.py"))
    cache_dir = ensure_dir(os.path.join(config_dir, "cache"))

    # Parse config file
    config_file = os.path.join(config_dir, "config")
    config = SafeConfigParser()
    config.read(config_file)

    config_default(config, "defaults", "lang", "en")
    config_default(config, "defaults", "words", "5")
    config_default(config, "defaults", "special", "0")
    config_default(config, "defaults", "file", "")
    config_default(config, "defaults", "separator", " ")

    # Sanity checks for config options
    if config.get("defaults", "lang") not in WORD_LIST_URLS.keys():
        print("error: '%s' is not a valid value for option 'lang'"
              % config.get("defaults", "lang"))
        sys.exit(1)
    try:
        config.getint("defaults", "words")
        config.getint("defaults", "special")
    except ValueError:
        print("error: 'words' and 'special' options must have integer values")
        sys.exit(1)

    # Parse command line arguments
    parser = OptionParser()
    parser.add_option("-g", "--grid", dest="grid", action="store_true",
                      help="Instead of a single line, generate NxN grid of "+
                      "words. This makes eavesdropping harder")
    parser.add_option("-n", "--words", dest="words", type="int", metavar="N",
                      help="generate N words (default: %default)",
                      default=config.getint("defaults", "words"))
    # todo: blend this template option with regular style here
    parser.add_option("-t", "--template", dest="template",
                      default=["adj", "noun", "adv", "verb", "noun", "adv", "verb"])
    parser.add_option("-s", "--special", dest="special", type="int", metavar="M",
                      help="insert M special characters (default: %default)",
                      default=config.getint("defaults", "special"))
    parser.add_option("-f", "--file", dest="file", metavar="FILE",
                      help="override the `lang' option and read the word list " +
                      "from FILE", default=config.get("defaults", "file"))
    parser.add_option("-p", "--separator", dest="separator", type="string", metavar="P",
                      help="specify the separator between words (default: %default)",
                      default=config.get("defaults", "separator"))
    linguas = sorted(WORD_LIST_URLS.keys())
    parser.add_option("-l", "--lang", dest="lang", metavar="LANG",
                      type="choice", choices=linguas,
                      help="use the word list for LANG (" + ", ".join(linguas) +
                      ") (default: %default)", default=config.get("defaults", "lang"))


    options, args = parser.parse_args()
    if args or options.words < 1 or options.special < 0:
        parser.print_help()
        sys.exit(0)

    parser.destroy()

    # todo change this hack
    if options.template:
        print options.template
        words = []
        for placeholder in options.template:
            words.append(select_word(placeholder))
        print ' '.join(words)
        sys.exit(0)

    # --file has higher precedence than --lang
    if options.file:
        try:
            fobj = open(options.file)
        except IOError:
            print("error: unable to open word list file '%s'" % options.file)
            sys.exit(1)
        try:
            word_list = read_word_list(fobj)
        except ValueError, e:
            print("error: %s" % e)
            sys.exit(1)
Пример #43
0
def main():
    def ensure_dir(path):
        """Ensure that path is a directory creating it if necessary.

        If path already exists and is not a directory, print an error
        message and quit with sys.exit().

        Parameters:
          path   String specifying the path to ensure

        Return value:
          path

        """
        if not os.path.exists(path):
            os.makedirs(path)
        elif not os.path.isdir(path):
            print("error: '%s' is not a directory" % path)
            sys.exit(1)
        return path

    def config_default(config, section, option, default):
        """Set default values for options that do not have a value."""
        try:
            config.get(section, option)
        except NoSectionError:
            config.add_section(section)
            config.set(section, option, default)
        except NoOptionError:
            config.set(section, option, default)

    config_dir = ensure_dir(os.path.expanduser("~/.diceware.py"))
    cache_dir = ensure_dir(os.path.join(config_dir, "cache"))

    # Parse config file
    config_file = os.path.join(config_dir, "config")
    config = SafeConfigParser()
    config.read(config_file)

    config_default(config, "defaults", "lang", "en")
    config_default(config, "defaults", "words", "5")
    config_default(config, "defaults", "special", "0")
    config_default(config, "defaults", "file", "")
    config_default(config, "defaults", "separator", " ")

    # Sanity checks for config options
    if config.get("defaults", "lang") not in WORD_LIST_URLS.keys():
        print("error: '%s' is not a valid value for option 'lang'" %
              config.get("defaults", "lang"))
        sys.exit(1)
    try:
        config.getint("defaults", "words")
        config.getint("defaults", "special")
    except ValueError:
        print("error: 'words' and 'special' options must have integer values")
        sys.exit(1)

    # Parse command line arguments
    parser = OptionParser()
    parser.add_option("-g",
                      "--grid",
                      dest="grid",
                      action="store_true",
                      help="Instead of a single line, generate NxN grid of " +
                      "words. This makes eavesdropping harder")
    parser.add_option("-n",
                      "--words",
                      dest="words",
                      type="int",
                      metavar="N",
                      help="generate N words (default: %default)",
                      default=config.getint("defaults", "words"))
    parser.add_option("-s",
                      "--special",
                      dest="special",
                      type="int",
                      metavar="M",
                      help="insert M special characters (default: %default)",
                      default=config.getint("defaults", "special"))
    parser.add_option(
        "-f",
        "--file",
        dest="file",
        metavar="FILE",
        help="override the `lang' option and read the word list " +
        "from FILE",
        default=config.get("defaults", "file"))
    parser.add_option(
        "-p",
        "--separator",
        dest="separator",
        type="string",
        metavar="P",
        help="specify the separator between words (default: %default)",
        default=config.get("defaults", "separator"))
    linguas = sorted(WORD_LIST_URLS.keys())
    parser.add_option("-l",
                      "--lang",
                      dest="lang",
                      metavar="LANG",
                      type="choice",
                      choices=linguas,
                      help="use the word list for LANG (" +
                      ", ".join(linguas) + ") (default: %default)",
                      default=config.get("defaults", "lang"))

    options, args = parser.parse_args()
    if args or options.words < 1 or options.special < 0:
        parser.print_help()
        sys.exit(0)

    parser.destroy()

    # --file has higher precedence than --lang
    if options.file:
        try:
            fobj = open(options.file)
        except IOError:
            print("error: unable to open word list file '%s'" % options.file)
            sys.exit(1)
        try:
            word_list = read_word_list(fobj)
        except ValueError as e:
            print("error: %s" % e)
            sys.exit(1)
    else:
        word_list = get_word_list(cache_dir, options.lang)

    if not options.grid:
        words, with_specials = generate(word_list, options.words,
                                        options.special)
        print("passphrase   : %s" % options.separator.join(words))
        if options.special > 0:
            print("with specials: %s" % options.separator.join(with_specials))
    else:
        words, length = generate_grid(word_list, options.words,
                                      options.special)
        for word_row in words:
            print(" ".join([word.ljust(length) for word in word_row]))
Пример #44
0
def ParseArguments(argv):
    """ Parse arguments """

    from optparse import OptionParser, make_option

    # Internal cmds supported by this handler
    _CMD_OPTIONS_LIST = [
        make_option("-p",
                    "--port",
                    dest="port",
                    default="443",
                    help="TCP port number"),
        make_option(
            "-H",
            "--host",
            dest="host",
            default="",
            help="Hostname, IPv4/IPv6 address of the server. By default, "
            "server will listen on all interfaces. This is only used "
            "when --port option is provided."),
        make_option("--unix", dest="unix", help="Unix socket path"),
        make_option("--keyfile",
                    dest="keyfile",
                    default=None,
                    help="Https server private key"),
        make_option("--certfile",
                    dest="certfile",
                    default=None,
                    help="Https server certificate"),
        make_option("-i",
                    "--interactive",
                    dest="interactive",
                    action="store_true",
                    help="Interactive mode"),
        make_option("-f", "--file", dest="file",
                    help="Read request from file"),
        make_option(
            "-g",
            "--cgi",
            dest="cgi",
            action="store_true",
            help="CGI mode: process a single SOAP request as a CGI script"),
        make_option(
            "--scgi",
            dest="scgi",
            action="store_true",
            help="SCGI mode: process multiple SOAP requests over stdio",
            default=False),
        make_option("--rhost",
                    dest="rhost",
                    default=None,
                    help="Proxy mode: Remote host"),
        make_option("--rport",
                    dest="rport",
                    default="443",
                    help="Proxy mode: Remote port"),
        make_option("--rns",
                    dest="rns",
                    default="vim25/5.5",
                    help="Proxy mode: Remote namespace"),
        make_option("--rpath",
                    dest="rpath",
                    default="/sdk",
                    help="Proxy mode: Remote path"),
        make_option(
            "--ignorePyMo",
            action="store_true",
            default=False,
            dest="ignorePyMo",
            help="Do not load the managed objects or types under pyMo"),
        make_option("-?", action="help")
    ]
    _STR_USAGE = "%prog [options]"

    # Get command line options
    cmdParser = OptionParser(option_list=_CMD_OPTIONS_LIST, usage=_STR_USAGE)
    cmdParser.allow_interspersed_args = False
    LoggingFactory.AddOptions(cmdParser)

    # Parse arguments
    (options, remainingOptions) = cmdParser.parse_args(argv)
    try:
        # optparser does not have a destroy() method in older python
        cmdParser.destroy()
    except Exception:
        pass
    del cmdParser
    return (options, remainingOptions)
Пример #45
0
def main():
    conf = {}
    pkgs = {}

    parser = OptionParser(version="%prog " + __version__)
    parser.usage = "%prog [options] [category/package] ..."
    parser.disable_interspersed_args()

    parser.add_option("-f",
                      "--file",
                      dest="filename",
                      action="store",
                      type="string",
                      help="write result into FILE [default: %default]",
                      metavar="FILE",
                      default="stdout")
    parser.add_option(
        "-m",
        "--main",
        dest="main_arch",
        action="store",
        type="string",
        help="set main ARCH (e.g. your arch) [default: %default]",
        metavar="ARCH",
        default=MAIN_ARCH)
    parser.add_option("-t",
                      "--target",
                      dest="target_arch",
                      action="store",
                      type="string",
                      help="set target ARCH (e.g. x86) [default: %default]",
                      metavar="ARCH",
                      default=TARGET_ARCH)
    parser.add_option("--mtime",
                      dest="mtime",
                      action="store",
                      type="int",
                      help="set minimum MTIME in days [default: %default]",
                      metavar="MTIME",
                      default=30)

    # TODO: leave a good comment here (about True/False) :)
    parser.add_option(
        "-s",
        "--stable",
        dest="stable",
        action="store_true",
        default=False,
        help=
        "just show stable candidates (e.g. -s and -k is the default result) [default: True]"
    )
    parser.add_option(
        "-k",
        "--keyword",
        dest="keyword",
        action="store_true",
        default=False,
        help=
        "just show keyword candidates (e.g. -s and -k is the default result) [default: True]"
    )

    parser.add_option("-M",
                      "--maintainer",
                      dest="maintainer",
                      action="store",
                      type="string",
                      help="Show only packages from the specified maintainer",
                      metavar="MAINTAINER",
                      default=None)

    parser.add_option("-H",
                      "--herd",
                      dest="herd",
                      action="store",
                      type="string",
                      help="Show only packages from the specified herd",
                      metavar="HERD",
                      default=None)

    #	# EXPERIMENTAL
    #	parser.add_option( "-e", "--experimental", dest = "experimental", action = "store_true", default = False,
    #			help = "enables experimental functions/features (have a look for # EXPERIMENTAL comments in the source) [default: %default]" )

    parser.add_option(
        "-C",
        "--category",
        "--categories",
        dest="categories",
        action="store",
        default=None,
        metavar="CATEGORIES",
        help=
        "just check in the specified category/categories (comma separated) [default: %default]"
    )

    (options, args) = parser.parse_args()

    if len(args) > 0:
        conf["USER_PKGS"] = args
    else:
        conf["USER_PKGS"] = []

    # cleanup optparse
    try:
        parser.destroy()
    except AttributeError:
        # to be at least python 2.4 compatible
        del parser._short_opt
        del parser._long_opt
        del parser.defaults

    # generated timestamp (UTC)
    conf["TIME"] = strftime("%a %b %d %H:%M:%S %Z %Y", gmtime())

    # package counter
    conf["KEYWORD_SUM"] = 0
    conf["STABLE_SUM"] = 0

    if not options.main_arch in portage.archlist and options.main_arch != "auto":
        raise ValueError("invalid MAIN ARCH defined!")
    if not options.target_arch in portage.archlist and options.target_arch != "auto":
        raise ValueError("invalid TARGET ARCH defined!")

    conf["MAIN_ARCH"] = options.main_arch
    conf["TARGET_ARCH"] = options.target_arch

    conf["FILE"] = options.filename
    conf["MTIME"] = options.mtime

    if not options.stable and not options.keyword:
        conf["STABLE"] = True
        conf["KEYWORD"] = True
    else:
        conf["STABLE"] = options.stable
        conf["KEYWORD"] = options.keyword


#	conf["EXPERIMENTAL"] = options.experimental
    conf["CATEGORIES"] = options.categories

    conf["MAINTAINER"] = options.maintainer
    conf["HERD"] = options.herd

    # append to our existing
    conf = get_settings(conf)
    pkgs = get_packages(conf)
    pkgs = get_imlate(conf, pkgs)

    show_result(conf, pkgs)
Пример #46
0
                  action="store_true",
                  help="Use svn to ignore images with local modifications")
(options, args) = parser.parse_args()

if options.web_url is not None:
    uri = options.web_url
else:
    uri = options.web_root + options.web_date + "/"
    mode = ""
    if options.mode == "sr" or options.mode == "scalable,parallel" or \
       options.mode == "scalable_parallel":
        mode = "davinci_scalable_parallel_icet"
    else:
        mode = "".join([s for s in ("davinci_", options.mode)])
    uri += mode + "/"
parser.destroy()

print("uri:", uri)


class MW(QtGui.QMainWindow):
    def __init__(self, parent=None):
        QtGui.QMainWindow.__init__(self, parent)


def real_dirname(path):
    """Python's os.path.dirname is not dirname."""
    return path.rsplit('/', 1)[0]


def real_basename(path):
Пример #47
0
def main():
    parser = OptionParser()
    parser.add_option(
        '--log',
        '--log-level',
        '--log_level',
        type='choice',
        dest='log_level',
        default='warn',
        choices=['debug', 'info', 'warn', 'error', 'critical'],
        help='Log level: debug|info|warn(default)|error|critical')
    parser.add_option(
        '--progress',
        dest='progress',
        default=False,
        action='store_true',
        help='Print progress messages instead of output of binary data')
    parser.add_option('-k',
                      '--socket-timeout',
                      '--socket_timeout',
                      dest='socket_timeout',
                      type='int',
                      default=10,
                      help='Timeout(sec) for sockets')
    parser.add_option('-s',
                      '--server-host',
                      dest='server_host',
                      type='string',
                      default='localhost',
                      help='Server host (can be a comma-delimited list)',
                      action='callback',
                      callback_args=(str, ),
                      callback=get_comma_separated_args)
    parser.add_option(
        '-p',
        '--server-port',
        dest='server_port',
        type='string',
        default=8073,
        help='Server port, default 8073 (can be a comma delimited list)',
        action='callback',
        callback_args=(int, ),
        callback=get_comma_separated_args)
    parser.add_option(
        '--pw',
        '--password',
        dest='password',
        type='string',
        default='',
        help='Kiwi login password (if required, can be a comma delimited list)',
        action='callback',
        callback_args=(str, ),
        callback=get_comma_separated_args)
    parser.add_option('-u',
                      '--user',
                      dest='user',
                      type='string',
                      default='kiwirecorder.py',
                      help='Kiwi connection user name',
                      action='callback',
                      callback_args=(str, ),
                      callback=get_comma_separated_args)
    parser.add_option('--launch-delay',
                      '--launch_delay',
                      dest='launch_delay',
                      type='int',
                      default=0,
                      help='Delay (secs) in launching multiple connections')
    parser.add_option(
        '-f',
        '--freq',
        dest='frequency',
        type='string',
        default=1000,
        help='Frequency to tune to, in kHz (can be a comma-separated list)',
        action='callback',
        callback_args=(float, ),
        callback=get_comma_separated_args)
    parser.add_option('-m',
                      '--modulation',
                      dest='modulation',
                      type='string',
                      default='am',
                      help='Modulation; one of am, lsb, usb, cw, nbfm, iq')
    parser.add_option('--ncomp',
                      '--no_compression',
                      dest='compression',
                      default=True,
                      action='store_false',
                      help='Don\'t use audio compression')
    parser.add_option('-L',
                      '--lp-cutoff',
                      dest='lp_cut',
                      type='float',
                      default=100,
                      help='Low-pass cutoff frequency, in Hz')
    parser.add_option('-H',
                      '--hp-cutoff',
                      dest='hp_cut',
                      type='float',
                      default=2600,
                      help='Low-pass cutoff frequency, in Hz')
    parser.add_option('--tlimit',
                      '--time-limit',
                      dest='tlimit',
                      type='float',
                      default=None,
                      help='Record time limit in seconds')
    parser.add_option('-T',
                      '--squelch-threshold',
                      dest='thresh',
                      type='float',
                      default=None,
                      help='Squelch threshold, in dB.')
    parser.add_option(
        '--squelch-tail',
        dest='squelch_tail',
        type='float',
        default=1,
        help=
        'Time for which the squelch remains open after the signal is below threshold.'
    )
    parser.add_option(
        '-g',
        '--agc-gain',
        dest='agc_gain',
        type='string',
        default=None,
        help=
        'AGC gain; if set, AGC is turned off (can be a comma-separated list)',
        action='callback',
        callback_args=(float, ),
        callback=get_comma_separated_args)
    parser.add_option('--wf',
                      '--waterfall',
                      dest='waterfall',
                      default=False,
                      action='store_true',
                      help='Process waterfall data instead of audio')
    parser.add_option(
        '--admin',
        dest='admin',
        default=False,
        action='store_true',
        help='Kiwi connection: admin instead of default audio stream.')

    (options, unused_args) = parser.parse_args()

    ## clean up OptionParser which has cyclic references
    parser.destroy()

    FORMAT = '%(asctime)-15s pid %(process)5d %(message)s'
    logging.basicConfig(level=logging.getLevelName(options.log_level.upper()),
                        format=FORMAT)
    if options.log_level.upper() == 'DEBUG':
        gc.set_debug(gc.DEBUG_SAVEALL | gc.DEBUG_LEAK | gc.DEBUG_UNCOLLECTABLE)

    run_event = threading.Event()
    run_event.set()

    options.raw = True
    options.S_meter = False
    options.is_kiwi_tdoa = False
    gopt = options
    multiple_connections, options = options_cross_product(options)

    nc_inst = []
    for i, opt in enumerate(options):
        opt.multiple_connections = multiple_connections
        opt.idx = 0
        nc_inst.append(KiwiWorker(args=(KiwiNetcat(opt, True), opt,
                                        run_event)))
        opt.writer_init = False
        opt.idx = 1
        nc_inst.append(
            KiwiWorker(args=(KiwiNetcat(opt, False), opt, run_event)))

    try:
        for i, r in enumerate(nc_inst):
            if opt.launch_delay != 0 and i != 0 and options[
                    i - 1].server_host == options[i].server_host:
                time.sleep(opt.launch_delay)
            r.start()
            #logging.info("started sound recorder %d, tstamp=%d" % (i, options[i].tstamp))
            logging.info("started sound recorder %d" % i)

        while run_event.is_set():
            time.sleep(.1)

    except KeyboardInterrupt:
        run_event.clear()
        join_threads(nc_inst)
        print("KeyboardInterrupt: threads successfully closed")
    except Exception as e:
        print_exc()
        run_event.clear()
        join_threads(nc_inst)
        print("Exception: threads successfully closed")

    logging.debug('gc %s' % gc.garbage)
Пример #48
0

    watchdirs = args or filter(os.path.isdir, sys.path)

    # Setup logging "alamano" since pyinotify already sets up some of its soup
    if options.quiet and options.verbose:
        parser.error("quiet and verbose options are both set")
    elif options.quiet:
        loglevel = "ERROR"
    elif options.verbose:
        loglevel = "DEBUG"
    else:
        loglevel = "INFO"

    logging.setLoggerClass(logging.Logger)
    logger = logging.getLogger("zulu")
    loghandler = logging.StreamHandler()
    loghandler.setFormatter(logging.Formatter('%(asctime)s - %(message)s'))

    logger.addHandler(loghandler)
    logger.setLevel(logging.getLevelName(loglevel))

    handler = GunicornHUP(watchdirs)
    handler.appname = options.appmodule
    handler.pidfile = options.pidfile
    handler.wait_time = max(20, options.wait)

    parser.destroy()

    handler.loop()
Пример #49
0
    def cmdline(self):
        '''Parse options from the command line. For an explanation of the
        options and their usage, use:

        python master.py --help
        '''
        # This is a m-m-m-monster function, but sometimes there are just lots
        # of things to do, and that is how it is.
        self.constants()
        # we add our own help option for obscure reasons
        parser = OptionParser(add_help_option = False)
        parser.add_option('-h', '--help', action = 'store_true',
                          help = 'Display this help and exit')
        # options other than --help are in loose alphabetical order
        if has_ipv6:
            parser.add_option('-4', '--ipv4', action = 'store_false',
                              default = True, dest = 'ipv6',
                              help = 'Only use IPv4')
            parser.add_option('-6', '--ipv6', action = 'store_false',
                              default = True, dest = 'ipv4',
                              help = 'Only use IPv6')
        # a better error message here for invalid values would be nice
        parser.add_option('-d', '--db', help = 'Database backend to use, '
                          '<none|tdb|sqlite|auto>',
                          metavar = 'NAME', default = 'auto',
                          choices = ['none', 'tdb', 'sqlite', 'auto'])
        parser.add_option('-g', '--game',
                          help = 'Game for which to be a master server',
                          metavar = 'GAME', default = 'unvanquished',
                          choices = ['trem', 'tremulous', 'unv', 'unvanquished'])
        if has_chroot:
            parser.add_option('-j', '--jail',
                              help = 'Path to chroot into at startup',
                              metavar = 'DIR')
        parser.add_option('-l', '--listen-addr',
                          help = 'IPv4 address to listen to',
                          metavar = 'ADDR')
        if has_ipv6:
            # Can we put this in the conditional above without spoiling
            # the ordering?
            parser.add_option('-L', '--listen6-addr',
                              help = 'IPv6 address to listen to',
                              metavar = 'ADDR')
        parser.add_option('-n', '--max-servers', type = 'int',
                          help = 'Maximum number of servers to track',
                          metavar = 'NUM')
        parser.add_option('-p', '--port', type = 'int', default = -1,
                          help = 'Port for incoming requests',
                          metavar = 'NUM')
        parser.add_option('-P', '--challengeport', type = 'int',
                          help = 'Port for outgoing challenges',
                          metavar = 'NUM')
        parser.add_option('-q', action = 'count', default = 0,
                          help = 'Decrease verbose level. Multiple -q options '
                                 'may suppress logging entirely.')
        if has_setuid:
            parser.add_option('-u', '--user',
                              help = 'User to switch to at startup')
        parser.add_option('-v', action = 'count', default = 0,
                          help = 'Increase verbose level. Multiple -v options '
                                 'increase the level further.')
        parser.add_option('--verbose', type = 'int', default = LOG_PRINT,
                          help = 'Set verbose level directly. Takes a single '
                                 'integer argument between {0} and {1}'.format(
                                 LOG_ALWAYS, LOG_LEVELS - 1),
                          metavar = 'LEVEL')
        parser.add_option('-V', '--version', action = 'store_true',
                          help = 'Show version information')
        self.options, args = parser.parse_args(argv[1:])
        if args:
            raise ConfigError('Unexpected command line arguments')

        if self.help:
            stdout.write(parser.format_help())
            exit(0)
        # don't need this anymore
        parser.destroy()
        del parser

        if self.game == 'trem' or self.game == 'tremulous':
            self.game_name = 'Tremulous'
            self.game_id = 'Tremulous'
            defaultPort = 30710
        else:
            self.game_name = 'Unvanquished'
            self.game_id = 'UNVANQUISHED'
            defaultPort = 27950

        self.VERSION = self.game_name + ' ' + self.VERSION

        if self.version:
            stdout.write('{0}\n'.format(self.VERSION))
            exit(0)

        self.verbose += self.v - self.q

        if not LOG_ALWAYS <= self.verbose < LOG_LEVELS:
            raise ConfigError('Verbose level must be between', LOG_ALWAYS,
                              'and', LOG_LEVELS - 1,
                              '(not {0})'.format(self.verbose))

        self.log(LOG_VERBOSE, 'Logging:', *loglevels[:self.verbose + 1])

        if not self.ipv4 and not self.ipv6:
            raise ConfigError('Cannot specify both --ipv4 and --ipv6')

        if self.user is not None:
            try:
                pwnam = getpwnam(self.user)
                uid = pwnam.pw_uid
            except KeyError:
                try:
                    uid = int(self.user)
                    pwnam = getpwuid(uid)
                except ValueError:
                    raise ConfigError(self.user, 'no such user', sep = ': ')

            if has_setgid:
                gid = pwnam.pw_gid

        if self.jail is not None:
            try:
                chdir(self.jail)
                chroot('.')
            except OSError as err:
                raise ConfigError('chroot {0}:'.format(self.jail),
                                  err.strerror)
            self.log(LOG_VERBOSE, 'Chrooted to', self.jail)

        if self.user is not None:
            # okay, probably root at this point
            if has_setgroups:
                try:
                    setgroups(())
                except OSError as err:
                    raise ConfigError('setgroups:', err.strerror)

            if has_setgid:
                try:
                    setgid(gid)
                except OSError as err:
                    raise ConfigError('setgid {0}:'.format(gid), err.strerror)

            # setuid last, so setgroups & setgid don't fail
            try:
                setuid(uid)
            except OSError as err:
                raise ConfigError('setuid {0}:'.format(uid), err.strerror)

            pwnam = None

            self.log(LOG_VERBOSE, 'UID set to', getuid())

        if self.port == -1:
            self.port = defaultPort

        if self.challengeport is None:
            if self.port == 0xffff:
                self.challengeport = 0xffff - 1
            else:
                self.challengeport = self.port + 1
            self.log(LOG_VERBOSE, 'Automatically set challenge port to',
                                  self.challengeport)
        elif self.challengeport == self.port:
            raise ConfigError('Request port and challenge port must not be '
                              'the same ({0})'.format(self.port))
Пример #50
0
def main():
    usage = 'usage: %prog [options] source_image output_image tiles_directory'
    parser = OptionParser(usage)
    parser.add_option(
        '-p',
        dest='ratio',
        type='int',
        default=1,
        help=
        'ratio between tile size and subdivisions of source image [default=1]')
    parser.add_option(
        '-m',
        '--method',
        type='choice',
        dest='method',
        default='inside-out',
        choices=['inside-out', 'top-down'],
        help='traversing method (inside-out, top-down) [default=%default]')
    parser.add_option('-r',
                      '--repeat',
                      dest='repeat',
                      action='store_true',
                      help='allow repeating tiles')
    parser.add_option('-n',
                      '--norepeat',
                      dest='repeat',
                      action='store_false',
                      default=False,
                      help='do not allow repeating tiles [default]')
    parser.add_option('-t',
                      '--threshold',
                      dest='threshold',
                      default=0,
                      type='int',
                      help='''threshold value for comparing colors. 
                      0 for no threshold [default=0]''')
    parser.add_option(
        '-x',
        '--xStart',
        dest='xStart',
        default=None,
        help='''X position of where to start matching. For inside-out
                      only''')
    parser.add_option(
        '-y',
        '--yStart',
        dest='yStart',
        default=None,
        help='''Y position of where to start matching. For inside-out
                      only''')
    parser.add_option('-v',
                      '--verbose',
                      dest='verbose',
                      action='store_true',
                      default=False)
    (options, args) = parser.parse_args()
    if len(args) == 3:
        create_mosaic(args[0], args[1], args[2], options.ratio, options.method,
                      options.repeat, options.threshold, options.verbose)
    else:
        parser.error('Incorrect number of arguments. ')
    parser.destroy()
Пример #51
0
def main():
    parser = OptionParser(usage="""
    %prog [--alg=ALG] [seed]
    """)
#     parser.add_option('--fixed', action='store_true',
#                       help="Use a fixed generic guide function")
    parser.add_option('--alg', action='store',
                      choices=['gradient', 'fixed', 'genetic', 'd_e'],
                      help="Algorithm - one of gradient, fixed, genetic, d_e [default %default]",
                      default="fixed")
    opts, args = parser.parse_args()
    if len(args) > 1:
        parser.error('Extra arguments found')
    if len(args) == 1:
        try:
            seed_row = int(args[0])
            seed_file = None
        except ValueError:
            if os.path.exists(args[0]):
                seed_row = None
                seed_file = args[0]
            else:
                parser.error('seed must be an integer row number or a pkl file containing one record')
    else:
        seed_row = None
        seed_file = None

    parser.destroy()
    
    rslt_path = get_rslt_path()
    os.makedirs(rslt_path)

    subDF, acesL, boolColL, scalarColL, fixedL, passiveL, ageL = load_dataset()

    #print(scalarColL)
    print('ages: ', ageL)
    ageMin = int(min(ageL))
    ageMax = int(max(ageL))
    scalarColL.remove('AGE')
    print('scalar columns: ', scalarColL)
    ageDFD = {}
    range_d = None
    for age in range(ageMin, ageMax+1):
        ageDF = subDF[subDF.AGE==age].drop(columns=['AGE', 'FIPSST'])
        ageDFD[age], _, _, _, dct = quantizeData(ageDF, acesL, boolColL, scalarColL)
        if range_d is None:
            range_d = dct
        else:
            assert dct == range_d, 'Quantized ranges do not match?'    

    weightedSampGen = createWeightedSamplesGenerator(1000)

    scSampGen = createWeightedSamplesGenerator(1)
    if seed_file is None:
        assert opts.alg != 'fixed', 'alg fixed requires a seed file from which to generate data dir name'
        opt_dct = {}
        if seed_row is None:
            df = subDF[subDF.AGE==ageMin]
            df = df[df.FIPSST == FIPS_DCT['SC']].drop(columns=['AGE', 'FIPSST'])
            df, _, _, _, dct = quantizeData(df, acesL, boolColL, scalarColL)
            assert dct == range_d, 'Quantized ranges do not match?'
            prototype = scSampGen(ageDFD[ageMin])
        else:
            df = subDF[subDF.AGE==ageMin].drop(columns=['AGE', 'FIPSST'])
            df = df[df.RECIDX == seed_row]
            assert df.shape[0] == 1, 'Seed matched %d samples' % df.count()
            df, _, _, _, dct = quantizeData(df, acesL, boolColL, scalarColL)
            assert dct == range_d, 'Quantized ranges do not match?'
            prototype = scSampGen(df)
    else:
        df = pd.read_pickle(seed_file)
        prototype = scSampGen(df)
        opt_dct = {'seed':os.path.splitext(seed_file)[0]}
        
    print('prototype columns: ', prototype.columns)

    agent = Agent(prototype, ageDFD[ageMin], weightedSampGen, fixedL, acesL, passiveL,
                  ageMin, range_d=range_d, algorithm=opts.alg, opt_dct=opt_dct)
    while agent.age < ageMax:
        new_age = agent.age + 1
        sub_path = os.path.join(rslt_path, '%d_%d' % (agent.age, new_age))
        os.makedirs(sub_path)
        agent.write_state(sub_path)
        agent.age_transition(ageDFD[new_age])