1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-04 17:24:46 +00:00

clean updater by adding profile as instance variable

This commit is contained in:
deadc0de6
2019-02-02 22:53:42 +01:00
parent c87539144f
commit c8d549d837
2 changed files with 14 additions and 13 deletions

View File

@@ -216,15 +216,15 @@ def cmd_compare(opts, conf, tmp, focus=[], ignore=[]):
def cmd_update(opts, conf, paths, iskey=False, ignore=[]):
"""update the dotfile(s) from path(s) or key(s)"""
ret = True
updater = Updater(conf, opts['dotpath'], opts['dry'],
opts['safe'], iskey=iskey,
updater = Updater(conf, opts['dotpath'], opts['profile'],
opts['dry'], opts['safe'], iskey=iskey,
debug=opts['debug'], ignore=[])
if not iskey:
# update paths
if opts['debug']:
LOG.dbg('update by paths: {}'.format(paths))
for path in paths:
if not updater.update_path(path, opts['profile']):
if not updater.update_path(path):
ret = False
else:
# update keys
@@ -235,7 +235,7 @@ def cmd_update(opts, conf, paths, iskey=False, ignore=[]):
if opts['debug']:
LOG.dbg('update by keys: {}'.format(keys))
for key in keys:
if not updater.update_key(key, opts['profile']):
if not updater.update_key(key):
ret = False
return ret

View File

@@ -20,10 +20,11 @@ TILD = '~'
class Updater:
def __init__(self, conf, dotpath, dry, safe,
def __init__(self, conf, dotpath, profile, dry, safe,
iskey=False, debug=False, ignore=[]):
self.conf = conf
self.dotpath = dotpath
self.profile = profile
self.dry = dry
self.safe = safe
self.iskey = iskey
@@ -31,13 +32,13 @@ class Updater:
self.ignore = ignore
self.log = Logger()
def update_path(self, path, profile):
def update_path(self, path):
"""update the dotfile installed on path"""
if not os.path.lexists(path):
self.log.err('\"{}\" does not exist!'.format(path))
return False
path = self._normalize(path)
dotfile = self._get_dotfile_by_path(path, profile)
dotfile = self._get_dotfile_by_path(path)
if not dotfile:
return False
path = os.path.expanduser(path)
@@ -45,9 +46,9 @@ class Updater:
self.log.dbg('updating {} from path \"{}\"'.format(dotfile, path))
return self._update(path, dotfile)
def update_key(self, key, profile):
def update_key(self, key):
"""update the dotfile referenced by key"""
dotfile = self._get_dotfile_by_key(key, profile)
dotfile = self._get_dotfile_by_key(key)
if not dotfile:
return False
if self.debug:
@@ -111,9 +112,9 @@ class Updater:
path = os.path.join(TILD, path)
return path
def _get_dotfile_by_key(self, key, profile):
def _get_dotfile_by_key(self, key):
"""get the dotfile matching this key"""
dotfiles = self.conf.get_dotfiles(profile)
dotfiles = self.conf.get_dotfiles(self.profile)
subs = [d for d in dotfiles if d.key == key]
if not subs:
self.log.err('key \"{}\" not found!'.format(key))
@@ -124,9 +125,9 @@ class Updater:
return None
return subs[0]
def _get_dotfile_by_path(self, path, profile):
def _get_dotfile_by_path(self, path):
"""get the dotfile matching this path"""
dotfiles = self.conf.get_dotfiles(profile)
dotfiles = self.conf.get_dotfiles(self.profile)
subs = [d for d in dotfiles if d.dst == path]
if not subs:
self.log.err('\"{}\" is not managed!'.format(path))