From 32d17f89c614a759b6747507daaeecb4ca2dea7b Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Mon, 3 Apr 2017 19:08:16 +0200 Subject: Allow get_vc_revision() to return None --- configure.py | 54 +++++++++++++++++++++++++----------------------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/configure.py b/configure.py index fd06549d4..176d43acd 100755 --- a/configure.py +++ b/configure.py @@ -53,37 +53,29 @@ def chunks(l, n): def get_vc_revision(): + vc_command = ['git', 'rev-parse', 'HEAD'] + cmdname = vc_command[0] - def get_vc_revision_impl(cmdlist): - try: - cmdname = cmdlist[0] - - vc = subprocess.Popen(cmdlist, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - universal_newlines=True) - - (stdout, stderr) = vc.communicate() - - if vc.returncode != 0: - logging.debug('Error getting rev from %s - %d (%s)' - % (cmdname, vc.returncode, stderr)) - return None - - rev = str(stdout).strip() - logging.debug('%s reported revision %s' % (cmdname, rev)) - - return '%s:%s' % (cmdname, rev) - except OSError as e: - logging.debug('Error getting rev from %s - %s' % (cmdname, e.strerror)) + try: + vc = subprocess.Popen( + vc_command, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True) + (stdout, stderr) = vc.communicate() + + if vc.returncode != 0: + logging.debug('Error getting rev from %s - %d (%s)' + % (cmdname, vc.returncode, stderr)) return None - vc_command = ['git', 'rev-parse', 'HEAD'] - rev = get_vc_revision_impl(vc_command) - if rev is not None: - return rev - else: - return 'unknown' + rev = str(stdout).strip() + logging.debug('%s reported revision %s' % (cmdname, rev)) + + return '%s:%s' % (cmdname, rev) + except OSError as e: + logging.debug('Error getting rev from %s - %s' % (cmdname, e.strerror)) + return None class Version(object): @@ -107,7 +99,11 @@ class Version(object): def vc_rev(): # Lazy load to ensure get_vc_revision() does not run before logger is set up if Version._vc_rev is None: - Version._vc_rev = botan_version.release_vc_rev if botan_version.release_vc_rev else get_vc_revision() + Version._vc_rev = botan_version.release_vc_rev + if Version._vc_rev is None: + Version._vc_rev = get_vc_revision() + if Version._vc_rev is None: + Version._vc_rev = 'unknown' return Version._vc_rev -- cgit v1.2.3