diff options
author | Daniil Baturin <daniil@baturin.org> | 2016-03-03 17:49:54 -0500 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2016-03-03 17:49:54 -0500 |
commit | 4b78ab4f94f74291f449a622625825c8f51a0ea7 (patch) | |
tree | 51b508061196f8120fff7e7e351f7ff677bee738 | |
parent | f432d9672202ff7f5e2e2ea2ce071f29db50d7f2 (diff) | |
download | vyos-build-4b78ab4f94f74291f449a622625825c8f51a0ea7.tar.gz vyos-build-4b78ab4f94f74291f449a622625825c8f51a0ea7.zip |
Make the query-config scripts more generic, it requires JSON file name now.
-rwxr-xr-x | scripts/query-config | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/scripts/query-config b/scripts/query-config index cfd26cc3..23e64ef7 100755 --- a/scripts/query-config +++ b/scripts/query-config @@ -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]) |