本文整理汇总了Python中datalad.distribution.dataset.Dataset.uninstall方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.uninstall方法的具体用法?Python Dataset.uninstall怎么用?Python Dataset.uninstall使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类datalad.distribution.dataset.Dataset
的用法示例。
在下文中一共展示了Dataset.uninstall方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_basic_aggregate
# 需要导入模块: from datalad.distribution.dataset import Dataset [as 别名]
# 或者: from datalad.distribution.dataset.Dataset import uninstall [as 别名]
def test_basic_aggregate(path):
# TODO give datasets some more metadata to actually aggregate stuff
base = Dataset(opj(path, 'origin')).create(force=True)
sub = base.create('sub', force=True)
#base.metadata(sub.path, init=dict(homepage='this'), apply2global=True)
subsub = base.create(opj('sub', 'subsub'), force=True)
base.add('.', recursive=True)
ok_clean_git(base.path)
# we will first aggregate the middle dataset on its own, this will
# serve as a smoke test for the reuse of metadata objects later on
sub.aggregate_metadata()
base.save()
ok_clean_git(base.path)
base.aggregate_metadata(recursive=True, update_mode='all')
ok_clean_git(base.path)
direct_meta = base.metadata(recursive=True, return_type='list')
# loose the deepest dataset
sub.uninstall('subsub', check=False)
# no we should eb able to reaggregate metadata, and loose nothing
# because we can aggregate aggregated metadata of subsub from sub
base.aggregate_metadata(recursive=True, update_mode='all')
# same result for aggregate query than for (saved) direct query
agg_meta = base.metadata(recursive=True, return_type='list')
for d, a in zip(direct_meta, agg_meta):
print(d['path'], a['path'])
assert_dict_equal(d, a)
# no we can throw away the subdataset tree, and loose no metadata
base.uninstall('sub', recursive=True, check=False)
assert(not sub.is_installed())
ok_clean_git(base.path)
# same result for aggregate query than for (saved) direct query
agg_meta = base.metadata(recursive=True, return_type='list')
for d, a in zip(direct_meta, agg_meta):
assert_dict_equal(d, a)
示例2: test_ls_uninstalled
# 需要导入模块: from datalad.distribution.dataset import Dataset [as 别名]
# 或者: from datalad.distribution.dataset.Dataset import uninstall [as 别名]
def test_ls_uninstalled(path):
ds = Dataset(path)
ds.create()
ds.create('sub')
ds.uninstall('sub', check=False)
with swallow_outputs() as cmo:
ls([path], recursive=True)
assert_in('not installed', cmo.out)
示例3: test_get_dataset_directories
# 需要导入模块: from datalad.distribution.dataset import Dataset [as 别名]
# 或者: from datalad.distribution.dataset.Dataset import uninstall [as 别名]
def test_get_dataset_directories(path):
assert_raises(ValueError, get_dataset_directories, path)
ds = Dataset(path).create()
# ignores .git always and .datalad by default
assert_equal(get_dataset_directories(path), [])
assert_equal(get_dataset_directories(path, ignore_datalad=False),
[opj(path, '.datalad')])
# find any directory, not just those known to git
testdir = opj(path, 'newdir')
os.makedirs(testdir)
assert_equal(get_dataset_directories(path), [testdir])
# do not find files
with open(opj(path, 'somefile'), 'w') as f:
f.write('some')
assert_equal(get_dataset_directories(path), [testdir])
# find more than one directory
testdir2 = opj(path, 'newdir2')
os.makedirs(testdir2)
assert_equal(sorted(get_dataset_directories(path)), sorted([testdir, testdir2]))
# find subdataset mount points
subdsdir = opj(path, 'sub')
subds = ds.create(subdsdir)
assert_equal(sorted(get_dataset_directories(path)), sorted([testdir, testdir2, subdsdir]))
# do not find content within subdataset dirs
os.makedirs(opj(path, 'sub', 'deep'))
assert_equal(sorted(get_dataset_directories(path)), sorted([testdir, testdir2, subdsdir]))
subsubdsdir = opj(subdsdir, 'subsub')
subds.create(subsubdsdir)
assert_equal(sorted(get_dataset_directories(path)), sorted([testdir, testdir2, subdsdir]))
# find nested directories
testdir3 = opj(testdir2, 'newdir21')
os.makedirs(testdir3)
assert_equal(sorted(get_dataset_directories(path)), sorted([testdir, testdir2, testdir3, subdsdir]))
# only return hits below the search path
assert_equal(sorted(get_dataset_directories(testdir2)), sorted([testdir3]))
# empty subdataset mount points are reported too
ds.uninstall(subds.path, check=False, recursive=True)
ok_(not subds.is_installed())
ok_(os.path.exists(subds.path))
assert_equal(sorted(get_dataset_directories(path)), sorted([testdir, testdir2, testdir3, subdsdir]))
示例4: test_ls_json
# 需要导入模块: from datalad.distribution.dataset import Dataset [as 别名]
# 或者: from datalad.distribution.dataset.Dataset import uninstall [as 别名]
def test_ls_json(topdir, topurl):
annex = AnnexRepo(topdir, create=True)
ds = Dataset(topdir)
# create some file and commit it
with open(opj(ds.path, 'subdsfile.txt'), 'w') as f:
f.write('123')
ds.add(path='subdsfile.txt')
ds.save("Hello!", version_tag=1)
# add a subdataset
ds.install('subds', source=topdir)
subdirds = ds.create(_path_('dir/subds2'), force=True)
subdirds.add('file')
git = GitRepo(opj(topdir, 'dir', 'subgit'), create=True) # create git repo
git.add(opj(topdir, 'dir', 'subgit', 'fgit.txt')) # commit to git to init git repo
git.commit()
annex.add(opj(topdir, 'dir', 'subgit')) # add the non-dataset git repo to annex
annex.add(opj(topdir, 'dir')) # add to annex (links)
annex.drop(opj(topdir, 'dir', 'subdir', 'file2.txt'), options=['--force']) # broken-link
annex.commit()
git.add('fgit.txt') # commit to git to init git repo
git.commit()
# annex.add doesn't add submodule, so using ds.add
ds.add(opj('dir', 'subgit')) # add the non-dataset git repo to annex
ds.add('dir') # add to annex (links)
ds.drop(opj('dir', 'subdir', 'file2.txt'), check=False) # broken-link
# register "external" submodule by installing and uninstalling it
ext_url = topurl + '/dir/subgit/.git'
# need to make it installable via http
Runner()('git update-server-info', cwd=opj(topdir, 'dir', 'subgit'))
ds.install(opj('dir', 'subgit_ext'), source=ext_url)
ds.uninstall(opj('dir', 'subgit_ext'))
meta_dir = opj('.git', 'datalad', 'metadata')
def get_metahash(*path):
if not path:
path = ['/']
return hashlib.md5(opj(*path).encode('utf-8')).hexdigest()
def get_metapath(dspath, *path):
return _path_(dspath, meta_dir, get_metahash(*path))
def get_meta(dspath, *path):
with open(get_metapath(dspath, *path)) as f:
return js.load(f)
# Let's see that there is no crash if one of the files is available only
# in relaxed URL mode, so no size could be picked up
ds.repo.add_url_to_file(
'fromweb', topurl + '/noteventhere', options=['--relaxed'])
for all_ in [True, False]: # recurse directories
for recursive in [True, False]:
for state in ['file', 'delete']:
# subdataset should have its json created and deleted when
# all=True else not
subds_metapath = get_metapath(opj(topdir, 'subds'))
exists_prior = exists(subds_metapath)
#with swallow_logs(), swallow_outputs():
dsj = _ls_json(
topdir,
json=state,
all_=all_,
recursive=recursive
)
ok_startswith(dsj['tags'], '1-')
exists_post = exists(subds_metapath)
# print("%s %s -> %s" % (state, exists_prior, exists_post))
assert_equal(exists_post, (state == 'file' and recursive))
# root should have its json file created and deleted in all cases
ds_metapath = get_metapath(topdir)
assert_equal(exists(ds_metapath), state == 'file')
# children should have their metadata json's created and deleted only when recursive=True
child_metapath = get_metapath(topdir, 'dir', 'subdir')
assert_equal(exists(child_metapath), (state == 'file' and all_))
# ignored directories should not have json files created in any case
for subdir in [('.hidden',), ('dir', 'subgit')]:
assert_false(exists(get_metapath(topdir, *subdir)))
# check if its updated in its nodes sublist too. used by web-ui json. regression test
assert_equal(dsj['nodes'][0]['size']['total'], dsj['size']['total'])
# check size of subdataset
subds = [item for item in dsj['nodes'] if item['name'] == ('subdsfile.txt' or 'subds')][0]
assert_equal(subds['size']['total'], '3 Bytes')
# dir/subds2 must not be listed among nodes of the top dataset:
topds_nodes = {x['name']: x for x in dsj['nodes']}
assert_in('subds', topds_nodes)
# XXX
#.........这里部分代码省略.........
示例5: test_create_raises
# 需要导入模块: from datalad.distribution.dataset import Dataset [as 别名]
# 或者: from datalad.distribution.dataset.Dataset import uninstall [as 别名]
def test_create_raises(path, outside_path):
ds = Dataset(path)
# incompatible arguments (annex only):
assert_raises(ValueError, ds.create, no_annex=True, description='some')
with open(op.join(path, "somefile.tst"), 'w') as f:
f.write("some")
# non-empty without `force`:
assert_in_results(
ds.create(force=False, **raw),
status='error',
message='will not create a dataset in a non-empty directory, use `force` option to ignore')
# non-empty with `force`:
ds.create(force=True)
# create sub outside of super:
assert_in_results(
ds.create(outside_path, **raw),
status='error',
message=(
'dataset containing given paths is not underneath the reference '
'dataset %s: %s', ds, outside_path))
obscure_ds = u"ds-" + OBSCURE_FILENAME
# create a sub:
ds.create(obscure_ds)
# fail when doing it again
assert_in_results(
ds.create(obscure_ds, **raw),
status='error',
message=('collision with content in parent dataset at %s: %s',
ds.path,
[text_type(ds.pathobj / obscure_ds)]),
)
# now deinstall the sub and fail trying to create a new one at the
# same location
ds.uninstall(obscure_ds, check=False)
assert_in(obscure_ds, ds.subdatasets(fulfilled=False, result_xfm='relpaths'))
# and now should fail to also create inplace or under
assert_in_results(
ds.create(obscure_ds, **raw),
status='error',
message=('collision with content in parent dataset at %s: %s',
ds.path,
[text_type(ds.pathobj / obscure_ds)]),
)
assert_in_results(
ds.create(op.join(obscure_ds, 'subsub'), **raw),
status='error',
message=('collision with %s (dataset) in dataset %s',
text_type(ds.pathobj / obscure_ds),
ds.path)
)
os.makedirs(op.join(ds.path, 'down'))
with open(op.join(ds.path, 'down', "someotherfile.tst"), 'w') as f:
f.write("someother")
ds.save()
assert_in_results(
ds.create('down', **raw),
status='error',
message=('collision with content in parent dataset at %s: %s',
ds.path,
[text_type(ds.pathobj / 'down' / 'someotherfile.tst')]),
)