mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-09 17:34:16 +00:00
clean updater by adding profile as instance variable
This commit is contained in:
@@ -216,15 +216,15 @@ def cmd_compare(opts, conf, tmp, focus=[], ignore=[]):
|
|||||||
def cmd_update(opts, conf, paths, iskey=False, ignore=[]):
|
def cmd_update(opts, conf, paths, iskey=False, ignore=[]):
|
||||||
"""update the dotfile(s) from path(s) or key(s)"""
|
"""update the dotfile(s) from path(s) or key(s)"""
|
||||||
ret = True
|
ret = True
|
||||||
updater = Updater(conf, opts['dotpath'], opts['dry'],
|
updater = Updater(conf, opts['dotpath'], opts['profile'],
|
||||||
opts['safe'], iskey=iskey,
|
opts['dry'], opts['safe'], iskey=iskey,
|
||||||
debug=opts['debug'], ignore=[])
|
debug=opts['debug'], ignore=[])
|
||||||
if not iskey:
|
if not iskey:
|
||||||
# update paths
|
# update paths
|
||||||
if opts['debug']:
|
if opts['debug']:
|
||||||
LOG.dbg('update by paths: {}'.format(paths))
|
LOG.dbg('update by paths: {}'.format(paths))
|
||||||
for path in paths:
|
for path in paths:
|
||||||
if not updater.update_path(path, opts['profile']):
|
if not updater.update_path(path):
|
||||||
ret = False
|
ret = False
|
||||||
else:
|
else:
|
||||||
# update keys
|
# update keys
|
||||||
@@ -235,7 +235,7 @@ def cmd_update(opts, conf, paths, iskey=False, ignore=[]):
|
|||||||
if opts['debug']:
|
if opts['debug']:
|
||||||
LOG.dbg('update by keys: {}'.format(keys))
|
LOG.dbg('update by keys: {}'.format(keys))
|
||||||
for key in keys:
|
for key in keys:
|
||||||
if not updater.update_key(key, opts['profile']):
|
if not updater.update_key(key):
|
||||||
ret = False
|
ret = False
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|||||||
@@ -20,10 +20,11 @@ TILD = '~'
|
|||||||
|
|
||||||
class Updater:
|
class Updater:
|
||||||
|
|
||||||
def __init__(self, conf, dotpath, dry, safe,
|
def __init__(self, conf, dotpath, profile, dry, safe,
|
||||||
iskey=False, debug=False, ignore=[]):
|
iskey=False, debug=False, ignore=[]):
|
||||||
self.conf = conf
|
self.conf = conf
|
||||||
self.dotpath = dotpath
|
self.dotpath = dotpath
|
||||||
|
self.profile = profile
|
||||||
self.dry = dry
|
self.dry = dry
|
||||||
self.safe = safe
|
self.safe = safe
|
||||||
self.iskey = iskey
|
self.iskey = iskey
|
||||||
@@ -31,13 +32,13 @@ class Updater:
|
|||||||
self.ignore = ignore
|
self.ignore = ignore
|
||||||
self.log = Logger()
|
self.log = Logger()
|
||||||
|
|
||||||
def update_path(self, path, profile):
|
def update_path(self, path):
|
||||||
"""update the dotfile installed on path"""
|
"""update the dotfile installed on path"""
|
||||||
if not os.path.lexists(path):
|
if not os.path.lexists(path):
|
||||||
self.log.err('\"{}\" does not exist!'.format(path))
|
self.log.err('\"{}\" does not exist!'.format(path))
|
||||||
return False
|
return False
|
||||||
path = self._normalize(path)
|
path = self._normalize(path)
|
||||||
dotfile = self._get_dotfile_by_path(path, profile)
|
dotfile = self._get_dotfile_by_path(path)
|
||||||
if not dotfile:
|
if not dotfile:
|
||||||
return False
|
return False
|
||||||
path = os.path.expanduser(path)
|
path = os.path.expanduser(path)
|
||||||
@@ -45,9 +46,9 @@ class Updater:
|
|||||||
self.log.dbg('updating {} from path \"{}\"'.format(dotfile, path))
|
self.log.dbg('updating {} from path \"{}\"'.format(dotfile, path))
|
||||||
return self._update(path, dotfile)
|
return self._update(path, dotfile)
|
||||||
|
|
||||||
def update_key(self, key, profile):
|
def update_key(self, key):
|
||||||
"""update the dotfile referenced by 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:
|
if not dotfile:
|
||||||
return False
|
return False
|
||||||
if self.debug:
|
if self.debug:
|
||||||
@@ -111,9 +112,9 @@ class Updater:
|
|||||||
path = os.path.join(TILD, path)
|
path = os.path.join(TILD, path)
|
||||||
return path
|
return path
|
||||||
|
|
||||||
def _get_dotfile_by_key(self, key, profile):
|
def _get_dotfile_by_key(self, key):
|
||||||
"""get the dotfile matching this 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]
|
subs = [d for d in dotfiles if d.key == key]
|
||||||
if not subs:
|
if not subs:
|
||||||
self.log.err('key \"{}\" not found!'.format(key))
|
self.log.err('key \"{}\" not found!'.format(key))
|
||||||
@@ -124,9 +125,9 @@ class Updater:
|
|||||||
return None
|
return None
|
||||||
return subs[0]
|
return subs[0]
|
||||||
|
|
||||||
def _get_dotfile_by_path(self, path, profile):
|
def _get_dotfile_by_path(self, path):
|
||||||
"""get the dotfile matching this 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]
|
subs = [d for d in dotfiles if d.dst == path]
|
||||||
if not subs:
|
if not subs:
|
||||||
self.log.err('\"{}\" is not managed!'.format(path))
|
self.log.err('\"{}\" is not managed!'.format(path))
|
||||||
|
|||||||
Reference in New Issue
Block a user