本文整理匯總了Python中datalad.support.annexrepo.AnnexRepo.git_get_branches方法的典型用法代碼示例。如果您正苦於以下問題:Python AnnexRepo.git_get_branches方法的具體用法?Python AnnexRepo.git_get_branches怎麽用?Python AnnexRepo.git_get_branches使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類datalad.support.annexrepo.AnnexRepo
的用法示例。
在下文中一共展示了AnnexRepo.git_get_branches方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_publish_file_handle
# 需要導入模塊: from datalad.support.annexrepo import AnnexRepo [as 別名]
# 或者: from datalad.support.annexrepo.AnnexRepo import git_get_branches [as 別名]
def test_publish_file_handle(origin, src_path, dst_path):
# prepare src
source = install(path=src_path, source=origin, recursive=True)
# TODO: For now, circumnavigate the detached head issue.
# Figure out, what to do.
for subds in source.get_dataset_handles(recursive=True):
AnnexRepo(opj(src_path, subds), init=True, create=True).git_checkout("master")
source.repo.get('test-annex.dat')
# create plain git at target:
target = AnnexRepo(dst_path, create=True)
# actually not needed for this test, but provide same setup as
# everywhere else:
target.git_checkout("TMP", "-b")
source.repo.git_remote_add("target", dst_path)
# directly publish a file handle, not the dataset itself:
res = publish(dataset=source, dest="target", path="test-annex.dat")
eq_(res, opj(source.path, 'test-annex.dat'))
# only file was published, not the dataset itself:
assert_not_in("master", target.git_get_branches())
eq_(Dataset(dst_path).get_dataset_handles(), [])
assert_not_in("test.dat", target.git_get_files())
# content is now available from 'target':
assert_in("target",
source.repo.annex_whereis('test-annex.dat',
output="descriptions"))
source.repo.annex_drop('test-annex.dat')
eq_(source.repo.file_has_content(['test-annex.dat']), [False])
source.repo._run_annex_command('get', annex_options=['test-annex.dat',
'--from=target'])
eq_(source.repo.file_has_content(['test-annex.dat']), [True])
示例2: Dataset
# 需要導入模塊: from datalad.support.annexrepo import AnnexRepo [as 別名]
# 或者: from datalad.support.annexrepo.AnnexRepo import git_get_branches [as 別名]
class Dataset(object):
__slots__ = ['_path', '_repo']
def __init__(self, path):
self._path = abspath(path)
self._repo = None
def __repr__(self):
return "<Dataset path=%s>" % self.path
@property
def path(self):
"""path to the dataset"""
return self._path
@property
def repo(self):
"""Get an instance of the version control system/repo for this dataset,
or None if there is none yet.
If creating an instance of GitRepo is guaranteed to be really cheap
this could also serve as a test whether a repo is present.
Returns
-------
GitRepo
"""
if self._repo is None:
with swallow_logs():
try:
self._repo = AnnexRepo(self._path, create=False, init=False)
except (InvalidGitRepositoryError, NoSuchPathError, RuntimeError):
try:
self._repo = GitRepo(self._path, create=False)
except (InvalidGitRepositoryError, NoSuchPathError):
pass
elif not isinstance(self._repo, AnnexRepo):
# repo was initially set to be self._repo but might become AnnexRepo
# at a later moment, so check if it didn't happen
if 'git-annex' in self._repo.git_get_branches():
# we acquired git-annex branch
self._repo = AnnexRepo(self._repo.path, create=False)
return self._repo
def register_sibling(self, name, url, publish_url=None, verify=None):
"""Register the location of a sibling dataset under a given name.
Optionally, different URLs can be given for retrieving information from
the sibling and for publishing information to it.
This is a cheap operation that does not confirm that at the given
location an actual sibling dataset is available, unless verify is set.
The value "dataset" verifies, that at the given URL an accessible
dataset is available and the value "sibling" furthermore verifies, that
this dataset shares at least one commit with self.
Parameters
----------
name
url
publish_url
verify
None | "dataset" | "sibling"
"""
repo = self.repo
if verify is not None:
raise NotImplementedError("TODO: verify not implemented yet")
if name not in repo.git_get_remotes():
# Add remote
repo.git_remote_add(name, url)
if publish_url is not None:
# set push url:
repo._git_custom_command('', ["git", "remote",
"set-url",
"--push", name,
publish_url])
lgr.info("Added remote '%s':\n %s (pull)\n%s (push)." %
(name, url, publish_url if publish_url else url))
else:
lgr.warning("Remote '%s' already exists. Ignore.")
raise ValueError("'%s' already exists. Couldn't register sibling.")
def get_dataset_handles(self, pattern=None, fulfilled=None, absolute=False,
recursive=False):
"""Get names/paths of all known dataset_handles (subdatasets),
optionally matching a specific name pattern.
Parameters
----------
pattern : None
Not implemented
fulfilled : None or bool
If not None, return either only present or absent datasets.
absolute : bool
If True, absolute paths will be returned.
recursive : bool
If True, recurse into all subdatasets and report their dataset
handles too.
#.........這裏部分代碼省略.........