1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-05 13:13:49 +00:00
This commit is contained in:
user
2025-05-19 21:53:29 +02:00
parent 00218887ae
commit 0513cba551
3 changed files with 44 additions and 44 deletions

View File

@@ -17,14 +17,14 @@ class Dotfile(DictParser):
key_trans_install = 'trans_install'
key_trans_update = 'trans_update'
key_template = 'template'
key_handle_dir_as_block = 'handle_dir_as_block'
key_dir_as_block = 'dir_as_block'
def __init__(self, key, dst, src,
actions=None, trans_install=None, trans_update=None,
link=LinkTypes.NOLINK, noempty=False,
cmpignore=None, upignore=None,
instignore=None, template=True, chmod=None,
ignore_missing_in_dotdrop=False, handle_dir_as_block=False):
ignore_missing_in_dotdrop=False, dir_as_block=False):
"""
constructor
@key: dotfile key
@@ -40,7 +40,7 @@ class Dotfile(DictParser):
@instignore: patterns to ignore when installing
@template: template this dotfile
@chmod: file permission
@handle_dir_as_block: handle directory as a single block
@dir_as_block: handle directory as a single block
"""
self.actions = actions or []
self.dst = dst
@@ -56,7 +56,7 @@ class Dotfile(DictParser):
self.template = template
self.chmod = chmod
self.ignore_missing_in_dotdrop = ignore_missing_in_dotdrop
self.handle_dir_as_block = handle_dir_as_block
self.dir_as_block = dir_as_block
if self.link != LinkTypes.NOLINK and \
(
@@ -99,8 +99,8 @@ class Dotfile(DictParser):
"""patch dict"""
value['noempty'] = value.get(cls.key_noempty, False)
value['template'] = value.get(cls.key_template, True)
value['handle_dir_as_block'] = value.get(
cls.key_handle_dir_as_block, False)
value['dir_as_block'] = value.get(
cls.key_dir_as_block, False)
# remove old entries
value.pop(cls.key_noempty, None)
return value
@@ -126,8 +126,8 @@ class Dotfile(DictParser):
msg += f', chmod:{self.chmod:o}'
else:
msg += f', chmod:\"{self.chmod}\"'
if self.handle_dir_as_block:
msg += f', handle_dir_as_block:{self.handle_dir_as_block}'
if self.dir_as_block:
msg += f', dir_as_block:{self.dir_as_block}'
return msg
def prt(self):
@@ -143,9 +143,9 @@ class Dotfile(DictParser):
out += f'\n{indent}chmod: \"{self.chmod:o}\"'
else:
out += f'\n{indent}chmod: \"{self.chmod}\"'
if self.handle_dir_as_block:
out += (f'\n{indent}handle_dir_as_block: '
f'"{self.handle_dir_as_block}"')
if self.dir_as_block:
out += (f'\n{indent}dir_as_block: '
f'"{self.dir_as_block}"')
out += f'\n{indent}pre-action:'
some = self.get_pre_actions()

View File

@@ -19,11 +19,11 @@ class FTreeDir:
"""
def __init__(self, path, ignores=None,
debug=False, handle_dir_as_block=False):
debug=False, dir_as_block=False):
self.path = path
self.ignores = ignores
self.debug = debug
self.handle_dir_as_block = handle_dir_as_block
self.dir_as_block = dir_as_block
self.entries = []
self.log = Logger(debug=self.debug)
if os.path.exists(path) and os.path.isdir(path):
@@ -37,7 +37,7 @@ class FTreeDir:
"""
# if directory should be handled as a block
# just add the directory itself
if self.handle_dir_as_block:
if self.dir_as_block:
self.log.dbg(
f'handle as block: {self.path}')
self.entries.append(self.path)

View File

@@ -132,6 +132,7 @@ class Installer:
isdir = os.path.isdir(src)
self.log.dbg(f'install {src} to {dst}')
self.log.dbg(f'\"{src}\" is a directory: {isdir}')
self.log.dbg(f'dir_as_block: {dir_as_block}')
if linktype == LinkTypes.NOLINK:
# normal file
@@ -619,7 +620,7 @@ class Installer:
fails
"""
self.log.dbg(f'deploy dir {src}')
self.log.dbg(f'handle_dir_as_block: {dir_as_block}')
self.log.dbg(f'dir_as_block: {dir_as_block}')
# Handle directory as a block if option is enabled
if dir_as_block:
@@ -657,31 +658,30 @@ class Installer:
if self.dry:
self.log.dry(f'would cp -r {src} {dst}')
return True, None, [dst]
else:
try:
# Execute pre actions
ret, err = self._exec_pre_actions(actionexec)
if not ret:
return False, err, []
# Copy the directory as a whole
shutil.copytree(src, dst)
# Record all files that were installed
for root, _, files in os.walk(dst):
for file in files:
path = os.path.join(root, file)
dst_dotfiles.append(path)
if not self.comparing:
self.log.sub(
f'installed directory {src} to {dst} as a block')
return True, None, dst_dotfiles
except (shutil.Error, OSError) as exc:
err = f'{src} installation failed: {exc}'
self.log.warn(err)
try:
# Execute pre actions
ret, err = self._exec_pre_actions(actionexec)
if not ret:
return False, err, []
# Copy the directory as a whole
shutil.copytree(src, dst)
# Record all files that were installed
for root, _, files in os.walk(dst):
for file in files:
path = os.path.join(root, file)
dst_dotfiles.append(path)
if not self.comparing:
self.log.sub(
f'installed directory {src} to {dst} as a block')
return True, None, dst_dotfiles
except (shutil.Error, OSError) as exc:
err = f'{src} installation failed: {exc}'
self.log.warn(err)
return False, err, []
# Regular directory installation (file by file)
# default to nothing installed and no error
ret = False
@@ -720,7 +720,8 @@ class Installer:
actionexec=actionexec,
noempty=noempty,
ignore=ignore,
is_template=is_template)
is_template=is_template,
dir_as_block=dir_as_block)
dst_dotfiles.extend(subs)
if not res and err:
# error occured
@@ -869,13 +870,12 @@ class Installer:
########################################################
# helpers
########################################################
@classmethod
def _get_tmp_file_vars(cls, src, dst):
"""Temporary file variables"""
# Correcting indentation and ensuring proper value assignment
x = 1 # Example fix for unexpected indent
return x
tmp = {}
tmp['_dotfile_sub_abs_src'] = src
tmp['_dotfile_sub_abs_dst'] = dst
return tmp
def _is_different(self, src, dst, content=None):
"""