Esempio n. 1
0
def handle_request(deprecated_options, config, req):
    if "version" not in req:
        return ["All requests must have a 'version'"]

    if req["version"] < MIN_PROTOCOL_VERSION or req[
            "version"] > MAX_PROTOCOL_VERSION:
        return [
            "Unsupported request version %d. Server supports versions %d-%d" %
            (req["version"], MIN_PROTOCOL_VERSION, MAX_PROTOCOL_VERSION)
        ]

    error = []

    if "load" in req:
        print("Loading config from %s..." % req["load"], file=sys.stderr)
        try:
            config.load_config(req["load"])
        except Exception as e:
            error += ["Failed to load from %s: %s" % (req["load"], e)]

    if "set" in req:
        handle_set(config, error, req["set"])

    if "save" in req:
        try:
            print("Saving config to %s..." % req["save"], file=sys.stderr)
            confgen.write_config(deprecated_options, config, req["save"])
        except Exception as e:
            error += ["Failed to save to %s: %s" % (req["save"], e)]

    return error
Esempio n. 2
0
def handle_request(config, req):
    if not "version" in req:
        return [ "All requests must have a 'version'" ]
    if int(req["version"]) != 1:
        return [ "Only version 1 requests supported" ]

    error = []

    if "load" in req:
        print("Loading config from %s..." % req["load"], file=sys.stderr)
        try:
            config.load_config(req["load"])
        except Exception as e:
            error += [ "Failed to load from %s: %s" % (req["load"], e) ]

    if "set" in req:
        handle_set(config, error, req["set"])

    if "save" in req:
        try:
            print("Saving config to %s..." % req["save"], file=sys.stderr)
            confgen.write_config(config, req["save"])
        except Exception as e:
            error += [ "Failed to save to %s: %s" % (req["save"], e) ]

    return error
Esempio n. 3
0
def handle_request(deprecated_options, config, req):
    if 'version' not in req:
        return ["All requests must have a 'version'"]

    if req['version'] < MIN_PROTOCOL_VERSION or req[
            'version'] > MAX_PROTOCOL_VERSION:
        return [
            'Unsupported request version %d. Server supports versions %d-%d' %
            (req['version'], MIN_PROTOCOL_VERSION, MAX_PROTOCOL_VERSION)
        ]

    error = []

    if 'load' in req:
        print('Loading config from %s...' % req['load'], file=sys.stderr)
        try:
            config.load_config(req['load'])
        except Exception as e:
            error += ['Failed to load from %s: %s' % (req['load'], e)]

    if 'set' in req:
        handle_set(config, error, req['set'])

    if 'save' in req:
        try:
            print('Saving config to %s...' % req['save'], file=sys.stderr)
            confgen.write_config(deprecated_options, config, req['save'])
        except Exception as e:
            error += ['Failed to save to %s: %s' % (req['save'], e)]

    return error
Esempio n. 4
0
def handle_request(config, req):
    if "version" not in req:
        return ["All requests must have a 'version'"]

    if req["version"] < MIN_PROTOCOL_VERSION or req["version"] > MAX_PROTOCOL_VERSION:
        return ["Unsupported request version %d. Server supports versions %d-%d" % (
            req["version"],
            MIN_PROTOCOL_VERSION,
            MAX_PROTOCOL_VERSION)]

    error = []

    if "load" in req:
        print("Loading config from %s..." % req["load"], file=sys.stderr)
        try:
            config.load_config(req["load"])
        except Exception as e:
            error += ["Failed to load from %s: %s" % (req["load"], e)]

    if "set" in req:
        handle_set(config, error, req["set"])

    if "save" in req:
        try:
            print("Saving config to %s..." % req["save"], file=sys.stderr)
            confgen.write_config(config, req["save"])
        except Exception as e:
            error += ["Failed to save to %s: %s" % (req["save"], e)]

    return error