diff --git a/Control/AthenaConfiguration/CMakeLists.txt b/Control/AthenaConfiguration/CMakeLists.txt index 9140101ce8f67d05b6d9f02ef90e784e32ebfdf4..5a5784cf23173bf9101bc577fa65fab8757eef10 100644 --- a/Control/AthenaConfiguration/CMakeLists.txt +++ b/Control/AthenaConfiguration/CMakeLists.txt @@ -13,3 +13,4 @@ atlas_install_python_modules( python/*.py ) atlas_install_runtime(python/*.pkl ) atlas_add_test( ComponentAccumulatorTest SCRIPT python -m AthenaConfiguration.ComponentAccumulator ) +atlas_install_scripts( share/confTool.py ) diff --git a/Control/AthenaConfiguration/share/confTool.py b/Control/AthenaConfiguration/share/confTool.py new file mode 100755 index 0000000000000000000000000000000000000000..f6e53b5467ab8f3ce429d0187837730f6df7b4c0 --- /dev/null +++ b/Control/AthenaConfiguration/share/confTool.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python + +# +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +# +import pickle +import pprint +import json +import sys +import argparse + +parser = argparse.ArgumentParser(description='Utility to transform/display athena configurations') +parser.add_argument('--print', dest="pr", action='store_true', help='Prints') +parser.add_argument('--toJSON', help='Convert to JSON file') +parser.add_argument('--toPKL', help='Convert to python pickle format file') +parser.add_argument('file', nargs=1, help='File to work with') +args = parser.parse_args() + + +conf = None +if args.file[0].endswith( ".pkl" ): + input_file = file( args.file[0] ) + conf = [] + while True: + try: + conf.append( pickle.load( input_file ) ) + except EOFError: + break + print "Red", len(conf), "items" + +if args.file[0].endswith( ".json" ): + + def __keepPlainStrings(element): + if isinstance(element, unicode): + return str(element) + if isinstance(element, list): + return [ __keepPlainStrings(x) for x in element ] + if isinstance(element, dict): + return dict( [ (__keepPlainStrings(key), __keepPlainStrings(value)) for key,value in element.iteritems() ] ) + return element + + conf = json.load( file( args.file[0] ), object_hook=__keepPlainStrings ) + +if args.pr: + for n,c in enumerate(conf): + print "Item", n, "*"*80 + pprint.pprint(dict(c)) + +if args.toJSON: + oFile = open( args.toJSON, "w" ) + json.dump( conf, oFile, indent=2, ensure_ascii=True ) + oFile.close() + +if args.toPKL: + oFile = open( args.toPKL, "w" ) + pickle.dump( conf, oFile ) + oFile.close() +