comparison install.py @ 438:3d999fcf62c6

Check for subrepo directories with no repos in them.
author Ludovic Chabant <ludovic@chabant.com>
date Sat, 17 Feb 2018 15:04:36 -0800
parents 21dd55ac743c
children edefbb8ea16a
comparison
equal deleted inserted replaced
437:21dd55ac743c 438:3d999fcf62c6
245 if not os.access(path, os.W_OK): 245 if not os.access(path, os.W_OK):
246 os.chmod(path, stat.S_IWUSR) 246 os.chmod(path, stat.S_IWUSR)
247 func(path) 247 func(path)
248 else: 248 else:
249 raise 249 raise
250
251
252 def _is_non_empty_dir_with(path, contains=None):
253 if not os.path.isdir(path):
254 return False
255 if isinstance(contains, str):
256 contains = [contains]
257 for cnt in contains:
258 if not os.path.exists(os.path.join(path, cnt)):
259 return False
260 return True
250 261
251 262
252 def clone_git(url, path, force=False): 263 def clone_git(url, path, force=False):
253 if os.path.isdir(path): 264 if _is_non_empty_dir_with(path, '.git'):
254 if not force: 265 if not force:
255 print("git pull origin master %s" % path) 266 print("git pull origin master %s" % path)
256 subprocess.check_call(['git', 'pull', 'origin', 'master'], 267 subprocess.check_call(['git', 'pull', 'origin', 'master'],
257 cwd=path) 268 cwd=path)
258 return 269 return
264 ensure_dir(os.path.dirname(path)) 275 ensure_dir(os.path.dirname(path))
265 subprocess.check_call(['git', 'clone', url, path]) 276 subprocess.check_call(['git', 'clone', url, path])
266 277
267 278
268 def clone_hg(url, path, force=False): 279 def clone_hg(url, path, force=False):
269 if os.path.isdir(path): 280 if _is_non_empty_dir_with(path, '.hg'):
270 if not force: 281 if not force:
271 print("hg pull -u %s" % path) 282 print("hg pull -u %s" % path)
272 subprocess.check_call(['hg', 'pull', '-u'], cwd=path) 283 subprocess.check_call(['hg', 'pull', '-u'], cwd=path)
273 return 284 return
274 else: 285 else:
388 local_func = getattr(local_mod, 'install_%s' % mn, None) 399 local_func = getattr(local_mod, 'install_%s' % mn, None)
389 if local_func is not None: 400 if local_func is not None:
390 lmn = '%s (local)' % mn 401 lmn = '%s (local)' % mn
391 funcs.append((lmn, local_func)) 402 funcs.append((lmn, local_func))
392 403
404 failed_installs = []
393 funcs = sorted(funcs, key=_get_install_func_priority, reverse=True) 405 funcs = sorted(funcs, key=_get_install_func_priority, reverse=True)
394 for name, func in funcs: 406 for name, func in funcs:
395 print("Installing %s" % name) 407 print("Installing %s" % name)
396 408
397 f_args = [] 409 f_args = []
403 415
404 try: 416 try:
405 func(*f_args, **f_kwargs) 417 func(*f_args, **f_kwargs)
406 except Exception as ex: 418 except Exception as ex:
407 print("ERROR: %s" % ex) 419 print("ERROR: %s" % ex)
408 print("Aborting install.") 420 print("Skipping install of '%s'." % name)
421 failed_installs.append(name)
422 if failed_installs:
423 for name in failed_installs:
424 print("ERROR: failed to install '%s'." % name)
409 425
410 426
411 def _get_install_func_priority(func_info): 427 def _get_install_func_priority(func_info):
412 func = func_info[1] 428 func = func_info[1]
413 return getattr(func, '__dotfiles_priority__', 0) 429 return getattr(func, '__dotfiles_priority__', 0)