3131 del multiprocessing
3232
3333# version string
34- __version__ = '0.7.3.post1 '
34+ __version__ = '0.7.3.post2 '
3535
3636# from configparser
3737BOOLEAN_STATES = {'1' : True , '0' : False ,
@@ -357,6 +357,45 @@ def get_parser():
357357 return parser
358358
359359
360+ def find (root ): # pragma: no cover
361+ """Recursively find all files under root.
362+
363+ Args:
364+ - root -- os.PathLike, root path to search
365+
366+ Returns:
367+ - typing.Generator -- yield all files under the root path
368+
369+ """
370+ flst = list ()
371+ temp = os .listdir (root )
372+ for file in temp :
373+ path = os .path .join (root , file )
374+ if os .path .isdir (path ):
375+ flst .extend (find (path ))
376+ elif os .path .isfile (path ):
377+ flst .append (path )
378+ elif os .path .islink (path ): # exclude symbolic links
379+ continue
380+ yield from flst
381+
382+
383+ def rename (path , root ):
384+ """Rename file for archiving.
385+
386+ Args:
387+ - path -- os.PathLike, file to rename
388+ - root -- os.PathLike, archive path
389+
390+ Returns:
391+ - str -- the archiving path
392+
393+ """
394+ stem , ext = os .path .splitext (path )
395+ name = '%s-%s%s' % (stem , uuid .uuid4 (), ext )
396+ return os .path .join (root , name )
397+
398+
360399def main (argv = None ):
361400 """Entry point for f2format.
362401
@@ -384,25 +423,6 @@ def main(argv=None):
384423 F2FORMAT_QUIET = os .getenv ('F2FORMAT_QUIET' )
385424 os .environ ['F2FORMAT_QUIET' ] = '1' if args .quiet else ('0' if F2FORMAT_QUIET is None else F2FORMAT_QUIET )
386425
387- def find (root ): # pragma: no cover
388- """Recursively find all files under root."""
389- flst = list ()
390- temp = os .listdir (root )
391- for file in temp :
392- path = os .path .join (root , file )
393- if os .path .isdir (path ):
394- flst .extend (find (path ))
395- elif os .path .isfile (path ):
396- flst .append (path )
397- elif os .path .islink (path ): # exclude symbolic links
398- continue
399- yield from flst
400-
401- def rename (path ):
402- stem , ext = os .path .splitext (path )
403- name = '%s-%s%s' % (stem , uuid .uuid4 (), ext )
404- return os .path .join (ARCHIVE , name )
405-
406426 # make archive directory
407427 if archive :
408428 os .makedirs (ARCHIVE , exist_ok = True )
@@ -412,13 +432,13 @@ def rename(path):
412432 for path in args .file :
413433 if os .path .isfile (path ):
414434 if archive :
415- dest = rename (path )
435+ dest = rename (path , root = ARCHIVE )
416436 os .makedirs (os .path .dirname (dest ), exist_ok = True )
417437 shutil .copy (path , dest )
418438 filelist .append (path )
419439 if os .path .isdir (path ):
420440 if archive :
421- shutil .copytree (path , rename (path ))
441+ shutil .copytree (path , rename (path , root = ARCHIVE ))
422442 filelist .extend (find (path ))
423443
424444 # check if file is Python source code
0 commit comments