Handle migration of both files and dirs

This commit is contained in:
Dan Buch 2016-05-30 10:21:13 -04:00
parent eadd3918f1
commit b47e152395
No known key found for this signature in database
GPG Key ID: FAEF12936DD3E3EC

View File

@ -36,7 +36,7 @@ def main(sysargs=sys.argv[:]):
parser = argparse.ArgumentParser(
description=_DESCRIPTION,
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('basedir', nargs='?', metavar='BASEDIR',
parser.add_argument('path', nargs='+',
type=os.path.abspath, default=os.getcwd())
parser.add_argument('-w', '--write', help='write changes back to file',
action='store_true', default=False)
@ -60,7 +60,7 @@ def main(sysargs=sys.argv[:]):
format='%(message)s'
)
for filepath in _find_candidate_files(args.basedir):
for filepath in _find_candidate_files(args.path):
updated_source = _update_filepath(filepath)
if args.write:
logging.info('Updating %s', filepath)
@ -74,8 +74,13 @@ def main(sysargs=sys.argv[:]):
return 0
def _find_candidate_files(basedir):
for curdir, dirs, files in os.walk(basedir):
def _find_candidate_files(paths):
for path in paths:
if not os.path.isdir(path):
yield path
continue
for curdir, dirs, files in os.walk(path):
for i, dirname in enumerate(dirs[:]):
if dirname.startswith('.'):
dirs.pop(i)