fsresource-tree 0.1.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ """
2
+ fsresources-tree
3
+
4
+ Filesystem implementation based on resourcetree
5
+ """#
6
+
7
+
8
+ from .directory import Directory
9
+ from .file import File
10
+
11
+
12
+ __version__ = "0.1.0"
13
+
14
+
15
+ __all__ = [
16
+ "Directory",
17
+ "File"
18
+ ]
@@ -0,0 +1,27 @@
1
+ from resourcetree import Container
2
+
3
+
4
+
5
+ class Directory(Container):
6
+
7
+
8
+ def __init__(
9
+ self,
10
+ name,
11
+ parent=None,
12
+ uid=None,
13
+
14
+ permissions="755",
15
+ owner=None
16
+ ):
17
+
18
+ super().__init__(
19
+ name,
20
+ parent,
21
+ uid
22
+ )
23
+
24
+
25
+ self.permissions = permissions
26
+
27
+ self.owner = owner
@@ -0,0 +1,40 @@
1
+ from resourcetree import Asset
2
+
3
+
4
+
5
+ class File(Asset):
6
+
7
+
8
+ def __init__(
9
+ self,
10
+ name,
11
+ parent=None,
12
+ uid=None,
13
+
14
+ content=None,
15
+
16
+ encoding="utf-8"
17
+ ):
18
+
19
+
20
+ super().__init__(
21
+ name,
22
+ parent,
23
+ uid,
24
+ content
25
+ )
26
+
27
+
28
+ self.encoding = encoding
29
+
30
+
31
+ self.size = (
32
+
33
+ len(
34
+ content.encode(encoding)
35
+ )
36
+
37
+ if content
38
+
39
+ else 0
40
+ )
@@ -0,0 +1,61 @@
1
+ from pathlib import Path
2
+
3
+ from .directory import Directory
4
+ from .file import File
5
+
6
+
7
+
8
+ def from_path(path):
9
+
10
+
11
+ path = Path(path)
12
+
13
+
14
+ root = Directory(
15
+ path.name
16
+ )
17
+
18
+
19
+ _load(
20
+ path,
21
+ root
22
+ )
23
+
24
+
25
+ return root
26
+
27
+
28
+
29
+
30
+ def _load(
31
+ path,
32
+ node
33
+ ):
34
+
35
+
36
+ for item in path.iterdir():
37
+
38
+
39
+ if item.is_dir():
40
+
41
+ directory = Directory(
42
+ item.name,
43
+ node
44
+ )
45
+
46
+
47
+ _load(
48
+ item,
49
+ directory
50
+ )
51
+
52
+
53
+ else:
54
+
55
+ File(
56
+ item.name,
57
+ node,
58
+ content=item.read_text(
59
+ errors="ignore"
60
+ )
61
+ )
@@ -0,0 +1,26 @@
1
+ Metadata-Version: 2.4
2
+ Name: fsresource-tree
3
+ Version: 0.1.3
4
+ Summary: Filesystem resource tree implementation
5
+ Requires-Python: >=3.11
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: resourcetree>=0.1.2
8
+
9
+ # fsresources-tree
10
+
11
+ Filesystem implementation using resourcetree.
12
+
13
+
14
+ Example:
15
+
16
+ ```python
17
+ import fsresources_tree as fs
18
+
19
+
20
+ root = fs.Directory("/")
21
+
22
+ file = fs.File(
23
+ "test.txt",
24
+ root,
25
+ content="hello"
26
+ )
@@ -0,0 +1,9 @@
1
+ fsresource_tree/__init__.py,sha256=MwwMvG3rc4dsv_0UWNyEPQdrNyUkYrqIkO1moCnRWt4,200
2
+ fsresource_tree/directory.py,sha256=tfl3qkBTEoNc0ATruXzji91Rw9ZtquspMhhmit2m8fk,366
3
+ fsresource_tree/file.py,sha256=89eV3ODYn8SxHAwambyuUjsqihJeQDqLRgF-kATkkhY,494
4
+ fsresource_tree/filesystem.py,sha256=Fe2S2YFyGg_zhfzRo8k2zoaNNFlwOtPootmXwbroDvI,713
5
+ tests/test_basic.py,sha256=CpCrvI7NtaXJhHoOhPT_d-ymsb41oM3dUlwWwoJRRF4,232
6
+ fsresource_tree-0.1.3.dist-info/METADATA,sha256=p6lIV21kRdrxES5R2PwLR3kBrwggokZCffrpG29bNUc,418
7
+ fsresource_tree-0.1.3.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
8
+ fsresource_tree-0.1.3.dist-info/top_level.txt,sha256=RVS_qjfHkt7Qol-OeWWGmDwWFwTbojOQYNjN6RJdLRk,22
9
+ fsresource_tree-0.1.3.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ fsresource_tree
2
+ tests
tests/test_basic.py ADDED
@@ -0,0 +1,20 @@
1
+ import fsresource_tree as fs
2
+
3
+
4
+
5
+ def test_filesystem():
6
+
7
+
8
+ root = fs.Directory("/")
9
+
10
+
11
+ file = fs.File(
12
+ "hello.txt",
13
+ root,
14
+ content="hello"
15
+ )
16
+
17
+
18
+ assert file.parent == root
19
+
20
+ assert file.size == 5