本文整理匯總了Python中py.path.local方法的典型用法代碼示例。如果您正苦於以下問題:Python path.local方法的具體用法?Python path.local怎麽用?Python path.local使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類py.path
的用法示例。
在下文中一共展示了path.local方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_kiwix_installs_zippedzim
# 需要導入模塊: from py import path [as 別名]
# 或者: from py.path import local [as 別名]
def test_kiwix_installs_zippedzim(settings, zippedzim_path):
from ideascube.serveradmin.catalog import Kiwix, ZippedZim
p = ZippedZim('wikipedia.tum', {
'url': 'https://foo.fr/wikipedia_tum_all_nopic_2015-08.zip'})
h = Kiwix()
h.install(p, zippedzim_path.strpath)
install_root = Path(settings.CATALOG_KIWIX_INSTALL_DIR)
data = install_root.join('data')
assert data.check(dir=True)
content = data.join('content')
assert content.check(dir=True)
assert content.join('{}.zim'.format(p.id)).check(file=True)
lib = data.join('library')
assert lib.check(dir=True)
assert lib.join('{}.zim.xml'.format(p.id)).check(file=True)
index = data.join('index')
assert index.check(dir=True)
assert index.join('{}.zim.idx'.format(p.id)).check(dir=True)
示例2: test_mediacenter_removes_zippedmedia
# 需要導入模塊: from py import path [as 別名]
# 或者: from py.path import local [as 別名]
def test_mediacenter_removes_zippedmedia(settings, zippedmedia_path):
from ideascube.serveradmin.catalog import MediaCenter, ZippedMedias
p = ZippedMedias('test-media', {
'url': 'https://foo.fr/test-media.zip'})
h = MediaCenter()
h.install(p, zippedmedia_path.strpath)
assert Document.objects.count() == 3
h.remove(p)
assert Document.objects.count() == 0
install_root = Path(settings.CATALOG_MEDIACENTER_INSTALL_DIR)
root = install_root.join('test-media')
assert root.check(exists=False)
示例3: test_catalog_existing_remote_json
# 需要導入模塊: from py import path [as 別名]
# 或者: from py.path import local [as 別名]
def test_catalog_existing_remote_json(settings):
from ideascube.serveradmin.catalog import Catalog
params = {
'id': 'foo', 'name': 'Content provided by Foo',
'url': 'http://foo.fr/catalog.yml'}
remotes_dir = Path(settings.CATALOG_STORAGE_ROOT).mkdir('remotes')
remotes_dir.join('foo.json').write(json.dumps(params))
c = Catalog()
remotes = c.list_remotes()
assert len(remotes) == 1
remote = remotes[0]
assert remote.id == params['id']
assert remote.name == params['name']
assert remote.url == params['url']
示例4: test_catalog_existing_remote_yml
# 需要導入模塊: from py import path [as 別名]
# 或者: from py.path import local [as 別名]
def test_catalog_existing_remote_yml(settings):
from ideascube.serveradmin.catalog import Catalog
params = {
'id': 'foo', 'name': 'Content provided by Foo',
'url': 'http://foo.fr/catalog.yml'}
remotes_dir = Path(settings.CATALOG_STORAGE_ROOT).mkdir('remotes')
yml_file = remotes_dir.join('foo.yml')
yml_file.write(yaml.safe_dump(params))
c = Catalog()
remotes = c.list_remotes()
assert len(remotes) == 1
remote = remotes[0]
assert remote.id == params['id']
assert remote.name == params['name']
assert remote.url == params['url']
assert yml_file.check(exists=False)
json_data = json.loads(remotes_dir.join('foo.json').read())
assert json_data == params
示例5: test_catalog_remove_remote_json
# 需要導入模塊: from py import path [as 別名]
# 或者: from py.path import local [as 別名]
def test_catalog_remove_remote_json(settings):
from ideascube.serveradmin.catalog import Catalog
params = {
'id': 'foo', 'name': 'Content provided by Foo',
'url': 'http://foo.fr/catalog.yml'}
remotes_dir = Path(settings.CATALOG_STORAGE_ROOT).mkdir('remotes')
json_file = remotes_dir.join('foo.json')
json_file.write(json.dumps(params))
c = Catalog()
c.remove_remote(params['id'])
remotes = c.list_remotes()
assert len(remotes) == 0
assert json_file.check(exists=False)
with pytest.raises(ValueError) as exc:
c.remove_remote(params['id'])
assert params['id'] in exc.exconly()
示例6: test_catalog_remove_remote_yml
# 需要導入模塊: from py import path [as 別名]
# 或者: from py.path import local [as 別名]
def test_catalog_remove_remote_yml(settings):
from ideascube.serveradmin.catalog import Catalog
params = {
'id': 'foo', 'name': 'Content provided by Foo',
'url': 'http://foo.fr/catalog.yml'}
remotes_dir = Path(settings.CATALOG_STORAGE_ROOT).mkdir('remotes')
yml_file = remotes_dir.join('foo.yml')
yml_file.write(yaml.safe_dump(params))
c = Catalog()
c.remove_remote(params['id'])
remotes = c.list_remotes()
assert len(remotes) == 0
assert yml_file.check(exists=False)
assert remotes_dir.join('foo.json').check(exists=False)
with pytest.raises(ValueError) as exc:
c.remove_remote(params['id'])
assert params['id'] in exc.exconly()
示例7: test_add_remote
# 需要導入模塊: from py import path [as 別名]
# 或者: from py.path import local [as 別名]
def test_add_remote(tmpdir, settings, capsys):
remote_catalog_file = tmpdir.mkdir('source').join('catalog.yml')
remote_catalog_file.write(
'all:\n foovideos:\n name: Videos from Foo')
expected = {
'id': 'foo', 'name': 'Content from Foo',
'url': 'file://{}'.format(remote_catalog_file.strpath),
}
call_command(
'catalog', 'remotes', 'add', expected['id'], expected['name'],
expected['url'])
# Ensure the remote has been added
remotes_dir = Path(settings.CATALOG_STORAGE_ROOT).join('remotes')
assert remotes_dir.check(dir=True)
assert remotes_dir.join('foo.json').check(file=True)
with remotes_dir.join('foo.json').open('r') as f:
assert json.load(f) == expected
示例8: test_remove_remote
# 需要導入模塊: from py import path [as 別名]
# 或者: from py.path import local [as 別名]
def test_remove_remote(tmpdir, settings, capsys):
remote_catalog_file = tmpdir.mkdir('source').join('catalog.yml')
remote_catalog_file.write(
'all:\n foovideos:\n name: Videos from Foo')
remote = {
'id': 'foo', 'name': 'Content from Foo',
'url': 'file://{}'.format(remote_catalog_file.strpath),
}
call_command(
'catalog', 'remotes', 'add', remote['id'], remote['name'],
remote['url'])
call_command('catalog', 'remotes', 'remove', remote['id'])
# Ensure the remote has been removed
remotes_dir = Path(settings.CATALOG_STORAGE_ROOT).join('remotes')
assert remotes_dir.check(dir=True)
assert remotes_dir.listdir() == []
示例9: test_clear_metadata_cache
# 需要導入模塊: from py import path [as 別名]
# 或者: from py.path import local [as 別名]
def test_clear_metadata_cache(tmpdir, settings, capsys):
remote_catalog_file = tmpdir.mkdir('source').join('catalog.yml')
remote_catalog_file.write(
'all:\n foovideos:\n name: Videos from Foo')
call_command(
'catalog', 'remotes', 'add', 'foo', 'Content from Foo',
'file://{}'.format(remote_catalog_file.strpath))
call_command('catalog', 'cache', 'update')
catalog_cache_dir = Path(settings.CATALOG_CACHE_ROOT)
catalog_cache_path = catalog_cache_dir.join('catalog.json')
downloaded_path = catalog_cache_dir.join('packages').join('foovideos')
downloaded_path.write_binary(b'content')
assert yaml.safe_load(catalog_cache_path.read_text('utf-8')) != {}
call_command('catalog', 'cache', 'clear', '--metadata')
assert catalog_cache_dir.join('catalog.json').check(file=True)
assert yaml.safe_load(catalog_cache_path.read_text('utf-8')) == {}
assert downloaded_path.read_binary() == b'content'
out, err = capsys.readouterr()
assert out.strip() == ''
assert err.strip() == ''
示例10: test_clear_package_cache
# 需要導入模塊: from py import path [as 別名]
# 或者: from py.path import local [as 別名]
def test_clear_package_cache(tmpdir, settings, capsys):
remote_catalog_file = tmpdir.mkdir('source').join('catalog.yml')
remote_catalog_file.write(
'all:\n foovideos:\n name: Videos from Foo')
call_command(
'catalog', 'remotes', 'add', 'foo', 'Content from Foo',
'file://{}'.format(remote_catalog_file.strpath))
call_command('catalog', 'cache', 'update')
catalog_cache_dir = Path(settings.CATALOG_CACHE_ROOT)
catalog_cache_path = catalog_cache_dir.join('catalog.json')
downloaded_path = catalog_cache_dir.join('packages').join('foovideos')
downloaded_path.write_binary(b'content')
assert yaml.safe_load(catalog_cache_path.read_text('utf-8')) != {}
call_command('catalog', 'cache', 'clear', '--packages')
assert catalog_cache_dir.join('catalog.json').check(file=True)
assert yaml.safe_load(catalog_cache_path.read_text('utf-8')) != {}
assert downloaded_path.check(exists=False)
out, err = capsys.readouterr()
assert out.strip() == ''
assert err.strip() == ''
示例11: test_clear_cache
# 需要導入模塊: from py import path [as 別名]
# 或者: from py.path import local [as 別名]
def test_clear_cache(tmpdir, settings, capsys):
remote_catalog_file = tmpdir.mkdir('source').join('catalog.yml')
remote_catalog_file.write(
'all:\n foovideos:\n name: Videos from Foo')
call_command(
'catalog', 'remotes', 'add', 'foo', 'Content from Foo',
'file://{}'.format(remote_catalog_file.strpath))
call_command('catalog', 'cache', 'update')
catalog_cache_dir = Path(settings.CATALOG_CACHE_ROOT)
catalog_cache_path = catalog_cache_dir.join('catalog.json')
downloaded_path = catalog_cache_dir.join('packages').join('foovideos')
downloaded_path.write_binary(b'content')
assert yaml.safe_load(catalog_cache_path.read_text('utf-8')) != {}
call_command('catalog', 'cache', 'clear')
assert catalog_cache_dir.join('catalog.json').check(file=True)
assert yaml.safe_load(catalog_cache_path.read_text('utf-8')) == {}
assert downloaded_path.check(exists=False)
out, err = capsys.readouterr()
assert out.strip() == ''
assert err.strip() == ''
示例12: test_move_remotes
# 需要導入模塊: from py import path [as 別名]
# 或者: from py.path import local [as 別名]
def test_move_remotes(tmpdir, settings):
remote_catalog_file = tmpdir.mkdir('source').join('catalog.yml')
remote_catalog_file.write(
'all:\n foovideos:\n name: Videos from Foo')
call_command(
'catalog', 'remotes', 'add', 'foo', 'Content from Foo',
'file://{}'.format(remote_catalog_file.strpath))
# Now move the remotes to the old location
catalog_cache_dir = Path(settings.CATALOG_CACHE_ROOT)
catalog_storage_dir = Path(settings.CATALOG_STORAGE_ROOT)
catalog_storage_dir.join('remotes').move(catalog_cache_dir.join('remotes'))
content = json.loads(catalog_cache_dir.join('remotes', 'foo.json').read())
catalog_cache_dir.join('remotes', 'foo.yml').write(yaml.safe_dump(content))
catalog_cache_dir.join('remotes', 'foo.json').remove()
assert catalog_storage_dir.join('remotes').check(exists=False)
# And check that it migrates properly
call_command('catalog', 'cache', 'update')
assert catalog_cache_dir.join('remotes').check(exists=False)
assert catalog_storage_dir.join('remotes', 'foo.json').check(file=True)
示例13: test_list_upgradable_removed_from_remote
# 需要導入模塊: from py import path [as 別名]
# 或者: from py.path import local [as 別名]
def test_list_upgradable_removed_from_remote(tmpdir, capsys, settings):
remote_catalog_file = tmpdir.mkdir('source').join('catalog.yml')
remote_catalog_file.write_text('all: {}', 'utf-8')
call_command(
'catalog', 'remotes', 'add', 'foo', 'Content from Foo',
'file://{}'.format(remote_catalog_file.strpath))
call_command('catalog', 'cache', 'update')
# Pretend we installed something which has since disapeared from the remote
Path(settings.CATALOG_STORAGE_ROOT).join('installed.yml').write_text(
'foovideos:\n'
' name: Videos from Foo\n'
' version: 2017-05\n'
' size: 3027988\n'
' type: zipped-medias',
'utf-8')
call_command('catalog', 'list', '--upgradable')
out, err = capsys.readouterr()
assert out.strip() == ''
assert err.strip() == ''
示例14: test_upgrade_unavailable_package
# 需要導入模塊: from py import path [as 別名]
# 或者: from py.path import local [as 別名]
def test_upgrade_unavailable_package(tmpdir, settings, staticsite_path):
remote_catalog_file = tmpdir.join('source').join('catalog.yml')
remote_catalog_file.write_text('all: {}', 'utf-8')
call_command(
'catalog', 'remotes', 'add', 'foo', 'Content from Foo',
'file://{}'.format(remote_catalog_file.strpath))
call_command('catalog', 'cache', 'update')
install_dir = Path(settings.CATALOG_NGINX_INSTALL_DIR)
assert install_dir.join('the-site').check(exists=False)
with pytest.raises(CommandError) as excinfo:
call_command('catalog', 'upgrade', 'the-site')
assert 'No such package: the-site' in excinfo.exconly()
assert install_dir.join('the-site').check(exists=False)
示例15: __find_config_files
# 需要導入模塊: from py import path [as 別名]
# 或者: from py.path import local [as 別名]
def __find_config_files(pattern="*.py", rcfile=False):
""" Finds configuration files
Looks for files with a given pattern in the following directory:
- config subdirectory of the pylada package
- directory pointed to by the "PYLADA_CONFIG_DIR" environment variable, if it exists
- in "~/.pylada" if it exist and is a directory
"""
from os.path import expandvars, expanduser
from py.path import local
from os import environ
filenames = local(__file__).dirpath("config").listdir(fil=pattern, sort=True)
for envdir in ['PYLADA_CONFIG_DIR', 'LADA_CONFIG_DIR']:
if envdir in environ:
configdir = expandvars(expanduser(environ[envdir]))
filenames += local(configdir).listdir(fil=pattern, sort=True)
pylada = local(expanduser("~/.pylada"))
if pylada.isdir():
filenames += pylada.listdir(fil=pattern, sort=True)
elif rcfile and pylada.check(file=True):
filenames += [pylada]
return filenames