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