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