1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-04 18:34:48 +00:00

add regex

This commit is contained in:
user
2025-05-19 22:00:43 +02:00
parent cc1ef5c001
commit fc96a94613
3 changed files with 28 additions and 14 deletions

View File

@@ -24,7 +24,7 @@ class Dotfile(DictParser):
link=LinkTypes.NOLINK, noempty=False,
cmpignore=None, upignore=None,
instignore=None, template=True, chmod=None,
ignore_missing_in_dotdrop=False, dir_as_block=False):
ignore_missing_in_dotdrop=False, dir_as_block=None):
"""
constructor
@key: dotfile key
@@ -56,7 +56,7 @@ class Dotfile(DictParser):
self.template = template
self.chmod = chmod
self.ignore_missing_in_dotdrop = ignore_missing_in_dotdrop
self.dir_as_block = dir_as_block
self.dir_as_block = dir_as_block or []
if self.link != LinkTypes.NOLINK and \
(
@@ -100,7 +100,7 @@ class Dotfile(DictParser):
value['noempty'] = value.get(cls.key_noempty, False)
value['template'] = value.get(cls.key_template, True)
value['dir_as_block'] = value.get(
cls.key_dir_as_block, False)
cls.key_dir_as_block, [])
# remove old entries
value.pop(cls.key_noempty, None)
return value

View File

@@ -18,12 +18,11 @@ class FTreeDir:
directory tree for comparison
"""
def __init__(self, path, ignores=None,
debug=False, dir_as_block=False):
def __init__(self, path, ignores=None, debug=False, dir_as_block=None):
self.path = path
self.ignores = ignores
self.debug = debug
self.dir_as_block = dir_as_block
self.dir_as_block = dir_as_block or []
self.entries = []
self.log = Logger(debug=self.debug)
if os.path.exists(path) and os.path.isdir(path):
@@ -35,13 +34,12 @@ class FTreeDir:
ignore empty directory
test for ignore pattern
"""
# if directory should be handled as a block
# just add the directory itself
if self.dir_as_block:
self.log.dbg(
f'handle as block: {self.path}')
self.entries.append(self.path)
return
import fnmatch
for pattern in self.dir_as_block:
if fnmatch.fnmatch(self.path, pattern):
self.log.dbg(f'dir_as_block match: {pattern} for {self.path}')
self.entries.append(self.path)
return
for root, dirs, files in os.walk(self.path, followlinks=True):
for file in files:

View File

@@ -79,7 +79,7 @@ class Installer:
def install(self, templater, src, dst, linktype,
actionexec=None, noempty=False,
ignore=None, is_template=True,
chmod=None, dir_as_block=False):
chmod=None, dir_as_block=None):
"""
install src to dst
@@ -99,6 +99,7 @@ class Installer:
- False, error_msg : error
- False, None : ignored
"""
dir_as_block = dir_as_block or []
if not src or not dst:
# fake dotfile
self.log.dbg('fake dotfile installed')
@@ -134,6 +135,21 @@ class Installer:
self.log.dbg(f'\"{src}\" is a directory: {isdir}')
self.log.dbg(f'dir_as_block: {dir_as_block}')
import fnmatch
treat_as_block = any(fnmatch.fnmatch(src, pattern) for pattern in dir_as_block)
self.log.dbg(f'dir_as_block patterns: {dir_as_block}, treat_as_block: {treat_as_block}')
if treat_as_block:
self.log.dbg(f'handling directory {src} as a block for installation')
ret, err, ins = self._copy_dir(templater, src, dst,
actionexec=actionexec,
noempty=noempty, ignore=ignore,
is_template=is_template,
chmod=chmod,
dir_as_block=True)
if self.remove_existing_in_dir and ins:
self._remove_existing_in_dir(dst, ins)
return self._log_install(ret, err)
if linktype == LinkTypes.NOLINK:
# normal file
if isdir: