From deada13eb7e36c4f18f4bcb4b91c6a7bd1dbf0b7 Mon Sep 17 00:00:00 2001 From: Dakota Benjamin Date: Tue, 29 Dec 2015 09:27:04 -0500 Subject: [PATCH] Pythonize ccd_defs_check and hook Former-commit-id: aeb2b243b1a56c6d28646aea876bece587ea7b16 --- ccd_defs_check.py | 25 +++++++++++++++++++++++++ hooks/pre-commit | 7 ++++--- 2 files changed, 29 insertions(+), 3 deletions(-) create mode 100755 ccd_defs_check.py diff --git a/ccd_defs_check.py b/ccd_defs_check.py new file mode 100755 index 00000000..efacfee6 --- /dev/null +++ b/ccd_defs_check.py @@ -0,0 +1,25 @@ +#!/usr/bin/python +import sys +import os +import json + +BIN_PATH_ABS = os.path.abspath(os.path.dirname(os.path.abspath(__file__))) + +def get_ccd_widths(): + """Return the CCD Width of the camera listed in the JSON defs file.""" + with open(BIN_PATH_ABS + '/data/ccd_defs.json') as jsonFile: + return json.load(jsonFile) + +try: + ccd_defs = get_ccd_widths() + print "CCD_DEFS compiles OK" + print "Definitions in file: {0}".format(len(ccd_defs)) + exit_code=0 +except IOError as e: + print "I/O error with CCD_DEFS file: {0}".format(e.strerror) + exit_code=255 +except: + print "Error with CCD_DEFS file: {0}".format(sys.exc_info()[1]) + exit_code=255 + +sys.exit(exit_code) diff --git a/hooks/pre-commit b/hooks/pre-commit index 71d12852..0a85afe4 100755 --- a/hooks/pre-commit +++ b/hooks/pre-commit @@ -10,13 +10,14 @@ exec 1>&2 echo "RUNNING PRE-COMMIT" - +EXIT_CODE=0 # Get list of files about to be committed if git diff --cached --name-only --diff-filter=ACM | grep 'ccd_defs.json'; then echo "We changed ccd_defs.json" GIT_ROOT=$(git rev-parse --show-toplevel) - perl $GIT_ROOT/ccd_defs_check.pl + python $GIT_ROOT/ccd_defs_check.py + EXIT_CODE=$(echo $?) fi # non-zero exit fails the commit -exit 0 +exit $EXIT_CODE