Skip to content

Commit

Permalink
improved exclude paths
Browse files Browse the repository at this point in the history
  • Loading branch information
zerwes committed Aug 8, 2022
1 parent 6325117 commit bd50dd1
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions fqcn-fixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import fileinput
import difflib
import fnmatch
import pathlib
import copy
import yaml

Expand All @@ -20,16 +21,36 @@

def isexcluded(path, _exclude_paths):
"""check if a path element should be excluded"""
ppath = pathlib.PurePath(path)
path = os.path.abspath(path)
return any(
path.startswith(ep)
or
ppath.match(ep)
or
fnmatch.fnmatch(path, ep)
or
fnmatch.fnmatch(ppath, ep)
for ep in _exclude_paths
)

basepath = os.path.dirname(os.path.realpath(__file__))

# this will be excluded
_general_exclude_paths = [
".cache",
".git",
".hg",
".svn",
".tox",
".collections/*",
".github/*",
"*/group_vars/",
"*/host_vars/",
"*/vars/",
"*/defaults/",
]

argparser = argparse.ArgumentParser(description=__doc__)
argparser.add_argument(
'-d', '--directory',
Expand Down Expand Up @@ -154,11 +175,9 @@ def isexcluded(path, _exclude_paths):

# build exclude_paths
exclude_paths = []
for ep in args.exclude_paths:
exclude_paths.append(os.path.abspath(ep))
# some deafaults to exclude
for ep in [".cache", ".git", ".hg", ".svn", ".tox", ".collections", args.fqcnmapfile]:
exclude_paths.append(os.path.abspath(ep))
for ep in args.exclude_paths + _general_exclude_paths:
exclude_paths.append(ep)
exclude_paths.append(args.fqcnmapfile)

# update some args from optional config file
config = False
Expand All @@ -176,6 +195,7 @@ def isexcluded(path, _exclude_paths):
parsefiles = []
for dirpath, dirnames, files in os.walk(os.path.abspath(args.directory)):
if isexcluded(dirpath, exclude_paths):
#print('exclude %s' % dirpath)
continue
for name in files:
for ext in args.fileextensions:
Expand Down

0 comments on commit bd50dd1

Please sign in to comment.