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 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)
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)
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: opts["read_default_file"] = mycnf elif olac: opts["host"] = olac.olacvar("mysql/host") opts["db"] = olac.olacvar("mysql/olacdb") opts["user"] = olac.olacvar("mysql/user")
save_command = Command ("s", "save", "Add current path into the database", save, syntax = "[LABEL]") parser.add (save_command) move_command = Command ("m", "move", "Rename an entry in the database", move, syntax = "FROM TO") parser.add (move_command) change_command = Command ("c", "change", "Changes the path of an entry in the database", change, syntax = "LABEL NEW_PATH") parser.add (change_command) delete_command = Command ("d", "delete", "Delete an entry from the database", delete, syntax = "LABEL") parser.add (delete_command) list_command = Command ("l", "list", "List the entries in the database", list) parser.add (list_command) retrieve_command = Command ("g", "get", "Retrieve an entry from the database", get, True, syntax = "LABEL") parser.add (retrieve_command) # Parse it! parser.parse ()