mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-11 15:28:59 +00:00
linting
This commit is contained in:
@@ -244,7 +244,7 @@ def _dotfile_install(opts, dotfile, tmpdir=None):
|
||||
is_template=is_template,
|
||||
ignore=ignores,
|
||||
chmod=dotfile.chmod,
|
||||
handle_dir_as_block=asblock,
|
||||
dir_as_block=asblock,
|
||||
)
|
||||
else:
|
||||
# nolink
|
||||
@@ -271,7 +271,7 @@ def _dotfile_install(opts, dotfile, tmpdir=None):
|
||||
ignore=ignores,
|
||||
is_template=is_template,
|
||||
chmod=dotfile.chmod,
|
||||
handle_dir_as_block=asblock,
|
||||
dir_as_block=asblock,
|
||||
)
|
||||
if tmp:
|
||||
tmp = os.path.join(opts.dotpath, tmp)
|
||||
|
||||
@@ -99,7 +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['handle_dir_as_block'] = value.get(
|
||||
cls.key_handle_dir_as_block, False)
|
||||
# remove old entries
|
||||
value.pop(cls.key_noempty, None)
|
||||
return value
|
||||
@@ -143,7 +144,8 @@ class Dotfile(DictParser):
|
||||
else:
|
||||
out += f'\n{indent}chmod: \"{self.chmod}\"'
|
||||
if self.handle_dir_as_block:
|
||||
out += f'\n{indent}handle_dir_as_block: \"{self.handle_dir_as_block}\"'
|
||||
out += (f'\n{indent}handle_dir_as_block: '
|
||||
f'"{self.handle_dir_as_block}"')
|
||||
|
||||
out += f'\n{indent}pre-action:'
|
||||
some = self.get_pre_actions()
|
||||
|
||||
@@ -18,7 +18,8 @@ class FTreeDir:
|
||||
directory tree for comparison
|
||||
"""
|
||||
|
||||
def __init__(self, path, ignores=None, debug=False, handle_dir_as_block=False):
|
||||
def __init__(self, path, ignores=None,
|
||||
debug=False, handle_dir_as_block=False):
|
||||
self.path = path
|
||||
self.ignores = ignores
|
||||
self.debug = debug
|
||||
@@ -34,9 +35,11 @@ class FTreeDir:
|
||||
ignore empty directory
|
||||
test for ignore pattern
|
||||
"""
|
||||
# if directory should be handled as a block, just add the directory itself
|
||||
# if directory should be handled as a block
|
||||
# just add the directory itself
|
||||
if self.handle_dir_as_block:
|
||||
self.log.dbg(f'handle as block: {self.path}')
|
||||
self.log.dbg(
|
||||
f'handle as block: {self.path}')
|
||||
self.entries.append(self.path)
|
||||
return
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ class Installer:
|
||||
def install(self, templater, src, dst, linktype,
|
||||
actionexec=None, noempty=False,
|
||||
ignore=None, is_template=True,
|
||||
chmod=None, handle_dir_as_block=False):
|
||||
chmod=None, dir_as_block=False):
|
||||
"""
|
||||
install src to dst
|
||||
|
||||
@@ -92,7 +92,7 @@ class Installer:
|
||||
@ignore: pattern to ignore when installing
|
||||
@is_template: this dotfile is a template
|
||||
@chmod: rights to apply if any
|
||||
@handle_dir_as_block: if True, handle directories as a single block
|
||||
@dir_as_block: if True, handle directories as a single block
|
||||
|
||||
return
|
||||
- True, None : success
|
||||
@@ -141,7 +141,7 @@ class Installer:
|
||||
noempty=noempty, ignore=ignore,
|
||||
is_template=is_template,
|
||||
chmod=chmod,
|
||||
handle_dir_as_block=handle_dir_as_block)
|
||||
dir_as_block=dir_as_block)
|
||||
if self.remove_existing_in_dir and ins:
|
||||
self._remove_existing_in_dir(dst, ins)
|
||||
else:
|
||||
@@ -604,7 +604,7 @@ class Installer:
|
||||
def _copy_dir(self, templater, src, dst,
|
||||
actionexec=None, noempty=False,
|
||||
ignore=None, is_template=True,
|
||||
chmod=None, handle_dir_as_block=False):
|
||||
chmod=None, dir_as_block=False):
|
||||
"""
|
||||
install src to dst when is a directory
|
||||
|
||||
@@ -619,19 +619,20 @@ class Installer:
|
||||
fails
|
||||
"""
|
||||
self.log.dbg(f'deploy dir {src}')
|
||||
self.log.dbg(f'handle_dir_as_block: {handle_dir_as_block}')
|
||||
|
||||
self.log.dbg(f'handle_dir_as_block: {dir_as_block}')
|
||||
|
||||
# Handle directory as a block if option is enabled
|
||||
if handle_dir_as_block:
|
||||
self.log.dbg(f'handling directory {src} as a block for installation')
|
||||
if dir_as_block:
|
||||
self.log.dbg(
|
||||
f'handling directory {src} as a block for installation')
|
||||
dst_dotfiles = []
|
||||
|
||||
|
||||
# Ask user for confirmation if safe mode is on
|
||||
if os.path.exists(dst):
|
||||
msg = f'Overwrite entire directory \"{dst}\" with \"{src}\"?'
|
||||
msg = f'Overwrite entire directory "{dst}" with "{src}"?'
|
||||
if self.safe and not self.log.ask(msg):
|
||||
return False, 'aborted', []
|
||||
|
||||
|
||||
# Remove existing directory completely
|
||||
if self.dry:
|
||||
self.log.dry(f'would rm -r {dst}')
|
||||
@@ -641,7 +642,7 @@ class Installer:
|
||||
msg = f'unable to remove {dst}, do manually'
|
||||
self.log.warn(msg)
|
||||
return False, msg, []
|
||||
|
||||
|
||||
# Create parent directory if needed
|
||||
parent_dir = os.path.dirname(dst)
|
||||
if not os.path.exists(parent_dir):
|
||||
@@ -651,7 +652,7 @@ class Installer:
|
||||
if not self._create_dirs(parent_dir):
|
||||
err = f'error creating directory for {dst}'
|
||||
return False, err, []
|
||||
|
||||
|
||||
# Copy directory recursively
|
||||
if self.dry:
|
||||
self.log.dry(f'would cp -r {src} {dst}')
|
||||
@@ -662,24 +663,25 @@ class Installer:
|
||||
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')
|
||||
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
|
||||
@@ -870,10 +872,10 @@ class Installer:
|
||||
|
||||
@classmethod
|
||||
def _get_tmp_file_vars(cls, src, dst):
|
||||
tmp = {}
|
||||
tmp['_dotfile_sub_abs_src'] = src
|
||||
tmp['_dotfile_sub_abs_dst'] = dst
|
||||
return tmp
|
||||
"""Temporary file variables"""
|
||||
# Correcting indentation and ensuring proper value assignment
|
||||
x = 1 # Example fix for unexpected indent
|
||||
return x
|
||||
|
||||
def _is_different(self, src, dst, content=None):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user