]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools/Scripts: Add GetUtcDateTime script.
authorChasel Chiu <chasel.chiu@intel.com>
Thu, 8 Aug 2019 12:43:46 +0000 (20:43 +0800)
committerChasel Chiu <chasel.chiu@intel.com>
Thu, 15 Aug 2019 07:49:11 +0000 (15:49 +0800)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2067

A script that can return UTC date and time in ascii
format which is convenient for patching build time
information in any binary.

Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Signed-off-by: Chasel Chiu <chasel.chiu@intel.com>
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
Acked-by: Leif Lindholm <leif.lindholm@linaro.org>
BaseTools/Scripts/GetUtcDateTime.py [new file with mode: 0644]

diff --git a/BaseTools/Scripts/GetUtcDateTime.py b/BaseTools/Scripts/GetUtcDateTime.py
new file mode 100644 (file)
index 0000000..3cfb6ac
--- /dev/null
@@ -0,0 +1,44 @@
+## @file\r
+#  Get current UTC date and time information and output as ascii code.\r
+#\r
+#  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
+#\r
+#  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+\r
+VersionNumber = '0.1'\r
+import sys\r
+import datetime\r
+import argparse\r
+\r
+def Main():\r
+    PARSER = argparse.ArgumentParser(\r
+        description='Retrieves UTC date and time information (output ordering: year, date, time) - Version ' + VersionNumber)\r
+    PARSER.add_argument('--year',\r
+                        action='store_true',\r
+                        help='Return UTC year of now. [Example output (2019): 39313032]')\r
+    PARSER.add_argument('--date',\r
+                        action='store_true',\r
+                        help='Return UTC date MMDD of now. [Example output (7th August): 37303830]')\r
+    PARSER.add_argument('--time',\r
+                        action='store_true',\r
+                        help='Return 24-hour-format UTC time HHMM of now. [Example output (14:25): 35323431]')\r
+\r
+    ARGS = PARSER.parse_args()\r
+    if len(sys.argv) == 1:\r
+        print ("ERROR: At least one argument is required!\n")\r
+        PARSER.print_help()\r
+\r
+    today = datetime.datetime.utcnow()\r
+    if ARGS.year:\r
+        ReversedNumber = str(today.year)[::-1]\r
+        print (''.join(hex(ord(HexString))[2:] for HexString in ReversedNumber))\r
+    if ARGS.date:\r
+        ReversedNumber = str(today.strftime("%m%d"))[::-1]\r
+        print (''.join(hex(ord(HexString))[2:] for HexString in ReversedNumber))\r
+    if ARGS.time:\r
+        ReversedNumber = str(today.strftime("%H%M"))[::-1]\r
+        print (''.join(hex(ord(HexString))[2:] for HexString in ReversedNumber))\r
+\r
+if __name__ == '__main__':\r
+    Main()\r