def run_durus_main(): parser = OptionParser() parser.set_description('Run a Durus Server') parser.add_option( '--port', dest='port', default=DEFAULT_PORT, type='int', help='Port to listen on. (default=%s)' % DEFAULT_PORT) parser.add_option( '--file', dest='file', default=None, help='If this is not given, the storage is in a new temporary file.') parser.add_option( '--host', dest='host', default=DEFAULT_HOST, help='Host to listen on. (default=%s)' % DEFAULT_HOST) logginglevel = logger.getEffectiveLevel() parser.add_option( '--logginglevel', dest='logginglevel', default=logginglevel, type='int', help=('Logging level. Lower positive numbers log more. (default=%s)' % logginglevel)) parser.add_option( '--logfile', dest='logfile', default=None, help=('Log file. (default=stderr)')) parser.add_option( '--repair', dest='repair', action='store_true', help=('Repair the filestorage by truncating to remove anything ' 'that is malformed. Without this option, errors ' 'will cause the program to report and terminate without ' 'attempting any repair.')) parser.add_option( '--readonly', dest='readonly', action='store_true', help='Open the file in read-only mode.') parser.add_option( '--stop', dest='stop', action='store_true', help='Instead of starting the server, try to stop a running one.') (options, args) = parser.parse_args() if not options.stop: start_durus(options.logfile, options.logginglevel, options.file, options.repair, options.readonly, options.host, options.port) else: stop_durus(options.host, options.port)
def run_durus_main(): parser = OptionParser() parser.set_description('Run a Durus Server') parser.add_option( '--port', dest='port', default=DEFAULT_PORT, type='int', help='Port to listen on. (default=%s)' % DEFAULT_PORT) parser.add_option( '--file', dest='file', default=None, help=('If not given, the storage is in a new temporary file.')) parser.add_option( '--host', dest='host', default=DEFAULT_HOST, help='Host to listen on. (default=%s)' % DEFAULT_HOST) parser.add_option( '--storage-class', dest='storage', default=None, help='Storage class (e.g. durus.file_storage.FileStorage).') parser.add_option( '--gcbytes', dest='gcbytes', default=DEFAULT_GCBYTES, type='int', help=('Trigger garbage collection after this many commits. (default=%s)' % DEFAULT_GCBYTES)) if hasattr(socket, 'AF_UNIX'): parser.add_option( '--address', dest="address", default=None, help=( "Address of the server.\n" "If given, this is the path to a Unix domain socket for " "the server.")) parser.add_option( '--owner', dest="owner", default=None, help="Owner of the Unix domain socket (the --address value).") parser.add_option( '--group', dest="group", default=None, help="group of the Unix domain socket (the --address value).") parser.add_option( '--umask', dest="umask", default=None, type="int", help="umask for the Unix domain socket (the --address value).") logginglevel = logger.getEffectiveLevel() parser.add_option( '--logginglevel', dest='logginglevel', default=logginglevel, type='int', help=('Logging level. Lower positive numbers log more. (default=%s)' % logginglevel)) parser.add_option( '--logfile', dest='logfile', default=None, help=('Log file. (default=stderr)')) parser.add_option( '--repair', dest='repair', action='store_true', help=('Repair the filestorage by truncating to remove anything ' 'that is malformed. Without this option, errors ' 'will cause the program to report and terminate without ' 'attempting any repair.')) parser.add_option( '--readonly', dest='readonly', action='store_true', help='Open the file in read-only mode.') parser.add_option( '--stop', dest='stop', action='store_true', help='Instead of starting the server, try to stop a running one.') (options, args) = parser.parse_args() if getattr(options, 'address', None) is None: address = SocketAddress.new((options.host, options.port)) else: address = SocketAddress.new(address=options.address, owner=options.owner, group=options.group, umask=options.umask) if not options.stop: storage = get_storage(options.file, storage_class=options.storage, repair=options.repair, readonly=options.readonly) start_durus(options.logfile, options.logginglevel, address, storage, options.gcbytes) else: stop_durus(address)