1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-05 10:18:49 +00:00

Changed string formatting, raise OSError instead of Exception, and catch it in link to skip the current dotfile

This commit is contained in:
moyiz
2017-05-05 16:33:55 +03:00
parent 6c6ce18d50
commit 6a178d746d
2 changed files with 14 additions and 11 deletions

View File

@@ -38,20 +38,23 @@ class Installer:
dst = os.path.join(self.base, os.path.expanduser(dst))
if os.path.exists(dst):
if os.path.realpath(dst) == os.path.realpath(src):
self.log.sub('ignoring "{}", link exists'.format(dst))
self.log.sub('ignoring "%s", link exists' % dst)
return []
if self.dry:
self.log.dry('would remove {} and link it to {}'
.format(dst, src))
self.log.dry('would remove %s and link it to %s'\
% (dst, src))
return []
if self.safe and not self.log.ask('Remove "{}" for link creation?'
.format(dst)):
self.log.warn('ignoring "{}", link was not created'
.format(dst))
if self.safe and \
not self.log.ask('Remove "%s" for link creation?' % dst):
self.log.warn('ignoring "%s", link was not created' % dst)
return []
try:
utils.remove(dst)
except OSError:
self.log.err('something went wrong with %s' % src)
return []
utils.remove(dst)
if self.dry:
self.log.dry('would link {} to {}'.format(dst, src))
self.log.dry('would link %s to %s' % (dst, src))
return []
os.symlink(src, dst)
self.log.sub('linked %s to %s' % (dst, src))

View File

@@ -37,10 +37,10 @@ def get_tmpdir():
def remove(path):
''' Remove a file / directory / symlink '''
if not os.path.exists(path):
raise Exception("ERROR in remove: File not found: {}".format(path))
raise OSError("File not found: %s" % path)
if os.path.islink(path) or os.path.isfile(path):
os.unlink(path)
elif os.path.isdir(path):
rmtree(path)
else:
raise Exception("Unsupported file type for deletion: {}".format(path))
raise OSError("Unsupported file type for deletion: %s" % path)