From c730fa9a23b6d27e5361b7ef1c9b97970df0a60d Mon Sep 17 00:00:00 2001 From: Magnus Ahltorp Date: Wed, 26 Jul 2017 00:30:49 +0200 Subject: Use centralized config parsing in initlog.py --- tools/initlog.py | 27 ++++++++++----------------- tools/mergetools.py | 23 ++++++++++++----------- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/tools/initlog.py b/tools/initlog.py index 222129c..da63206 100755 --- a/tools/initlog.py +++ b/tools/initlog.py @@ -10,26 +10,11 @@ import sys import os import argparse -import yaml import errno from time import time from base64 import b64encode from certtools import build_merkle_tree, write_file, generate_tree_head_signature -from mergetools import get_sth, perm, get_logorder, hexencode - -def parse_args(): - parser = argparse.ArgumentParser(description="") - parser.add_argument('--promote-secondary', action='store_true') - parser.add_argument('--config', help="System configuration", - required=True) - parser.add_argument('--localconfig', help="Local configuration", - required=True) - - args = parser.parse_args() - config = yaml.load(open(args.config)) - localconfig = yaml.load(open(args.localconfig)) - - return (args, config, localconfig) +from mergetools import get_sth, perm, get_logorder, hexencode, parse_args # TODO: Add a `--init-secondary' option too? @@ -52,7 +37,15 @@ def main(): - write n to minsize - create perm database if it doesn't exist """ - args, config, localconfig = parse_args() + parser = argparse.ArgumentParser(description="") + parser.add_argument('--promote-secondary', action='store_true') + parser.add_argument('--config', help="System configuration", + required=True) + parser.add_argument('--localconfig', help="Local configuration", + required=True) + + args, config, localconfig = parse_args(parser=parser) + paths = localconfig["paths"] own_key = (localconfig["nodename"], "%s/%s-private.pem" % (paths["privatekeys"], diff --git a/tools/mergetools.py b/tools/mergetools.py index 0afec24..62b11e4 100644 --- a/tools/mergetools.py +++ b/tools/mergetools.py @@ -417,17 +417,18 @@ def get_missingentriesforbackup(node, baseurl, own_key, paths): def chunks(l, n): return [l[i:i+n] for i in range(0, len(l), n)] -def parse_args(): - parser = argparse.ArgumentParser(description="") - parser.add_argument('node', nargs='*', help="Node to operate on") - parser.add_argument('--config', help="System configuration", - required=True) - parser.add_argument('--localconfig', help="Local configuration", - required=True) - parser.add_argument('--interval', type=int, metavar="n", - help="Repeate every N seconds") - parser.add_argument("--timing", action='store_true', - help="Print timing information") +def parse_args(parser=None): + if parser == None: + parser = argparse.ArgumentParser(description="") + parser.add_argument('node', nargs='*', help="Node to operate on") + parser.add_argument('--config', help="System configuration", + required=True) + parser.add_argument('--localconfig', help="Local configuration", + required=True) + parser.add_argument('--interval', type=int, metavar="n", + help="Repeate every N seconds") + parser.add_argument("--timing", action='store_true', + help="Print timing information") args = parser.parse_args() localconfig = readconfig.read_config(args.localconfig) -- cgit v1.1