本文整理汇总了Python中datalad.support.annexrepo.AnnexRepo.add_to_annex方法的典型用法代码示例。如果您正苦于以下问题:Python AnnexRepo.add_to_annex方法的具体用法?Python AnnexRepo.add_to_annex怎么用?Python AnnexRepo.add_to_annex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类datalad.support.annexrepo.AnnexRepo
的用法示例。
在下文中一共展示了AnnexRepo.add_to_annex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: put_file_under_git
# 需要导入模块: from datalad.support.annexrepo import AnnexRepo [as 别名]
# 或者: from datalad.support.annexrepo.AnnexRepo import add_to_annex [as 别名]
def put_file_under_git(path, filename=None, content=None, annexed=False):
"""Place file under git/annex and return used Repo
"""
annex, file_repo_path, filename, path, repo = _prep_file_under_git(path, filename)
if content is None:
content = ""
with open(opj(repo.path, file_repo_path), 'w') as f_:
f_.write(content)
if annexed:
if not isinstance(repo, AnnexRepo):
repo = AnnexRepo(repo.path)
repo.add_to_annex(file_repo_path)
else:
repo.git_add(file_repo_path)
ok_file_under_git(repo.path, file_repo_path, annexed)
return repo
示例2: test_update_fetch_all
# 需要导入模块: from datalad.support.annexrepo import AnnexRepo [as 别名]
# 或者: from datalad.support.annexrepo.AnnexRepo import add_to_annex [as 别名]
def test_update_fetch_all(src, remote_1, remote_2):
rmt1 = AnnexRepo(remote_1, src)
rmt2 = AnnexRepo(remote_2, src)
ds = Dataset(src)
ds.add_sibling(name="sibling_1", url=remote_1)
ds.add_sibling(name="sibling_2", url=remote_2)
# modify the remotes:
with open(opj(remote_1, "first.txt"), "w") as f:
f.write("some file load")
rmt1.add_to_annex("first.txt")
# TODO: Modify an already present file!
with open(opj(remote_2, "second.txt"), "w") as f:
f.write("different file load")
rmt2.git_add("second.txt")
rmt2.git_commit("Add file to git.")
# fetch all remotes
ds.update(fetch_all=True)
# no merge, so changes are not in active branch:
assert_not_in("first.txt",
ds.repo.git_get_files(ds.repo.git_get_active_branch()))
assert_not_in("second.txt",
ds.repo.git_get_files(ds.repo.git_get_active_branch()))
# but we know the changes in remote branches:
assert_in("first.txt", ds.repo.git_get_files("sibling_1/master"))
assert_in("second.txt", ds.repo.git_get_files("sibling_2/master"))
# no merge strategy for multiple remotes yet:
assert_raises(NotImplementedError, ds.update, merge=True, fetch_all=True)
# merge a certain remote:
ds.update(name="sibling_1", merge=True)
# changes from sibling_2 still not present:
assert_not_in("second.txt",
ds.repo.git_get_files(ds.repo.git_get_active_branch()))
# changes from sibling_1 merged:
assert_in("first.txt",
ds.repo.git_get_files(ds.repo.git_get_active_branch()))
# it's known to annex, but has no content yet:
ds.repo.get_file_key("first.txt") # raises if unknown
eq_([False], ds.repo.file_has_content(["first.txt"]))