aboutsummaryrefslogtreecommitdiffstats
path: root/build/scripts/touch.py
diff options
context:
space:
mode:
authoralexv-smirnov <alex@ydb.tech>2023-06-13 11:05:01 +0300
committeralexv-smirnov <alex@ydb.tech>2023-06-13 11:05:01 +0300
commitbf0f13dd39ee3e65092ba3572bb5b1fcd125dcd0 (patch)
tree1d1df72c0541a59a81439842f46d95396d3e7189 /build/scripts/touch.py
parent8bfdfa9a9bd19bddbc58d888e180fbd1218681be (diff)
downloadydb-bf0f13dd39ee3e65092ba3572bb5b1fcd125dcd0.tar.gz
add ymake export to ydb
Diffstat (limited to 'build/scripts/touch.py')
-rwxr-xr-xbuild/scripts/touch.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/build/scripts/touch.py b/build/scripts/touch.py
new file mode 100755
index 0000000000..e01ba7f86b
--- /dev/null
+++ b/build/scripts/touch.py
@@ -0,0 +1,50 @@
+#!/usr/bin/env python
+
+import optparse
+import os
+import sys
+import time
+
+
+def main(argv):
+ parser = optparse.OptionParser(add_help_option=False)
+ parser.disable_interspersed_args()
+
+ parser.add_option('-?', '--help', dest='help',
+ action='store_true', default=None, help='print help')
+ parser.add_option('-t', dest='t', action='store', default=None)
+
+ opts, argv_rest = parser.parse_args(argv)
+ if getattr(opts, 'help', False):
+ parser.print_help()
+ return 0
+
+ tspec = opts.t
+ if tspec is None:
+ times = None
+ else:
+ head, sep, tail = tspec.partition('.')
+ if 8 > len(head):
+ raise Exception("time spec must follow format [[CC]YY]MMDDhhmm[.SS]: " + tspec + '; ' + head)
+ tfmt = ''
+ if 12 == len(head):
+ tfmt += '%Y'
+ elif 10 == len(head):
+ tfmt += '%y'
+ tfmt += '%m%d%H%M'
+ if 2 == len(tail):
+ tfmt += '.%S'
+ mtime = time.mktime(time.strptime(tspec, tfmt))
+ times = (mtime, mtime)
+
+ for file in argv_rest:
+ try:
+ os.utime(file, times)
+ except:
+ open(file, 'w').close()
+ if times is not None:
+ os.utime(file, times)
+
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv[1:]))