本文整理汇总了Python中getopt.getopt方法的典型用法代码示例。如果您正苦于以下问题:Python getopt.getopt方法的具体用法?Python getopt.getopt怎么用?Python getopt.getopt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类getopt
的用法示例。
在下文中一共展示了getopt.getopt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import getopt [as 别名]
# 或者: from getopt import getopt [as 别名]
def main():
exploits = []
outfile = None
if len (sys.argv) != 7:
print ("Usage: ./runExploits.py -t <target-ip> -o <output-dir> -e <exploits>")
print ("Note: <exploits> can be 'all' or a list of exploits seperated by ','")
exit (1)
opts, argv = getopt.getopt(sys.argv[1:], 'e:t:o:')
for k, v in opts:
if k == '-e':
if v == 'all':
exploits = list (METASPLOIT_EXPLOITS.keys()) + list (SHELL_EXPLOITS.keys())
else:
exploits = [int(x) for x in v.split(',')]
if k == '-t':
target = v
if k == '-o':
if not os.path.isdir(v):
if os.path.exists(v):
os.remove(v)
os.makedirs(v, 0o755);
outfile = v + "/%(exploit)s.log"
process(target, exploits, outfile)
示例2: main
# 需要导入模块: import getopt [as 别名]
# 或者: from getopt import getopt [as 别名]
def main(self, argv: List[str]) -> None:
try:
opts, args = getopt.getopt(argv, "hlvV ", ['help', 'log', 'version', 'version', 'dependency-versions'])
except getopt.GetoptError:
self.help_command()
for opt, _ in opts:
if opt in ['-h', '--help']:
self.help_command()
if opt in ['-v', '-V', '--version']:
self.version_command()
if opt in ['--dependency-versions']:
self.dependency_versions_command()
if len(args):
if args[0] in ('run', 'start', 'go'):
self.run_command(args[1:])
self.help_command()
示例3: main
# 需要导入模块: import getopt [as 别名]
# 或者: from getopt import getopt [as 别名]
def main():
infile = iid = None
opts, argv = getopt.getopt(sys.argv[1:], "f:i:")
for k, v in opts:
if k == '-i':
iid = int(v)
if k == '-f':
infile = v
if infile and not iid:
m = re.match(r"(\d+)\.tar\.gz", infile)
if m:
iid = int(m.groups(1))
getarch (infile)
process(iid, infile)
示例4: main
# 需要导入模块: import getopt [as 别名]
# 或者: from getopt import getopt [as 别名]
def main():
"""Small main program"""
import sys, getopt
try:
opts, args = getopt.getopt(sys.argv[1:], 'deut')
except getopt.error as msg:
sys.stdout = sys.stderr
print(msg)
print("""usage: %s [-d|-e|-u|-t] [file|-]
-d, -u: decode
-e: encode (default)
-t: encode and decode string 'Aladdin:open sesame'"""%sys.argv[0])
sys.exit(2)
func = encode
for o, a in opts:
if o == '-e': func = encode
if o == '-d': func = decode
if o == '-u': func = decode
if o == '-t': test(); return
if args and args[0] != '-':
with open(args[0], 'rb') as f:
func(f, sys.stdout.buffer)
else:
func(sys.stdin.buffer, sys.stdout.buffer)
示例5: app
# 需要导入模块: import getopt [as 别名]
# 或者: from getopt import getopt [as 别名]
def app():
# Parse and interpret options.
(opts, _) = getopt.getopt(argv[1:], "l:p:sh",
["logfile=", "port=", "server-mode", "help"])
port = 8000
server_mode = False
help_mode = False
logfilename = None
for (opt, value) in opts:
if (opt == "-l") or (opt == "--logfile"):
logfilename = str(value)
elif (opt == "-p") or (opt == "--port"):
port = int(value)
elif (opt == "-s") or (opt == "--server-mode"):
server_mode = True
elif (opt == "-h") or (opt == "--help"):
help_mode = True
if help_mode:
usage()
else:
wnb(port, not server_mode, logfilename)
示例6: ParseArgs
# 需要导入模块: import getopt [as 别名]
# 或者: from getopt import getopt [as 别名]
def ParseArgs(argv):
options, args = getopt.getopt(
argv[1:],
'h:e:p:f:',
['host=', 'email=', 'params=', 'mysql_default_file='])
host = None
gae_user = None
params = None
mysql_default_file = None
for option_key, option_value in options:
if option_key in ('-h', '--host'):
host = option_value
elif option_key in ('-e', '--email'):
gae_user = option_value
elif option_key in ('-p', '--params'):
params = option_value
elif option_key in ('-f', '--mysql_default_file'):
mysql_default_file = option_value
return host, gae_user, params, mysql_default_file, args
示例7: ParseArgs
# 需要导入模块: import getopt [as 别名]
# 或者: from getopt import getopt [as 别名]
def ParseArgs(argv):
options, args = getopt.getopt(
argv[1:],
'h:e:f:rc',
['host=', 'email=', 'mysql_default_file=',
'release', 'category_browsers_only'])
host = None
gae_user = None
mysql_default_file = None
is_release = False
is_category_browsers_only = False
for option_key, option_value in options:
if option_key in ('-h', '--host'):
host = option_value
elif option_key in ('-e', '--email'):
gae_user = option_value
elif option_key in ('-f', '--mysql_default_file'):
mysql_default_file = option_value
elif option_key in ('-r', '--release'):
is_release = True
elif option_key in ('-c', '--category_browsers_only'):
is_category_browsers_only = True
return host, gae_user, mysql_default_file, is_release, is_category_browsers_only, args
示例8: ParseArgs
# 需要导入模块: import getopt [as 别名]
# 或者: from getopt import getopt [as 别名]
def ParseArgs(argv):
options, args = getopt.getopt(
argv[1:],
'h:u:p:',
['host=', 'gae_user=', 'params='])
host = None
gae_user = None
params = None
for option_key, option_value in options:
if option_key in ('-h', '--host'):
host = option_value
elif option_key in ('-u', '--gae_user'):
gae_user = option_value
elif option_key in ('-p', '--params'):
params = option_value
return host, gae_user, params, args
示例9: _parsebase
# 需要导入模块: import getopt [as 别名]
# 或者: from getopt import getopt [as 别名]
def _parsebase(argv):
"""Parse until the second part of the command.
"""
shortopts = 'vf:m:' # version, file, model
longopts = ['version', 'file=', 'model=', 'samples-dir=', 'test-split=', 'val-split=',
'cache-dir=', 'random-seed=', 'trainings-dir=', 'project-dir=',
'cache=', 'device=', 'device-memory=']
args, rest = getopt.getopt(argv, shortopts, longopts)
args = dict(args)
# don't match prefix
for opt in map(lambda s: s.rstrip("="), longopts):
# pylint: disable=W0640
if ''f'--{opt}' in args and not any(map(lambda a: a.startswith('--' + opt), argv)):
# find the key that does not match
keys = map(lambda a: a.split("=")[0].lstrip("-"), argv)
keys = list(filter(lambda k: k in opt, keys))
if keys:
raise getopt.GetoptError('Invalid key', opt='--' + keys[0])
else:
raise getopt.GetoptError('Invalid key')
# convert from short to long names
for sht, lng in (('-v', '--version'), ('-m', '--model'), ('-f', '--file')):
if sht in args:
args[lng] = args[sht]
del args[sht]
args = {k.strip('-'):v for k, v in args.items()}
return args, rest
示例10: main
# 需要导入模块: import getopt [as 别名]
# 或者: from getopt import getopt [as 别名]
def main(argv):
try:
opts, args = getopt.getopt(argv, "hi:d", ["ip="])
except getopt.GetoptError:
usage()
sys.exit(2)
if not opts:
usage()
sys.exit(2)
for opt, arg in opts:
if opt == "-h":
print '### HELP? ma LOL ###'
sys.exit()
elif opt == "-i":
ipToCheck = arg
print '## Checking IP:',arg
print '## Verify EGBL...'
verifyConfig()
print '## Check vulnerability...'
verifyVuln(ipToCheck)
示例11: main
# 需要导入模块: import getopt [as 别名]
# 或者: from getopt import getopt [as 别名]
def main():
infile = None
makeQemuCmd = False
iid = None
outfile = None
arch = None
endianness = None
(opts, argv) = getopt.getopt(sys.argv[1:], 'f:i:S:a:oqd')
for (k, v) in opts:
if k == '-f':
infile = v
if k == '-d':
global debug
debug += 1
if k == '-q':
makeQemuCmd = True
if k == '-i':
iid = int(v)
if k == '-S':
VMDIR = v
if k == '-o':
outfile = True
if k == '-a':
(arch, endianness) = archEnd(v)
if not arch or not endianness:
raise Exception("Either arch or endianness not found try mipsel/mipseb/armel/armeb")
if not infile and iid:
infile = "%s/%i/qemu.initial.serial.log" % (VMDIR, iid)
if outfile and iid:
outfile = """%s/%i/run.sh""" % (VMDIR, iid)
if debug:
print("processing %i" % iid)
if infile:
process(infile, iid, arch, endianness, makeQemuCmd, outfile)
示例12: main
# 需要导入模块: import getopt [as 别名]
# 或者: from getopt import getopt [as 别名]
def main():
##
# Handle command line input
##
num_clips = 5000000
try:
opts, _ = getopt.getopt(sys.argv[1:], 'n:t:c:oH',
['num_clips=', 'train_dir=', 'clips_dir=', 'overwrite', 'help'])
except getopt.GetoptError:
usage()
sys.exit(2)
for opt, arg in opts:
if opt in ('-n', '--num_clips'):
num_clips = int(arg)
if opt in ('-t', '--train_dir'):
c.TRAIN_DIR = c.get_dir(arg)
if opt in ('-c', '--clips_dir'):
c.TRAIN_DIR_CLIPS = c.get_dir(arg)
if opt in ('-o', '--overwrite'):
c.clear_dir(c.TRAIN_DIR_CLIPS)
if opt in ('-H', '--help'):
usage()
sys.exit(2)
# set train frame dimensions
assert os.path.exists(c.TRAIN_DIR)
c.FULL_HEIGHT, c.FULL_WIDTH = c.get_train_frame_dims()
##
# Process data for training
##
process_training_data(num_clips)
示例13: init
# 需要导入模块: import getopt [as 别名]
# 或者: from getopt import getopt [as 别名]
def init(argv):
"""Read the args and return all variable
Will return:
- the number of error encounter
- the absolute path of the output directory
- an array of collection id given as args (in fact everything that is
not a recognised arg
- the absolute path of the save file
Return int(error), string(output_dir), array(collections_id),
string(save_file)
"""
error = 0
output_dir = os.getcwd()
collections_id_list = []
save_file = os.path.join(output_dir, "addons.lst")
if len(argv) == 1 and not os.path.isfile(save_file):
print("No save file found")
usage(argv[0], 0)
try:
opts, args = getopt.getopt(argv[1:],"ho:")
except getopt.GetoptError:
usge(argv[0], 2)
else:
for opt, arg in opts:
if opt == 'h':
usge(argv[0], 0)
elif opt == '-o':
output_dir = os.path.abspath(arg)
save_file = os.path.join(output_dir, "addons.lst")
if not os.path.exists(output_dir):
print(output_dir + ": path doesn't exist\nEnd of program")
error += 1
collections_id_list = argv[len(opts) * 2 + 1:]
return error, output_dir, collections_id_list, save_file
示例14: run
# 需要导入模块: import getopt [as 别名]
# 或者: from getopt import getopt [as 别名]
def run(self, args):
rid = RegressiveImageryDictionary()
load_default_dict = True
load_default_exc = True
html_output = False
title = "RID Analysis"
try:
optlist, args = getopt.getopt(sys.argv[1:], 'd:e:ht:',
['add-dict=', 'add-exc='])
for (o, v) in optlist:
if o == '-d':
rid.load_dictionary_from_file(v)
load_default_dict = False
elif o == '-e':
rid.load_exclusion_list_from_file(v)
load_default_exc = False
elif o == '--add-dict':
rid.load_dictionary_from_file(v)
elif o == '--add-exc':
rid.load_exclusion_list_from_file(v)
elif o == '-h':
html_output = True
elif o == '-t':
title = v
else:
sys.stderr.write("%s: illegal option '%s'\n" % (args[0], o))
self.usage(args)
except getopt.GetoptError, e:
sys.stderr.write("%s: %s\n" % (args[0], e.msg))
self.usage(args)
sys.exit(1)
示例15: main
# 需要导入模块: import getopt [as 别名]
# 或者: from getopt import getopt [as 别名]
def main(argv):
trainIds = False
try:
opts, args = getopt.getopt(argv,"ht")
except getopt.GetoptError:
printError( 'Invalid arguments' )
for opt, arg in opts:
if opt == '-h':
printHelp()
sys.exit(0)
elif opt == '-t':
trainIds = True
else:
printError( "Handling of argument '{}' not implementend".format(opt) )
if len(args) == 0:
printError( "Missing input json file" )
elif len(args) == 1:
printError( "Missing output image filename" )
elif len(args) > 2:
printError( "Too many arguments" )
inJson = args[0]
outImg = args[1]
if trainIds:
json2instanceImg( inJson , outImg , 'trainIds' )
else:
json2instanceImg( inJson , outImg )
# call the main method