import os
import sys
import subprocess
+import argparse
+
+from datetime import datetime
+
+parser = argparse.ArgumentParser(description='Generate Graphviz version.')
+parser.add_argument('--committer-date-iso',
+ action='store_true',
+ help='Print ISO formatted committer date in UTC instead of version'
+)
+
+args = parser.parse_args()
major_version, minor_version, patch_version = version.split('.')
-try:
- int(patch_version)
-except ValueError:
- # Non-numerical patch version; add committer date
+if not patch_version.isnumeric() or args.committer_date_iso:
os.environ['TZ'] = 'UTC'
try:
- committer_date = subprocess.run(
- [
- 'git',
- 'log',
- '-n',
- '1',
- '--format=%cd',
- '--date=format-local:%Y%m%d.%H%M'
- ],
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- check=True,
- ).stdout.decode('utf-8').strip()
- patch_version += '.' + committer_date
+ committer_date = datetime.strptime(
+ subprocess.check_output(
+ [
+ 'git',
+ 'log',
+ '-n',
+ '1',
+ '--format=%cd',
+ '--date=format-local:%Y-%m-%d %H:%M:%S'
+ ],
+ universal_newlines=True,
+ ).strip(),
+ '%Y-%m-%d %H:%M:%S',
+ )
except (subprocess.CalledProcessError, FileNotFoundError):
print('Warning: build not started in a Git clone, or Git is not installed: setting version date to 0.', file=sys.stderr)
- patch_version += '.0'
+ committer_date = '0'
-print(f'{major_version}.{minor_version}.{patch_version}')
+if args.committer_date_iso:
+ print(committer_date)
+else:
+ if not patch_version.isnumeric():
+ # Non-numerical patch version; add committer date
+ patch_version += '.' + committer_date.strftime('%Y%m%d.%H%M')
+ print('{0}.{1}.{2}'.format(major_version, minor_version, patch_version))