mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-12 08:23:29 +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:
@@ -38,20 +38,23 @@ class Installer:
|
|||||||
dst = os.path.join(self.base, os.path.expanduser(dst))
|
dst = os.path.join(self.base, os.path.expanduser(dst))
|
||||||
if os.path.exists(dst):
|
if os.path.exists(dst):
|
||||||
if os.path.realpath(dst) == os.path.realpath(src):
|
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 []
|
return []
|
||||||
if self.dry:
|
if self.dry:
|
||||||
self.log.dry('would remove {} and link it to {}'
|
self.log.dry('would remove %s and link it to %s'\
|
||||||
.format(dst, src))
|
% (dst, src))
|
||||||
return []
|
return []
|
||||||
if self.safe and not self.log.ask('Remove "{}" for link creation?'
|
if self.safe and \
|
||||||
.format(dst)):
|
not self.log.ask('Remove "%s" for link creation?' % dst):
|
||||||
self.log.warn('ignoring "{}", link was not created'
|
self.log.warn('ignoring "%s", link was not created' % dst)
|
||||||
.format(dst))
|
return []
|
||||||
|
try:
|
||||||
|
utils.remove(dst)
|
||||||
|
except OSError:
|
||||||
|
self.log.err('something went wrong with %s' % src)
|
||||||
return []
|
return []
|
||||||
utils.remove(dst)
|
|
||||||
if self.dry:
|
if self.dry:
|
||||||
self.log.dry('would link {} to {}'.format(dst, src))
|
self.log.dry('would link %s to %s' % (dst, src))
|
||||||
return []
|
return []
|
||||||
os.symlink(src, dst)
|
os.symlink(src, dst)
|
||||||
self.log.sub('linked %s to %s' % (dst, src))
|
self.log.sub('linked %s to %s' % (dst, src))
|
||||||
|
|||||||
@@ -37,10 +37,10 @@ def get_tmpdir():
|
|||||||
def remove(path):
|
def remove(path):
|
||||||
''' Remove a file / directory / symlink '''
|
''' Remove a file / directory / symlink '''
|
||||||
if not os.path.exists(path):
|
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):
|
if os.path.islink(path) or os.path.isfile(path):
|
||||||
os.unlink(path)
|
os.unlink(path)
|
||||||
elif os.path.isdir(path):
|
elif os.path.isdir(path):
|
||||||
rmtree(path)
|
rmtree(path)
|
||||||
else:
|
else:
|
||||||
raise Exception("Unsupported file type for deletion: {}".format(path))
|
raise OSError("Unsupported file type for deletion: %s" % path)
|
||||||
|
|||||||
Reference in New Issue
Block a user