]> granicus.if.org Git - graphviz/commitdiff
Add --committer-date-iso option
authorMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Wed, 22 Jul 2020 18:09:44 +0000 (20:09 +0200)
committerMagnus Jacobsson <magnus.jacobsson@berotec.se>
Tue, 28 Jul 2020 15:53:10 +0000 (17:53 +0200)
gen_version.py

index 1bc0ee2a0f9d4ad3e9667901412fb3851effd973..c35bf17c414dc4714b785c1e7a6380c65662f6d3 100644 (file)
@@ -23,32 +23,46 @@ version = '2.44.2-dev'
 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))