cmd/touch.py

53 lines
1.2 KiB
Python
Raw Normal View History

import argparse
import os
import sys
2022-02-13 03:50:00 +00:00
from voussoirkit import betterhelp
from voussoirkit import pipeable
from voussoirkit import winglob
def touch_argparse(args):
2021-05-25 08:35:55 +00:00
patterns = pipeable.input_many(args.patterns, skip_blank=True)
for pattern in patterns:
filenames = winglob.glob(pattern)
if len(filenames) == 0 and not winglob.is_glob(pattern):
open(pattern, 'a').close()
pipeable.stdout(pattern)
for filename in filenames:
os.utime(filename)
pipeable.stdout(filename)
return 0
def main(argv):
2022-02-13 03:50:00 +00:00
parser = argparse.ArgumentParser(
description='''
Create blank files, or update mtimes of existing files.
''',
)
parser.add_argument(
'patterns',
type=str,
nargs='+',
help='''
One or more filenames or glob patterns.
''',
)
parser.add_argument(
'--sleep',
type=float,
default=None,
help='''
Sleep for this many seconds between touching each file.
''',
)
parser.set_defaults(func=touch_argparse)
2022-02-13 03:50:00 +00:00
return betterhelp.go(parser, argv)
if __name__ == '__main__':
raise SystemExit(main(sys.argv[1:]))