add includes
This commit is contained in:
@@ -16,13 +16,20 @@ programs:
|
|||||||
enable_pcre2: false
|
enable_pcre2: false
|
||||||
remove_old_files: true # Optional.
|
remove_old_files: true # Optional.
|
||||||
ignore_hidden_files: true # Optional.
|
ignore_hidden_files: true # Optional.
|
||||||
excludes: # Optional. Exculde some files/folders
|
excludes: # Optional. Exculde some files. Only effected when path is a folder.
|
||||||
- data.db # Releative path
|
- data.db # Releative path
|
||||||
- /path/to/data.db # Absolute path
|
- /path/to/data.db # Absolute path
|
||||||
- type: wildcards
|
- type: wildcards
|
||||||
rule: "*/*.db"
|
rule: "*/*.db"
|
||||||
- type: regex
|
- type: regex
|
||||||
rule: "\\d+\\.db"
|
rule: "\\d+\\.db"
|
||||||
|
includes: # Optional. Only include some files. Only effected when path is a folder.
|
||||||
|
- data.db
|
||||||
|
- /path/to/data.db
|
||||||
|
- type: wildcards
|
||||||
|
rule: "*/*.db"
|
||||||
|
- type: regex
|
||||||
|
rule: "\\d+\\.db"
|
||||||
- type: leveldb # module plyvel is needed to support this type. This will store leveldb database to a single file database (sqlite3)
|
- type: leveldb # module plyvel is needed to support this type. This will store leveldb database to a single file database (sqlite3)
|
||||||
path: leveldb # path to leveldb. Must be relative path.
|
path: leveldb # path to leveldb. Must be relative path.
|
||||||
name: dest # optional. path to the backup files. Shoule be a relative path
|
name: dest # optional. path to the backup files. Shoule be a relative path
|
||||||
|
|||||||
@@ -149,6 +149,20 @@ class BasicConfig:
|
|||||||
# pylint: enable=unsupported-membership-test, unsubscriptable-object
|
# pylint: enable=unsupported-membership-test, unsubscriptable-object
|
||||||
|
|
||||||
|
|
||||||
|
def parse_ex_or_in_cludes(li: list, enable_pcre2) -> List[Union[str, Regex]]:
|
||||||
|
r = []
|
||||||
|
for i in li:
|
||||||
|
if isinstance(i, str):
|
||||||
|
r.append(i)
|
||||||
|
elif isinstance(i, dict):
|
||||||
|
t = i['type']
|
||||||
|
if t == 'wildcards':
|
||||||
|
r.append(wildcards_to_regex(i['rule'], use_pcre2=enable_pcre2))
|
||||||
|
elif t == "regex":
|
||||||
|
r.append(Regex(i['rule'], use_pcre2=enable_pcre2))
|
||||||
|
return r
|
||||||
|
|
||||||
|
|
||||||
class ConfigPath(BasicOption, NFBasicOption, BasicConfig):
|
class ConfigPath(BasicOption, NFBasicOption, BasicConfig):
|
||||||
def __init__(self, data, cfg, prog):
|
def __init__(self, data, cfg, prog):
|
||||||
NFBasicOption.__init__(self, cfg, prog)
|
NFBasicOption.__init__(self, cfg, prog)
|
||||||
@@ -169,24 +183,26 @@ class ConfigPath(BasicOption, NFBasicOption, BasicConfig):
|
|||||||
del t
|
del t
|
||||||
if 'excludes' in self.data:
|
if 'excludes' in self.data:
|
||||||
if isinstance(self.data['excludes'], list):
|
if isinstance(self.data['excludes'], list):
|
||||||
r = []
|
r = parse_ex_or_in_cludes(self.data["excludes"], self.enable_pcre2) # noqa: E501
|
||||||
for i in self.data["excludes"]:
|
|
||||||
if isinstance(i, str):
|
|
||||||
r.append(i)
|
|
||||||
elif isinstance(i, dict):
|
|
||||||
t = i['type']
|
|
||||||
if t == 'wildcards':
|
|
||||||
r.append(wildcards_to_regex(i['rule'], use_pcre2=self.enable_pcre2)) # noqa: E501
|
|
||||||
elif t == "regex":
|
|
||||||
r.append(Regex(i['rule'],
|
|
||||||
use_pcre2=self.enable_pcre2))
|
|
||||||
self.__excludes = r
|
self.__excludes = r
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def is_exclude(self, b: str, loc: str) -> bool:
|
@property
|
||||||
e = self.excludes
|
def includes(self) -> List[Union[str, Regex]]:
|
||||||
|
t = getattr(self, "__includes", None)
|
||||||
|
if t is not None:
|
||||||
|
return t
|
||||||
|
del t
|
||||||
|
if 'includes' in self.data:
|
||||||
|
if isinstance(self.data['includes'], list):
|
||||||
|
r = parse_ex_or_in_cludes(self.data["includes"], self.enable_pcre2) # noqa: E501
|
||||||
|
self.__includes = r
|
||||||
|
return r
|
||||||
|
|
||||||
|
def is_ex_or_in_clude(self, b: str, loc: str, exclude: bool) -> bool:
|
||||||
|
e = self.excludes if exclude else self.includes
|
||||||
if e is None:
|
if e is None:
|
||||||
return False
|
return False if exclude else True
|
||||||
if isabs(loc):
|
if isabs(loc):
|
||||||
bl = abspath(loc)
|
bl = abspath(loc)
|
||||||
rl = relpath(loc, b)
|
rl = relpath(loc, b)
|
||||||
@@ -208,6 +224,12 @@ class ConfigPath(BasicOption, NFBasicOption, BasicConfig):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def is_exclude(self, b: str, loc: str) -> bool:
|
||||||
|
return self.is_ex_or_in_clude(b, loc, True)
|
||||||
|
|
||||||
|
def is_include(self, b: str, loc: str) -> bool:
|
||||||
|
return self.is_ex_or_in_clude(b, loc, False)
|
||||||
|
|
||||||
|
|
||||||
class ConfigOLeveldb(BasicOption, NFBasicOption, BasicConfig):
|
class ConfigOLeveldb(BasicOption, NFBasicOption, BasicConfig):
|
||||||
def __init__(self, data, cfg, prog):
|
def __init__(self, data, cfg, prog):
|
||||||
@@ -315,6 +337,8 @@ class Program(BasicOption, NFBasicOption):
|
|||||||
for ii in ll:
|
for ii in ll:
|
||||||
if i.is_exclude(bp, ii):
|
if i.is_exclude(bp, ii):
|
||||||
continue
|
continue
|
||||||
|
if not i.is_include(bp, ii):
|
||||||
|
continue
|
||||||
tname = relpath(join(b, join(name, relpath(ii, bp))), b) # noqa: E501
|
tname = relpath(join(b, join(name, relpath(ii, bp))), b) # noqa: E501
|
||||||
tmp = ConfigNormalFile(tname, ii)
|
tmp = ConfigNormalFile(tname, ii)
|
||||||
del tname
|
del tname
|
||||||
|
|||||||
Reference in New Issue
Block a user