improved exclude paths

This commit is contained in:
Klaus Zerwes 2022-08-08 09:46:09 +02:00
parent 6325117cb2
commit bd50dd14c8

View File

@ -11,6 +11,7 @@ import re
import fileinput import fileinput
import difflib import difflib
import fnmatch import fnmatch
import pathlib
import copy import copy
import yaml import yaml
@ -20,16 +21,36 @@ simple script to fix the fqcn module names
def isexcluded(path, _exclude_paths): def isexcluded(path, _exclude_paths):
"""check if a path element should be excluded""" """check if a path element should be excluded"""
ppath = pathlib.PurePath(path)
path = os.path.abspath(path) path = os.path.abspath(path)
return any( return any(
path.startswith(ep) path.startswith(ep)
or or
ppath.match(ep)
or
fnmatch.fnmatch(path, ep) fnmatch.fnmatch(path, ep)
or
fnmatch.fnmatch(ppath, ep)
for ep in _exclude_paths for ep in _exclude_paths
) )
basepath = os.path.dirname(os.path.realpath(__file__)) 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 = argparse.ArgumentParser(description=__doc__)
argparser.add_argument( argparser.add_argument(
'-d', '--directory', '-d', '--directory',
@ -154,11 +175,9 @@ for fqcn in copy.copy(fqcndict).values():
# build exclude_paths # build exclude_paths
exclude_paths = [] exclude_paths = []
for ep in args.exclude_paths: for ep in args.exclude_paths + _general_exclude_paths:
exclude_paths.append(os.path.abspath(ep)) exclude_paths.append(ep)
# some deafaults to exclude exclude_paths.append(args.fqcnmapfile)
for ep in [".cache", ".git", ".hg", ".svn", ".tox", ".collections", args.fqcnmapfile]:
exclude_paths.append(os.path.abspath(ep))
# update some args from optional config file # update some args from optional config file
config = False config = False
@ -176,6 +195,7 @@ if config and config['exclude_paths']:
parsefiles = [] parsefiles = []
for dirpath, dirnames, files in os.walk(os.path.abspath(args.directory)): for dirpath, dirnames, files in os.walk(os.path.abspath(args.directory)):
if isexcluded(dirpath, exclude_paths): if isexcluded(dirpath, exclude_paths):
#print('exclude %s' % dirpath)
continue continue
for name in files: for name in files:
for ext in args.fileextensions: for ext in args.fileextensions: