本文整理匯總了Python中datalad.support.gitrepo.GitRepo.get_git_dir方法的典型用法代碼示例。如果您正苦於以下問題:Python GitRepo.get_git_dir方法的具體用法?Python GitRepo.get_git_dir怎麽用?Python GitRepo.get_git_dir使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類datalad.support.gitrepo.GitRepo
的用法示例。
在下文中一共展示了GitRepo.get_git_dir方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_get_git_dir
# 需要導入模塊: from datalad.support.gitrepo import GitRepo [as 別名]
# 或者: from datalad.support.gitrepo.GitRepo import get_git_dir [as 別名]
def test_get_git_dir(path):
# minimal, only missing coverage
assert_raises(RuntimeError, GitRepo.get_git_dir, path)
srcpath = opj(path, 'src')
targetpath = opj(path, 'target')
targetgitpath = opj(targetpath, '.git')
os.makedirs(srcpath)
os.makedirs(targetpath)
if not on_windows:
# with PY3 would also work with Windows 6+
os.symlink(srcpath, targetgitpath)
eq_(srcpath, GitRepo.get_git_dir(targetpath))
# cleanup for following test
unlink(targetgitpath)
with open(targetgitpath, 'w') as f:
f.write('gitdir: {}'.format(srcpath))
eq_(srcpath, GitRepo.get_git_dir(targetpath))
示例2: __call__
# 需要導入模塊: from datalad.support.gitrepo import GitRepo [as 別名]
# 或者: from datalad.support.gitrepo.GitRepo import get_git_dir [as 別名]
def __call__(dataset=None, what=None, recursive=False, recursion_limit=None):
ds = require_dataset(dataset, purpose='clean-up')
res_kwargs = dict(action='clean', logger=lgr, refds=ds.path)
for ap in AnnotatePaths.__call__(
dataset=ds.path,
recursive=recursive,
recursion_limit=recursion_limit,
action='clean',
unavailable_path_status='impossible',
nondataset_path_status='impossible',
return_type='generator',
on_failure='ignore'):
if ap.get('status', None):
yield ap
continue
if ap.get('type', None) != 'dataset':
ap.update(status='impossible',
message='only datasets can be cleaned')
yield ap
continue
d = ap['path']
gitdir = GitRepo.get_git_dir(d)
DIRS_PLURAL = ("directory", "directories")
FILES_PLURAL = ("file", "files")
for dirpath, flag, msg, sing_pl in [
(ARCHIVES_TEMP_DIR, "cached-archives",
"temporary archive", DIRS_PLURAL),
(ANNEX_TEMP_DIR, "annex-tmp",
"temporary annex", FILES_PLURAL),
(ANNEX_TRANSFER_DIR, "annex-transfer",
"annex temporary transfer", DIRS_PLURAL),
(opj(gitdir, SEARCH_INDEX_DOTGITDIR), 'search-index',
"metadata search index", FILES_PLURAL),
]:
topdir = opj(d, dirpath)
lgr.debug("Considering to clean %s:%s", d, dirpath)
if not ((what is None) or (flag in what)):
yield get_status_dict(
path=topdir, status='notneeded', type='directory', **res_kwargs)
continue
paths = glob(opj(topdir, '*'))
if not paths:
yield get_status_dict(
path=topdir, status='notneeded', type='directory', **res_kwargs)
continue
pl = len(paths) > 1
message = ("Removed %d %s %s: %s",
len(paths), msg, sing_pl[int(pl)],
", ".join(sorted([x[len(topdir) + 1:] for x in paths])))
rmtree(topdir)
yield get_status_dict(
path=topdir, status='ok', type='dir', message=message,
**res_kwargs)