|
7 | 7 | import socket |
8 | 8 | import json |
9 | 9 |
|
| 10 | + |
| 11 | +def get_shell_output_as_string(commandlist): |
| 12 | + """ |
| 13 | + A wrapper function for getting shell values back as strings |
| 14 | + for both python2 and python3 |
| 15 | + :param commandlist: |
| 16 | + :return: A newline stripped string object (i.e. not a byte object) |
| 17 | + """ |
| 18 | + if sys.version_info[0] < 3: |
| 19 | + return subprocess.check_output(commandlist).strip() |
| 20 | + else: |
| 21 | + # In python 3, subprocess.check_call returns byte string. |
| 22 | + # https://stackoverflow.com/questions/18244126/python3-subprocess-output/18244485 |
| 23 | + return subprocess.getoutput(' '.join(commandlist)).strip() |
| 24 | + |
10 | 25 | class FullPaths(argparse.Action): |
11 | 26 | """Expand user- and relative-paths""" |
12 | 27 | def __call__(self, parser, namespace, values, option_string=None): |
@@ -107,14 +122,14 @@ def extract_itk_information(itk_src): |
107 | 122 | information['ITK_MANUAL_BUILD_INFORMATION'] = dict() |
108 | 123 | manual_build_info = information['ITK_MANUAL_BUILD_INFORMATION'] |
109 | 124 | os.chdir(itk_src) |
110 | | - itk_git_sha = subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip() |
111 | | - manual_build_info['GIT_CONFIG_SHA1'] = itk_git_sha |
112 | | - itk_git_date = subprocess.check_output(['git', 'show', '-s', '--format=%ci', |
113 | | - 'HEAD']).strip() |
114 | | - manual_build_info['GIT_CONFIG_DATE'] = itk_git_date |
115 | | - local_modifications = subprocess.check_output(['git', 'diff', '--shortstat', |
116 | | - 'HEAD']) |
117 | | - manual_build_info['GIT_LOCAL_MODIFICATIONS'] = local_modifications |
| 125 | + itk_git_sha = get_shell_output_as_string(['git', 'rev-parse', 'HEAD']) |
| 126 | + manual_build_info['GIT_CONFIG_SHA1'] = str(itk_git_sha) |
| 127 | + itk_git_date = get_shell_output_as_string(['git', 'show', '-s', '--format=%ci', |
| 128 | + 'HEAD']) |
| 129 | + manual_build_info['GIT_CONFIG_DATE'] = str(itk_git_date) |
| 130 | + local_modifications = get_shell_output_as_string( |
| 131 | + ['git', 'diff', '--shortstat', 'HEAD']) |
| 132 | + manual_build_info['GIT_LOCAL_MODIFICATIONS'] = str(local_modifications) |
118 | 133 | print(local_modifications) |
119 | 134 | return information |
120 | 135 |
|
|
0 commit comments