mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-09 06:34:16 +00:00
allow parallel update
This commit is contained in:
@@ -71,6 +71,16 @@ def action_executor(o, actions, defactions, templater, post=False):
|
|||||||
return execute
|
return execute
|
||||||
|
|
||||||
|
|
||||||
|
def _dotfile_update(o, path, key=False):
|
||||||
|
updater = Updater(o.dotpath, o.variables, o.conf,
|
||||||
|
dry=o.dry, safe=o.safe, debug=o.debug,
|
||||||
|
ignore=o.update_ignore,
|
||||||
|
showpatch=o.update_showpatch)
|
||||||
|
if key:
|
||||||
|
return updater.update_key(path)
|
||||||
|
return updater.update_path(path)
|
||||||
|
|
||||||
|
|
||||||
def _dotfile_install(o, dotfile, tmpdir=None):
|
def _dotfile_install(o, dotfile, tmpdir=None):
|
||||||
"""
|
"""
|
||||||
install a dotfile
|
install a dotfile
|
||||||
@@ -370,18 +380,19 @@ def cmd_compare(o, tmp):
|
|||||||
|
|
||||||
def cmd_update(o):
|
def cmd_update(o):
|
||||||
"""update the dotfile(s) from path(s) or key(s)"""
|
"""update the dotfile(s) from path(s) or key(s)"""
|
||||||
ret = True
|
|
||||||
cnt = 0
|
cnt = 0
|
||||||
paths = o.update_path
|
paths = o.update_path
|
||||||
iskey = o.update_iskey
|
iskey = o.update_iskey
|
||||||
ignore = o.update_ignore
|
|
||||||
showpatch = o.update_showpatch
|
|
||||||
|
|
||||||
if not paths:
|
if not paths:
|
||||||
# update the entire profile
|
# update the entire profile
|
||||||
if iskey:
|
if iskey:
|
||||||
|
if o.debug:
|
||||||
|
LOG.dbg('update by keys: {}'.format(paths))
|
||||||
paths = [d.key for d in o.dotfiles]
|
paths = [d.key for d in o.dotfiles]
|
||||||
else:
|
else:
|
||||||
|
if o.debug:
|
||||||
|
LOG.dbg('update by paths: {}'.format(paths))
|
||||||
paths = [d.dst for d in o.dotfiles]
|
paths = [d.dst for d in o.dotfiles]
|
||||||
msg = 'Update all dotfiles for profile \"{}\"'.format(o.profile)
|
msg = 'Update all dotfiles for profile \"{}\"'.format(o.profile)
|
||||||
if o.safe and not LOG.ask(msg):
|
if o.safe and not LOG.ask(msg):
|
||||||
@@ -391,37 +402,31 @@ def cmd_update(o):
|
|||||||
if not paths:
|
if not paths:
|
||||||
LOG.log('\nno dotfile to update')
|
LOG.log('\nno dotfile to update')
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if o.debug:
|
if o.debug:
|
||||||
LOG.dbg('dotfile to update: {}'.format(paths))
|
LOG.dbg('dotfile to update: {}'.format(paths))
|
||||||
|
|
||||||
updater = Updater(o.dotpath, o.variables, o.conf,
|
# update each dotfile
|
||||||
dry=o.dry, safe=o.safe, debug=o.debug,
|
if o.update_parallel > 1:
|
||||||
ignore=ignore, showpatch=showpatch)
|
# in parallel
|
||||||
cnt = 0
|
ex = futures.ThreadPoolExecutor(max_workers=o.update_parallel)
|
||||||
if not iskey:
|
|
||||||
# update paths
|
wait_for = []
|
||||||
if o.debug:
|
|
||||||
LOG.dbg('update by paths: {}'.format(paths))
|
|
||||||
for path in paths:
|
for path in paths:
|
||||||
if not updater.update_path(path):
|
j = ex.submit(_dotfile_update, o, path, key=iskey)
|
||||||
ret = False
|
wait_for.append(j)
|
||||||
else:
|
# check result
|
||||||
|
for f in futures.as_completed(wait_for):
|
||||||
|
if f.result():
|
||||||
cnt += 1
|
cnt += 1
|
||||||
else:
|
else:
|
||||||
# update keys
|
# sequentially
|
||||||
keys = paths
|
for path in paths:
|
||||||
if not keys:
|
if _dotfile_update(o, path, key=iskey):
|
||||||
# if not provided, take all keys
|
|
||||||
keys = [d.key for d in o.dotfiles]
|
|
||||||
if o.debug:
|
|
||||||
LOG.dbg('update by keys: {}'.format(keys))
|
|
||||||
for key in keys:
|
|
||||||
if not updater.update_key(key):
|
|
||||||
ret = False
|
|
||||||
else:
|
|
||||||
cnt += 1
|
cnt += 1
|
||||||
|
|
||||||
LOG.log('\n{} file(s) updated.'.format(cnt))
|
LOG.log('\n{} file(s) updated.'.format(cnt))
|
||||||
return ret
|
return cnt == len(paths)
|
||||||
|
|
||||||
|
|
||||||
def cmd_importer(o):
|
def cmd_importer(o):
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ Usage:
|
|||||||
dotdrop compare [-LVb] [-c <path>] [-p <profile>]
|
dotdrop compare [-LVb] [-c <path>] [-p <profile>]
|
||||||
[-C <file>...] [-i <pattern>...]
|
[-C <file>...] [-i <pattern>...]
|
||||||
dotdrop update [-VbfdkP] [-c <path>] [-p <profile>]
|
dotdrop update [-VbfdkP] [-c <path>] [-p <profile>]
|
||||||
[-i <pattern>...] [<path>...]
|
[-w <nb>] [-i <pattern>...] [<path>...]
|
||||||
dotdrop remove [-Vbfdk] [-c <path>] [-p <profile>] [<path>...]
|
dotdrop remove [-Vbfdk] [-c <path>] [-p <profile>] [<path>...]
|
||||||
dotdrop files [-VbTG] [-c <path>] [-p <profile>]
|
dotdrop files [-VbTG] [-c <path>] [-p <profile>]
|
||||||
dotdrop detail [-Vb] [-c <path>] [-p <profile>] [<key>...]
|
dotdrop detail [-Vb] [-c <path>] [-p <profile>] [<key>...]
|
||||||
@@ -277,6 +277,15 @@ class Options(AttrMonitor):
|
|||||||
self.update_ignore.append('*{}'.format(self.install_backup_suffix))
|
self.update_ignore.append('*{}'.format(self.install_backup_suffix))
|
||||||
self.update_ignore = uniq_list(self.update_ignore)
|
self.update_ignore = uniq_list(self.update_ignore)
|
||||||
self.update_showpatch = self.args['--show-patch']
|
self.update_showpatch = self.args['--show-patch']
|
||||||
|
try:
|
||||||
|
if ENV_WORKERS in os.environ:
|
||||||
|
workers = int(os.environ[ENV_WORKERS])
|
||||||
|
else:
|
||||||
|
workers = int(self.args['--workers'])
|
||||||
|
self.update_parallel = workers
|
||||||
|
except ValueError:
|
||||||
|
self.log.err('bad option for --workers')
|
||||||
|
sys.exit(USAGE)
|
||||||
|
|
||||||
# "detail" specifics
|
# "detail" specifics
|
||||||
self.detail_keys = self.args['<key>']
|
self.detail_keys = self.args['<key>']
|
||||||
|
|||||||
Reference in New Issue
Block a user