def main(): parser = argparse.ArgumentParser(description="Parser Program") subparser = parser.add_subparsers(help="Sub parser for program") sumNumbersParser = subparser.add_parser('sum', help='Sum Numbers') genSubParser = subparser.add_parser('generate', help='generate String') jsonTocsvParser = subparser.add_parser('convert', help='convert json to csv') sumNumbersParser.add_argument('numbers', type=int, nargs='+') sumNumbersParser.set_defaults(func=sumNumbers) genSubParser.add_argument('--start', type=int) genSubParser.add_argument('--stop', type=int) genSubParser.add_argument('--step', type=int, default=1, required=bool(0)) genSubParser.set_defaults(func=generateSeries) jsonTocsvParser.add_argument('-i', '--input', type=str) jsonTocsvParser.add_argument('-o', '--output', type=str) jsonTocsvParser.set_defaults(func=converter) try: args2 = parser.parse_args() args2.func(args2) except Exception as e: print(e) parser.print_help()
def parse_arguments(): """Define possible arguments""" desc = """Port scanner outputting its results as an HTML page.""" # use argparse to parse args parser = argparse.ArgumentParser(prog='scanner', description=desc) parser.add_argument( '-t', '--target', metavar='Target', help= 'Can pass hostnames, IP addresses, networks.\nEx: scanme.nmap.org; microsoft.com/24; 192.168.0.1; 192.168.0.0/24;', nargs='+') parser.add_argument( '-p', '--port', metavar='Port', help='Only scan specified ports.\nEx: -p 22; -p 80,443; -p 1-65535;', nargs='?') parser.add_argument('-o', '--ouput', metavar='Output path', help='Path of the output file.\nEx: /home/user', nargs='?') parser.add_argument('-f', '--file', metavar='File', help='File containing a target list (host, ip, cidr)', type=argparse.FileType('r'), nargs='+') if len(sys.argv) == 1: parser.print_help() sys.exit(2) else: return get_args(parser.parse_args())
def main(): import sys import os h = 6.6260689633e-34 c = 299792458 electron = 1.60217653141e-19 def toenergy(wave): energy = (h*c)/(float(wave)*1e-10*electron) return energy def towave(energy): wave = (h*c)/(float(energy)*electron) return wave from optparse import OptionParser parser = OptionParser() parser.add_option("--energy","-e",dest="energy",metavar="energy ev",help="Energy in ev") parser.add_option("--wave","-w",dest="wave",metavar="wave A",help="wavelenbth in Angstrom") (options,spillover) = parser.parse_args() if options.energy is not None: energy = options.energy wave = towave(energy) print "The input %s energy in ev corresponds to %s wavelength" % ( energy , wave) elif options.wave is not None: wave = sys.argv[2] energy = toenergy(wave) print "The input %s wavelength corressponds to %s ev " % (wave,energy) else: parser.print_help() exit()
def main(): args = parse_args() if (not args.rebuild) and (not args.render): parser.print_help() exit(1) if args.rebuild: rebuild_tree() elif args.render: try: category_id = int(args.render[0]) tree_markup = database.render_tree(category_id) output_html = treeGenerator.HTML_TEMPLATE % tree_markup print('Opening %s.html' % category_id) render_html(output_html, '%s.html' % category_id) except ValueError: print('Please enter a valid number') exit(1)
def badArgs(parser): print "Incorrect Arguments" parser.print_help() exit(0)
def main(name, version, datatype): log.info("------------- %s %s -----------------", name, version) usage = """usage: python %prog [options] <foldername> PartitionFinder and PartitionFinderProtein are designed to discover optimal partitioning schemes for nucleotide and amino acid sequence alignments. They are also useful for finding the best model of sequence evolution for datasets. The Input: <foldername>: the full path to a folder containing: - A configuration file (partition_finder.cfg) - A nucleotide/aa alignment in Phylip format Take a look at the included 'example' folder for more details. The Output: A file in the same directory as the .cfg file, named 'analysis' This file contains information on the best partitioning scheme, and the best model for each partiiton Usage Examples: >python %prog example Analyse what is in the 'example' sub-folder in the current folder. >python %prog -v example Analyse what is in the 'example' sub-folder in the current folder, but show all the debug output >python %prog -c ~/data/frogs Check the configuration files in the folder data/frogs in the current user's home folder. >python %prog --force-restart ~/data/frogs Deletes any data produced by the previous runs (which is in ~/data/frogs/output) and starts afresh """ parser = OptionParser(usage) parser.add_option( "-v", "--verbose", action="store_true", dest="verbose", help="show verbose (debug) output") parser.add_option( "-c", "--check-only", action="store_true", dest="check_only", help="just check the configuration files, don't do any processing") parser.add_option( "--force-restart", action="store_true", dest="force_restart", help="delete all previous output and start afresh (!)") parser.add_option( "-p", "--processes", type="int", dest="processes", default=-1, metavar="N", help="Number of concurrent processes to use." " Use -1 to match the number of cpus on the machine." " The default is to use -1.") parser.add_option( "--show-python-exceptions", action="store_true", dest="show_python_exceptions", help="If errors occur, print the python exceptions") parser.add_option( "--save-phyml", action="store_true", dest="save_phyml", help="save all of the phyml output. This can take a lot of space(!)") parser.add_option( "--dump-results", action="store_true", dest="dump_results", help="Dump all results to a binary file. " "This is only of use for testing purposes.") parser.add_option( "--compare-results", action="store_true", dest="compare_results", help="Compare the results to previously dumped binary results. " "This is only of use for testing purposes.") options, args = parser.parse_args() # Error checking if options.dump_results and options.compare_results: log.error("You can't dump and compare results in one run!") log.error("Please select just one of these") # We should have one argument: the folder to read the configuration from if not args: # Otherwise exit, printing the help parser.print_help() return 2 #before we start, let's check the python version is above 2.7 but lower than 3.0 python_version = float("%d.%d" %(sys.version_info[0], sys.version_info[1])) log.info("You have Python version %.1f" %python_version) if python_version<2.7: log.error("Your Python version is %.1f, but this program requires Python 2.7. " "Please upgrade to version 2.7 by visiting www.python.org/getit, or by following" " the instructions in the PartitionFinder manual." % python_version) return 0 if python_version>3.0: log.warning("Your Python version is %.1f. This program was not built to run with " "version 3 or higher. To guarantee success, please use Python 2.7.x" % python_version) # Load, using the first argument as the folder try: cfg = config.Configuration(datatype) cfg.load_base_path(args[0]) if options.check_only: log.info("Exiting without processing (because of the -c/--check-only option ...") else: # For now, we just turn on debugging for the analysis section # For finer grain, see the logging.cfg file if options.verbose: logging.getLogger('analysis').setLevel(logging.DEBUG) logging.getLogger('analysis_method').setLevel(logging.DEBUG) # Now try processing everything.... method = analysis_method.choose_method(cfg.search) rpt = reporter.TextReporter(cfg) anal = method(cfg, rpt, options.force_restart, options.save_phyml, options.processes) results = anal.analyse() if options.dump_results: results.dump(cfg) elif options.compare_results: results.compare(cfg) # Successful exit log.info("Processing complete.") return 0 except util.PartitionFinderError: log.error("Failed to run. See previous errors.") if options.show_python_exceptions: raise except KeyboardInterrupt: log.error("User interrupted the Program") return 1
(options, args) = parser.parse_args() # create my parameter container params = roi.ROI_Data() params.extraTargetCode = options.extraTargetCode if options.testing: params.roiName = 'IncaCity' params.obsID = 'PSP_003092_0985' params.ccdColour = 'RED' params.inputSample = '6849' params.inputLine = '18426' params.extraTargetCode = '0815' elif len(args) == 0: parser.print_help() sys.exit(1) else: try: params.roiName, params.obsID, params.ccdColour, params.inputSample, \ params.inputLine = args except: try: params.roiName, params.obsID, params.inputSample, \ params.inputLine = args params.ccdColour = '' except: print('\n Something wrong with parameters.') parser.print_help() sys.exit(1)
"--thread", dest="count", type="int", default=1, help="count of scan thread") parser.add_option("-d", "--domain", dest="domain", help="target domain for scan") (option, args) = parser.parse_args() if option.url and option.ext: print("[+]Scan for %s will start ! Filetype is %s..." % (option.url, option.ext)) d = DirScanMain(option) d.start() print("\n") sys.exit(0) elif option.ip: print("[+]Scan for %s ip scan will start..." % (option.ip)) c = CIPscanMain(option) c.start() sys.exit(0) elif option.domain: cs = crtScan(option.domain) result = cs.run() print(result) sys.exit(0) else: parser.print_help() sys.exit(0)