From 799ee44546a9001e5dbc1728830da08cb53a6ab3 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Mon, 7 Oct 2013 09:14:46 -0400 Subject: [PATCH] Add script to quickly sanity check json files Change-Id: I0982ddb50b196beb899d01557c5fb44436b03bb5 --- testprojectinfo.py | 32 ++++++++++++++++++++++++++++++++ utils.py | 8 +++++++- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100755 testprojectinfo.py diff --git a/testprojectinfo.py b/testprojectinfo.py new file mode 100755 index 0000000..1adbc61 --- /dev/null +++ b/testprojectinfo.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python +# +# Copyright (C) 2013 - Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +import logging +import sys + +import utils + + +def main(): + logging.basicConfig(level=logging.DEBUG) + # Make sure all projects info load successfully + projects = utils.get_projects_info('', True) + return 0 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/utils.py b/utils.py index bf62cae..1720298 100644 --- a/utils.py +++ b/utils.py @@ -26,6 +26,8 @@ import logging CACHE_AGE = 3600 # Seconds +LOG = logging.getLogger(__name__) + def get_projects_info(project=None, all_projects=False, base_dir='./projects'): if all_projects: @@ -38,7 +40,11 @@ def get_projects_info(project=None, all_projects=False, base_dir='./projects'): for fn in files: if os.path.isfile(fn): with open(fn, 'r') as f: - project = json.loads(f.read()) + try: + project = json.loads(f.read()) + except Exception: + LOG.error('Failed to parse %s' % fn) + raise if not (all_projects and project.get('unofficial')): projects.append(project)