1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-04 19:09:44 +00:00

fix update usage (adding profile switch)

This commit is contained in:
deadc0de6
2018-10-08 18:03:39 +02:00
parent bad483935b
commit c0cb08c226
2 changed files with 22 additions and 22 deletions

View File

@@ -46,7 +46,7 @@ Usage:
dotdrop import [-ldVb] [-c <path>] [-p <profile>] <paths>...
dotdrop compare [-Vb] [-c <path>] [-p <profile>]
[-o <opts>] [-C <file>...] [-i <pattern>...]
dotdrop update [-fdVb] [-c <path>] <paths>...
dotdrop update [-fdVb] [-c <path>] [-p <profile>] <paths>...
dotdrop listfiles [-VTb] [-c <path>] [-p <profile>]
dotdrop list [-Vb] [-c <path>]
dotdrop --help

View File

@@ -28,6 +28,27 @@ class Updater:
self.debug = debug
self.log = Logger()
def update(self, path, profile):
"""update the dotfile installed on path"""
if not os.path.lexists(path):
self.log.err('\"{}\" does not exist!'.format(path))
return False
left = self._normalize(path)
dotfile = self._get_dotfile(left, profile)
if not dotfile:
return False
if self.debug:
self.log.dbg('updating {} from {}'.format(dotfile, path))
right = os.path.join(self.conf.abs_dotpath(self.dotpath), dotfile.src)
# expands user
left = os.path.expanduser(left)
right = os.path.expanduser(right)
# go through all files and update
if os.path.isdir(path):
return self._handle_dir(left, right)
return self._handle_file(left, right)
def _normalize(self, path):
"""normalize the path to match dotfile"""
path = os.path.expanduser(path)
@@ -52,27 +73,6 @@ class Updater:
return None
return subs[0]
def update(self, path, profile):
"""update the dotfile installed on path"""
if not os.path.lexists(path):
self.log.err('\"{}\" does not exist!'.format(path))
return False
left = self._normalize(path)
dotfile = self._get_dotfile(left, profile)
if not dotfile:
return False
if self.debug:
self.log.dbg('updating {} from {}'.format(dotfile, path))
right = os.path.join(self.conf.abs_dotpath(self.dotpath), dotfile.src)
# expands user
left = os.path.expanduser(left)
right = os.path.expanduser(right)
# go through all files and update
if os.path.isdir(path):
return self._handle_dir(left, right)
return self._handle_file(left, right)
def _is_template(self, path):
if not Templategen.is_template(path):
return False