diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /build/scripts/touch.py | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'build/scripts/touch.py')
-rwxr-xr-x | build/scripts/touch.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/build/scripts/touch.py b/build/scripts/touch.py new file mode 100755 index 00000000000..e01ba7f86b3 --- /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:])) |