MCPcopy
hub / github.com/deadc0de6/dotdrop / cmd_install

Function cmd_install

dotdrop/dotdrop.py:292–381  ·  view source on GitHub ↗

install dotfiles for this profile

(opts)

Source from the content-addressed store, hash-verified

290
291
292def cmd_install(opts):
293 """install dotfiles for this profile"""
294 dotfiles = opts.dotfiles
295 prof = opts.conf.get_profile()
296
297 adapt_workers(opts, LOG)
298
299 pro_pre_actions = prof.get_pre_actions() if prof else []
300 pro_post_actions = prof.get_post_actions() if prof else []
301
302 if opts.install_keys:
303 # filtered dotfiles to install
304 uniq = uniq_list(opts.install_keys)
305 dotfiles = [d for d in dotfiles if d.key in uniq]
306
307 if not dotfiles:
308 msg = f'no dotfile to install for this profile (\"{opts.profile}\")'
309 LOG.warn(msg)
310 return False
311
312 lfs = [k.key for k in dotfiles]
313 LOG.dbg(f'dotfiles registered for install: {lfs}')
314
315 # the installer
316 tmpdir = None
317 if opts.install_temporary:
318 tmpdir = get_tmpdir()
319
320 installed = []
321
322 # clear the workdir
323 if opts.install_clear_workdir and not opts.dry:
324 LOG.dbg(f'clearing the workdir under {opts.workdir}')
325 for root, _, files in os.walk(opts.workdir):
326 for file in files:
327 fpath = os.path.join(root, file)
328 # ignore error
329 removepath(fpath, logger=LOG)
330
331 # execute profile pre-action
332 LOG.dbg(f'run {len(pro_pre_actions)} profile pre actions')
333 templ = _get_templater(opts)
334 ret, _ = action_executor(opts, pro_pre_actions, [], templ, post=False)()
335 if not ret:
336 return False
337
338 # install each dotfile
339 if opts.workers > 1:
340 # in parallel
341 LOG.dbg(f'run with {opts.workers} workers')
342 ex = futures.ThreadPoolExecutor(max_workers=opts.workers)
343
344 wait_for = []
345 for dotfile in dotfiles:
346 j = ex.submit(_dotfile_install, opts, dotfile, tmpdir=tmpdir)
347 wait_for.append(j)
348 # check result
349 for fut in futures.as_completed(wait_for):

Callers 4

test_installMethod · 0.90
test_jhelpersMethod · 0.90
_exec_commandFunction · 0.85

Calls 14

adapt_workersFunction · 0.90
uniq_listFunction · 0.90
get_tmpdirFunction · 0.90
removepathFunction · 0.90
_get_templaterFunction · 0.85
action_executorFunction · 0.85
_dotfile_installFunction · 0.85
get_profileMethod · 0.80
warnMethod · 0.80
dbgMethod · 0.80
errMethod · 0.80
logMethod · 0.80

Tested by 3

test_installMethod · 0.72
test_jhelpersMethod · 0.72