genesis_util: Implement two new utilities
This commit is contained in:
parent
434efcaa47
commit
3023a37b80
2 changed files with 75 additions and 0 deletions
14
programs/genesis_util/python_format.py
Executable file
14
programs/genesis_util/python_format.py
Executable file
|
|
@ -0,0 +1,14 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
|
||||||
|
if len(sys.argv) < 3:
|
||||||
|
print("syntax: "+sys.argv[0]+" INFILE OUTFILE")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
with open(sys.argv[1], "r") as infile:
|
||||||
|
genesis = json.load(infile)
|
||||||
|
with open(sys.argv[2], "w") as outfile:
|
||||||
|
json.dump(genesis, outfile, indent=2, sort_keys=True)
|
||||||
61
programs/genesis_util/upgrade_members.py
Executable file
61
programs/genesis_util/upgrade_members.py
Executable file
|
|
@ -0,0 +1,61 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import json
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def dump_json(obj, out, pretty):
|
||||||
|
if pretty:
|
||||||
|
json.dump(obj, out, indent=2, sort_keys=True)
|
||||||
|
else:
|
||||||
|
json.dump(obj, out, separators=(",", ":"), sort_keys=True)
|
||||||
|
return
|
||||||
|
|
||||||
|
re_init = re.compile(r"^init[0-9]+$")
|
||||||
|
|
||||||
|
def load_names(infile):
|
||||||
|
names = set()
|
||||||
|
for line in infile:
|
||||||
|
if '#' in line:
|
||||||
|
line = line[:line.index('#')]
|
||||||
|
line = line.strip()
|
||||||
|
if line == "":
|
||||||
|
continue
|
||||||
|
names.add(line)
|
||||||
|
return names
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser(description="Remove entities from snapshot")
|
||||||
|
parser.add_argument("-o", "--output", metavar="OUT", default="-", help="output filename (default: stdout)")
|
||||||
|
parser.add_argument("-i", "--input", metavar="IN", default="-", help="input filename (default: stdin)")
|
||||||
|
parser.add_argument("-n", "--names", metavar="NAMES", default="", help="file containing names to upgrade")
|
||||||
|
parser.add_argument("-p", "--pretty", action="store_true", default=False, help="pretty print output")
|
||||||
|
opts = parser.parse_args()
|
||||||
|
|
||||||
|
if opts.input == "-":
|
||||||
|
genesis = json.load(sys.stdin)
|
||||||
|
else:
|
||||||
|
with open(opts.input, "r") as f:
|
||||||
|
genesis = json.load(f)
|
||||||
|
|
||||||
|
if opts.names == "-":
|
||||||
|
names = load_names(sys.stdin)
|
||||||
|
else:
|
||||||
|
with open(opts.names, "r") as f:
|
||||||
|
names = load_names(f)
|
||||||
|
|
||||||
|
for account in genesis["initial_accounts"]:
|
||||||
|
if account["name"] in names:
|
||||||
|
account["is_lifetime_member"] = True
|
||||||
|
|
||||||
|
if opts.output == "-":
|
||||||
|
dump_json( genesis, sys.stdout, opts.pretty )
|
||||||
|
sys.stdout.flush()
|
||||||
|
else:
|
||||||
|
with open(opts.output, "w") as f:
|
||||||
|
dump_json( genesis, f, opts.pretty )
|
||||||
|
return
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Reference in a new issue