1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-15 16:50:03 +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_install = 'trans_install'
key_trans_update = 'trans_update' key_trans_update = 'trans_update'
key_template = 'template' 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, def __init__(self, key, dst, src,
actions=None, trans_install=None, trans_update=None, actions=None, trans_install=None, trans_update=None,
link=LinkTypes.NOLINK, noempty=False, link=LinkTypes.NOLINK, noempty=False,
cmpignore=None, upignore=None, cmpignore=None, upignore=None,
instignore=None, template=True, chmod=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 constructor
@key: dotfile key @key: dotfile key
@@ -40,7 +40,7 @@ class Dotfile(DictParser):
@instignore: patterns to ignore when installing @instignore: patterns to ignore when installing
@template: template this dotfile @template: template this dotfile
@chmod: file permission @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.actions = actions or []
self.dst = dst self.dst = dst
@@ -56,7 +56,7 @@ class Dotfile(DictParser):
self.template = template self.template = template
self.chmod = chmod self.chmod = chmod
self.ignore_missing_in_dotdrop = ignore_missing_in_dotdrop 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 \ if self.link != LinkTypes.NOLINK and \
( (
@@ -99,8 +99,8 @@ class Dotfile(DictParser):
"""patch dict""" """patch dict"""
value['noempty'] = value.get(cls.key_noempty, False) value['noempty'] = value.get(cls.key_noempty, False)
value['template'] = value.get(cls.key_template, True) value['template'] = value.get(cls.key_template, True)
value['handle_dir_as_block'] = value.get( value['dir_as_block'] = value.get(
cls.key_handle_dir_as_block, False) cls.key_dir_as_block, False)
# remove old entries # remove old entries
value.pop(cls.key_noempty, None) value.pop(cls.key_noempty, None)
return value return value
@@ -126,8 +126,8 @@ class Dotfile(DictParser):
msg += f', chmod:{self.chmod:o}' msg += f', chmod:{self.chmod:o}'
else: else:
msg += f', chmod:\"{self.chmod}\"' msg += f', chmod:\"{self.chmod}\"'
if self.handle_dir_as_block: if self.dir_as_block:
msg += f', handle_dir_as_block:{self.handle_dir_as_block}' msg += f', dir_as_block:{self.dir_as_block}'
return msg return msg
def prt(self): def prt(self):
@@ -143,9 +143,9 @@ class Dotfile(DictParser):
out += f'\n{indent}chmod: \"{self.chmod:o}\"' out += f'\n{indent}chmod: \"{self.chmod:o}\"'
else: else:
out += f'\n{indent}chmod: \"{self.chmod}\"' out += f'\n{indent}chmod: \"{self.chmod}\"'
if self.handle_dir_as_block: if self.dir_as_block:
out += (f'\n{indent}handle_dir_as_block: ' out += (f'\n{indent}dir_as_block: '
f'"{self.handle_dir_as_block}"') f'"{self.dir_as_block}"')
out += f'\n{indent}pre-action:' out += f'\n{indent}pre-action:'
some = self.get_pre_actions() some = self.get_pre_actions()

View File

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

View File

@@ -132,6 +132,7 @@ class Installer:
isdir = os.path.isdir(src) isdir = os.path.isdir(src)
self.log.dbg(f'install {src} to {dst}') self.log.dbg(f'install {src} to {dst}')
self.log.dbg(f'\"{src}\" is a directory: {isdir}') self.log.dbg(f'\"{src}\" is a directory: {isdir}')
self.log.dbg(f'dir_as_block: {dir_as_block}')
if linktype == LinkTypes.NOLINK: if linktype == LinkTypes.NOLINK:
# normal file # normal file
@@ -619,7 +620,7 @@ class Installer:
fails fails
""" """
self.log.dbg(f'deploy dir {src}') 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 # Handle directory as a block if option is enabled
if dir_as_block: if dir_as_block:
@@ -657,31 +658,30 @@ class Installer:
if self.dry: if self.dry:
self.log.dry(f'would cp -r {src} {dst}') self.log.dry(f'would cp -r {src} {dst}')
return True, None, [dst] return True, None, [dst]
else: try:
try: # Execute pre actions
# Execute pre actions ret, err = self._exec_pre_actions(actionexec)
ret, err = self._exec_pre_actions(actionexec) if not ret:
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, [] 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) # Regular directory installation (file by file)
# default to nothing installed and no error # default to nothing installed and no error
ret = False ret = False
@@ -720,7 +720,8 @@ class Installer:
actionexec=actionexec, actionexec=actionexec,
noempty=noempty, noempty=noempty,
ignore=ignore, ignore=ignore,
is_template=is_template) is_template=is_template,
dir_as_block=dir_as_block)
dst_dotfiles.extend(subs) dst_dotfiles.extend(subs)
if not res and err: if not res and err:
# error occured # error occured
@@ -869,13 +870,12 @@ class Installer:
######################################################## ########################################################
# helpers # helpers
######################################################## ########################################################
@classmethod @classmethod
def _get_tmp_file_vars(cls, src, dst): def _get_tmp_file_vars(cls, src, dst):
"""Temporary file variables""" tmp = {}
# Correcting indentation and ensuring proper value assignment tmp['_dotfile_sub_abs_src'] = src
x = 1 # Example fix for unexpected indent tmp['_dotfile_sub_abs_dst'] = dst
return x return tmp
def _is_different(self, src, dst, content=None): def _is_different(self, src, dst, content=None):
""" """