From 6b324328b6bdcd046751a213d044fa5d8beb81cb Mon Sep 17 00:00:00 2001 From: Ivan Brkanac Date: Fri, 10 Feb 2017 14:18:33 +0100 Subject: [PATCH] Start from previous work by ibeex on #90 For ibeex's original code see: https://github.com/anishathalye/dotbot/issues/90#issuecomment-279323350 --- dotbot/plugins/link.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/dotbot/plugins/link.py b/dotbot/plugins/link.py index 152fd91..a0109d7 100644 --- a/dotbot/plugins/link.py +++ b/dotbot/plugins/link.py @@ -2,6 +2,7 @@ import glob import os import shutil import sys +import errno from ..plugin import Plugin from ..util import shell_command @@ -120,6 +121,28 @@ class Link(Plugin): self._log.debug("Test '%s' returned false" % command) return ret == 0 + def _move(self, link_name, path): + success = True + source = os.path.expanduser(link_name) + destination = os.path.join(self._context.base_directory(), path) + if os.path.isdir(source): + shutil.copytree(source, destination) + shutil.rmtree(source, ignore_errors=True) + elif os.path.isfile(source): + try: + os.makedirs(os.path.split(destination)[0]) + except OSError as exception: + if exception.errno != errno.EEXIST: + success = False + # TODO: check what is eerno.EEXIST and replace above with pass if relevant + shutil.copy(source, destination) + os.unlink(source) + else: + self._log.warning("Config file missing %s" % source) + return False + self._log.info("Moved existing config %s" % source) + return success + def _default_source(self, destination, source): if source is None: basename = os.path.basename(destination)