1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-04 23:14:47 +00:00

refactoring

This commit is contained in:
deadc0de6
2020-11-06 09:03:51 +01:00
parent 204871e725
commit 358dbe7c3b
4 changed files with 16 additions and 16 deletions

View File

@@ -17,7 +17,7 @@ from dotdrop.templategen import Templategen
from dotdrop.installer import Installer
from dotdrop.updater import Updater
from dotdrop.comparator import Comparator
from dotdrop.utils import get_tmpdir, remove, strip_home, \
from dotdrop.utils import get_tmpdir, removepath, strip_home, \
uniq_list, patch_ignores, dependencies_met
from dotdrop.linktypes import LinkTypes
from dotdrop.exceptions import YamlException, UndefinedException
@@ -154,7 +154,7 @@ def cmd_install(o):
if tmp:
tmp = os.path.join(o.dotpath, tmp)
if os.path.exists(tmp):
remove(tmp, LOG)
removepath(tmp, LOG)
if r:
# dotfile was installed
if not o.install_temporary:
@@ -287,7 +287,7 @@ def cmd_compare(o, tmp):
if tmpsrc:
tmpsrc = os.path.join(o.dotpath, tmpsrc)
if os.path.exists(tmpsrc):
remove(tmpsrc, LOG)
removepath(tmpsrc, LOG)
if diff == '':
# no difference
@@ -597,7 +597,7 @@ def cmd_remove(o):
# remove dotfile from dotpath
dtpath = os.path.join(o.dotpath, dotfile.src)
remove(dtpath, LOG)
removepath(dtpath, LOG)
# remove empty directory
parent = os.path.dirname(dtpath)
# remove any empty parent up to dotpath
@@ -606,7 +606,7 @@ def cmd_remove(o):
msg = 'Remove empty dir \"{}\"'.format(parent)
if o.safe and not LOG.ask(msg):
break
remove(parent, LOG)
removepath(parent, LOG)
parent = os.path.dirname(parent)
removed.append(dotfile.key)
@@ -678,7 +678,7 @@ def apply_trans(dotpath, dotfile, templater, debug=False):
msg = 'transformation \"{}\" failed for {}'
LOG.err(msg.format(trans.key, dotfile.key))
if new_src and os.path.exists(new_src):
remove(new_src, LOG)
removepath(new_src, LOG)
return None
return new_src
@@ -737,7 +737,7 @@ def main():
tmp = get_tmpdir()
ret = cmd_compare(o, tmp)
# clean tmp directory
remove(tmp, LOG)
removepath(tmp, LOG)
elif o.cmd_import:
# import dotfile(s)

View File

@@ -281,7 +281,7 @@ class Installer:
return False, err
overwrite = True
try:
utils.remove(dst)
utils.removepath(dst)
except OSError as e:
err = 'something went wrong with {}: {}'.format(src, e)
return False, err
@@ -302,7 +302,7 @@ class Installer:
err = 'ignoring "{}", link was not created'.format(dst)
return False, err
try:
utils.remove(dst)
utils.removepath(dst)
except OSError as e:
err = 'something went wrong with {}: {}'.format(src, e)
return False, err
@@ -537,7 +537,7 @@ class Installer:
diff = utils.diff(modified=src, original=dst, raw=False,
diff_cmd=self.diff_cmd)
if tmp:
utils.remove(tmp, logger=self.log)
utils.removepath(tmp, logger=self.log)
if not quiet and diff:
self._print_diff(src, dst, diff)

View File

@@ -12,7 +12,7 @@ import filecmp
# local imports
from dotdrop.logger import Logger
from dotdrop.templategen import Templategen
from dotdrop.utils import patch_ignores, remove, get_unique_tmp_name, \
from dotdrop.utils import patch_ignores, removepath, get_unique_tmp_name, \
write_to_tmpfile, must_ignore, mirror_file_rights
from dotdrop.exceptions import UndefinedException
@@ -114,7 +114,7 @@ class Updater:
ret = self._handle_file(new_path, dtpath)
# clean temporary files
if new_path != path and os.path.exists(new_path):
remove(new_path, logger=self.log)
removepath(new_path, logger=self.log)
return ret
def _apply_trans_w(self, path, dotfile):
@@ -133,7 +133,7 @@ class Updater:
msg = 'transformation \"{}\" failed for {}'
self.log.err(msg.format(trans.key, dotfile.key))
if os.path.exists(tmp):
remove(tmp, logger=self.log)
removepath(tmp, logger=self.log)
return None
return tmp
@@ -273,7 +273,7 @@ class Updater:
self.log.dbg('rm -r {}'.format(old))
if not self._confirm_rm_r(old):
continue
remove(old, logger=self.log)
removepath(old, logger=self.log)
self.log.sub('\"{}\" dir removed'.format(old))
# handle files diff
@@ -326,7 +326,7 @@ class Updater:
continue
if self.debug:
self.log.dbg('rm {}'.format(new))
remove(new, logger=self.log)
removepath(new, logger=self.log)
self.log.sub('\"{}\" removed'.format(new))
# compare rights

View File

@@ -129,7 +129,7 @@ def get_unique_tmp_name():
return os.path.join(tmpdir, unique)
def remove(path, logger=None):
def removepath(path, logger=None):
"""
remove a file/directory/symlink
if logger is defined, OSError are catched