def run(): parser = OptionParser(usage="usage: %prog [options] file1 file2 ...") parser.version = VERSION parser.add_option('-f', '--file', dest="filename", metavar="FILE", help=("File to which to save. It will be loaded if " "file exists and contains result of image2py"), default=None) parser.add_option("-t", "--template", action="store", dest="template", default=None, help="template of output (qt, pyqt, pyside)") (options, args) = parser.parse_args() if len(args) < 1: parser.print_help() sys.exit(0) try: conv = Converter(options.filename) if options.template is not None: conv.set_template(templates.templateByName(options.template)) for item in args: conv.add_file(item) if options.filename is None: print(conv.output()) else: conv.save(options.filename) print("File has been saved") except Exception as e: print('Error: {!s}'.format(e))
def input_parse(): parser = OptionParser('python m7-05.py -l <Low Privilege Username> ' '[-h <High Privilege Username> -p <Path for Scan>]') parser.version = "M7-05 v1.0" parser.add_option("-v", "--version", dest="version", action="store_true", help="show scanner's version and exit") parser.add_option('--low-privilege-user', dest='low_privilege_user', type='string', help='low privilege username') parser.add_option('--high-privilege-user', dest='high_privilege_user', type='string', default=DEFAULT_HIGH_PRIVILEGE_USER, help='[Optional] high privilege username (default "root")') parser.add_option('-p', '--path', dest='path', type='string', default=DEFAULT_PATH, help='[Optional] path for scan (default "/")') (options, args) = parser.parse_args() if options.version: print(parser.version, " -- By Mi1k7ea") sys.exit(1) if not options.low_privilege_user: parser.print_help() sys.exit(1) if options.path: if not os.path.exists(options.path): parser.error("[-]Path doesn't exist.") sys.exit(1) return options
def create_parser(self, prog_name, subcommand): parser = OptionParser(prog=prog_name, add_help_option=False, formatter=SynnefoCommandFormatter()) parser.set_usage(self.usage(subcommand)) parser.version = self.get_version() # Handle Django's and common options common_options = OptionGroup(parser, "Common Options") common_options.add_option("-h", "--help", action="help", help="show this help message and exit") common_options.add_option("--version", action="version", help="show program's version number and" " exit") [common_options.add_option(o) for o in self.option_list] if common_options.option_list: parser.add_option_group(common_options) # Handle command specific options command_options = OptionGroup(parser, "Command Specific Options") [ command_options.add_option(o) for o in getattr(self, "command_option_list", ()) ] if command_options.option_list: parser.add_option_group(command_options) return parser
def opt_parser(data): from optparse import OptionParser parser = OptionParser() parser.version = get_current_version() parser.add_option("-s", "--skeleton", dest="skeleton", help="specify the skeleton file") parser.add_option("-o", "--output", dest="output", help="specify the output file") parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="show more detailed information") (options, args) = parser.parse_args() if options.skeleton and options.output: if options.verbose: print "Generate %s from skeleton file %s (if the specified skeleton file can't be found, it will be searched in skeleton directory in the current working directory)..." % ( options.output, options.skeleton, ) import os, sys if os.path.isfile(options.skeleton): writer = Writer(options.skeleton, data) elif os.path.isfile(os.path.join("skeleton", options.skeleton)): writer = Writer(os.path.join("skeleton", options.skeleton), data) else: print "skeleton file you specified (%s) not found." % options.skeleton return if options.output in os.listdir(os.getcwd()): print "output file you specified (%s) has existed already." % options.output return else: writer.write_to_dest(options.output) if options.verbose: print "The generating process is done successfully." else: parser.print_usage()
def create_parser(self, prog_name, subcommand): parser = OptionParser(prog=prog_name, add_help_option=False, formatter=SynnefoCommandFormatter()) parser.set_usage(self.usage(subcommand)) parser.version = self.get_version() # Handle Django's and common options common_options = OptionGroup(parser, "Common Options") common_options.add_option("-h", "--help", action="help", help="show this help message and exit") common_options.add_option("--version", action="version", help="show program's version number and" " exit") [common_options.add_option(o) for o in self.option_list] if common_options.option_list: parser.add_option_group(common_options) # Handle command specific options command_options = OptionGroup(parser, "Command Specific Options") [command_options.add_option(o) for o in getattr(self, "command_option_list", ())] if command_options.option_list: parser.add_option_group(command_options) return parser
def do_command(): arg_parser = OptionParser() arg_parser.usage = 'usage: %prog [options] INFILE.EDL [...]' arg_parser.version = '0.1' arg_parser.description = 'Read a CMX 3600-style EDL and convert it into an AAF.' common = OptionGroup(arg_parser, title='Common Options') common.add_option( '-s', '--source-list', dest='source_list', metavar='PATH_LIST', action='append', help='A list of source Broadcast-WAV files, one file path per line.') common.add_option( '-n', '--name', dest='sequence_name', metavar='NAME', help= 'The name for the composition to create. By default, this will be the title of the EDL.' ) common.add_option( '--fs', dest='frame_rate', metavar='FPS', default=24, help= 'The integer frame rate of the EDL. The tracks of the output composition will have ' + 'this rate as well. Default is 24.') common.add_option( '-L', dest='log_file', metavar='LOGFILE', help= 'Log file. A log file is always generated. By default, this is the name of the output ' 'file with \'.log\' appended.') arg_parser.add_option_group(common) unimplemented = OptionGroup( arg_parser, title="Experimental Options (probably don't work)") unimplemented.add_option( '-b', '--blanks', help='Create and embed dummy silent audio media for each unmatched EDL ' 'event.') arg_parser.add_option_group(unimplemented) arg_parser.description = "The command attempts to merge a CMX EDL with a list of source Broadcast-WAV files and " \ "writes the result to an AAF file as an AAF composition. At this time, only audio " \ "tracks are translated." options, edl_files = arg_parser.parse_args() print(options)
def main(): usage = "%prog DIR1 DIR2 ... -l LICENSE [OPTIONS]" parser = OptionParser(usage) parser.prog = "addlicense" parser.version = "0.1" parser.description = "Add license header to all the files in the \ specified directories (and their sub-directories). If no directory is \ specified, the current working directory will be considered. \ Insert license headers for Java and PHP files, based on the file \ extension. Supported licenses are: Apache v2, GPL v3" parser.add_option("-e", "--exclude", dest="exclude", \ help="exclude all files in DIR and sub-DIRs", \ metavar="DIR", action="append") parser.add_option("-f", "--file", dest="file", help="include FILE, has to be an absolute path", metavar="FILE", action="append") parser.add_option("-l", "--license", dest="license", \ help="add LICENSE header; accepted LICENSEs are: \ 'apache2', 'gpl3'" , \ action="store", metavar="LICENSE") parser.add_option("-y", "--year", metavar="YEAR", dest="year", \ help="use YEAR as the license year; default \ is the current year" , \ action="store") parser.add_option("-r", "--holder", metavar="HOLDER", dest="holder", \ action="store", \ help="use HOLDER as the copyright's holder") parser.add_option("-m", "--email", metavar="EMAIL", dest="holder_email", \ action="store", \ help="use EMAIL as the email of the copyright's holder") parser.add_option("-v", "--verbose", dest="verbose", action="store_true", \ help="be verbose", default=False) (options, args) = parser.parse_args() if len(args) == 0 and (options.license == None or options.license not in valid_licenses): print "Usage: addlicense DIR1 DIR2 ... -l LICENSE [OPTIONS]\n" print "Type 'addlicense -h' for more information." exit(2) # if no directory is specified, add the current one if len(args) == 0 and options.file == None: args.append(os.getcwd()) if len(args) > 0: _check_args(args) _check_options(options) crawldirs.crawl(args, cmd_options, excluded_dirs, included_files)
def parse_args(): parser = OptionParser() parser.description = "Check streaming replication delay" parser.version = __version__ parser.add_option("-H", "--host", dest="hostname", default="127.0.0.1", help="Name of the host you are checking") parser.add_option("-O", "--port", dest="port", default="5432", help="Port you will connect to the database with") parser.add_option("-U", "--user", dest="username", default="postgres", help="Username for the database") parser.add_option("-P", "--password", dest="password", help="Password the database") parser.add_option("-D", "--database", dest="database", help="Datbase you are checking") parser.add_option("-W", "--warn", dest="warn", default="300", help="Warning alert delay in seconds") parser.add_option("-C", "--crit", dest="crit", default="1800", help="Critical alert delay in seconds") (options, args) = parser.parse_args() return options
def main(): usage = "%prog DIR1 DIR2 ... -l LICENSE [OPTIONS]" parser = OptionParser(usage) parser.prog = "addlicense" parser.version = "0.1" parser.description = "Add license header to all the files in the \ specified directories (and their sub-directories). If no directory is \ specified, the current working directory will be considered. \ Insert license headers for Java and PHP files, based on the file \ extension. Supported licenses are: Apache v2, GPL v3" parser.add_option("-e", "--exclude", dest="exclude", \ help="exclude all files in DIR and sub-DIRs", \ metavar="DIR", action="append") parser.add_option("-f", "--file", dest="file", help="include FILE, has to be an absolute path", metavar="FILE", action="append") parser.add_option("-l", "--license", dest="license", \ help="add LICENSE header; accepted LICENSEs are: \ 'apache2', 'gpl3'", \ action="store", metavar="LICENSE") parser.add_option("-y", "--year", metavar="YEAR", dest="year", \ help="use YEAR as the license year; default \ is the current year", \ action="store") parser.add_option("-r", "--holder", metavar="HOLDER", dest="holder", \ action="store", \ help="use HOLDER as the copyright's holder") parser.add_option("-m", "--email", metavar="EMAIL", dest="holder_email", \ action="store", \ help="use EMAIL as the email of the copyright's holder") parser.add_option("-v", "--verbose", dest="verbose", action="store_true", \ help="be verbose", default=False) (options, args) = parser.parse_args() if len(args) == 0 and (options.license == None or options.license not in valid_licenses): print "Usage: addlicense DIR1 DIR2 ... -l LICENSE [OPTIONS]\n" print "Type 'addlicense -h' for more information." exit(2) # if no directory is specified, add the current one if len(args) == 0 and options.file == None: args.append(os.getcwd()) if len(args) > 0: _check_args(args) _check_options(options) crawldirs.crawl(args, cmd_options, excluded_dirs, included_files)
def __init__(self, version = ''): """Constructor Input: none Output: (ConfigCli) class instance """ UserDict.__init__(self) defaults = {} # defaults['PATHS'] = {} # defaults['SERVER'] = {} defaults['config_file'] = defaultOptions['PATHS']['config_file'] defaults['foreground'] = defaultOptions['SERVER']['foreground'] defaults['no_threads'] = defaultOptions['SERVER']['no_threads'] defaults['log_to_screen'] = defaultOptions['SERVER']['log_to_screen'] defaults['debug_mode'] = defaultOptions['SERVER']['debug_mode'] defaults['log_client'] = defaultOptions['SERVER']['log_client'] self._defaults = defaults usage = "usage: %prog [options]" parser = OptionParser(usage=usage) parser.version = version parser.set_defaults(**defaults) # set up available options parser.add_option("-v", "--version", action="version", help = "Print version info") parser.add_option("-c", "--configuration-file", action="store", dest="config_file", help="Path to configuration file", metavar="FILE") parser.add_option("-f", "--foreground", action="store_true", dest="foreground", help="Run server in foreground") parser.add_option("-n", "--no-threads", action="store_true", dest="no_threads", help="Run server with only one packet processing thread") parser.add_option("-s", "--log-to-screen", action="store_true", dest="log_to_screen", help="Print all log messages to screen (stdout) only") parser.add_option("-d", "--debug", action="store_true", dest="debug_mode", help="Run server in debugging mode. Implifies: -f -n -s") parser.add_option("-l", "--log-client", action="store", dest="log_client", help="Print log messages regarding only one server client.", metavar="ADDRESS") self._parser = parser # read arguments self.read()
def parse_args(): parser = OptionParser() parser.description = "Check streaming replication delay" parser.version = __version__ parser.add_option("-H", "--host", dest="hostname", default="127.0.0.1", help="Name of the host you are checking") parser.add_option("-m", "--master", dest="master", help="Name of the master of the host you are checking") parser.add_option("-O", "--port", dest="port", default="5432", help="Port you will connect to the database with") parser.add_option("-U", "--user", dest="username", default="postgres", help="Username for the database") parser.add_option("-P", "--password", dest="password", help="Password the database") parser.add_option("-D", "--database", dest="database", help="Database you are checking") parser.add_option("-W", "--warn", dest="warn", default="300", help="Warning alert delay in seconds") parser.add_option("-C", "--crit", dest="crit", default="1800", help="Critical alert delay in seconds") (options, args) = parser.parse_args() if not options.master: parser.error('master not given') if not options.password: parser.error('password not given') if not options.database: parser.error('database not given') return options
def input_parse(): parser = OptionParser( 'python m7-04.py -t <Scan Type> [-u <Target URL>] [-f <Target Swf File>]' ) parser.version = "M7-04 v1.0" parser.add_option("-v", "--version", dest="version", action="store_true", help="show scanner's version and exit") parser.add_option('-t', '--type', dest='type', type='string', help='scan type (xss or csrf), combine with -f or -u') parser.add_option('-u', '--url', dest='url', type='string', help='target url for flash csrf scan') parser.add_option('-f', '--file', dest='file', type='string', help='target swf file for flash xss scan') (options, args) = parser.parse_args() if options.version: print(parser.version, " -- By Mi1k7ea") sys.exit(1) if not options.type: parser.print_help() sys.exit(1) if options.type.lower() == "xss" and options.file: return options elif options.type.lower() == "csrf" and options.url: # url参数是必须的且能正常访问 try: request.urlopen(options.url) except error.HTTPError: parser.error("URL can not be visited.") except error.URLError: parser.error("URL can not be visited.") return options else: parser.print_help() sys.exit(1)
def get_project_path_from_args(): """ Used in calling the project, getting a source as an argument for the logs :return string project_path: A path for the project to write log files """ optp = OptionParser() optp.version = '%%prog 0.1' optp.usage = "Usage: %%prog <project_path> [options] " opts, args = optp.parse_args() # Make sure we received enough input args if len(args) < 1: optp.print_help() exit() # Take the folder path from the options project_path = args[0] return project_path
logging.error('Could not subscribe %s to node %s' % (self.boundjid.bare, self.node)) def unsubscribe(self): try: result = self['xep_0060'].unsubscribe(self.pubsub_server, self.node) print('Unsubscribed %s from node %s' % (self.boundjid.bare, self.node)) except: logging.error('Could not unsubscribe %s from node %s' % (self.boundjid.bare, self.node)) if __name__ == '__main__': # Setup the command line arguments. optp = OptionParser() optp.version = '%%prog 0.1' optp.usage = "Usage: %%prog [options] <jid> " + \ 'nodes|create|delete|purge|subscribe|unsubscribe|publish|retract|get' + \ ' [<node> <data>]' optp.add_option('-q','--quiet', help='set logging to ERROR', action='store_const', dest='loglevel', const=logging.ERROR, default=logging.ERROR) optp.add_option('-d','--debug', help='set logging to DEBUG', action='store_const', dest='loglevel', const=logging.DEBUG, default=logging.ERROR) optp.add_option('-v','--verbose', help='set logging to COMM',
print "This usually means the file is corrupt, and removing it will fix the problem." return 1 if not rawdog.check_state_version(): print "The state file " + statedir + "/state was created by an older" print "version of rawdog, and cannot be read by this version." print "Removing the state file will fix it." return 1 rawdog.sync_from_config(config) plugins.call_hook("startup", rawdog, config) from optparse import OptionParser parser = OptionParser() parser.version = VERSION parser.add_option('-u', '--update', action='store_const', const='update', dest='op') parser.add_option('-w', '--write', action='store_const', const='write', dest='op') parser.add_option('-c', '--config', action='store', type='string', dest='configfile') parser.add_option('-d', '--dir', action='store', type='string', dest='statedir') parser.add_option('-N', '--no-locking', action='store_false', dest='locking') parser.add_option('-l', '--lang', action='store', type='string', dest='lang') parser.add_option('-L', '--locale', action='store', type='string', dest='locale') parser.add_option('--output-dir', action='store', type='string', dest='output_dir') parser.add_option('-o', '--output-file', action='store', type='string', dest='output_file') parser.add_option('--no-feed-list', action='store_false', dest='feedlist', default=True) plugins.call_hook("add_args", parser) (options, args) = parser.parse_args()
print("Features:") for feature in info["disco_info"]["features"]: print(" - %s" % feature) if self.get in self.items_types: print("Items:") for item in items["disco_items"]["items"]: print(" - %s" % str(item)) self.disconnect() if __name__ == "__main__": # Setup the command line arguments. optp = OptionParser() optp.version = "%%prog 0.1" optp.usage = "Usage: %%prog [options] %s <jid> [<node>]" % "all|info|items|identities|features" optp.add_option( "-q", "--quiet", help="set logging to ERROR", action="store_const", dest="loglevel", const=logging.ERROR, default=logging.ERROR, ) optp.add_option( "-d", "--debug", help="set logging to DEBUG",
def unsubscribe(self): try: result = self['xep_0060'].unsubscribe(self.pubsub_server, self.node) print('Unsubscribed %s from node %s' % (self.boundjid.bare, self.node)) except: logging.error('Could not unsubscribe %s from node %s' % (self.boundjid.bare, self.node)) if __name__ == '__main__': # Setup the command line arguments. optp = OptionParser() optp.version = '%%prog 0.1' optp.usage = "Usage: %%prog [options] <jid> " + \ 'nodes|create|delete|purge|subscribe|unsubscribe|publish|retract|get' + \ ' [<node> <data>]' optp.add_option('-q', '--quiet', help='set logging to ERROR', action='store_const', dest='loglevel', const=logging.ERROR, default=logging.ERROR) optp.add_option('-d', '--debug', help='set logging to DEBUG', action='store_const',
import ppplot import sys ############################################## # NB: this is a convenient command-line script # ... but ppclass is more versatile # ... than what is proposed here # ... e.g. differences between files, # ... complex operations, # ... see sample scripts ###################################### # define parser with version and usage ###################################### parser = OptionParser() parser.version = \ '''************************************************** ******** PLANETOPLOT (for help: pp.py -h) ******** **************************************************''' parser.usage = \ '''pp.py [options] netCDF file(s) (NB: no options --> simple inspection of variables and dimensions in netCDF files) ------------------- PLANETOPLOT --> command line tool to make nice & quick plots from netCDF files --> based on python + numpy + scipy + matplotlib + basemap + netCDF4 --> Author: A. Spiga (LMD/UPMC) [email protected] -------------------''' ######################################## # set options for the pp.py command line ########################################
def input_parse(): parser = OptionParser( 'python m7-03.py -u <Target URL> [-t <Thread_count>] [-s <Sleep_time>] [-l <Log_level>]' ) parser.version = "M7-03 v1.0" parser.add_option("-v", "--version", dest="version", action="store_true", help="show scanner's version and exit") parser.add_option('-u', '--url', dest='url', type='string', help='target url for scan') parser.add_option('-t', '--thread', dest='count', type='int', default=DEFAULT_THREAD_COUNT, help='[Optional] scan thread_count (default 30)') parser.add_option('-s', '--sleep', dest='sleep', type='int', default=DEFAULT_SLEEP_TIME, help='[Optional] sleep time per request (default 1s)') parser.add_option( '-l', '--log-level', dest='loglevel', type='int', default=DEFAULT_LOG_LEVEL, help= '[Optional] log level 1-5: CRITICAL,ERROR(default),WARNING,INFO,DEBUG') (options, args) = parser.parse_args() if options.version: print(parser.version, " -- By Mi1k7ea") sys.exit(1) # url参数是必须的且能正常访问 if not options.url: parser.print_help() sys.exit(1) else: try: request.urlopen(options.url) except error.HTTPError: parser.error("URL can not be visited.") except error.URLError: parser.error("URL can not be visited.") # 设置日志级别: 1-5 log_level = options.loglevel if log_level == 1: log_level = logging.CRITICAL elif log_level == 2: log_level = logging.ERROR elif log_level == 3: log_level = logging.WARN elif log_level == 4: log_level = logging.INFO elif log_level == 5: log_level = logging.DEBUG else: parser.error("Log level value must be between 1-5.") # 以域名或IP地址为日志文件名,开启日志功能 log_name = options.url.split("://")[1].split("/")[0].replace(".", "_") log(log_name, log_level) if options.count <= 0 or options.count > 100: logger.error("Thread count invalid.") parser.error("Thread count should between 1-100.") if options.sleep < 0 or options.sleep > 10: logger.error("Sleep time invalid.") parser.error("Sleep time should between 0-10.") logger.info("Log level is " + str(options.loglevel)) logger.info("Thread count is " + str(options.count)) logger.info("Sleep time is " + str(options.sleep) + "s") return options
parser.add_option("--man", action = 'store_true', help = "generate a manual") parser.add_option("--doctest", action = 'store_true', help = "perform doc tests") parser.add_option("-v","--verbose", action = 'store_true', help = "be verbose in all things, go with god") parser.add_option("-V","--version", action = 'store_true', help = "show version") parser.add_option("--limit", type = "int", help = "the maximum number of nodes to add to the tree") parser.version = __version__ parser.usage = __doc__ + """ e.g. %prog [--pretty|--compact] %prog --pretty --infile "../OVis/source/ovOrlandoTagInfo.cpp" Grovel data out of a local copy of the file %prog Grovel data of the the latest version of the file on github %prog --pretty Generate a human readable version """ (options,args) = parser.parse_args() show_usage = True
def oparser(): # 处理参数 parser = OptionParser() parser.version = conf['version'] parser.add_option("--version", "-v", dest="showVersion", action="store_true", help="show program's version and exit") # 必选参数 target = OptionGroup(parser, "Target", "At least one of these options has to be provided to define the target(s)") target.add_option("-u", dest="url", help="Target URL") target.add_option("--test", dest="test", action="store_true", help="auto test") # 可选参数 opt = OptionGroup(parser, "Options", "Optional parameters") opt.add_option("-t", "--thread", dest="thread", type="int", help="thread number(default 30)") opt.add_option("-e", "--ext", dest="extensions", action="store_true", help="Whether to use file extension(default false)") opt.add_option("-f", "--filename", dest="filename", help="Scanner dictionary (default ./php.txt)") opt.add_option("-s", "--sleeptime", dest="stime", type="int", help="Each request of sleep time (default 1)") opt.add_option("-l", dest="loglevel", type="int", help="log level(1-5) " "1, CRITICAL; " "2, ERROR(default); " "3, WARN; " "4, INFO; " "5, DEBUG;") parser.add_option_group(target) parser.add_option_group(opt) (args, _) = parser.parse_args(sys.argv) if args.showVersion: print parser.version print "-- By LoRexxar" exit(0) if not (args.url or args.test): errMsg = "missing a mandatory option (-u) or (--test), " errMsg += "use -h for basic or --help for advanced help" parser.error(errMsg) conf['url'] = (args.url.rstrip('/').rstrip('"').rstrip('\'') if args.url else "http://testphp.vulnweb.com/") # 处理下url用来log的名字 name = re.findall("[\w\.-]+", conf['url']) try: conf['name'] = (name[1] if len(name) == 2 else name[0]) except IndexError: errMsg = "url input error!" logger.error("url matching fail!") parser.error(errMsg) conf['thread'] = (args.thread if args.thread else 30) if conf['thread'] < 1 or conf['thread'] > 50: # 线程数为0-50 errMsg = "thread value error (1-50)" parser.error(errMsg) # 设置睡眠时间 conf['stime'] = (args.stime if args.stime else 1) if conf['stime'] < 0 or conf['stime'] > 10: # 睡眠时间为0-10 errMsg = "time value error (0-10)" parser.error(errMsg) conf['loglevel'] = (args.loglevel if args.loglevel else 2) if conf['loglevel'] < 1 or conf['loglevel'] > 5: # loglevel: 1-5 errMsg = "loglevel value error(input 1-5)" parser.error(errMsg) if conf['loglevel'] == 1: conf['loglevel'] = logging.CRITICAL elif conf['loglevel'] == 2: conf['loglevel'] = logging.ERROR elif conf['loglevel'] == 3: conf['loglevel'] = logging.WARN elif conf['loglevel'] == 4: conf['loglevel'] = logging.INFO elif conf['loglevel'] == 5: conf['loglevel'] = logging.DEBUG else: conf['loglevel'] = logging.ERROR # 开启log log(conf['name'], conf['loglevel']) # 设置扫描器字典 wordlist_file = (args.filename if args.filename else "./dic/php.txt") word_queue = build_wordlist(wordlist_file) extensions = ['.bak', '.orig', '.inc', '.swp', '~'] # 进度条 pbar = tqdm(total=word_queue.qsize(), leave=False) # 开始扫描 if args.extensions: tqdm.write('start scanning with extensions...') for i in range(conf['thread']): t = threading.Thread(target=dir_bruter, args=(word_queue, conf['url'], conf['stime'], extensions, pbar)) t.start() else: tqdm('start scanning...') for i in range(conf['thread']): t = threading.Thread(target=dir_bruter, args=(word_queue, conf['url'], conf['stime'], None, pbar)) t.start()
def segment_sentences(): usage = ''' Usage of segment_sentences: python segment_sentences.py [options] [arg] Options and arguments: -d, --debug print the debug information of the segmentation, default is not -f, --file [filename] segment sentences from the specified file -h, --help display this help info and exit -i, --interactive go into interactive mode -o, --out [filename] write the segment result into the specified file -s, --separator specified the separator of the segmentation result -t, --train [filename] use the training set to train the algorithm -v, --version output version info and exit ''' paser = OptionParser(usage) paser.version = 'Version 0.1' paser.add_option( '-d', '--debug', action='store_true', dest='debug', help='print the debug information of the segmentation, default is not') paser.add_option('-f', '--file', action='store', dest='file', help='segment sentences from the specified file') paser.add_option('-i', '--interactive', action='store_true', dest='interactive', help='go into interactive mode') paser.add_option('-o', '--out', action='store', dest='out', help='write the segment result into the specified file') paser.add_option('-s', '--separator', action='store', dest='separator', help='specified the separator of the segmentation result') paser.add_option('-t', '--train', action='store', dest='train', help='use the training set to train the algorithm') paser.add_option('-v', '--version', action='store_true', dest='version', help='output version info and exit') seg = Segment() operation, arg = paser.parse_args(sys.argv) if operation.version: # print 'Version info: ', operation.version print paser.version if operation.debug: print 'Debug: ', operation.debug seg.debug = True if operation.separator: print 'Specify the separator: ', operation.separator seg.separator = operation.separator if operation.out: print 'Save the output to file: ', operation.out if operation.interactive: print 'Interactive Mode:' if operation.file: print 'Sentences input from file: ', operation.file if operation.train: print 'Train from file: ', operation.train if operation.train: pro_dic = ProDict(operation.train) print 'Train the algorithm successfully!' elif operation.interactive or operation.file: pro_dic = ProDict() seg.pro_dictionary = pro_dic if operation.interactive: interactive_mode(seg, operation) elif operation.file: print 'Read the input file...' input_file = open(operation.file) sens = input_file.readlines() input_file.close() print 'Start segment the input lines...' results = seg.segment(sens) print 'Segment outcome:' for result in results: print result # write the result to the specified file # print results if operation.out: write_result = open(operation.out, 'w') for result in results: result = result.encode('utf-8') write_result.write(result) write_result.close()
Created 2008-11-01 by Maximillian Dornseif. You may consider it BSD licensed.''' import email import mimetypes import getpass import os import sys import imaplib from optparse import OptionParser __revision__ = '$Revision: 3958 $' parser = OptionParser(version=True) parser.version = "%%prog %s" % (__revision__.strip('$Revision: ')) parser.description = __doc__ parser.set_usage('usage: %prog [email protected] [options].\nTry %prog --help for details.') parser.add_option('--server', action='store', type='string', default='mail.hudora.biz', help='hostname of the IMAPS server where the messages are stored (default: "%default")') parser.add_option('--user', action='store', type='string', help='User name for logging into the server (default: "%default")') parser.add_option('--password', action='store', type='string', default=0, help='Pasword used to login (default: ask for password)') parser.add_option('--folder', action='store', type='string', default="INBOX", help='Folder to scann for messages (default: "%default")') parser.add_option('--sender', action='store', type='string', default='scanner@', help='Sender whose messages to process (default: "%default")') parser.add_option('--dir', action='store', type='string', default='.', help='Destination directory (default: "%default")')
def segment_sentences(): usage = ''' Usage of segment_sentences: python segment_sentences.py [options] [arg] Options and arguments: -d, --debug print the debug information of the segmentation, default is not -f, --file [filename] segment sentences from the specified file -h, --help display this help info and exit -i, --interactive go into interactive mode -o, --out [filename] write the segment result into the specified file -s, --separator specified the separator of the segmentation result -t, --train [filename] use the training set to train the algorithm -v, --version output version info and exit ''' paser = OptionParser(usage) paser.version = 'Version 0.1' paser.add_option('-d', '--debug', action='store_true', dest='debug', help='print the debug information of the segmentation, default is not') paser.add_option('-f', '--file', action='store', dest='file', help='segment sentences from the specified file') paser.add_option('-i', '--interactive', action='store_true', dest='interactive', help='go into interactive mode') paser.add_option('-o', '--out', action='store', dest='out', help='write the segment result into the specified file') paser.add_option('-s', '--separator', action='store', dest='separator', help='specified the separator of the segmentation result') paser.add_option('-t', '--train', action='store', dest='train', help='use the training set to train the algorithm') paser.add_option('-v', '--version', action='store_true', dest='version', help='output version info and exit') seg = Segment() operation, arg = paser.parse_args(sys.argv) if operation.version: # print 'Version info: ', operation.version print paser.version if operation.debug: print 'Debug: ', operation.debug seg.debug = True if operation.separator: print 'Specify the separator: ', operation.separator seg.separator = operation.separator if operation.out: print 'Save the output to file: ', operation.out if operation.interactive: print 'Interactive Mode:' if operation.file: print 'Sentences input from file: ', operation.file if operation.train: print 'Train from file: ', operation.train if operation.train: pro_dic = ProDict(operation.train) print 'Train the algorithm successfully!' elif operation.interactive or operation.file: pro_dic = ProDict() seg.pro_dictionary = pro_dic if operation.interactive: interactive_mode(seg, operation) elif operation.file: print 'Read the input file...' input_file = open(operation.file) sens = input_file.readlines() input_file.close() print 'Start segment the input lines...' results = seg.segment(sens) print 'Segment outcome:' for result in results: print result # write the result to the specified file # print results if operation.out: write_result = open(operation.out, 'aw') for result in results: result = result.encode('utf-8') write_result.write(result) write_result.close()
action='store_true', help="bs4.decompose, ie remove tags: revisiondesc") parser.add_option("--man", action='store_true', help="show the manual for this program") parser.add_option("-v", "--verbose", action='store_true', help="be verbose in all things, go with god") parser.add_option("-V", "--version", action='store_true', help="show version") parser.add_option("--int", type="int", help="accept an integer") parser.add_option("--str", help="accept a string") parser.version = __version__ parser.usage = """ e.g. %prog --doctest Perform unit tests on the %prog """ (options, args) = parser.parse_args() show_usage = True if options.doctest: show_usage = False import doctest doctest.testmod(verbose=options.verbose) if options.version: show_usage = False if options.verbose: print __cvs_id__
def main(options): log.info('Loading config from %s' % options.config) with open(options.config, 'r') as config_file: config = yaml.load(config_file) if config['release-runner'].get('verbose', False): log_level = logging.DEBUG else: log_level = logging.INFO logging.basicConfig(format="%(asctime)s - %(levelname)s - %(message)s", level=log_level) # Suppress logging of retry(), see bug 925321 for the details logging.getLogger("util.retry").setLevel(logging.WARN) api_root = config['api']['api_root'] username = config['api']['username'] password = config['api']['password'] rr_config = config['release-runner'] sleeptime = rr_config['sleeptime'] smtp_server = rr_config.get('smtp_server', 'localhost') notify_from = rr_config.get('notify_from') notify_to = rr_config.get('notify_to_announce') if isinstance(notify_to, basestring): notify_to = [x.strip() for x in notify_to.split(',')] rr = ReleaseRunner(api_root=api_root, username=username, password=password) while True: try: log.debug('Fetching release requests') rr.get_release_requests([r['pattern'] for r in config['releases']]) if rr.new_releases: new_releases = run_prebuild_sanity_checks( rr, config['releases']) break else: log.debug('Sleeping for %d seconds before polling again' % sleeptime) time.sleep(sleeptime) except: log.error("Caught exception when polling:", exc_info=True) sys.exit(5) rc = 0 for release in new_releases: try: relconfigs_tmpl = '{}_{}_fennec_full_graph.yml'.format( rr_config['relconfigs_prefix'], release['branchShortName']) configs = '/'.join([rr_config['relconfigs_root'], relconfigs_tmpl]) # process stuff for releasetasks_graph_gen.py script release_runner_config = yaml.safe_load( open(rr_config['release_runner_config'])) tc_config = { "credentials": { "clientId": release_runner_config["taskcluster"].get("client_id"), "accessToken": release_runner_config["taskcluster"].get("access_token"), }, "maxRetries": 12, } branch_product_config = load_branch_and_product_config(configs) # hack: we simulate the options argument for the # releasetasks_graph_gen.py script in order to reuse some of the # functions defined there fake_options = OptionParser() fake_options.version = release['version'] fake_options.build_number = release['buildNumber'] fake_options.mozilla_revision = release['mozillaRevision'] fake_options.common_task_id = None fake_options.partials = '' fake_options.dry_run = False releasetasks_kwargs = {} releasetasks_kwargs.update(branch_product_config) releasetasks_kwargs.update( get_release_items_from_runner_config(release_runner_config)) releasetasks_kwargs.update( get_unique_release_items(fake_options, tc_config)) rr.update_status(release, 'Generating task graph') task_group_id = gen_main(release_runner_config, releasetasks_kwargs, tc_config, options=fake_options) rr.mark_as_completed(release) l10n_url = rr.release_l10n_api.getL10nFullUrl(release['name']) email_release_drivers(smtp_server=smtp_server, from_=notify_from, to=notify_to, release=release, task_group_id=task_group_id, l10n_url=l10n_url) except Exception as exception: # We explicitly do not raise an error here because there's no # reason not to start other releases if creating the Task Graph # fails for another one. We _do_ need to set this in order to exit # with the right code, though. rc = 2 rr.mark_as_failed( release, 'Failed to start release promotion. Error(s): %s' % (exception)) log.exception('Failed to start release "%s". Error(s): %s', release['name'], exception) log.debug('Release failed: %s', release) if rc != 0: sys.exit(rc) log.debug('Sleeping for %s seconds before polling again', sleeptime) time.sleep(sleeptime)
from PyQt4 import QtGui from ui_dialog import Ui_ParametersDialog app = QtGui.QApplication(sys.argv) window = QtGui.QDialog() ui = Ui_ParametersDialog() ui.setupUi(window) window.accepted.connect(check_generate) window.show() app.exec_() parser = OptionParser() parser.version = "0.2" parser.add_option("-g", "--gui", dest="gui", action='store_true') parser.add_option("-s", "--use-simple", dest="use_simple", action='store_true', help="If enabled, then generated Reply class will inherit SimpleDataPPReply. This is usually more convinient") parser.add_option("-r", "--plugin-version", dest="version", help="Initial version of the plugin. This is the version that will be used in .desktop file for this plugin and presented to the user") parser.add_option("-v", "--version", dest="print_version", action='store_true') parser.add_option("-a", "--git", dest="git_enabled",action='store_true', help="use git to get missed values") parser.add_option("-n", "--name", dest = "name", help="plugin name. It is used for generating filenames and class names") parser.add_option("-t", "--author", dest = "author", help="Author name") parser.add_option("-m", "--mail", dest = "mail", help="Author mail") parser.add_option("-i", "--internal-version", dest="internal_version", help="This is the integer number. It is used as internal version of the DataPP. \ You must increase this number ONLY when there are serious \ improvments in quality of the generated the Decisions. \ " ) parser.add_option("-k", "--kcm", dest="generate_kcm", action='store_true', help="Use this selector if you want to generate KCModule for you plugin")
def oparser(): ''' 设置, 初始化输入参数 ''' parser = OptionParser() parser.version = "B0.8" parser.add_option("--version", "-v", dest="showVersion", action="store_true", help="Show program's version number and exit") # 必选参数 target = OptionGroup(parser, "Target", "At least one of these " "options has to be provided to define the target(s)") target.add_option("-u", dest="url", help="Target URL") target.add_option("-d", dest="deep", type="int", help="spider the depth") target.add_option("--testself", dest="test", action="store_true", help="auto test") # 可选参数 opt = OptionGroup(parser, "Options", "Optional parameters") opt.add_option("-f", dest="logfile", help="The custom log file path") opt.add_option("--key", dest="key", help="Page keywords") opt.add_option("-l", dest="loglevel", type="int", help="log level(1-5) " "1, CRITICAL; " "2, ERROR(default); " "3, WARN; " "4, INFO; " "5, DEBUG;") opt.add_option("--thread", dest="thread", type="int", help="thread number(default 10)") opt.add_option("--dbfile", dest="dbfile", help="set sqlite database file") parser.add_option_group(target) parser.add_option_group(opt) (args, _) = parser.parse_args(sys.argv) if args.showVersion: print parser.version print "-- By Hcamael" exit(0) if not (args.url or args.test): errMsg = "missing a mandatory option (-u) or (--testself), " errMsg += "use -h for basic or -hh for advanced help" parser.error(errMsg) # 进行输入参数初始化 conf['url'] = (args.url if args.url else "http://sina.com.cn") name = re.findall("[\w\.-]+", conf['url']) try: conf['name'] = (name[1] if len(name) == 2 else name[0]) except IndexError: errMsg = "url input error!" logger.error("url matching fail!") parser.error(errMsg) conf['deep'] = (args.deep if args.deep else 2) if conf['deep'] > 50: # 上限为50 errMsg = "The deep is too large(0 <= deep <= 50)" parser.error(errMsg) if conf['deep'] < 0: # 禁止小于0 errMsg = "The deep input error(0 < deep <= 50)" parser.error(errMsg) conf['test'] = args.test conf['key'] = args.key conf['loglevel'] = (args.loglevel if args.loglevel else 2) if conf['loglevel'] < 1 or conf['loglevel'] > 5: # loglevel: 1-5 errMsg = "loglevel value error(input 1-5)" parser.error(errMsg) if conf['loglevel'] == 1: loglevel = logging.CRITICAL elif conf['loglevel'] == 2: loglevel = logging.ERROR elif conf['loglevel'] == 3: loglevel = logging.WARN elif conf['loglevel'] == 4: loglevel = logging.INFO elif conf['loglevel'] == 5: loglevel = logging.DEBUG else: loglevel = logging.ERROR conf['logfile'] = (os.path.basename(args.logfile) if args.logfile \ else 'spider.log' if args.test \ else conf['name']+".log") f = open("log/" + conf['logfile'], 'a+') Log_Handle = logging.StreamHandler(f) # Log_Handle = logging.StreamHandler(sys.stdout) FORMATTER = logging.Formatter("\r[%(asctime)s] [%(levelname)s] [%(thread)d] %(message)s", "%H:%M:%S") Log_Handle.setFormatter(FORMATTER) logger.addHandler(Log_Handle) logger.setLevel(loglevel) conf['dbfile'] = (os.path.basename(args.dbfile) if args.dbfile else conf['name']+".db") conf['thread'] = (args.thread if args.thread else 10) if conf['thread'] < 0 or conf['thread'] > 50: # thread = 0 表示不使用多线程 # 最大值设为50 errMsg = "thread value error (0-50, 0 means not use thread)" parser.error(errMsg) logger.debug('parsing command line suc')
def __init__(self, version=''): """Constructor Input: none Output: (ConfigCli) class instance """ UserDict.__init__(self) defaults = {} # defaults['PATHS'] = {} # defaults['SERVER'] = {} defaults['config_file'] = defaultOptions['PATHS']['config_file'] defaults['foreground'] = defaultOptions['SERVER']['foreground'] defaults['no_threads'] = defaultOptions['SERVER']['no_threads'] defaults['log_to_screen'] = defaultOptions['SERVER']['log_to_screen'] defaults['debug_mode'] = defaultOptions['SERVER']['debug_mode'] defaults['log_client'] = defaultOptions['SERVER']['log_client'] self._defaults = defaults usage = "usage: %prog [options]" parser = OptionParser(usage=usage) parser.version = version parser.set_defaults(**defaults) # set up available options parser.add_option("-v", "--version", action="version", help="Print version info") parser.add_option("-c", "--configuration-file", action="store", dest="config_file", help="Path to configuration file", metavar="FILE") parser.add_option("-f", "--foreground", action="store_true", dest="foreground", help="Run server in foreground") parser.add_option( "-n", "--no-threads", action="store_true", dest="no_threads", help="Run server with only one packet processing thread") parser.add_option( "-s", "--log-to-screen", action="store_true", dest="log_to_screen", help="Print all log messages to screen (stdout) only") parser.add_option( "-d", "--debug", action="store_true", dest="debug_mode", help="Run server in debugging mode. Implifies: -f -n -s") parser.add_option( "-l", "--log-client", action="store", dest="log_client", help="Print log messages regarding only one server client.", metavar="ADDRESS") self._parser = parser # read arguments self.read()
def input_parse(): parser = OptionParser( 'python m7-01.py -u <Target URL> [-f <Custom dictionary file name>] ' '[-t <Thread_count>] [-s <Sleep_time>] [-l <Log_level>]') parser.version = "M7-01 v1.0" parser.add_option("-v", "--version", dest="version", action="store_true", help="show scanner's version and exit") parser.add_option('-u', '--url', dest='url', type='string', help='target url for scan') parser.add_option( '-f', '--file', dest='filename', type='string', default=DEFAULT_DICTIONARY_FILE, help='[Optional] custom dictionary filename (default ./dict/DIR.txt)') parser.add_option('-t', '--thread', dest='count', type='int', default=DEFAULT_THREAD_COUNT, help='[Optional] scan thread_count (default 30)') parser.add_option('-s', '--sleep', dest='sleep', type='int', default=DEFAULT_SLEEP_TIME, help='[Optional] sleep time per request (default 1s)') parser.add_option( '-l', '--log-level', dest='loglevel', type='int', default=DEFAULT_LOG_LEVEL, help= '[Optional] log level 1-5: CRITICAL,ERROR(default),WARNING,INFO,DEBUG') (options, args) = parser.parse_args() if options.version: print(parser.version, " -- By Mi1k7ea") sys.exit(1) # url参数是必须的且能正常访问 if not options.url: parser.print_help() sys.exit(1) else: try: request.urlopen(options.url) except error.HTTPError: parser.error("URL can not be visited.") except error.URLError: parser.error("URL can not be visited.") # 设置日志级别: 1-5 log_level = options.loglevel if log_level == 1: log_level = logging.CRITICAL elif log_level == 2: log_level = logging.ERROR elif log_level == 3: log_level = logging.WARN elif log_level == 4: log_level = logging.INFO elif log_level == 5: log_level = logging.DEBUG else: parser.error("Log level value must be between 1-5.") # 以域名或IP地址为日志文件名,开启日志功能 log_name = options.url.split("://")[1].split("/")[0].replace(".", "_") log(log_name, log_level) # 检测输入的自定义字典文件是否存在且是否为空 if options.filename: try: f = open(options.filename, "r") if len(f.readlines()) == 0: logger.error("Custom dictionary file is empty") parser.error("File is empty.") f.close() except FileNotFoundError: logger.error("Custom dictionary file is not found") parser.error("File is not found.") except PermissionError: logger.error("No permission to access custom dictionary file") parser.error("You don't have permission to access this file.") if options.count <= 0 or options.count > 100: logger.error("Thread count invalid.") parser.error("Thread count should between 1-100.") if options.sleep < 0 or options.sleep > 10: logger.error("Sleep time invalid.") parser.error("Sleep time should between 0-10.") logger.info("Log level is " + str(options.loglevel)) logger.info("Dictionary file is " + options.filename) logger.info("Thread count is " + str(options.count)) logger.info("Sleep time is " + str(options.sleep) + "s") return options