aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Bachelier <laurent@bachelier.name>2011-10-25 23:33:32 +0200
committerLaurent Bachelier <laurent@bachelier.name>2011-10-25 23:33:32 +0200
commita090960af95d89022e5ada64fabca201fd6fcb63 (patch)
tree79db223ac5c101ef5c3f7fece1a86e4303274db1
parentPEP8 fixes (diff)
downloadconfman-a090960af95d89022e5ada64fabca201fd6fcb63.tar.xz
Print friendly message to help resolving conflicts
This happens often after updating portage for instance, symbolic links are replaced by files with the contents of the target. An evolution would be to automatically replace the file if the contents are the same.
-rw-r--r--confman.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/confman.py b/confman.py
index fc27c38..d6c8e5f 100644
--- a/confman.py
+++ b/confman.py
@@ -35,12 +35,16 @@ class ConfmanException(Exception):
class ActionException(ConfmanException):
- def __init__(self, action, value):
+ def __init__(self, action, value, resolve=None):
self.action = action
+ self.resolve = resolve
ConfmanException.__init__(self, value)
def __str__(self):
- return "%s (%s)" % (ConfmanException.__str__(self), repr(self.action))
+ s = "%s (%s)" % (ConfmanException.__str__(self), repr(self.action))
+ if self.resolve:
+ s += "\nResolve the issue with:\n%s" % self.resolve
+ return s
class Action(object):
@@ -97,8 +101,10 @@ class SymlinkAction(Action):
dest = self.dest_path()
if osp.lexists(dest):
if not osp.islink(dest):
+ resolve = "diff %s %s\nrm -vi %s" % (osp.abspath(source), osp.abspath(dest), osp.abspath(dest))
raise ActionException(self,
- "Destination exists and is not a link")
+ "Destination exists and is not a link",
+ resolve=resolve)
def sync(self):
source = self.source_path()