예제 #1
0
def configure(args):
    opts = parse_args(args)

    validator_config = {}
    if opts.config is not None:
        if os.path.exists(opts.config):
            validator_config = parse_configuration_file(opts.config)
        else:
            raise ExitError("Config file does not exist: {}".format(
                opts.config))

    opts.log_config_dict = None
    if opts.log_config is not None:
        if not os.path.exists(opts.log_config):
            raise ExitError("log-config file does not exist: {}"
                            .format(opts.log_config))
        else:
            opts.log_config_dict = load_log_config(opts.log_config)

    keys = [
        'NodeName',
        'Listen',
        'KeyFile',
        'AdministrationNode',
        'DataDirectory',
        'LedgerURL',
    ]
    if any(k in validator_config for k in keys):
        print("Overriding the following keys from validator configuration "
              "file: {}".format(opts.config))
        for k in keys:
            if k in validator_config:
                print("\t{}".format(k))
                del validator_config[k]
    if opts.log_config:
        print("\tLogConfigFile")

    opts.validator_config = validator_config

    opts.count = max(1, opts.count)

    print("Configuration:")
    pp.pprint(opts.__dict__)

    return vars(opts)
def configure(opts):
    scriptdir = os.path.dirname(os.path.realpath(__file__))

    # Find the validator to use
    if opts.validator is None:
        opts.validator = find_txn_validator()
        if not os.path.isfile(opts.validator):
            print "txnvalidator: {}".format(opts.validator)
            raise ExitError("Could not find txnvalidator.")
    else:
        if not os.path.isfile(opts.validator):
            print "txnvalidator: {}".format(opts.validator)
            raise ExitError("txnvalidator script does not exist.")

    # Create directory -- after the params have been validated
    if opts.data_dir is None:
        opts.data_dir_is_tmp = True  # did we make up a directory
        opts.data_dir = tempfile.mkdtemp()
    else:
        opts.data_dir = os.path.abspath(opts.data_dir)
        if not os.path.exists(opts.data_dir):
            os.makedirs(opts.data_dir)

    if opts.load_blockchain is not None:
        if not os.path.isfile(opts.load_blockchain):
            raise ExitError("Blockchain archive to load {} does not "
                            "exist.".format(opts.load_blockchain))
        else:
            opts.config = get_archive_config(opts.data_dir,
                                             opts.load_blockchain)
            if opts.config is None:
                raise ExitError("Could not read config from Blockchain "
                                "archive: {}".format(opts.load_blockchain))

    validator_config = {}

    if opts.config is not None:
        if os.path.exists(opts.config):
            validator_config = parse_configuration_file(opts.config)
        else:
            raise ExitError("Config file does not exist: {}".format(
                opts.config))
    else:
        opts.config = os.path.realpath(os.path.join(scriptdir, "..", "etc",
                                                    "txnvalidator.js"))
        print "No config file specified, loading  {}".format(opts.config)
        if os.path.exists(opts.config):
            validator_config = parse_configuration_file(opts.config)
        else:
            raise ExitError(
                "Default config file does not exist: {}".format(opts.config))

    keys = [
        'NodeName',
        'Host',
        'HttpPort',
        'Port',
        'LogFile',
        'LogLevel',
        'KeyFile',
        "AdministrationNode",
        "DataDirectory",
        "GenesisLedger",
    ]
    if any(k in validator_config for k in keys):
        print "Overriding the following keys from validator configuration " \
              "file: {}".format(opts.config)
        for k in keys:
            if k in validator_config:
                print "\t{}".format(k)
                del validator_config[k]

    opts.count = max(1, opts.count)
    opts.validator_config = validator_config
    opts.validator_config['LogLevel'] = opts.log_level

    print "Configuration:"
    pp.pprint(opts.__dict__)
def configure(opts):
    scriptDir = os.path.dirname(os.path.realpath(__file__))

    # Find the validator to use
    if opts.validator is None:
        opts.validator = find_txn_validator()
        if not os.path.isfile(opts.validator):
            print("txnvalidator: {}".format(opts.validator))
            raise ExitError("Could not find txnvalidator.")
    else:
        if not os.path.isfile(opts.validator):
            print("txnvalidator: {}".format(opts.validator))
            raise ExitError("txnvalidator script does not exist.")

    validatorConfig = {}
    if opts.config is not None:
        if os.path.exists(opts.config):
            validatorConfig = parse_configuration_file(opts.config)
        else:
            raise ExitError("Config file does not exist: {}".format(
                opts.config))
    else:
        opts.config = os.path.realpath(
            os.path.join(scriptDir, "..", "etc", "txnvalidator.js"))
        print("No config file specified, loading  {}".format(opts.config))
        if os.path.exists(opts.config):
            validatorConfig = parse_configuration_file(opts.config)
        else:
            raise ExitError("Default config file does not exist: {}".format(
                opts.config))

    if opts.load_blockchain is not None:
        if not os.path.isfile(opts.load_blockchain):
            raise ExitError("Blockchain archive to load {} does not "
                            "exist.".format(opts.load_blockchain))

    # Create directory -- after the params have been validated
    if opts.data_dir is None:
        opts.data_dir_is_tmp = True  # did we make up a directory
        opts.data_dir = tempfile.mkdtemp()
    else:
        opts.data_dir = os.path.abspath(opts.data_dir)
        if not os.path.exists(opts.data_dir):
            os.makedirs(opts.data_dir)

    keys = [
        'NodeName',
        'Host',
        'HttpPort',
        'Port',
        'LogFile',
        'LogLevel',
        'KeyFile',
        "AdministrationNode",
        "DataDirectory",
        "GenesisLedger",
    ]
    if any(k in validatorConfig for k in keys):
        print "Overriding the following keys from validator configuration " \
              "file: {}".format(opts.config)
        for k in keys:
            if k in validatorConfig:
                print "\t{}".format(k)
                del validatorConfig[k]

    opts.count = max(1, opts.count)
    opts.validator_config = validatorConfig
    opts.validator_config['LogLevel'] = opts.log_level

    print "Configuration:"
    pp.pprint(opts.__dict__)
예제 #4
0
def configure(args):
    opts = parse_args(args)

    script_dir = os.path.dirname(os.path.realpath(__file__))

    # Find the validator to use
    if opts.validator is None:
        opts.validator = find_executable('txnvalidator')
        if not os.path.isfile(opts.validator):
            print "txnvalidator: {}".format(opts.validator)
            raise ExitError("Could not find txnvalidator.")
    else:
        if not os.path.isfile(opts.validator):
            print "txnvalidator: {}".format(opts.validator)
            raise ExitError("txnvalidator script does not exist.")

    # Create directory -- after the params have been validated
    if opts.data_dir is None:
        opts.data_dir_is_tmp = True  # did we make up a directory
        opts.data_dir = tempfile.mkdtemp()
    else:
        opts.data_dir = os.path.abspath(opts.data_dir)
        if not os.path.exists(opts.data_dir):
            os.makedirs(opts.data_dir)

    if opts.load_blockchain is not None:
        if not os.path.isfile(opts.load_blockchain):
            raise ExitError("Blockchain archive to load {} does not "
                            "exist.".format(opts.load_blockchain))
        else:
            opts.config = get_archive_config(opts.data_dir,
                                             opts.load_blockchain)
            if opts.config is None:
                raise ExitError("Could not read config from Blockchain "
                                "archive: {}".format(opts.load_blockchain))

    if opts.config is not None:
        if os.path.exists(opts.config):
            validator_config = parse_configuration_file(opts.config)
        else:
            raise ExitError("Config file does not exist: {}".format(
                opts.config))
    else:
        opts.config = os.path.realpath(
            os.path.join(script_dir, "..", "etc", "txnvalidator.js"))
        print "No config file specified, loading  {}".format(opts.config)
        if os.path.exists(opts.config):
            validator_config = parse_configuration_file(opts.config)
        else:
            raise ExitError("Default config file does not exist: {}".format(
                opts.config))

    opts.log_config_dict = None
    if opts.log_config is not None:
        if not os.path.exists(opts.log_config):
            raise ExitError("log-config file does not exist: {}".format(
                opts.log_config))
        else:
            opts.log_config_dict = load_log_config(opts.log_config)

    keys = [
        'NodeName',
        'Listen',
        'KeyFile',
        'AdministrationNode',
        'DataDirectory',
        'LedgerURL',
    ]
    if any(k in validator_config for k in keys):
        print "Overriding the following keys from validator configuration " \
              "file: {}".format(opts.config)
        for k in keys:
            if k in validator_config:
                print "\t{}".format(k)
                del validator_config[k]
    if opts.log_config:
        print "\tLogConfigFile"

    opts.validator_config = validator_config

    opts.count = max(1, opts.count)

    print "Configuration:"
    pp.pprint(opts.__dict__)

    return vars(opts)