mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-10 03:24:17 +00:00
Merge branch 'master' of https://github.com/deadc0de6/dotdrop
This commit is contained in:
@@ -119,11 +119,20 @@ class Cfg:
|
||||
raise ValueError('config is not valid')
|
||||
|
||||
def eval_dotfiles(self, profile, debug=False):
|
||||
"""resolve dotfiles src/dst templating for this profile"""
|
||||
"""resolve dotfiles src/dst/actions templating for this profile"""
|
||||
t = Templategen(variables=self.get_variables(profile, debug=debug))
|
||||
for d in self.get_dotfiles(profile):
|
||||
# src and dst path
|
||||
d.src = t.generate_string(d.src)
|
||||
d.dst = t.generate_string(d.dst)
|
||||
# pre actions
|
||||
if self.key_actions_pre in d.actions:
|
||||
for action in d.actions[self.key_actions_pre]:
|
||||
action.action = t.generate_string(action.action)
|
||||
# post actions
|
||||
if self.key_actions_post in d.actions:
|
||||
for action in d.actions[self.key_actions_post]:
|
||||
action.action = t.generate_string(action.action)
|
||||
|
||||
def _load_file(self):
|
||||
"""load the yaml 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
|
||||
|
||||
@@ -332,7 +332,7 @@ def cmd_list_files(opts, conf, templateonly=False):
|
||||
if not Templategen.is_template(src):
|
||||
continue
|
||||
LOG.log('{} (src: \"{}\", link: {})'.format(dotfile.key, dotfile.src,
|
||||
dotfile.link))
|
||||
dotfile.link.name.lower()))
|
||||
LOG.sub('{}'.format(dotfile.dst))
|
||||
LOG.log('')
|
||||
|
||||
@@ -360,7 +360,7 @@ def cmd_detail(opts, conf, keys=None):
|
||||
def _detail(dotpath, dotfile):
|
||||
"""print details on all files under a dotfile entry"""
|
||||
LOG.log('{} (dst: \"{}\", link: {})'.format(dotfile.key, dotfile.dst,
|
||||
dotfile.link))
|
||||
dotfile.link.name.lower()))
|
||||
path = os.path.join(dotpath, os.path.expanduser(dotfile.src))
|
||||
if not os.path.isdir(path):
|
||||
template = 'no'
|
||||
|
||||
@@ -37,7 +37,7 @@ class Dotfile:
|
||||
|
||||
def __str__(self):
|
||||
msg = 'key:\"{}\", src:\"{}\", dst:\"{}\", link:\"{}\"'
|
||||
return msg.format(self.key, self.src, self.dst, self.link.name)
|
||||
return msg.format(self.key, self.src, self.dst, self.link.name.lower())
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
@@ -64,7 +64,8 @@ class Installer:
|
||||
if self.debug:
|
||||
self.log.dbg('link {} to {}'.format(src, dst))
|
||||
self.action_executed = False
|
||||
src = os.path.join(self.base, os.path.expanduser(src))
|
||||
src = os.path.normpath(os.path.join(self.base,
|
||||
os.path.expanduser(src)))
|
||||
if not os.path.exists(src):
|
||||
self.log.err('source dotfile does not exist: {}'.format(src))
|
||||
return []
|
||||
@@ -124,8 +125,10 @@ class Installer:
|
||||
os.mkdir(dst)
|
||||
|
||||
children = os.listdir(parent)
|
||||
srcs = [os.path.join(parent, child) for child in children]
|
||||
dsts = [os.path.join(dst, child) for child in children]
|
||||
srcs = [os.path.normpath(os.path.join(parent, child))
|
||||
for child in children]
|
||||
dsts = [os.path.normpath(os.path.join(dst, child))
|
||||
for child in children]
|
||||
|
||||
for i in range(len(children)):
|
||||
src = srcs[i]
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user