From 6a178d746d15df29bfd81b762ab5664d470b527a Mon Sep 17 00:00:00 2001 From: moyiz Date: Fri, 5 May 2017 16:33:55 +0300 Subject: [PATCH] Changed string formatting, raise OSError instead of Exception, and catch it in link to skip the current dotfile --- dotdrop/installer.py | 21 ++++++++++++--------- dotdrop/utils.py | 4 ++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/dotdrop/installer.py b/dotdrop/installer.py index 35502ec..23a8dfb 100644 --- a/dotdrop/installer.py +++ b/dotdrop/installer.py @@ -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)) diff --git a/dotdrop/utils.py b/dotdrop/utils.py index 5d78efe..8c2f450 100644 --- a/dotdrop/utils.py +++ b/dotdrop/utils.py @@ -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)