Make the query-config scripts more generic, it requires JSON file name now.

This commit is contained in:
Daniil Baturin 2016-03-03 17:49:54 -05:00
parent f432d96722
commit 4b78ab4f94

View File

@ -14,7 +14,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# File: query-config
# Purpose: Extracts field values from the build config,
# Purpose: Extracts field values a flat JSON file,
# for use in languages that can't handle JSON easily,
# (I'm looking at you, Bourne shell!)
@ -25,12 +25,17 @@ import json
import defaults
import util
if len(sys.argv) < 2:
print("Usage: {0} <config field name>".format(sys.argv[0]))
if len(sys.argv) < 3:
print("Usage: {0} <flat JSON file> <config field name>".format(sys.argv[0]))
sys.exit(1)
util.check_build_config()
with open(defaults.BUILD_CONFIG, 'r') as f:
build_config = json.load(f)
# Note: lack of error handling is deliberate, if some field is expected to be there
# but isn't, it's better if the failure will be obvious and spectacular
print(build_config[sys.argv[1]])
file = sys.argv[1]
key = sys.argv[2]
with open(file, 'r') as f:
json_data = json.load(f)
print(json_data[key])