def test_gnu_getopt(self):
        # Test handling of GNU style scanning mode.
        cmdline = ['-a', 'arg1', '-b', '1', '--alpha', '--beta=2']

        # GNU style
        opts, args = getopt.gnu_getopt(cmdline, 'ab:', ['alpha', 'beta='])
        self.assertEqual(args, ['arg1'])
        self.assertEqual(opts, [('-a', ''), ('-b', '1'),
                                ('--alpha', ''), ('--beta', '2')])

        # recognize "-" as an argument
        opts, args = getopt.gnu_getopt(['-a', '-', '-b', '-'], 'ab:', [])
        self.assertEqual(args, ['-'])
        self.assertEqual(opts, [('-a', ''), ('-b', '-')])

        # Posix style via +
        opts, args = getopt.gnu_getopt(cmdline, '+ab:', ['alpha', 'beta='])
        self.assertEqual(opts, [('-a', '')])
        self.assertEqual(args, ['arg1', '-b', '1', '--alpha', '--beta=2'])

        # Posix style via POSIXLY_CORRECT
        self.env["POSIXLY_CORRECT"] = "1"
        opts, args = getopt.gnu_getopt(cmdline, 'ab:', ['alpha', 'beta='])
        self.assertEqual(opts, [('-a', '')])
        self.assertEqual(args, ['arg1', '-b', '1', '--alpha', '--beta=2'])
def main():
    global _ros_started
    try:
        msg_recorder = MtraceRecorder()

        # first see if ros should be started
        useROS = True
        short_opts = 'hf:N'
        long_opts = ['no-ros']
        argv = sys.argv[1:]
        optlist,ignore = getopt.gnu_getopt(argv, short_opts, long_opts)
        for opt,arg in optlist:
            if (opt == "-N") or (opt == '--no-ros'):
                useROS = False

        if useROS:
            _ros_started = True
            rospy.init_node('mtrace_plotter', anonymous=True, disable_signals=True)
            argv = rospy.myargv(argv=argv)
            msg_recorder.startRosRecording()
    
        optlist,argv = getopt.gnu_getopt(argv, short_opts, long_opts);
        for opt,arg in optlist:
            if (opt == "-f"):
                msg_recorder.loadBagFileAsync(arg)
            elif (opt == "-h"):
                usage()
                return 0
            elif (opt == '-N') or (opt == '--no-ros'):
                pass
            else :
                print "Internal error : opt = ", opt
                return 1

        app = MtracePlotApp(msg_recorder)
        app.MainLoop()

    except wx.PyDeadObjectError:
        pass
    except KeyboardInterrupt:
        pass
    except:
        print 'Printing exc'
        import traceback
        traceback.print_exc()

    if _ros_started:
        rospy.signal_shutdown("Shutdown");
Esempio n. 3
0
def main():
  try:
    shortflags = 'h'
    longflags = ['help', 'username='******'password='******'encoding=']
    opts, args = getopt.gnu_getopt(sys.argv[1:], shortflags, longflags)
  except getopt.GetoptError:
    PrintUsageAndExit()
  usernameflag = None
  passwordflag = None
  encoding = None
  for o, a in opts:
    if o in ("-h", "--help"):
      PrintUsageAndExit()
    if o in ("--username"):
      usernameflag = a
    if o in ("--password"):
      passwordflag = a
    if o in ("--encoding"):
      encoding = a
  message = ' '.join(args)
  if not message:
    PrintUsageAndExit()
  rc = TweetRc()
  username = usernameflag or GetUsernameEnv() or rc.GetUsername()
  password = passwordflag or GetPasswordEnv() or rc.GetPassword()
  if not username or not password:
    PrintUsageAndExit()
  api = twitterapi.Api(username=username, password=password, input_encoding=encoding)
  try:
    status = api.PostUpdate(message)
  except UnicodeDecodeError:
    print "Your message could not be encoded.  Perhaps it contains non-ASCII characters? "
    print "Try explicitly specifying the encoding with the  it with the --encoding flag"
    sys.exit(2)
  print "%s just posted: %s" % (status.user.name, status.text)
Esempio n. 4
0
 def main (self) :
     # parse the command line
     logfile = ''
     opts, args = getopt.gnu_getopt(sys.argv[1:], 'l:')
     for o, a in opts :
         if o in ('-l',) :
             logfile = a
         else :
             assert 0, (o, a)
     assert not args, args
     # redirect and run
     if logfile :
         flog = open(logfile, 'wt')
         os.dup2(flog.fileno(), sys.stderr.fileno())
     exc = None
     try:
         self.real_main()
     except Exception:
         exc = sys.exc_info()
     if exc :
         fexc = format_exception(exc)
         sys.stderr.writelines(fexc)
         text = _("Sorry, something terrible just happened:") + "\n\n"
         text += ''.join(fexc)
         DMsgBox(text=text).run()
         r = 1
     else :
         r = 0
     if logfile :
         flog.close()
     return r
Esempio n. 5
0
def main():
    '''
    CLI implementation.
    '''

    # If we're running on Python 2.6+, turn off warnings until a version of the
    # SDK is released that doesn't trigger them.
    if sys.version_info > (2.5):
        warnings.filterwarnings('ignore')

    app_name = None
    email = None
    password = None
    remote_path = '/remote_api'
    lib_paths = []
    model_modules = []
    sql_path = './models.sqlite3'
    exclude_models = []
    level = logging.INFO
    worker_count = 5
    batch_size = 50
    batch = False
    sdk_path = None
    trigger_commands = []
    trigger_statements = []

    optlist = 'a:e:p:r:L:m:d:x:vN:C:'
    longopts = [ 'batch', 'sdk-path=', 'help', 'trigger-cmd=', 'trigger-sql=' ]
    try:
        opts, args = getopt.gnu_getopt(sys.argv[1:], optlist, longopts)
    except getopt.GetoptError, e:
        usage(str(e))
        return 1
Esempio n. 6
0
def run_cmd(cmd, argv=[]):

    verbose = False
    try:
        options_pair = cmd_opt_dict[cmd]

        options = globalOptions + options_pair[0]

        options_long = []
        options_long.extend(globalOptionsLong)
        options_long.extend(options_pair[1])

        opts, args = gnu_getopt(argv, options, options_long)

        for o, a in opts:
            if o in ("-v", "--verbose"):
                verbose = True

                # pass args and optarg data to command handler, which figures out
                # how to handle the arguments
        handler = toolchain.CommandHandler(argv, opts, args, verbose)

        # use reflection to get the function pointer
        cmd_func = getattr(handler, cmd)

        cmd_func()
    except:
        if not verbose:
            # print friendly error for users
            sys.stderr.write("Error: " + sys.exc_info()[1].__str__() + "\n")
            sys.exit(1)
        else:
            # if user wants to be verbose let python do it's thing
            raise
Esempio n. 7
0
	def parseConfig(self,args):
                '''
                This method takes a list of the switches supplied by the 
                commandline and builds a `self.options` dictionary
                
                @type args : String 
                @param args : args passed in from the command line
    
                @rtype : Boolean
                @param : Returns whether the parsing of the config was 
                         a success or failure 
                 

                '''
                
		#if type(args) != type(list): #check that a list was supplied, if not then a .rc file is being read :)
		#	return
		long_opIndex = 1
              
		if ''.join(args).split('-')[0] == '':
                        '''
                         splits the string and looks  
                        '''
			long_opIndex = 0 #no dork was supplied
			self.options['hasDork'] = False
		else:
			self.options['dork'] = ''.join(args).split('-')[0] # First argument is regarded as dork. No switches necessary.
			self.options['hasDork'] = True
		try:
			args,opts = gnu_getopt(args,self.shortOptionsList,self.longOptionsList)
		except GetoptError, e:
			raise Exception('[goo_config] unknown option(s) were supplied: '+str(e))
			return False #problem with the options supplied
def processinput(inputs):
    try:
        opts, args = getopt.gnu_getopt(sys.argv[1:], 'x:y:e:z:')     
    except getopt.GetoptError as err:
        sys.stderr.write(err + '\n')
        usage()
        sys.exit(2)
    
    if len(args) < 1:
        usage()
        print('missing:')
        print('   .log file(s)')
        sys.exit(2)

    x, y, z = 'Auto', 'Auto', False
    energytype = 'default' # oniom/scf/model/low

    for o, a in opts:
        if o == '-x':   x = a
        elif o == '-y': y = a
        elif o == '-e': energytype = a.lower()
        elif o == '-z': z = a

    if (x == 'Auto') != (y == 'Auto'):
        usage()
        print('input error:')
        print('    -x and -y must be (un)used together')
        sys.exit(2)

    return (args, x, y, z, energytype)
Esempio n. 9
0
def main():
    try:
        opts, args = getopt.gnu_getopt(sys.argv[1:], "hu:p:",
                     ['help', 'user='******'pass='******'query='])

    except getopt.GetoptError, e:
        usage(e)
Esempio n. 10
0
def main():
    try:
        opts, args = getopt.gnu_getopt(sys.argv[1:], options, long_options)
    except getopt.GetoptError, err:
        print str(err)
        usage()
        sys.exit(2)
Esempio n. 11
0
def main(argv):
	try:
		opts, args = getopt.gnu_getopt(argv[1:], 'h?u:p:P:', ['help', 'host=', 'username='******'password='******'database=', 'table=', 'port=', 'host=', 'charset='])
	except getopt.GetoptError, e:
		sys.stderr.write(e.msg+'\n')
		sys.stderr.write(u"Try '-?' or '--help' for help.\n")
		return -1
Esempio n. 12
0
def main():
  try:
    opts, args = getopt.gnu_getopt(sys.argv[1:],"ho:v",["help", "host=", "dict="])
  except (getopt.GetoptError, NameError):
    usage()
    sys.exit()

  # defaults
  hostname = 'localhost'
  dict_file = 'dictionary.txt'

  # get parameters
  for o,v in opts:
    if o in ['--host']:
      hostname = v
    elif o in ['--dict']:
      dict_file = v
    elif o in ['-h','--help']:
      usage()
      sys.exit(1)
    else:
      print('unknown parameter %s'%o)
      sys.exit(1)

  # read dictionary from file 
  dictionary = []
  with open(dict_file, 'r') as file_content:
    for line in file_content.readlines():
      user, password = line.strip().split()
      dictionary.append( (user, password) )
  
  # start attack 
  attackFTP(hostname, dictionary)
Esempio n. 13
0
def get_config():
    shortopts = 'hs:o:t:n:c'
    longopts = ['help', 'cname']

    try:
        optlist, args = getopt.gnu_getopt(sys.argv[1:], shortopts, longopts)
    except getopt.GetoptError as e:
        print e, '\n'
        print_help()
        sys.exit(1)

    global config
    for key, value in optlist:
        if key == '-s':
            config['dns'] = value
        elif key == '-o':
            config['outfile'] = value
        elif key == '-t':
            config['querytype'] = value
        elif key in ('-c', '--cname'):
            config['cname'] = True
        elif key == '-n':
            config['threadnum'] = int(value)
        elif key in ('-h', '--help'):
            print_help()
            sys.exit(0)

    if len(args) != 1:
        print "You must specify the input hosts file (only one)."
        sys.exit(1)

    config['infile'] = args[0]
    if config['outfile'] == '':
        config['outfile'] = config['infile'] + '.out'
Esempio n. 14
0
def main():
    validate = False
    opts, args = getopt.gnu_getopt(sys.argv[1:], "v", [])
    if ("-v", '') in opts:
        validate = True

    inpath = args[0]
    if len(args) > 1:
        outpath = args[1]
    else:
        outpath = os.path.splitext(os.path.basename(inpath))[0] + ".out"

    with InFileWrapper(inpath) as f, OutFileWrapper(outpath) as of:
        T = f.readint()
        print("Running [{}] Cases".format(T))

        for t in range(1, T + 1):
            res = solve_one(f)
            of.write_case(t)
            of.write_string(res)
            of.write_case_end()

    if validate:
        correct = True
        expected_path = os.path.splitext(inpath)[0] + ".expected"
        with open(outpath, "r") as out, open(expected_path, "r") as expected:
            for line in out:
                expected_line = expected.readline()
                if line.strip() != expected_line.strip():
                    correct = False
                    print("Output [{}]\nExpected [{}]".format(line.strip(), expected_line.strip()))
        if not correct:
            raise Exception("Did not validate")
Esempio n. 15
0
def main():
    global keepLinks, keepSections, prefix
    script_name = os.path.basename(sys.argv[0])

    try:
        long_opts = ['help', 'compress', 'bytes=', 'basename=','links', 'sections', 'output=', 'version']
        opts, args = getopt.gnu_getopt(sys.argv[1:], 'cb:hlo:B:sv', long_opts)
    except getopt.GetoptError:
        show_usage(script_name)
        sys.exit(1)

    compress = False
    file_size = 500 * 1024
    output_dir = '.'

    for opt, arg in opts:
        if opt in ('-h', '--help'):
            show_help()
            sys.exit()
        elif opt in ('-c', '--compress'):
            compress = True
        elif opt in ('-l', '--links'):
            keepLinks = True
        elif opt in ('-s', '--sections'):
            keepSections = True
        elif opt in ('-B', '--base'):
            prefix = arg
        elif opt in ('-b', '--bytes'):
            try:
                if arg[-1] in 'kK':
                    file_size = int(arg[:-1]) * 1024
                elif arg[-1] in 'mM':
                    file_size = int(arg[:-1]) * 1024 * 1024
                else:
                    file_size = int(arg)
                if file_size < minFileSize: raise ValueError()
            except ValueError:
                print >> sys.stderr, \
                '%s: %s: Insufficient or invalid size' % (script_name, arg)
                sys.exit(2)
        elif opt in ('-o', '--output'):
                output_dir = arg
        elif opt in ('-v', '--version'):
                print 'WikiExtractor.py version:', version
                sys.exit(0)

    if len(args) > 0:
        show_usage(script_name)
        sys.exit(4)

    if not os.path.isdir(output_dir):
        try:
            os.makedirs(output_dir)
        except:
            print >> sys.stderr, 'Could not create: ', output_dir
            return

    output_splitter = OutputSplitter(compress, file_size, output_dir)
    process_data(sys.stdin, output_splitter)
    output_splitter.close()
Esempio n. 16
0
def main(argv):
  try:
    opts, args = getopt.gnu_getopt(argv[1:], "hp:o:d:z:", ["help", "publish_on_pubrel=", "overlapping_single=", 
        "dropQoS0=", "port=", "zero_length_clientids="])
  except getopt.GetoptError as err:
    print(err) # will print something like "option -a not recognized"
    usage()
    sys.exit(2)
  publish_on_pubrel = overlapping_single = dropQoS0 = zero_length_clientids = True
  port = 1883
  for o, a in opts:
    if o in ("-h", "--help"):
      usage()
      sys.exit()
    elif o in ("-p", "--publish_on_pubrel"):
      publish_on_pubrel = False if a in ["off", "false", "0"] else True
    elif o in ("-o", "--overlapping_single"):
      overlapping_single = False if a in ["off", "false", "0"] else True
    elif o in ("-d", "--dropQoS0"):
      dropQoS0 = False if a in ["off", "false", "0"] else True
    elif o in ("-z", "--zero_length_clientids"):
      zero_length_clientids = False if a in ["off", "false", "0"] else True
    elif o in ("--port"):
      port = int(a)
    else:
      assert False, "unhandled option"

  run(publish_on_pubrel=publish_on_pubrel, overlapping_single=overlapping_single, dropQoS0=dropQoS0, port=port,
     zero_length_clientids=zero_length_clientids)
Esempio n. 17
0
def local_getopts(errexp,progname,argv,opts,longopts=[]):
	try:
		return getopt.gnu_getopt(argv,opts,longopts)
	except getopt.GetoptError, e:
		print errexp,e.msg
		print "Try '"+progname,"--help' for more information."
		sys.exit(126) 
Esempio n. 18
0
 def _parse(self, argv, store):
     """
     Parse the command line specified by argv, and store the options
     in store.
     """
     shortnames = "".join([o.shortident for o in self._optslist if o.shortname != ""])
     longnames = [o.longident for o in self._optslist if o.longname != ""]
     longnames += ["help", "version"]
     if len(self._subcommands) == 0:
         opts, args = getopt.gnu_getopt(argv, shortnames, longnames)
     else:
         opts, args = getopt.getopt(argv, shortnames, longnames)
     for opt, value in opts:
         if opt == "--help":
             self._usage()
         if opt == "--version":
             self._version()
         o = self._options[opt]
         if not store.has_section(o.section):
             store.add_section(o.section)
         if isinstance(o, Switch):
             if o.reverse == True:
                 store.set(o.section, o.override, "false")
             else:
                 store.set(o.section, o.override, "true")
         elif isinstance(o, Option):
             store.set(o.section, o.override, value)
     if len(self._subcommands) > 0:
         if len(args) == 0:
             raise ConfigureError("no subcommand specified")
         if not args[0] in self._subcommands:
             raise ConfigureError("no subcommand named '%s'" % args[0])
         return self._subcommands[args[0]]._parse(args[1:], store)
     return self, args
Esempio n. 19
0
def print_preprocess_script_option_description(preprocessorName, argv):
    options, args = getopt.gnu_getopt(argv, "so:")
    optionRawString = None
    outputFile = None
    for name, value in options:
        if name == "-s":
            optionRawString = True
        elif name == "-o":
            outputFile = value

    m = __mlu.load("pp." + preprocessorName)
    prep = m.getpreprocessor()

    prepVersion = m.getversion()
    versionStr = ".".join([str(i) for i in prepVersion])

    if not optionRawString:
        try:
            t = json.loads(prep.getoptiondescription())
        except ValueError:
            descriptionStr = prep.getoptiondescription()
        else:
            descriptionStr = build_commandline_help_string(t)
    else:
        descriptionStr = prep.getoptiondescription()

    s = "%s %s\n%s" % (preprocessorName, versionStr, descriptionStr)
    if outputFile:
        f = fopen(outputFile, "w")
        print >> f, s
        f.flush()
        f.close()
    else:
        print s
Esempio n. 20
0
def print_default_parameterizing(preprocessorName, argv):
    options, args = getopt.gnu_getopt(argv, "o:")
    outputFile = None
    for name, value in options:
        if name == "-o":
            outputFile = value
    if len(args) > 0:
        print >> sys.stderr, "error: too many command-line arguments (2)"
        sys.exit(1)

    preprocessModule = __mlu.load("pp." + preprocessorName)
    prep = preprocessModule.getpreprocessor()
    parameterizingTable = prep.getdefaultparameterizing()

    if outputFile:
        f = fopen(outputFile, "w")
    else:
        f = sys.stdout

    for k, v in sorted(parameterizingTable.iteritems()):
        if v == pp.Param.ANY_MATCH:
            s = "ANY_MATCH"
        elif v == pp.Param.EXACT_MATCH:
            s = "EXACT_MATCH"
        elif v == pp.Param.P_MATCH:
            s = "P_MATCH"
        else:
            print >> sys.stderr, "error: internal. invalid parameterizing table"
            sys.exit(1)
        print >> f, "%s\t%s" % (k, s)

    if outputFile:
        f.flush()
        f.close()
Esempio n. 21
0
def main():
    signal.signal(signal.SIGINT, signal.SIG_IGN)
    try:
        opts, args = getopt.gnu_getopt(sys.argv[1:], "h", 
                                       ['help', 'apikey=', 'fqdn='])
    except getopt.GetoptError, e:
        usage(e)
Esempio n. 22
0
def parse_args(argv):
    global site_domain, dsn, smtp_host, smtp_username, smtp_password, ssl, starttls
    try:                                
        opts, args = getopt.gnu_getopt(argv, 'hsS', [
                'smtp-host=', 'smtp-username='******'smtp-password='******'ssl', 'starttls',
                'site-domain=', 'dsn=', 'help'])
    except getopt.GetoptError:
        print(USAGE)
        sys.exit(2)

    if len(args) != 0:
        print(USAGE)
        sys.exit(2)

    for opt, arg in opts:
        if opt in ('-h', '--help'):
            print(USAGE)
            sys.exit()                  
        elif opt == '--dsn':
            dsn = arg
        elif opt == '--smtp-host':
            smtp_host = arg
        elif opt == '--smtp-username':
            smtp_username = arg
        elif opt == '--smtp-password':
            smtp_password = arg
        elif opt == '--site-domain':
            site_domain = arg
        elif opt in ('-s', '--ssl'):
            ssl = True
        elif opt in ('-S', '--starttls'):
            starttls = True
Esempio n. 23
0
File: pd1.py Progetto: alimka/pas
def main():
    try:
        opts, args = getopt.gnu_getopt(sys.argv[1:], "hcr", ["help", "content"])
    except getopt.GetoptError, err:
        print str(err)
        print __doc__
        return 1
Esempio n. 24
0
def main():
    'do all the work, main entry point'

    defaults = {'port': '8001', 'manifests': '/etc/puppet',
                'logging': '/var/log/pupaas_errors',
                'server': None, 'iface': 'eth0'}
    default_config_file = '/etc/pupaas/pupaas.conf'

    try:
        (options, remainder) = getopt.gnu_getopt(
            sys.argv[1:], "c:l:m:p:vh", ["config=", "logging=",
                                         "manifests=", "port=",
                                         "server=", "iface=",
                                         "version", "help"])
    except getopt.GetoptError as err:
        usage("Unknown option specified: " + str(err))

    if len(remainder) > 0:
        usage("Unknown option(s) specified: <%s>" % remainder[0])

    config_file, args = process_options(options)
    configs = get_config(config_file, default_config_file)
    options = opts_merge(defaults, configs, args)

    be_daemon()
    puppet = PupServer(options)
    while True:
        puppet.handle_request()
def main():

    cores = 1
    burnin = 5000
    samples = 1000
    lag = 100
    treedepth = 100
    opts, args = getopt.gnu_getopt(sys.argv[1:], "c:b:s:l:t:")
    for o, a in opts:
        if o == "-c":
            cores = int(a)
        elif o == "-b":
            burnin = int(a)
        elif o == "-s":
            samples = int(a)
        elif o == "-l":
            lag = int(a)
        elif o == "-t":
            treedepth = int(a)

    commands = []
    for method in range(0, 4):
        # COMMON Q
        # Unsplit, unshuffled
        commands.append("./inference.exe -m -b %d -s %d -l %d -t %d -c %d" % (burnin, samples, lag, treedepth, method))
        # Unsplit, shuffled
        commands.append("./inference.exe -m -b %d -s %d -l %d -t %d -c %d -S" % (burnin, samples, lag, treedepth, method))
        # Split, unshuffled
        commands.append("./inference.exe -m -b %d -s %d -l %d -t %d -c %d -x" % (burnin, samples, lag, treedepth, method))
        # INDIVIDUAL Q
        # Unsplit, unshuffled
        commands.append("./inference.exe -b %d -s %d -l %d -t %d -c %d" % (burnin, samples, lag, treedepth, method))

    initial_length = len(commands)
    start_time = time.time()

    procs = []

    # Start initial procs, one per core
    for i in range(0,cores):
        command = commands.pop()
        print "Starting an initial job..."
        proc = subprocess.Popen(command.split(), stdout=open("/dev/null","w"))
        procs.append(proc)

    # Poll procs to replace when finished
    while procs:
        time.sleep(1)
        proc = procs.pop()
        proc.poll()
        if proc.returncode != None:
            # Finished, start a new job
            print "Trees left to analyse: ", len(commands)
            print_eta(initial_length, start_time, len(commands), time.time())
            if commands:
                command = commands.pop()
                proc = subprocess.Popen(command.split(), stdout=open("/dev/null","w"))
                procs.insert(0, proc)
        else:
            procs.insert(0, proc)
Esempio n. 26
0
def main():
    USAGE = '''Usage: tweet [options] message

This script scrapes all raw files from path and write it to js file as an javascript array.

Options:

  -h --help : print this help
  -r --raw-path : path to raw files
  -j --js-path : path to js files
  -v --verbose : more output, more power
  '''
    raw_path = ''
    js_path = ''
    verbose = False

    print '#############################################################'
    print '#                                                           #'
    print '#    make_wordlist v'+ __version__+'                                   #'
    print '#                                                           #'
    print '#############################################################\n'
    
    try:
        shortflags = 'hr:j:v'
        longflags = ['help', 'raw-path=', 'js-path=', 'verbose']
        opts, args = getopt.gnu_getopt(sys.argv[1:], shortflags, longflags)
    except getopt.GetoptError, e:
        print e
Esempio n. 27
0
def main():
	try:
		shortflags = 'h'
		longflags = ['help', 'consumer_key=', 'access_token=']
		opts, args = getopt.gnu_getopt(sys.argv[1:], shortflags, longflags)
	except getopt.GetoptError:
		print_usage_and_exit()

	consumer_key = None
	access_token = None

	for o, a in opts:
		if o in ('-h', '--help'):
			print_usage_and_exit()
		if o in ('--consumer_key'):
			consumer_key = a
		if o in ('--access_token'):
			access_token = a

	url = ' '.join(args)
	if not url or not consumer_key or not access_token:
		print_usage_and_exit()

	api = pocket.Api(consumer_key = consumer_key, access_token = access_token)

	try:
		item = api.add(url)
		print 'Item \'%s\' added successfuly!' % item.normal_url
	except e:
		print e
		sys.exit(2)
Esempio n. 28
0
def get_args():
    '''
    get and return command line args
    '''
    configfile = False
    dryrun = False
    date = None
    output_dir = None
    overwrite = True
    script = None
    query = None
    retries = None
    wikiname = None
    basename = None
    verbose = False
    filenameformat = "{w}-{d}-{s}"

    try:
        (options, remainder) = getopt.gnu_getopt(
            sys.argv[1:], "c:d:f:o:w:b:s:q:r:nDvh",
            ['configfile=', 'date=', 'filenameformat=',
             'outdir=', 'script=', 'query=', 'retries=',
             'wiki=', 'base=', 'dryrun', 'nooverwrite',
             'verbose', 'help'])

    except getopt.GetoptError as err:
        print str(err)
        usage("Unknown option specified")

    for (opt, val) in options:
        if opt in ["-c", "--configfile"]:
            configfile = val
        elif opt in ["-d", "--date"]:
            date = val
        elif opt in ["-f", "--filenameformat"]:
            filenameformat = val
        elif opt in ["-o", "--outdir"]:
            output_dir = val
        elif opt in ["-w", "--wiki"]:
            wikiname = val
        elif opt in ["-b", "--base"]:
            basename = val
        elif opt in ["-s", "--script"]:
            script = val
        elif opt in ["-q", "--query"]:
            query = val
        elif opt in ["-r", "--retries"]:
            retries = val
        elif opt in ["-n", "--nooverwrite"]:
            overwrite = False
        elif opt in ["-D", "--dryrun"]:
            dryrun = True
        elif opt in ["-v", "--verbose"]:
            verbose = True
        elif opt in ["-h", "--help"]:
            usage("Help for this script:")

    return(configfile, date, dryrun, filenameformat,
           output_dir, overwrite, wikiname, script,
           basename, query, retries, verbose, remainder)
Esempio n. 29
0
def get_opts():
    try:
        opts, args = getopt.gnu_getopt(sys.argv[1:], "b:p:s:r:", ["base=","path=","soname=", "realname="])
    except getopt.GetoptError:
        usage()
        sys.exit(2)

    for o, a in opts:
        if o in ("-b", "--base"):
            cmd = 'base'
            arg = a
        elif o in ("-p", "--path"):
            cmd = 'path'
            arg = a
        elif o in ("-s", "--soname"):
            cmd = 'soname'
            arg = a
        elif o in ("-r", "--realname"):
            cmd  = 'realname'
            arg = a
        else:
            assert False, "unhundled option"
            usage()
    
    # print("result:{0},{1}".format(cmd, arg))
    return (cmd, arg)
Esempio n. 30
0
def run(*args):
    # TODO add '--state=on/offline' option
    optlist, args = getopt.gnu_getopt(args, '', ['json', 'props'])
    optlist = dict(optlist)
    restUrl = '/devices'

    if len(args) > 0:
        raise exception.UsageError('Unsupported commandline arguments: {0}'.format(args))

    if '--props' in optlist:
        restUrl = '/devices?props=true'
    resp = rest.apiGET(restUrl)

    if '--json' in optlist:
        for dev in resp['devices']:
            print(json.dumps(dev))
#    elif '--raw' in args:
#        print(json.dumps(resp))
    else:
        fmt='{id:20s} {state:10s} {ip:15s} {version:15s} {name}'
        print(fmt.format(id='ID',state='State', ip='IP', version='Version', name='Title'))

        for dev in resp['devices']:
            # add missing values
            for key in ['name','ip','version']:
                if not key in dev:
                    dev[key] = ''
            
            print(fmt.format(**dev))
Esempio n. 31
0
def main():
    try:
        opts, args = getopt.gnu_getopt(sys.argv[1:], "h", ["help"])
    except getopt.GetoptError, e:
        usage(e)
Esempio n. 32
0
File: ca.py Progetto: ckelleyRH/pki
    def execute(self, argv):

        try:
            opts, _ = getopt.gnu_getopt(argv, 'i:v', [
                'instance=', 'pkcs12-file=', 'pkcs12-password='******'pkcs12-password-file=', 'no-key', 'verbose', 'debug', 'help'
            ])

        except getopt.GetoptError as e:
            logger.error(e)
            self.print_help()
            sys.exit(1)

        instance_name = 'pki-tomcat'
        pkcs12_file = None
        pkcs12_password = None
        no_key = False

        for o, a in opts:
            if o in ('-i', '--instance'):
                instance_name = a

            elif o == '--pkcs12-file':
                pkcs12_file = a

            elif o == '--pkcs12-password':
                pkcs12_password = a.encode()

            elif o == '--pkcs12-password-file':
                with io.open(a, 'rb') as f:
                    pkcs12_password = f.read()

            elif o == '--no-key':
                no_key = True

            elif o in ('-v', '--verbose'):
                logging.getLogger().setLevel(logging.INFO)

            elif o == '--debug':
                logging.getLogger().setLevel(logging.DEBUG)

            elif o == '--help':
                self.print_help()
                sys.exit()

            else:
                logger.error('Invalid option: %s', o)
                self.print_help()
                sys.exit(1)

        if not pkcs12_file:
            logger.error('Missing PKCS #12 file')
            self.print_help()
            sys.exit(1)

        if not pkcs12_password:
            logger.error('Missing PKCS #12 password')
            self.print_help()
            sys.exit(1)

        instance = pki.server.instance.PKIServerFactory.create(instance_name)
        if not instance.exists():
            logger.error('Invalid instance: %s', instance_name)
            sys.exit(1)

        instance.load()

        subsystem = instance.get_subsystem('ca')
        if not subsystem:
            logger.error('No CA subsystem in instance %s', instance_name)
            sys.exit(1)

        tmpdir = tempfile.mkdtemp()

        try:
            pkcs12_password_file = os.path.join(tmpdir, 'pkcs12_password.txt')
            with open(pkcs12_password_file, 'wb') as f:
                f.write(pkcs12_password)

            subsystem.export_system_cert('subsystem',
                                         pkcs12_file,
                                         pkcs12_password_file,
                                         no_key=no_key)
            subsystem.export_system_cert('signing',
                                         pkcs12_file,
                                         pkcs12_password_file,
                                         no_key=no_key,
                                         append=True)
            subsystem.export_system_cert('ocsp_signing',
                                         pkcs12_file,
                                         pkcs12_password_file,
                                         no_key=no_key,
                                         append=True)
            subsystem.export_system_cert('audit_signing',
                                         pkcs12_file,
                                         pkcs12_password_file,
                                         no_key=no_key,
                                         append=True)
            instance.export_external_certs(pkcs12_file,
                                           pkcs12_password_file,
                                           append=True)

        finally:
            shutil.rmtree(tmpdir)
Esempio n. 33
0
    def execute(self, argv):

        try:
            opts, args = getopt.gnu_getopt(
                argv, 'i:v', ['tomcat=', 'verbose', 'debug', 'help'])

        except getopt.GetoptError as e:
            print('ERROR: ' + str(e))
            self.print_help()
            sys.exit(1)

        tomcat_version = None

        for o, a in opts:
            if o == '--tomcat':
                tomcat_version = a

            elif o in ('-v', '--verbose'):
                self.set_verbose(True)

            elif o == '--debug':
                self.set_verbose(True)
                self.set_debug(True)

            elif o == '--help':
                self.print_help()
                sys.exit()

            else:
                print('ERROR: unknown option ' + o)
                self.print_help()
                sys.exit(1)

        if len(args) != 1:
            print('ERROR: missing instance ID')
            self.print_help()
            sys.exit(1)

        instance_name = args[0]

        if not tomcat_version:
            tomcat_version = pki.server.Tomcat.get_major_version()

        if self.verbose:
            print('Migrating to Tomcat %s' % tomcat_version)

        module = self.get_top_module().find_module('migrate')
        module.set_verbose(self.verbose)
        module.set_debug(self.debug)

        instance = pki.server.PKIInstance(instance_name)

        if not instance.is_valid():
            print('ERROR: Invalid instance %s.' % instance_name)
            sys.exit(1)

        instance.load()

        module.migrate(  # pylint: disable=no-member,maybe-no-member
            instance, tomcat_version)

        self.print_message('%s instance migrated' % instance_name)
Esempio n. 34
0
    def execute(self, argv):

        try:
            opts, args = getopt.gnu_getopt(argv, 'i:v', [
                'instance=', 'pkcs12-file=', 'pkcs12-password='******'pkcs12-password-file=', 'append', 'no-trust-flags', 'no-key',
                'no-chain', 'verbose', 'debug', 'help'
            ])

        except getopt.GetoptError as e:
            print('ERROR: ' + str(e))
            self.print_help()
            sys.exit(1)

        nicknames = args

        instance_name = 'pki-tomcat'
        pkcs12_file = None
        pkcs12_password = None
        pkcs12_password_file = None
        append = False
        include_trust_flags = True
        include_key = True
        include_chain = True
        debug = False

        for o, a in opts:
            if o in ('-i', '--instance'):
                instance_name = a

            elif o == '--pkcs12-file':
                pkcs12_file = a

            elif o == '--pkcs12-password':
                pkcs12_password = a

            elif o == '--pkcs12-password-file':
                pkcs12_password_file = a

            elif o == '--append':
                append = True

            elif o == '--no-trust-flags':
                include_trust_flags = False

            elif o == '--no-key':
                include_key = False

            elif o == '--no-chain':
                include_chain = False

            elif o in ('-v', '--verbose'):
                self.set_verbose(True)

            elif o == '--debug':
                debug = True

            elif o == '--help':
                self.print_help()
                sys.exit()

            else:
                print('ERROR: unknown option ' + o)
                self.print_help()
                sys.exit(1)

        if not pkcs12_file:
            print('ERROR: missing output file')
            self.print_help()
            sys.exit(1)

        instance = pki.server.PKIInstance(instance_name)

        if not instance.is_valid():
            print('ERROR: Invalid instance %s.' % instance_name)
            sys.exit(1)

        instance.load()

        if not pkcs12_password and not pkcs12_password_file:
            pkcs12_password = getpass.getpass(
                prompt='Enter password for PKCS #12 file: ')

        nssdb = instance.open_nssdb()
        try:
            nssdb.export_pkcs12(pkcs12_file=pkcs12_file,
                                pkcs12_password=pkcs12_password,
                                pkcs12_password_file=pkcs12_password_file,
                                nicknames=nicknames,
                                append=append,
                                include_trust_flags=include_trust_flags,
                                include_key=include_key,
                                include_chain=include_chain,
                                debug=debug)
        finally:
            nssdb.close()
Esempio n. 35
0
    beautifulsoup = False
    reverse = False
    scraps = False
    favs = False
    collection = False
    collectionS = ""
    testOnly = False
    album = False
    albumId = -1
    query = False
    queryS = ""

    try:
        options, deviants = getopt.gnu_getopt(
            sys.argv[1:], 'u:p:x:a:q:c:vfgshrtob', [
                'username='******'password='******'proxy=', 'album=', 'query=',
                'collection=', 'verbose', 'favs', 'gallery', 'scraps', 'help',
                'reverse', 'test', 'overwrite', 'beautifulsoup'
            ])
    except getopt.GetoptError, err:
        print "Options error:", str(err)
        sys.exit()
    for opt, arg in options:
        if opt in ('-h', '--help'):
            printHelpDetailed()
            sys.exit()
        elif opt in ('-u', '--username'):
            username = arg
        elif opt in ('-p', '--password'):
            password = arg
        elif opt in ('-x', '--proxy'):
            proxy = arg
Esempio n. 36
0
    if len(tr.ch) == 2 and '-lA' in tr.ch[0].c and tr.ch[1].c == 'D-aN':
        return getHead(
            tr.ch[0])  # special case for complement of 's as actual head
    for subtr in tr.ch:
        if '-l' not in subtr.c:
            return getHead(subtr)
    return tr


def addCoref(tr, beg, end):
    ls = smallestContainingCat(tr, beg - 1, end)[1]
    return getHead(ls[0]) if len(ls) > 0 else tree.Tree()


## command-line options...
optlist, args = getopt.gnu_getopt(sys.argv, 'd')

treefile = open(args[1])  #sys.argv[1] )

PrevMention = {}

linenum = 0
for line in sys.stdin:

    if line.startswith('<TEXT') or line.startswith(
            '</TEXT') or line.startswith('</DOC'):
        continue

    linenum += 1
    treestring = treefile.readline()
def main(argv):
    options, remainder = getopt.gnu_getopt(argv[1:], 'ohp:',
                                           ['output', 'help', 'path='])
    OUTPUT, HELP, PATH = False, False, './dataset/'
    for opt, arg in options:
        if opt in ('-o', '--output'):
            OUTPUT = True
        elif opt in ('-h', '--help'):
            HELP = True
        elif opt in ('-p', '--path'):
            PATH = arg

    if HELP:
        print("\n*** Baseline for the CoNLL-SIGMORPHON 2017 shared task ***\n")
        print("By default, the program runs both tasks and all languages")
        print("only evaluating accuracy. To create output files, use -o")
        print("The training and dev-data are assumed to live in ./dataset/ \n")
        print("Options:")
        print(
            " -o         create output files with guesses (and don't just evaluate)"
        )
        print(" -p [path]  data files path. Default is ./../")
        quit()

    runningavg, numiter = 0.0, 0

    allprules, allsrules = {}, {}
    lines = [
        line.strip()
        for line in codecs.open(PATH + 'en-train', "r", encoding="utf-8")
    ]

    # First, test if language is predominantly suffixing or prefixing
    # If prefixing, work with reversed strings
    prefbias, suffbias = 0, 0
    for l in lines:
        lemma, form, _ = l.split(u'\t')
        aligned = halign(lemma, form)
        if ' ' not in aligned[0] and ' ' not in aligned[
                1] and '-' not in aligned[0] and '-' not in aligned[1]:
            prefbias += numleadingsyms(aligned[0], '_') + numleadingsyms(
                aligned[1], '_')
            suffbias += numtrailingsyms(aligned[0], '_') + numtrailingsyms(
                aligned[1], '_')

    for l in lines:  # Read in lines and extract transformation rules from pairs
        lemma, form, msd = l.split(u'\t')
        if prefbias > suffbias:
            lemma = lemma[::-1]
            form = form[::-1]
        prules, srules = prefix_suffix_rules_get(lemma, form)

        if msd not in allprules and len(prules) > 0:
            allprules[msd] = {}
        if msd not in allsrules and len(srules) > 0:
            allsrules[msd] = {}

        for r in prules:
            if (r[0], r[1]) in allprules[msd]:
                allprules[msd][(r[0], r[1])] = allprules[msd][(r[0], r[1])] + 1
            else:
                allprules[msd][(r[0], r[1])] = 1

        for r in srules:
            if (r[0], r[1]) in allsrules[msd]:
                allsrules[msd][(r[0], r[1])] = allsrules[msd][(r[0], r[1])] + 1
            else:
                allsrules[msd][(r[0], r[1])] = 1

    ## Store model
    with open('allsrules.pkl', 'wb') as f:
        pickle.dump(allsrules, f)

    with open('allprules.pkl', 'wb') as f:
        pickle.dump(allprules, f)

    with open('prefbias.pkl', 'wb') as f:
        pickle.dump(prefbias, f)

    with open('suffbias.pkl', 'wb') as f:
        pickle.dump(suffbias, f)

    # Run eval on dev
    devlines = [
        line.strip()
        for line in codecs.open(PATH + 'en-dev', "r", encoding="utf-8")
    ]

    numcorrect = 0
    numguesses = 0

    if OUTPUT:
        outfile = codecs.open(PATH + "en-out", "w", encoding="utf-8")

    for l in devlines:
        lemma, correct, msd, = l.split(u'\t')
        lemmaorig = lemma
        if prefbias > suffbias:
            lemma = lemma[::-1]
        outform = apply_best_rule(lemma, msd, allprules, allsrules)
        if prefbias > suffbias:
            outform = outform[::-1]
        if outform == correct:
            numcorrect += 1
        numguesses += 1
        if OUTPUT:
            outfile.write(lemmaorig + "\t" + outform + "\t" + msd + "\n")

    if OUTPUT:
        outfile.close()

    runningavg += numcorrect / float(numguesses)
    numiter += 1

    print("en" + ": " + str(str(numcorrect / float(numguesses)))[0:7])
    print("Average:", str(runningavg / float(numiter)))
    print("------------------------------------\n")
Esempio n. 38
0
File: ca.py Progetto: ckelleyRH/pki
    def execute(self, argv):

        try:
            opts, _ = getopt.gnu_getopt(argv, 'i:v', [
                'instance=', 'cert=', 'cert-file=', 'verbose', 'debug', 'help'
            ])

        except getopt.GetoptError as e:
            logger.error(e)
            self.print_help()
            sys.exit(1)

        instance_name = 'pki-tomcat'
        cert = None

        for o, a in opts:
            if o in ('-i', '--instance'):
                instance_name = a

            elif o == '--cert':
                cert = a

            elif o == '--cert-file':
                with io.open(a, 'rb') as f:
                    cert = f.read()

            elif o in ('-v', '--verbose'):
                logging.getLogger().setLevel(logging.INFO)

            elif o == '--debug':
                logging.getLogger().setLevel(logging.DEBUG)

            elif o == '--help':
                self.print_help()
                sys.exit()

            else:
                logger.error('Invalid option: %s', o)
                self.print_help()
                sys.exit(1)

        instance = pki.server.instance.PKIServerFactory.create(instance_name)
        if not instance.exists():
            logger.error('Invalid instance: %s', instance_name)
            sys.exit(1)

        instance.load()

        subsystem = instance.get_subsystem('ca')
        if not subsystem:
            logger.error('No CA subsystem in instance %s', instance_name)
            sys.exit(1)

        results = subsystem.find_cert_requests(cert=cert)

        self.print_message('%s entries matched' % len(results))

        first = True
        for request in results:
            if first:
                first = False
            else:
                print()

            CACertRequestCLI.print_request(request)
Esempio n. 39
0
#coding=utf-8
import getopt
import sys
from difffile import difffile
import scriptrunner

opts, args = getopt.gnu_getopt(sys.argv[1:], 'r:o', ['root=', 'objfile'])
ROOT_DIR = './'
OBJ_FILE = ''
if (args.__len__() == 0):
    print '使用方式:\npython diffexe difffile1.diff difffile2.diff ... [-r ROOT_DIR] [-o OBJ_FILE]'
else:
    for dfpath in args:
        for opt in opts:
            if (opt[0] == '-r' or opt[0] == '--root'):
                ROOT_DIR = opt[1]
            elif (opt[0] == '-o' or opt[0] == '--objfile'):
                OBJ_FILE = opt[1]
        f = difffile(dfpath)
        if (f.isValidDIffFile()):
            f.execute(ROOT_DIR, OBJ_FILE)
        else:
            f._error('无效文件!')
Esempio n. 40
0
File: ca.py Progetto: ckelleyRH/pki
    def execute(self, argv):

        try:
            opts, args = getopt.gnu_getopt(
                argv, 'i:v',
                ['instance=', 'output-file=', 'verbose', 'debug', 'help'])

        except getopt.GetoptError as e:
            logger.error(e)
            self.print_help()
            sys.exit(1)

        if len(args) != 1:
            logger.error('Missing request ID')
            self.print_help()
            sys.exit(1)

        request_id = args[0]
        instance_name = 'pki-tomcat'
        output_file = None

        for o, a in opts:
            if o in ('-i', '--instance'):
                instance_name = a

            elif o == '--output-file':
                output_file = a

            elif o in ('-v', '--verbose'):
                logging.getLogger().setLevel(logging.INFO)

            elif o == '--debug':
                logging.getLogger().setLevel(logging.DEBUG)

            elif o == '--help':
                self.print_help()
                sys.exit()

            else:
                logger.error('Invalid option: %s', o)
                self.print_help()
                sys.exit(1)

        instance = pki.server.instance.PKIServerFactory.create(instance_name)
        if not instance.exists():
            logger.error('Invalid instance: %s', instance_name)
            sys.exit(1)

        instance.load()

        subsystem = instance.get_subsystem('ca')
        if not subsystem:
            logger.error('No CA subsystem in instance %s', instance_name)
            sys.exit(1)

        request = subsystem.get_cert_requests(request_id)

        if output_file:
            with io.open(output_file, 'wb') as f:
                f.write(request['request'].encode())

        else:
            CACertRequestCLI.print_request(request, details=True)
Esempio n. 41
0
    def call(self):
        if not len(self.args):
            self.errorWrite("cp: missing file operand\n")
            self.errorWrite("Try `cp --help' for more information.\n")
            return
        try:
            optlist, args = getopt.gnu_getopt(self.args,
                                              '-abdfiHlLPpRrsStTuvx')
        except getopt.GetoptError as err:
            self.errorWrite('Unrecognized option\n')
            return
        recursive = False
        for opt in optlist:
            if opt[0] in ('-r', '-a', '-R'):
                recursive = True

        def resolv(pname):
            return self.fs.resolve_path(pname, self.protocol.cwd)

        if len(args) < 2:
            self.errorWrite(
                "cp: missing destination file operand after `{}'\n".format(
                    self.args[0]))
            self.errorWrite("Try `cp --help' for more information.\n")
            return
        sources, dest = args[:-1], args[-1]
        if len(sources) > 1 and not self.fs.isdir(resolv(dest)):
            self.errorWrite(
                "cp: target `{}' is not a directory\n".format(dest))
            return

        if dest[-1] == '/' and not self.fs.exists(resolv(dest)) and \
                not recursive:
            self.errorWrite(
                "cp: cannot create regular file `{}': Is a directory\n".format(
                    dest))
            return

        if self.fs.isdir(resolv(dest)):
            isdir = True
        else:
            isdir = False
            parent = os.path.dirname(resolv(dest))
            if not self.fs.exists(parent):
                self.errorWrite("cp: cannot create regular file " + \
                           "`{}': No such file or directory\n".format(dest))
                return

        for src in sources:
            if not self.fs.exists(resolv(src)):
                self.errorWrite(
                    "cp: cannot stat `{}': No such file or directory\n".format(
                        src))
                continue
            if not recursive and self.fs.isdir(resolv(src)):
                self.errorWrite("cp: omitting directory `{}'\n".format(src))
                continue
            s = copy.deepcopy(self.fs.getfile(resolv(src)))
            if isdir:
                dir = self.fs.get_path(resolv(dest))
                outfile = os.path.basename(src)
            else:
                dir = self.fs.get_path(os.path.dirname(resolv(dest)))
                outfile = os.path.basename(dest.rstrip('/'))
            if outfile in [x[A_NAME] for x in dir]:
                dir.remove([x for x in dir if x[A_NAME] == outfile][0])
            s[A_NAME] = outfile
            dir.append(s)
Esempio n. 42
0
             --dcptsFileName=FILE        : the file with dense CPTs {%s}
             --dpmfsFileName=FILE        : the file with sparse CPTs {%s}
             --wordDtFileName=FILE       : the file with word decision tree {%s} 
             --concept2DtFileName=FILE   : the file with concept2 decision tree {%s} 
             --conceptMap=FILE           : the concept map file name {%s}
             --wordMap=FILE              : the word map file name {%s} """ %
          (dirOut, dcptsFileName, dpmfsFileName, wordDtFileName,
           concept2DtFileName, conceptFileName, wordFileName))


###################################################################################################
###################################################################################################

try:
    opts, args = getopt.gnu_getopt(sys.argv[1:], "hv", [
        "dirOut=", "dcptsFileName=", "dpmfsFileName=", "wordDtFileName=",
        "concept2DtFileName=", "conceptMap=", "wordMap="
    ])

except getopt.GetoptError, exc:
    print("ERROR: " + exc.msg)
    usage()
    sys.exit(2)

verbose = None

for o, a in opts:
    if o == "-h":
        usage()
        sys.exit()
    elif o == "-v":
        verbose = True
Esempio n. 43
0
def parse_colour(col):
    if col[:1] != "#" or len(col) % 3 != 1 or \
            col[1:].lstrip(string.hexdigits) != "":
        sys.stderr.write("expected colours of the form #rrggbb\n")
        sys.exit(1)
    col = col[1:]
    n = len(col) / 3
    r = int(col[:n], 16) / (16.0**n - 1)
    g = int(col[n:2 * n], 16) / (16.0**n - 1)
    b = int(col[2 * n:3 * n], 16) / (16.0**n - 1)
    return "%f %f %f setrgbcolor" % (r, g, b)


try:
    options, args = getopt.gnu_getopt(
        sys.argv[1:], 's:S:X:Y:R:fTp:a:',
        ['linear', 'tabcolour=', 'tabcolor=', 'linewidth='])
except getopt.GetoptError as e:
    sys.stderr.write("drawnet.py: %s\n" % str(e))
    sys.exit(1)

for opt, val in options:
    if opt == "-s":
        firstface = val
    elif opt == "-S":
        cmdlinescale = float(val)
    elif opt == "-X":
        cmdlinex = float(val)
    elif opt == "-Y":
        cmdliney = float(val)
    elif opt == "-R":
Esempio n. 44
0
    def call(self):
        if not len(self.args):
            self.errorWrite("mv: missing file operand\n")
            self.errorWrite("Try `mv --help' for more information.\n")
            return

        try:
            optlist, args = getopt.gnu_getopt(self.args, '-bfiStTuv')
        except getopt.GetoptError as err:
            self.errorWrite('Unrecognized option\n')
            self.exit()

        def resolv(pname):
            return self.fs.resolve_path(pname, self.protocol.cwd)

        if len(args) < 2:
            self.errorWrite(
                "mv: missing destination file operand after `{}'\n".format(
                    self.args[0]))
            self.errorWrite("Try `mv --help' for more information.\n")
            return
        sources, dest = args[:-1], args[-1]
        if len(sources) > 1 and not self.fs.isdir(resolv(dest)):
            self.errorWrite(
                "mv: target `{}' is not a directory\n".format(dest))
            return

        if dest[-1] == '/' and not self.fs.exists(resolv(dest)) and \
                        len(sources) != 1:
            self.errorWrite(
                "mv: cannot create regular file `{}': Is a directory\n".format(
                    dest))
            return

        if self.fs.isdir(resolv(dest)):
            isdir = True
        else:
            isdir = False
            parent = os.path.dirname(resolv(dest))
            if not self.fs.exists(parent):
                self.errorWrite("mv: cannot create regular file " + \
                           "`{}': No such file or directory\n".format(dest))
                return

        for src in sources:
            if not self.fs.exists(resolv(src)):
                self.errorWrite(
                    "mv: cannot stat `{}': No such file or directory\n".format(
                        src))
                continue
            s = self.fs.getfile(resolv(src))
            if isdir:
                dir = self.fs.get_path(resolv(dest))
                outfile = os.path.basename(src)
            else:
                dir = self.fs.get_path(os.path.dirname(resolv(dest)))
                outfile = os.path.basename(dest)
            if dir != os.path.dirname(resolv(src)):
                s[A_NAME] = outfile
                dir.append(s)
                sdir = self.fs.get_path(os.path.dirname(resolv(src)))
                sdir.remove(s)
            else:
                s[A_NAME] = outfile
Esempio n. 45
0
            ieconv = 1


def Abort():
    print 'Aborting...'
    sys.exit()


### Parse input ###
if len(sys.argv) == 1:
    helpme()
    sys.exit()
manual_units = False  # Turned on via command line
args = list(sys.argv[1:])
myopts, args = getopt.gnu_getopt(args, 'fh', [
    'pair-style=', 'bond-style=', 'angle-style=', 'dihedral-style=',
    'improper-style=', 'name=', 'units'
])
filenames = list(args)
pstyle = ''
bstyle = ''
astyle = ''
dstyle = ''
istyle = ''
name = ''
for opt, arg in myopts:
    if opt in ('-f'):
        filenames = arg
    elif opt in ('--pair-style'):
        pstyle = arg
    elif opt in ('--bond-style'):
        bstyle = arg
Esempio n. 46
0
def main(argv):
    """Main program."""

    # Environment
    if sys.version_info < (2, 3):
        stderr('%s: need Python 2.3 or later' % argv[0])
        stderr('your python is %s' % sys.version)
        return 1

    # Defaults
    cfg = Options()
    cfg.basedir = os.path.join(os.path.dirname(argv[0]), 'src')
    cfg.basedir = os.path.abspath(cfg.basedir)

    # Figure out terminal size
    try:
        import curses
    except ImportError:
        pass
    else:
        try:
            curses.setupterm()
            cols = curses.tigetnum('cols')
            if cols > 0:
                cfg.screen_width = cols
        except curses.error:
            pass

    # Option processing
    opts, args = getopt.gnu_getopt(argv[1:], 'hvpqufw', [
        'list-files', 'list-tests', 'list-hooks', 'level=', 'all-levels',
        'coverage'
    ])
    for k, v in opts:
        if k == '-h':
            print(__doc__)
            return 0
        elif k == '-v':
            cfg.verbosity += 1
            cfg.quiet = False
        elif k == '-p':
            cfg.progress = True
            cfg.quiet = False
        elif k == '-q':
            cfg.verbosity = 0
            cfg.progress = False
            cfg.quiet = True
        elif k == '-u':
            cfg.unit_tests = True
        elif k == '-f':
            cfg.functional_tests = True
        elif k == '-w':
            cfg.warn_omitted = True
        elif k == '--list-files':
            cfg.list_files = True
            cfg.run_tests = False
        elif k == '--list-tests':
            cfg.list_tests = True
            cfg.run_tests = False
        elif k == '--list-hooks':
            cfg.list_hooks = True
            cfg.run_tests = False
        elif k == '--coverage':
            cfg.coverage = True
        elif k == '--level':
            try:
                cfg.level = int(v)
            except ValueError:
                stderr('%s: invalid level: %s' % (argv[0], v))
                stderr('run %s -h for help')
                return 1
        elif k == '--all-levels':
            cfg.level = None
        else:
            stderr('%s: invalid option: %s' % (argv[0], k))
            stderr('run %s -h for help')
            return 1
    if args:
        cfg.pathname_regex = args[0]
    if len(args) > 1:
        cfg.test_regex = args[1]
    if len(args) > 2:
        stderr('%s: too many arguments: %s' % (argv[0], args[2]))
        stderr('run %s -h for help')
        return 1
    if not cfg.unit_tests and not cfg.functional_tests:
        cfg.unit_tests = True

    # Set up the python path
    sys.path[0] = cfg.basedir

    # Set up tracing before we start importing things
    tracer = None
    if cfg.run_tests and cfg.coverage:
        import trace
        # trace.py in Python 2.3.1 is buggy:
        # 1) Despite sys.prefix being in ignoredirs, a lot of system-wide
        #    modules are included in the coverage reports
        # 2) Some module file names do not have the first two characters,
        #    and in general the prefix used seems to be arbitrary
        # These bugs are fixed in src/trace.py which should be in PYTHONPATH
        # before the official one.
        ignoremods = ['test']
        ignoredirs = [sys.prefix, sys.exec_prefix]
        tracer = trace.Trace(count=True,
                             trace=False,
                             ignoremods=ignoremods,
                             ignoredirs=ignoredirs)

    # Finding and importing
    test_files = get_test_files(cfg)

    if sys.version_info[:2] < (2, 5):
        # exclude tests that require the 'with' statement
        test_files = [
            test_file for test_file in test_files
            if 'test_incremental_xmlfile.py' not in test_file
        ]

    if sys.version_info[:2] < (2, 6):
        # exclude tests that require recent Python features
        test_files = [
            test_file for test_file in test_files
            if 'test_http_io.py' not in test_file
        ]

    if cfg.list_tests or cfg.run_tests:
        test_cases = get_test_cases(test_files, cfg, tracer=tracer)
    if cfg.list_hooks or cfg.run_tests:
        test_hooks = get_test_hooks(test_files, cfg, tracer=tracer)

    # Configure the logging module
    import logging
    logging.basicConfig()
    logging.root.setLevel(logging.CRITICAL)

    # Running
    success = True
    if cfg.list_files:
        baselen = len(cfg.basedir) + 1
        print("\n".join([fn[baselen:] for fn in test_files]))
    if cfg.list_tests:
        print("\n".join([test.id() for test in test_cases]))
    if cfg.list_hooks:
        print("\n".join([str(hook) for hook in test_hooks]))
    if cfg.run_tests:
        runner = CustomTestRunner(cfg, test_hooks)
        suite = unittest.TestSuite()
        suite.addTests(test_cases)
        if tracer is not None:
            success = tracer.runfunc(runner.run, suite).wasSuccessful()
            results = tracer.results()
            results.write_results(show_missing=True, coverdir=cfg.coverdir)
        else:
            success = runner.run(suite).wasSuccessful()

    # That's all
    if success:
        return 0
    else:
        return 1
Esempio n. 47
0
def _getopts(args, shortopts, longopts=()):
    try:
        opts, remainder = getopt.gnu_getopt(args, shortopts, longopts)
    except getopt.GetoptError, e:
        raise Exception("Options: -%s (%s)" % (shortopts, e))
Esempio n. 48
0
##--------------------------------------------------------------------------##
##*********************       Parse command line:      *********************##
##--------------------------------------------------------------------------##

## Options:
short_opts = 'E:P:Z:o:hqtv'  # n:s:
long_opts = [
    'ephems=', 'period=', 'zshifts=', 'output=', 'debug', 'help', 'quiet',
    'timer', 'verbose'
]
# 'numtodo=', 'sigcut='

## GNU-style parsing (with exception handling):
try:
    options, remainder = getopt.gnu_getopt(sys.argv[1:], short_opts, long_opts)
except getopt.GetoptError, err:
    sys.stderr.write("%s\n" % str(err))
    usage(sys.stderr)
    sys.exit(2)

## Handle selected options:
for opt, arg in options:
    # ------------------------------------------------
    if (opt == '--debug'):
        debug = True
        sys.stderr.write(BRED + "\nDebugging output enabled!" + ENDC + "\n")
    # ------------------------------------------------
    # ------------------------------------------------
    elif ((opt == '-E') or (opt == '--ephems')):
        if not os.path.isfile(arg):
Esempio n. 49
0
test_dir = '../data'


def syntax(exitcode=0):
    print('SYNTAX: %s' % sys.argv[0])
    print('  -h|-?           : this help page')
    print('  -d dir')
    print('  --test_dir=dir  : use this directory for output data ')
    print('')
    sys.exit(exitcode)


long_options = ['test_dir=']

try:
    opts, args = getopt.gnu_getopt(sys.argv[1:], 'h?d:', long_options)
except getopt.GetoptError as s:
    print('Error while parsing command parameters!')
    syntax(1)

for key, val in opts:
    if (key == '-?') or (key == '-h'):
        syntax()
    elif (key == '-d') or (key == '--test_dir'):
        test_dir = val


def preparations():
    if (os.path.isdir(test_dir) == False):
        print('%s is missing, creating ...')
        print('Done.')
Esempio n. 50
0
# TODO -t, -U, -T, -L, -M, -r, -R,

import getopt, sys, re, os
from concurrent.futures import ThreadPoolExecutor
from itertools import count

from bampy.util import open_buffer
from bampy.mt.bgzf import zlib
from bampy.itr import filter
import bampy.mt as bampy

region_re = re.compile('([^:]+)(?::(\d+)(?:-(\d+)))')

if __name__ == '__main__':
    opts, args = getopt.gnu_getopt(
        sys.argv, 'bC1uhHc?o:U:t:T:LM:r:R:q:l:m:f:F:G:x:Bs:@:S')
    opts = dict(opts)

    if '-?' in opts:
        print(__doc__)
        exit(0)

    assert len(args), "No input file specified"
    arg_itr = iter(args)
    next(arg_itr)  # Discard arg[0]

    # Open input file/stream
    path = next(arg_itr)
    if path == '-':
        input = sys.stdin.buffer
    else:
Esempio n. 51
0
def main(argv=None):
    if argv is None:
        argv = sys.argv

    opts, extraparams = getopt.gnu_getopt(argv[1:], "hvf",
                                          ["help", "--filter"])

    verbose = False
    more_info = False
    filter = False
    filter_url = u'http://aranzulla.tecnologia.virgilio.it/s/'
    upper_bound = 1000
    lower_bound = -1
    num_words = 3

    google = Google()

    for o, a in opts:
        if o == "-v":
            verbose = True
        elif o in ("-u", "--upper-bound"):
            upper_bound = int(a)
        elif o in ("-l", "--lower-bound"):
            lower_bound = int(a)
        elif o in ("-n", "--num-words"):
            num_words = int(a)
        elif o in ("-f", "--filter"):
            filter = True
        elif o in ("-h", "--help"):
            print __doc__
            sys.exit(0)
        else:
            assert False, "UnhandledOption"

    for keyword in extraparams:
        km = KeywordManager(keyword)
        keywords = google.getKeywords(keyword)
        km.importKeywords(keyword, keywords)
        #WARNING: do not filter for bannedchars for now

        print 'Computing results...'
        doc = km.genXml(lower_bound, upper_bound)
        f = codecs.open(os.path.join('output', keyword + '.xml'), 'w', 'utf-8')
        f.write(doc.toprettyxml(indent='  '))
        f.close()

        if filter:
            print 'Computing filtered results...'
            doc = km.genXml(lower_bound, upper_bound, filter_url)
            f = codecs.open(os.path.join('output', keyword + '-filtered.xml'),
                            'w', 'utf-8')
            f.write(doc.toprettyxml(indent='  '))
            f.close()
            #make diff
            subprocess.Popen([
                'diff -Naru ' + os.path.join('output', keyword + '.xml') +
                ' ' + os.path.join('output', keyword + '-filtered.xml') +
                ' > ' + os.path.join('output', keyword + '-filtered.diff')
            ],
                             shell=True)

        #save everything
        f = codecs.open(os.path.join('output', keyword + '.txt'), 'w', 'utf-8')
        if more_info:
            f.writelines([unicode(obj) + '\n' for obj in km.getKeywords()])
        else:
            f.writelines([
                unicode(obj.keyword) + '\n' for obj in km.getKeywordEntries()
            ])
        f.close()

    print 'Program terminates correctly'
    return 0
def main(argv):
    options, remainder = getopt.gnu_getopt(argv[1:], 'ohp:', ['output','help','path='])
    OUTPUT, HELP, PATH = False, False, './../all/'
    for opt, arg in options:
        if opt in ('-o', '--output'):
            OUTPUT = True
        elif opt in ('-h', '--help'):
            HELP = True
        elif opt in ('-p', '--path'):
            PATH = arg
            
    if HELP:
            print("\n*** Baseline for the CoNLL-SIGMORPHON 2017 shared task ***\n")
            print("By default, the program runs both tasks and all languages")
            print("only evaluating accuracy. To create output files, use -o")
            print("The training and dev-data are assumed to live in ./../all/task1/ and")
            print("./../all/task2/\n")
            print("Options:")
            print(" -o         create output files with guesses (and don't just evaluate)")           
            print(" -p [path]  data files path. Default is ./../")
            quit()
    
    for task in [1,2]:
        runningavgLow, runningavgMed, runningavgHigh, numiterLow, numiterMed, numiterHigh = 0.0, 0.0, 0.0, 0, 0, 0
        for lang in sorted(set(x.split('-train')[0] for x in os.listdir(PATH + "task" + str(task) + "/"))):
            for quantity in ['low','medium','high']:
                allprules, allsrules = {}, {}
                if not os.path.isfile(PATH + "task" + str(task) + "/" + lang + "-train-" + quantity):
                    continue
                lines = [line.strip() for line in codecs.open(PATH + "task" + str(task) + "/" + lang + "-train-" + quantity, "r", encoding="utf-8")]

                # First, test if language is predominantly suffixing or prefixing
                # If prefixing, work with reversed strings
                prefbias, suffbias = 0,0
                for l in lines:
                    lemma, form, _ = l.split(u'\t')
                    aligned = halign(lemma, form)
                    if ' ' not in aligned[0] and ' ' not in aligned[1] and '-' not in aligned[0] and '-' not in aligned[1]:
                        prefbias += numleadingsyms(aligned[0],'_') + numleadingsyms(aligned[1],'_')
                        suffbias += numtrailingsyms(aligned[0],'_') + numtrailingsyms(aligned[1],'_')

                for l in lines: # Read in lines and extract transformation rules from pairs
                    lemma, form, msd = l.split(u'\t')
                    if prefbias > suffbias:
                        lemma = lemma[::-1]
                        form = form[::-1]
                    prules, srules = prefix_suffix_rules_get(lemma, form)
        
                    if msd not in allprules and len(prules) > 0:
                        allprules[msd] = {}
                    if msd not in allsrules and len(srules) > 0:
                        allsrules[msd] = {}

                    for r in prules:
                        if (r[0],r[1]) in allprules[msd]:
                            allprules[msd][(r[0],r[1])] = allprules[msd][(r[0],r[1])] + 1
                        else:
                            allprules[msd][(r[0],r[1])] = 1

                    for r in srules:
                        if (r[0],r[1]) in allsrules[msd]:
                            allsrules[msd][(r[0],r[1])] = allsrules[msd][(r[0],r[1])] + 1
                        else:
                            allsrules[msd][(r[0],r[1])] = 1

                # Run eval on dev
                if task == 1:
                    devlines = [line.strip() for line in codecs.open(PATH + "task" + str(task) + "/" + lang + "-dev", "r", encoding="utf-8")]
                else:
                    devcoveredlines = [line.strip() for line in codecs.open(PATH + "task" + str(task) + "/" + lang + "-covered-dev", "r", encoding="utf-8")]
                    devalllines = [line.strip() for line in codecs.open(PATH + "task" + str(task) + "/" + lang + "-uncovered-dev", "r", encoding="utf-8")]
            
                numcorrect = 0
                numguesses = 0
                if OUTPUT:
                    outfile = codecs.open(PATH + "task" + str(task) + "/" + lang + "-" + quantity + "-out", "w", encoding="utf-8")
                if task == 1:
                    for l in devlines:
                        lemma, correct, msd, = l.split(u'\t')
                        if prefbias > suffbias:
                            lemma = lemma[::-1]
                        outform = apply_best_rule(lemma, msd, allprules, allsrules)
                        if prefbias > suffbias:
                            outform = outform[::-1]
                        if outform == correct:
                            numcorrect += 1
                        numguesses += 1
                        if OUTPUT:
                            outfile.write(lemma + "\t" + outform + "\t" + msd + "\n")
                else:
                    for i in range(len(devalllines)):
                         lemma, form, msd, = devcoveredlines[i].split(u'\t')
                         if form == '': # i.e. form is missing
                             if prefbias > suffbias:
                                 lemma = lemma[::-1]
                             outform = apply_best_rule(lemma, msd, allprules, allsrules)
                             if prefbias > suffbias:
                                 outform = outform[::-1]
                             _, correct, _ = devalllines[i].split(u'\t')
                             if outform == correct:
                                 numcorrect += 1
                             numguesses += 1
                         else:
                             outform = form
                         if OUTPUT:
                             outfile.write(lemma + "\t" + outform + "\t" + msd + "\n")
                if OUTPUT:
                    outfile.close()
                         
                if quantity == 'low':
                    runningavgLow += numcorrect/float(numguesses)
                    numiterLow += 1
                if quantity == 'medium':
                    runningavgMed += numcorrect/float(numguesses)
                    numiterMed += 1
                if quantity == 'high':
                    runningavgHigh += numcorrect/float(numguesses)
                    numiterHigh += 1                    
                
                print(lang + "[task " + str(task) + "/" + quantity + "]" + ": " + str(str(numcorrect/float(numguesses)))[0:7])
        print("Average[low]:", str(runningavgLow/float(numiterLow)))
        print("Average[medium]:", str(runningavgMed/float(numiterMed)))
        print("Average[high]:", str(runningavgHigh/float(numiterHigh)))
        print("------------------------------------\n")
Esempio n. 53
0
    print 'Usage:', sys.argv[0], ' [options described below] datasets description-file(s)'
    print ""
    print "Options with parameters:"
    print "-r\t--reference\tFile with reference genome (Mandatory parameter)"
    print "-o\t--output-dir\tDirectory to store all result files"
    print "-t\t--thread-num\tMax number of threads (default is " + str(thread_num) + ")"
    print "-s\t--skip-trimming\tSkip N-trimming for speed-up"
    
def check_file(f):
    if not os.path.isfile(f):
        print "Error - file not found:", f
        sys.exit(2)
    return f

try:
    options, datasets = getopt.gnu_getopt(sys.argv[1:], short_options, long_options)
except getopt.GetoptError, err:
    print str(err)
    print ""
    usage()
    sys.exit(1)

for opt, arg in options:
    if opt in ('-o', "--output-dir"):
        output_dir = arg
        make_latest_symlink = False  
    elif opt in ('-r', "--reference"):
        reference = arg
    elif opt in ('-t', "--thread-num"):
        thread_num = int(arg)
        if thread_num < 1:
Esempio n. 54
0
def ParseArguments(argv):
    """Parses command-line arguments.

  Args:
    argv: Command-line arguments, including the executable name, used to
      execute this application.

  Returns:
    Tuple (args, option_dict) where:
      args: List of command-line arguments following the executable name.
      option_dict: Dictionary of parsed flags that maps keys from DEFAULT_ARGS
        to their values, which are either pulled from the defaults, or from
        command-line flags.
  """
    option_dict = DEFAULT_ARGS.copy()

    try:
        opts, args = getopt.gnu_getopt(argv[1:], 'a:cdhp:', [
            'address=',
            'admin_console_host=',
            'admin_console_server=',
            'allow_skipped_files',
            'auth_domain=',
            'backends',
            'blobstore_path=',
            'clear_datastore',
            'clear_prospective_search',
            'datastore_path=',
            'debug',
            'debug_imports',
            'default_partition=',
            'disable_static_caching',
            'disable_task_running',
            'enable_sendmail',
            'help',
            'high_replication',
            'history_path=',
            'multiprocess',
            'multiprocess_api_port=',
            'multiprocess_api_server',
            'multiprocess_app_instance_id=',
            'multiprocess_backend_id=',
            'multiprocess_backend_instance_id=',
            'multiprocess_min_port=',
            'mysql_host=',
            'mysql_password='******'mysql_port=',
            'mysql_socket=',
            'mysql_user='******'persist_logs',
            'port=',
            'require_indexes',
            'show_mail_body',
            'skip_sdk_update_check',
            'smtp_host=',
            'smtp_password='******'smtp_port=',
            'smtp_user='******'task_retry_seconds=',
            'trusted',
            'use_sqlite',
        ])
    except getopt.GetoptError, e:
        print >> sys.stderr, 'Error: %s' % e
        PrintUsageExit(1)
from helix.public import request_reboot, request_infra_retry, send_metric, send_metrics

### This script's purpose is to parse the diagnostics.json file produced by XHarness, evaluate it and send it to AppInsights
### The diagnostics.json file contains information about each XHarness command executed during the job
### In case of events that suggest infrastructure issues, we request a retry and for some reboot the agent

# Name of metrics we send (to Kusto)
EVENT_TYPE = 'MobileDeviceOperation'
OPERATION_METRIC_NAME = 'ExitCode'
DURATION_METRIC_NAME = 'Duration'
RETRY_METRIC_NAME = 'Retry'
REBOOT_METRIC_NAME = 'Reboot'
NETWORK_CONNECTIVITY_METRIC_NAME = 'NoInternet'

opts, args = getopt.gnu_getopt(sys.argv[1:], 'd:', ['diagnostics-data='])
opt_dict = dict(opts)

diagnostics_file = None

if '--data' in opt_dict:
    diagnostics_file = opt_dict['--data']
elif '-d' in opt_dict:
    diagnostics_file = opt_dict['-d']
else:
    diagnostics_file = os.getenv('XHARNESS_DIAGNOSTICS_PATH')

if not diagnostics_file:
    print('ERROR: Expected path to the diagnostics JSON file generated by XHarness')
    exit(1)
Esempio n. 56
0
        pdi=libxml2.parseDoc(blat).xpathEval("//blat/VulnDiscussion")[0].get_content()


        entries[lineItem] = summary.splitlines()[0].strip()
    return entries, (scapSource, scapName, "V%sR%s" % (scapVer,scapRel))
     
def usage():
    print "%s: -s SCAPDOC [-g GUIDEDOC] -o NEWGUIDEDOC [-n NAME] [-t TITLE] [-r RELEASE] [-S SOURCE ] [-e | -d] " % sys.argv[0]
    print "    : -e == enabled,  -d == disabled"
    sys.exit(0)
    
if __name__ == "__main__":
    scapDoc = None
    guideDoc = None
    newGuideDoc = None
    opts,args = getopt.gnu_getopt(sys.argv[1:], "edt:n:v:s:g:o:S:vh")
    source=None
    name=None
    title=None
    version=None
    enabled="True"
    for o,a in opts:
        if o == '-h':
            usage()
        elif o == '-s':
            scapDoc = a
        elif o == '-t':
            title = a
        elif o == '-S':
            source = a
        elif o == '-g':
Esempio n. 57
0
from dm.cnn import loaded_model, charset, prepared

log = logging.getLogger(__name__)

if __name__ == '__main__':
    import sys
    import json
    import os
    import random
    import getopt
    import numpy as np

    model_fn = None
    output_model_fn = None

    opts,captchas = getopt.gnu_getopt(sys.argv[1:], 'm:', ['model='])
    for o,a in opts:
        if o in ['-m', '--model']:
            model_fn = a

    valid_dataset = []

    logging.basicConfig(level=logging.INFO, format='%(msg)s')

    model = loaded_model(model_fn)

    for captcha in captchas:
        image = cv2.imread(captcha, cv2.IMREAD_GRAYSCALE)
        digits = Segmenter().segment(image)
        if len(digits) == 4:
            X = prepared(digits)
Esempio n. 58
0
  --latin=FILE          file name of latin font
  --farsi-digits        rewrite latin and arabic digits with persian digits
  --ui-args                  decrease font height for user interface

  -h, --help            print this message and exit
""" % os.path.basename(sys.argv[0])

    print(message)
    sys.exit(code)


if __name__ == "__main__":
    import getopt
    try:
        opts, args = getopt.gnu_getopt(sys.argv[1:], "h", [
            "help", "input=", "output=", "latin=", "latin-copyright=",
            "farsi-digits", "ui-args="
        ])
    except (getopt.GetoptError, err):
        usage(str(err), -1)

    infile = None
    outfile = None
    latinfile = None
    latincopyright = None
    farsidigits = False
    uiargs = None

    for opt, arg in opts:
        if opt in ("-h", "--help"):
            usage("", 0)
        elif opt == "--input":
Esempio n. 59
0
    def execute(self, argv):
        try:
            opts, _ = getopt.gnu_getopt(argv, 'i:v', [
                'instance=', 'cert-file=', 'trust-args=', 'nickname=',
                'token=', 'verbose', 'help'
            ])

        except getopt.GetoptError as e:
            print('ERROR: ' + str(e))
            self.print_help()
            sys.exit(1)

        instance_name = 'pki-tomcat'
        cert_file = None
        trust_args = '\",,\"'
        nickname = None
        token = pki.nssdb.INTERNAL_TOKEN_NAME

        for o, a in opts:
            if o in ('-i', '--instance'):
                instance_name = a

            elif o == '--cert-file':
                cert_file = a

            elif o == '--trust-args':
                trust_args = a

            elif o == '--nickname':
                nickname = a

            elif o == '--token':
                token = a

            elif o in ('-v', '--verbose'):
                self.set_verbose(True)

            elif o == '--help':
                self.print_help()
                sys.exit()

            else:
                print('ERROR: unknown option ' + o)
                self.print_help()
                sys.exit(1)

        if not cert_file:
            print('ERROR: missing input file containing certificate')
            self.print_help()
            sys.exit(1)

        if not nickname:
            print('ERROR: missing nickname')
            self.print_help()
            sys.exit(1)

        instance = pki.server.PKIInstance(instance_name)

        if not instance.is_valid():
            print('ERROR: Invalid instance %s.' % instance_name)
            sys.exit(1)

        instance.load()

        if instance.external_cert_exists(nickname, token):
            print('ERROR: Certificate already imported for instance %s.' %
                  instance_name)
            sys.exit(1)

        nicks = self.import_certs(instance, cert_file, nickname, token,
                                  trust_args)
        self.update_instance_config(instance, nicks, token)

        self.print_message('Certificate imported for instance %s.' %
                           instance_name)
            self.h('#endif /* defined (%s) */' % self.guard)
            self.h('')

        file_set_contents(self.basename + '.h',
                          u('\n').join(self.__header).encode('utf-8'))
        file_set_contents(self.basename + '-body.h',
                          u('\n').join(self.__body).encode('utf-8'))
        file_set_contents(self.basename + '-gtk-doc.h',
                          u('\n').join(self.__docs).encode('utf-8'))


def types_to_gtypes(types):
    return [type_to_gtype(t)[1] for t in types]


if __name__ == '__main__':
    options, argv = gnu_getopt(sys.argv[1:], '', [
        'group=', 'subclass=', 'subclass-assert=', 'iface-quark-prefix=',
        'tp-proxy-api=', 'generate-reentrant=', 'deprecate-reentrant=',
        'deprecation-attribute=', 'guard='
    ])

    opts = {}

    for option, value in options:
        opts[option] = value

    dom = xml.dom.minidom.parse(argv[0])

    Generator(dom, argv[1], argv[2], opts)()