本文整理汇总了Python中fs.open_fs方法的典型用法代码示例。如果您正苦于以下问题:Python fs.open_fs方法的具体用法?Python fs.open_fs怎么用?Python fs.open_fs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fs
的用法示例。
在下文中一共展示了fs.open_fs方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cachedir
# 需要导入模块: import fs [as 别名]
# 或者: from fs import open_fs [as 别名]
def test_cachedir(self):
mem_fs = open_fs("mem://")
mem_fs.makedirs("foo/bar/baz")
mem_fs.touch("egg")
fs = wrap.cache_directory(mem_fs)
self.assertEqual(sorted(fs.listdir("/")), ["egg", "foo"])
self.assertEqual(sorted(fs.listdir("/")), ["egg", "foo"])
self.assertTrue(fs.isdir("foo"))
self.assertTrue(fs.isdir("foo"))
self.assertTrue(fs.isfile("egg"))
self.assertTrue(fs.isfile("egg"))
self.assertEqual(fs.getinfo("foo"), mem_fs.getinfo("foo"))
self.assertEqual(fs.getinfo("foo"), mem_fs.getinfo("foo"))
self.assertEqual(fs.getinfo("/"), mem_fs.getinfo("/"))
self.assertEqual(fs.getinfo("/"), mem_fs.getinfo("/"))
with self.assertRaises(errors.ResourceNotFound):
fs.getinfo("/foofoo")
示例2: test_entry_point_create_error
# 需要导入模块: import fs [as 别名]
# 或者: from fs import open_fs [as 别名]
def test_entry_point_create_error(self):
class BadOpener(opener.Opener):
def __init__(self, *args, **kwargs):
raise ValueError("some creation error")
def open_fs(self, *args, **kwargs):
pass
entry_point = mock.MagicMock()
entry_point.load = mock.MagicMock(return_value=BadOpener)
iter_entry_points = mock.MagicMock(return_value=iter([entry_point]))
with mock.patch("pkg_resources.iter_entry_points", iter_entry_points):
with self.assertRaises(errors.EntryPointError) as ctx:
opener.open_fs("test://")
self.assertEqual(
"could not instantiate opener; some creation error", str(ctx.exception)
)
示例3: test_copy_large
# 需要导入模块: import fs [as 别名]
# 或者: from fs import open_fs [as 别名]
def test_copy_large(self):
data1 = b"foo" * 512 * 1024
data2 = b"bar" * 2 * 512 * 1024
data3 = b"baz" * 3 * 512 * 1024
data4 = b"egg" * 7 * 512 * 1024
with open_fs("temp://") as src_fs:
src_fs.writebytes("foo", data1)
src_fs.writebytes("bar", data2)
src_fs.makedir("dir1").writebytes("baz", data3)
src_fs.makedirs("dir2/dir3").writebytes("egg", data4)
for workers in (0, 1, 2, 4):
with open_fs("temp://") as dst_fs:
fs.copy.copy_fs(src_fs, dst_fs, workers=workers)
self.assertEqual(dst_fs.readbytes("foo"), data1)
self.assertEqual(dst_fs.readbytes("bar"), data2)
self.assertEqual(dst_fs.readbytes("dir1/baz"), data3)
self.assertEqual(dst_fs.readbytes("dir2/dir3/egg"), data4)
示例4: test_copy_file_if_newer_same_fs
# 需要导入模块: import fs [as 别名]
# 或者: from fs import open_fs [as 别名]
def test_copy_file_if_newer_same_fs(self):
src_fs = open_fs("mem://")
src_fs.makedir("foo2").touch("exists")
src_fs.makedir("foo1").touch("test1.txt")
src_fs.settimes(
"foo2/exists", datetime.datetime.utcnow() + datetime.timedelta(hours=1)
)
self.assertTrue(
fs.copy.copy_file_if_newer(
src_fs, "foo1/test1.txt", src_fs, "foo2/test1.txt.copy"
)
)
self.assertFalse(
fs.copy.copy_file_if_newer(src_fs, "foo1/test1.txt", src_fs, "foo2/exists")
)
self.assertTrue(src_fs.exists("foo2/test1.txt.copy"))
示例5: test_copy_file_if_newer_dst_is_newer
# 需要导入模块: import fs [as 别名]
# 或者: from fs import open_fs [as 别名]
def test_copy_file_if_newer_dst_is_newer(self):
try:
src_dir = self._create_sandbox_dir()
src_file1 = self._touch(src_dir, "file1.txt")
self._write_file(src_file1)
dst_dir = self._create_sandbox_dir()
dst_file1 = self._touch(dst_dir, "file1.txt")
self._write_file(dst_file1)
src_fs = open_fs("osfs://" + src_dir)
dst_fs = open_fs("osfs://" + dst_dir)
self.assertTrue(dst_fs.exists("/file1.txt"))
copied = fs.copy.copy_file_if_newer(
src_fs, "/file1.txt", dst_fs, "/file1.txt"
)
self.assertEqual(copied, False)
finally:
shutil.rmtree(src_dir)
shutil.rmtree(dst_dir)
示例6: test_copy_dir_if_newer_multiple_files
# 需要导入模块: import fs [as 别名]
# 或者: from fs import open_fs [as 别名]
def test_copy_dir_if_newer_multiple_files(self):
try:
src_dir = self._create_sandbox_dir()
src_fs = open_fs("osfs://" + src_dir)
src_fs.makedirs("foo/bar")
src_fs.makedirs("foo/empty")
src_fs.touch("test.txt")
src_fs.touch("foo/bar/baz.txt")
dst_dir = self._create_sandbox_dir()
dst_fs = open_fs("osfs://" + dst_dir)
fs.copy.copy_dir_if_newer(src_fs, "/foo", dst_fs, "/")
self.assertTrue(dst_fs.isdir("bar"))
self.assertTrue(dst_fs.isdir("empty"))
self.assertTrue(dst_fs.isfile("bar/baz.txt"))
finally:
shutil.rmtree(src_dir)
shutil.rmtree(dst_dir)
示例7: open_fs
# 需要导入模块: import fs [as 别名]
# 或者: from fs import open_fs [as 别名]
def open_fs(cls, *args, **kwargs):
return cls(open_fs(*args, **kwargs))
示例8: __init__
# 需要导入模块: import fs [as 别名]
# 或者: from fs import open_fs [as 别名]
def __init__(self, pyfs, *args, **kwargs):
if isinstance(pyfs, str):
# pyfs is an opener url
self._pyfilesystem_instance = open_fs(pyfs, *args, **kwargs)
elif isinstance(pyfs, type) and issubclass(pyfs, FS):
# pyfs is an FS subclass
self._pyfilesystem_instance = pyfs(*args, **kwargs)
elif isinstance(pyfs, FS):
# pyfs is a FS instance
self._pyfilesystem_instance = pyfs
else:
raise TypeError("pyfs must be a url, an FS subclass, or an FS instance")
示例9: test_open_fs_url_strict_parameter_works
# 需要导入模块: import fs [as 别名]
# 或者: from fs import open_fs [as 别名]
def test_open_fs_url_strict_parameter_works(query_param, strict):
fs = open_fs("gs://{}?{}".format(TEST_BUCKET, query_param))
assert fs.strict == strict
示例10: test_open_fs_project_parameter_works
# 需要导入模块: import fs [as 别名]
# 或者: from fs import open_fs [as 别名]
def test_open_fs_project_parameter_works(query_param, project):
fs = open_fs("gs://{}?{}".format(TEST_BUCKET, query_param))
assert fs.client.project == project
示例11: test_open_fs_api_endpoint_parameter_works
# 需要导入模块: import fs [as 别名]
# 或者: from fs import open_fs [as 别名]
def test_open_fs_api_endpoint_parameter_works():
fs = open_fs("gs://{}?api_endpoint=http%3A//localhost%3A8888".format(TEST_BUCKET))
assert fs.client.client_options == {"api_endpoint": "http://localhost:8888"}
示例12: default_fs_factory
# 需要导入模块: import fs [as 别名]
# 或者: from fs import open_fs [as 别名]
def default_fs_factory(path: str) -> FS:
from fs import open_fs
return open_fs(path, create=True)
示例13: __init__
# 需要导入模块: import fs [as 别名]
# 或者: from fs import open_fs [as 别名]
def __init__(
self,
src_path: str,
src_fs_factory: Callable[..., FS] = default_fs_factory,
output_prefix: str = "",
dry_run: bool = False,
):
"""
Args:
src_path (str): root path of the directory to modify via staging technique
src_fs_factory (Callable[..., FS], optional): Factory method for returning
def default_fs_factory(path: str) -> FS:
PyFileSystem object. Defaults to default_fs_factory.
"""
self.dry_run = dry_run
self._deleted_files: List[str] = []
self.src_path = src_path
# self.src_fs = src_fs_factory(".")
# The src_fs root is the primary reference path from which files are created,
# diffed, etc
self.src_fs = src_fs_factory(src_path or ".")
# The stg_fs mirrors src_fs as an in-memory buffer of changes to be made
self.stg_fs = fs.open_fs(f"mem://")
# The render_fs is contained within stg_fs at the relative path `output_prefix`.
# Rendering file system is from the frame-of-reference of the output_prefix
if not self.stg_fs.isdir(output_prefix):
self.stg_fs.makedirs(output_prefix)
self.render_fs = self.stg_fs.opendir(output_prefix)
示例14: __init__
# 需要导入模块: import fs [as 别名]
# 或者: from fs import open_fs [as 别名]
def __init__(
self,
schematic_path: str,
src_path: str = ".",
output_prefix: str = "",
dry_run: bool = False,
):
from jinja2 import Environment
from flaskerize.fileio import StagedFileSystem
self.src_path = src_path
self.output_prefix = output_prefix
self.schematic_path = schematic_path
self.schematic_files_path = os.path.join(
self.schematic_path, self.DEFAULT_FILES_DIRNAME
)
self.schema_path = self._get_schema_path()
self._load_schema()
self.arg_parser = self._check_get_arg_parser()
self.env = Environment()
self.fs = StagedFileSystem(
src_path=self.src_path, output_prefix=output_prefix, dry_run=dry_run
)
self.sch_fs = fs.open_fs(f"osfs://{self.schematic_files_path}")
self.dry_run = dry_run
示例15: get_filesystem
# 需要导入模块: import fs [as 别名]
# 或者: from fs import open_fs [as 别名]
def get_filesystem(path, create=False, **kwargs):
""" A utility function for initializing any type of filesystem object with PyFilesystem2 package
:param path: A filesystem path
:type path: str
:param create: If the filesystem path doesn't exist this flag indicates to either create it or raise an error
:type create: bool
:param kwargs: Any keyword arguments to be passed forward
:return: A filesystem object
:rtype: fs.FS
"""
if path.startswith('s3://'):
return load_s3_filesystem(path, *kwargs)
return fs.open_fs(path, create=create, **kwargs)