Rewrite touch.py with argparse, pipeable.
This commit is contained in:
parent
8ff596a95e
commit
8fe13e0f83
1 changed files with 22 additions and 11 deletions
|
@ -1,23 +1,34 @@
|
||||||
'''
|
'''
|
||||||
Create the file, or update the last modified timestamp.
|
Create the file, or update the last modified timestamp.
|
||||||
'''
|
'''
|
||||||
|
import argparse
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from voussoirkit import clipext
|
from voussoirkit import pipeable
|
||||||
from voussoirkit import winglob
|
from voussoirkit import winglob
|
||||||
|
|
||||||
def touch(glob_pattern):
|
def touch_argparse(args):
|
||||||
filenames = winglob.glob(glob_pattern)
|
patterns = [pattern for arg in args.patterns for pattern in pipeable.input(arg)]
|
||||||
if len(filenames) == 0:
|
for pattern in patterns:
|
||||||
open(glob_pattern, 'a').close()
|
filenames = winglob.glob(pattern)
|
||||||
return [glob_pattern]
|
|
||||||
else:
|
if len(filenames) == 0 and not winglob.is_glob(pattern):
|
||||||
|
open(pattern, 'a').close()
|
||||||
|
print(pattern)
|
||||||
|
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
os.utime(filename)
|
os.utime(filename)
|
||||||
return filenames
|
print(filename)
|
||||||
|
|
||||||
|
def main(argv):
|
||||||
|
parser = argparse.ArgumentParser(description=__doc__)
|
||||||
|
|
||||||
|
parser.add_argument('patterns', nargs='+')
|
||||||
|
parser.set_defaults(func=touch_argparse)
|
||||||
|
|
||||||
|
args = parser.parse_args(argv)
|
||||||
|
return args.func(args)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
glob_patterns = [clipext.resolve(x).strip() for x in sys.argv[1:]]
|
raise SystemExit(main(sys.argv[1:]))
|
||||||
for glob_pattern in glob_patterns:
|
|
||||||
touch(glob_pattern)
|
|
||||||
|
|
Loading…
Reference in a new issue