def process_options(): usageString = """\ Usage: %(prog)s [-h] [-c <mycnf>] [-H <host>] [-d <db>] report options: -h print this message and exit -c <mycnf> mycnf file; if missing, system configuration is used -H <host> hostname of the mysql server -d <db> name of the olac database """ % {"prog":os.path.basename(sys.argv[0])} def usage(msg=None): print >>sys.stderr, usageString if msg: print >>sys.stderr, "ERROR:", msg print >>sys.stderr sys.exit(1) op = OptionParser( "*-h", "*-c:", "*-H:", "*-d:", ) try: op.parse(sys.argv[1:]) except OptionParser.ParseError, e: usage(e.message)
def process_cmdline_options(): import sys try: from optionparser import OptionParser except ImportError: print >>sys.stderr, """ Can't find the 'optionparser' module, which can be obtained from here: http://olac.svn.sourceforge.net/viewvc/*checkout*/web/lib/python/optionparser.py """ sys.exit(1) usageString = """\ Usage: %(prog)s [options] dumpfile zipfile options: -h print this message and quit -c mycnf MySQL option file, e.g. ~/.my.cnf If not given, system configuration is consulted. -H host host name of the MySQL server -d db name of the OLAC database -s schema sqlite schema for OLAC database """ % {"prog":os.path.basename(sys.argv[0])} def usage(msg=None): print >>sys.stderr, usageString if msg: print >>sys.stderr, "ERROR:", msg print >>sys.stderr sys.exit(1) op = OptionParser( "*-h", "*-c:", "*-H:", "*-d:", "*-s:", ) try: op.parse(sys.argv[1:]) except OptionParser.ParseError, e: usage(e.message)
def process_options(): usageString = """\ Usage: %(prog)s [-h] [-c <mycnf>] [-H <host>] [-d <db>] [-t <db>] [-x <path>] [-l] options: -h print this message and exit -c <mycnf> mycnf file. If not given, system configuration is used. -H <host> hostname of the mysql server -d <db> name of the main OLAC database -t <db> name of a temporary database -x <path> path to the OLAC harvester. By default, system configuration is checked and then 'harvester.py' is searched in the same directory as the monthly harvester. -l send log message to the log daemon (unix) """ % {"prog":os.path.basename(sys.argv[0])} def usage(msg=None): print >>sys.stderr, usageString if msg: print >>sys.stderr, "ERROR:", msg print >>sys.stderr sys.exit(1) op = OptionParser( "*-h", "*-c:", "*-H:", "*-d:", "*-t:", "*-x:", "*-l", ) try: op.parse(sys.argv[1:]) except OptionParser.ParseError, e: usage(e.message)
def main(): global SCRIPTS_DIR global LOG_DIR global Q_DIR usage = """\ Usage: %(prog)s -h %(prog)s [-s DIR | -l DIR | -q DIR] Options: -h Print out this message and exit -s DIR Specify the directory where webcol harvesters and converters are searched. The default location is: %(scripts_dir)s -l DIR Specify the directory where log files will be stored. Default is /tmp. -q DIR Specify the directory where queue files will be stored. Default is /tmp. -S SID Specify a site ID. This option can be used multiple times. -G GID Specify a group ID. This option can be used multiple times. If -S option is used, this option is ignored. """ % {"prog": sys.argv[0], "scripts_dir": SCRIPTS_DIR, } op = OptionParser( "*-h", "*-s:", "*-l:", "*-q:", "*-S:", "*-G:", ) op.usageString = usage try: op.parse(sys.argv[1:]) except OptionParser.ParseError, e: op.usage(e.message)
-u resource-not-found/-available checks only (by defaults, these checks are excluded) """ % {"prog":os.path.basename(sys.argv[0])} def usage(msg=None): print >>sys.stderr, usageString if msg: print >>sys.stderr, "ERROR:", msg print >>sys.stderr sys.exit(1) op = OptionParser( "*-h", "*-c:", "*-H:", "*-d:", "*-a:", "*-u", ) try: op.parse(sys.argv[1:]) except OptionParser.ParseError, e: usage(e.message) if op.get('-h'): usage() mycnf = op.getOne('-c') host = op.getOne('-H') db = op.getOne('-d') opts = {"use_unicode":True, "charset":"utf8"} if mycnf:
def createQcdCmdLineParser(): # The command line parser cmdParser = OptionParser(name) # The options cmdParser.addConfiguration("f", "file", "Specifies which database to use", defaultDbFile, syntax="FILENAME") # The commands cmdParser.addCommand("h", "help", "Prints this helpful message", lambda _, args: cmdParser.usage()) cmdParser.addCommand("a", "add", "Add a new entry into the database", add, syntax="[LABEL] PATH") cmdParser.addCommand("s", "save", "Add current path into the database", save, syntax="[LABEL]") cmdParser.addCommand("m", "move", "Rename an entry in the database", move, syntax="FROM TO") cmdParser.addCommand("c", "change", "Changes the path of an entry in the database", change, syntax="LABEL NEW_PATH") cmdParser.addCommand("d", "delete", "Delete an entry from the database", delete, syntax="LABEL") cmdParser.addCommand("l", "list", "List the entries in the database", list) cmdParser.addCommand("g", "get", "Retrieve an entry from the database", get, True, syntax="LABEL") return cmdParser
-att When used with -add or -setcv, specify key-value pair to added to the item in the following format: -att KEY VAL TYPE. KEY is the name of the attribute. VAL is the value. TYPE is tye type of the value and it's one of the following: str, unicode, int and float. """ % {"cmd": os.path.basename(sys.argv[0])} op = OptionParser( "*-h", "*-l:", "*-r", "*-pop", "*-del", "*-add:", "*-top", "*-list", "*-levels", "*-cl", "*-cv", "*-setcl:", "*-setcv:", "*-backup", "*-recover", "*-att:::", ) op.usageString = usage try: op.parse(sys.argv[1:]) except OptionParser.ParseError, e: op.usage(e.message)
""" % {"prog":os.path.basename(sys.argv[0])} def usage(msg=None): print >>sys.stderr, usageString if msg: print >>sys.stderr, "ERROR:", msg print >>sys.stderr sys.exit(1) op = OptionParser( "*-h", "*-c:", "*-H:", "*-d:", "*-f", "*-s:", "*-t:", "*-u", "*-U:", "*-l", "*--static", "*--stdout", ) try: op.parse(sys.argv[1:]) except OptionParser.ParseError, e: usage(e.message) if op.get('-h'): usage() if bool(op.get('-l')): USESYSLOG = True
-u turn on utf-8 cleaner """ % {"prog":os.path.basename(sys.argv[0])} def usage(msg=None): print >>sys.stderr, usageString if msg: print >>sys.stderr, "ERROR:", msg print >>sys.stderr sys.exit(1) op = OptionParser( "*-h", "-c:", "*-H:", "*-d:", "*-f", "*-s:", "*-u", ) try: op.parse(sys.argv[1:]) except OptionParser.ParseError, e: usage(e.message) if op.get('-h'): usage() mycnf = op.getOne('-c') host = op.getOne('-H') db = op.getOne('-d') full = bool(op.get('-f')) url = op.getOne('-s')
syntaxError () db = initialize_database () try: print db[args[0]] except: print >> sys.stderr, args[0] + " does not exist in the database." close_database (db) sys.exit (1) close_database (db) # The command line parser parser = OptionParser (name) # The options file_option = Configuration ("f", "file", "Specifies which database to use", default_db_file, syntax = "FILENAME") parser.add (file_option) # The commands help_command = Command ("h", "help", "Prints this helpful message", lambda args:parser.usage ()) parser.add (help_command) add_command = Command ("a", "add", "Add a new entry into the database", add, syntax = "[LABEL] PATH") parser.add (add_command)
-d <db> name of the olac database -n <ver> OLAC version (=1.0|1.1) """ % {"prog":os.path.basename(sys.argv[0])} def usage(msg=None): print >>sys.stderr, usageString if msg: print >>sys.stderr, "ERROR:", msg print >>sys.stderr sys.exit(1) op = OptionParser( "*-h", "-c:", "*-H:", "*-d:", "-n:", ) try: op.parse(sys.argv[1:]) except OptionParser.ParseError, e: usage(e.message) if op.get('-h'): usage() mycnf = op.getOne('-c') host = op.getOne('-H') db = op.getOne('-d') ver = op.getOne('-n') if ver not in ("1.0", "1.1"): msg = "invalid OLAC version: %s" % `ver`
-c <mycnf> mycnf file -t <table> name of the table to be populated with the data options: -h print this message and exit -H <host> hostname of the mysql server -d <db> name of the olac database -e <encoding> character encoding of the input data (default: UTF-8) """ % {"prog":os.path.basename(sys.argv[0])} op = OptionParser( "*-h", "-c:", "*-H:", "*-d:", "-t:", "*-e:", ) def usage(msg=None): print >>sys.stderr, usageString if msg: print >>sys.stderr, "ERROR:", msg print >>sys.stderr sys.exit(1) try: op.parse(sys.argv[1:]) except OptionParser.ParseError, e: usage(e.message)
def createQcdCmdLineParser(): # The command line parser cmdParser = OptionParser (name) # The options cmdParser.addConfiguration("f", "file", "Specifies which database to use", defaultDbFile, syntax = "FILENAME") # The commands cmdParser.addCommand("h", "help", "Prints this helpful message", lambda _,args:cmdParser.usage ()) cmdParser.addCommand("a", "add", "Add a new entry into the database", add, syntax = "[LABEL] PATH") cmdParser.addCommand("s", "save", "Add current path into the database", save, syntax = "[LABEL]") cmdParser.addCommand("m", "move", "Rename an entry in the database", move, syntax = "FROM TO") cmdParser.addCommand("c", "change", "Changes the path of an entry in the database", change, syntax = "LABEL NEW_PATH") cmdParser.addCommand("d", "delete", "Delete an entry from the database", delete, syntax = "LABEL") cmdParser.addCommand("l", "list", "List the entries in the database", list) cmdParser.addCommand("g", "get", "Retrieve an entry from the database", get, True, syntax = "LABEL") return cmdParser