beet-observer 0.7.2__py3-none-any.whl → 0.7.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.
- beet_observer/__init__.py +1 -1
- beet_observer/data_pack.py +17 -5
- beet_observer/plugin.py +56 -6
- beet_observer/resource_pack.py +13 -3
- {beet_observer-0.7.2.dist-info → beet_observer-0.7.3.dist-info}/METADATA +1 -1
- beet_observer-0.7.3.dist-info/RECORD +8 -0
- beet_observer-0.7.2.dist-info/RECORD +0 -8
- {beet_observer-0.7.2.dist-info → beet_observer-0.7.3.dist-info}/LICENSE +0 -0
- {beet_observer-0.7.2.dist-info → beet_observer-0.7.3.dist-info}/WHEEL +0 -0
beet_observer/__init__.py
CHANGED
beet_observer/data_pack.py
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
from pathlib import PosixPath
|
1
2
|
from typing import Any
|
2
3
|
|
3
4
|
import beet.contrib.worldgen as wg
|
@@ -6,9 +7,10 @@ from beet import Context, NamespaceProxy, Structure
|
|
6
7
|
|
7
8
|
def gen_dp_overlays(
|
8
9
|
ctx: Context, ctx_overlay: Context, overlay_dir: str, ignore: list[str]
|
9
|
-
) ->
|
10
|
+
) -> list[PosixPath]:
|
10
11
|
"""
|
11
|
-
Generates overlays between two datapacks.
|
12
|
+
Generates overlays between two datapacks. \n
|
13
|
+
Returns a list of deleted files from the source pack.
|
12
14
|
|
13
15
|
Keyword arguments: \n
|
14
16
|
`ctx` -- the build context \n
|
@@ -108,8 +110,9 @@ def gen_dp_overlays(
|
|
108
110
|
),
|
109
111
|
]
|
110
112
|
# for each file type, check for required overlays
|
113
|
+
deleted: list[PosixPath] = []
|
111
114
|
for registry, registry_overlay in file_types:
|
112
|
-
check_registry(ctx, overlay_dir, registry, registry_overlay)
|
115
|
+
deleted.extend(check_registry(ctx, overlay_dir, registry, registry_overlay))
|
113
116
|
|
114
117
|
# get pack.mcmeta overlay entries
|
115
118
|
mcmeta: dict[str, dict[str, list[dict[str, Any]]]] = ctx.data.mcmeta.data.copy()
|
@@ -154,15 +157,18 @@ def gen_dp_overlays(
|
|
154
157
|
if len(entries) > 0:
|
155
158
|
ctx.data.mcmeta.data.update({"overlays": {"entries": entries}})
|
156
159
|
|
160
|
+
return deleted
|
161
|
+
|
157
162
|
|
158
163
|
def check_registry(
|
159
164
|
ctx: Context,
|
160
165
|
overlay_dir: str,
|
161
166
|
registry: NamespaceProxy[Any],
|
162
167
|
registry_overlay: NamespaceProxy[Any],
|
163
|
-
) ->
|
168
|
+
) -> list[PosixPath]:
|
164
169
|
"""
|
165
|
-
Generates overlays for each namespace proxy.
|
170
|
+
Generates overlays for each namespace proxy. \n
|
171
|
+
Returns a list of deleted files from the source pack.
|
166
172
|
|
167
173
|
Keyword arguments: \n
|
168
174
|
`ctx` -- the build context \n
|
@@ -170,6 +176,9 @@ def check_registry(
|
|
170
176
|
`registry` -- the namespace proxy from the build context \n
|
171
177
|
`registry_overlay` -- the namespace proxy from the overlay context \n
|
172
178
|
"""
|
179
|
+
# prepare cache deletion list
|
180
|
+
deleted: list[PosixPath] = []
|
181
|
+
|
173
182
|
# check each file in the build pack
|
174
183
|
for name in list(registry):
|
175
184
|
if name in registry_overlay:
|
@@ -177,6 +186,7 @@ def check_registry(
|
|
177
186
|
gen_registry_overlay(ctx, overlay_dir, name, registry, registry_overlay)
|
178
187
|
else:
|
179
188
|
# exists only in overlay, so create a deletion overlay
|
189
|
+
deleted.append(registry[name].source_path)
|
180
190
|
gen_registry_overlay(
|
181
191
|
ctx, overlay_dir, name, registry, registry_overlay, "deletion"
|
182
192
|
)
|
@@ -187,6 +197,8 @@ def check_registry(
|
|
187
197
|
ctx, overlay_dir, name, registry, registry_overlay, "addition"
|
188
198
|
)
|
189
199
|
|
200
|
+
return deleted
|
201
|
+
|
190
202
|
|
191
203
|
def gen_registry_overlay(
|
192
204
|
ctx: Context,
|
beet_observer/plugin.py
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
from pathlib import PosixPath
|
2
|
+
|
1
3
|
from beet import Context, run_beet
|
2
4
|
|
3
5
|
from .data_pack import gen_dp_overlays
|
@@ -17,12 +19,52 @@ def beet_default(ctx: Context):
|
|
17
19
|
if ctx.data:
|
18
20
|
dp_path = cache.get_path(f"{ctx.directory} saved_data_pack")
|
19
21
|
if dp_path.is_dir():
|
20
|
-
|
22
|
+
# get files that were moved to an overlay
|
23
|
+
with open(f"{dp_path}/deleted.txt", mode="r") as del_list:
|
24
|
+
deleted = del_list.read().splitlines()
|
25
|
+
|
26
|
+
# delete files that were moved to an overlay
|
27
|
+
for target in deleted:
|
28
|
+
# get file location
|
29
|
+
target_path = PosixPath(target)
|
30
|
+
folders = target_path.parts
|
31
|
+
ext = "." + folders[-1].split(".")[-1]
|
32
|
+
loc = f"{folders[1]}:{folders[-1].removesuffix(ext)}"
|
33
|
+
# get resource location
|
34
|
+
for location, resource in ctx.data.all(loc):
|
35
|
+
p = str(resource.source_path) # type: ignore
|
36
|
+
resource_path = PosixPath((p[p.find("/data/") + 1 :]))
|
37
|
+
# delete resource from pack
|
38
|
+
if target_path == resource_path:
|
39
|
+
del ctx.data[type(resource)][location]
|
40
|
+
|
41
|
+
# add overlays to pack
|
42
|
+
ctx.data.load(f"{dp_path}/pack")
|
21
43
|
cached_dp = True
|
22
44
|
if ctx.assets:
|
23
45
|
rp_path = cache.get_path(f"{ctx.directory} saved_resource_pack")
|
24
46
|
if rp_path.is_dir():
|
25
|
-
|
47
|
+
# get files that were moved to an overlay
|
48
|
+
with open(f"{rp_path}/deleted.txt", mode="r") as del_list:
|
49
|
+
deleted = del_list.read().splitlines()
|
50
|
+
|
51
|
+
# delete files that were moved to an overlay
|
52
|
+
for target in deleted:
|
53
|
+
# get file location
|
54
|
+
target_path = PosixPath(target)
|
55
|
+
folders = target_path.parts
|
56
|
+
ext = "." + folders[-1].split(".")[-1]
|
57
|
+
loc = f"{folders[1]}:{folders[-1].removesuffix(ext)}"
|
58
|
+
# get resource location
|
59
|
+
for location, resource in ctx.assets.all(loc):
|
60
|
+
p = str(resource.source_path) # type: ignore
|
61
|
+
resource_path = PosixPath((p[p.find("/assets/") + 1 :]))
|
62
|
+
# delete resource from pack
|
63
|
+
if target_path == resource_path:
|
64
|
+
del ctx.assets[type(resource)][location]
|
65
|
+
|
66
|
+
# add overlays to pack
|
67
|
+
ctx.assets.load(f"{rp_path}/pack")
|
26
68
|
cached_rp = True
|
27
69
|
if cached_dp and cached_rp:
|
28
70
|
return
|
@@ -52,6 +94,8 @@ def beet_default(ctx: Context):
|
|
52
94
|
for overlay in ctx.assets.overlays:
|
53
95
|
save_rp.append(overlay)
|
54
96
|
# loop through all overlays
|
97
|
+
deleted_dp: list[PosixPath] = []
|
98
|
+
deleted_rp: list[PosixPath] = []
|
55
99
|
for overlay in ctx.meta["observer"]["overlays"]:
|
56
100
|
# get pack
|
57
101
|
if overlay["process"].startswith("https://"):
|
@@ -70,12 +114,18 @@ def beet_default(ctx: Context):
|
|
70
114
|
rp_dir = overlay["directory"]
|
71
115
|
# compare build pack and overlay pack
|
72
116
|
if not cached_dp and ctx.data:
|
73
|
-
gen_dp_overlays(ctx, ctx_overlay, dp_dir, save_dp)
|
117
|
+
deleted_dp = gen_dp_overlays(ctx, ctx_overlay, dp_dir, save_dp)
|
74
118
|
if not cached_rp and ctx.assets:
|
75
|
-
gen_rp_overlays(ctx, ctx_overlay, rp_dir, save_rp)
|
119
|
+
deleted_rp = gen_rp_overlays(ctx, ctx_overlay, rp_dir, save_rp)
|
76
120
|
|
77
121
|
# save to cache
|
78
122
|
if not cached_dp and ctx.data:
|
79
|
-
ctx.data.save(path=dp_path)
|
123
|
+
ctx.data.save(path=f"{dp_path}/pack")
|
124
|
+
with open(f"{dp_path}/deleted.txt", mode="x") as file:
|
125
|
+
for s in deleted_dp:
|
126
|
+
file.write(str(s)[str(s).find("/data/") + 1 :] + "\n")
|
80
127
|
if not cached_rp and ctx.assets:
|
81
|
-
ctx.assets.save(path=rp_path)
|
128
|
+
ctx.assets.save(path=f"{rp_path}/pack")
|
129
|
+
with open(f"{rp_path}/deleted.txt", mode="x") as file:
|
130
|
+
for s in deleted_rp:
|
131
|
+
file.write(str(s)[str(s).find("/assets/") + 1 :] + "\n")
|
beet_observer/resource_pack.py
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
from pathlib import PosixPath
|
1
2
|
from typing import Any
|
2
3
|
|
3
4
|
from beet import Context, NamespaceProxy
|
@@ -5,7 +6,7 @@ from beet import Context, NamespaceProxy
|
|
5
6
|
|
6
7
|
def gen_rp_overlays(
|
7
8
|
ctx: Context, ctx_overlay: Context, overlay_dir: str, ignore: list[str]
|
8
|
-
) ->
|
9
|
+
) -> list[PosixPath]:
|
9
10
|
"""
|
10
11
|
Generates overlays between two resource packs.
|
11
12
|
|
@@ -36,8 +37,9 @@ def gen_rp_overlays(
|
|
36
37
|
(ctx.assets.atlases, ctx_overlay.assets.atlases),
|
37
38
|
]
|
38
39
|
# for each file type, check for required overlays
|
40
|
+
deleted: list[PosixPath] = []
|
39
41
|
for registry, registry_overlay in file_types:
|
40
|
-
check_registry(ctx, overlay_dir, registry, registry_overlay)
|
42
|
+
deleted.extend(check_registry(ctx, overlay_dir, registry, registry_overlay))
|
41
43
|
|
42
44
|
# get pack.mcmeta overlay entries
|
43
45
|
mcmeta: dict[str, dict[str, list[dict[str, Any]]]] = ctx.assets.mcmeta.data.copy()
|
@@ -82,13 +84,15 @@ def gen_rp_overlays(
|
|
82
84
|
if len(entries) > 0:
|
83
85
|
ctx.assets.mcmeta.data.update({"overlays": {"entries": entries}})
|
84
86
|
|
87
|
+
return deleted
|
88
|
+
|
85
89
|
|
86
90
|
def check_registry(
|
87
91
|
ctx: Context,
|
88
92
|
overlay_dir: str,
|
89
93
|
registry: NamespaceProxy[Any],
|
90
94
|
registry_overlay: NamespaceProxy[Any],
|
91
|
-
) ->
|
95
|
+
) -> list[PosixPath]:
|
92
96
|
"""
|
93
97
|
Generates overlays for each namespace proxy.
|
94
98
|
|
@@ -98,6 +102,9 @@ def check_registry(
|
|
98
102
|
`registry` -- the namespace proxy from the build context \n
|
99
103
|
`registry_overlay` -- the namespace proxy from the overlay context \n
|
100
104
|
"""
|
105
|
+
# prepare cache deletion list
|
106
|
+
deleted: list[PosixPath] = []
|
107
|
+
|
101
108
|
# check each file in the build pack
|
102
109
|
for name in list(registry):
|
103
110
|
if name in registry_overlay:
|
@@ -105,6 +112,7 @@ def check_registry(
|
|
105
112
|
gen_registry_overlay(ctx, overlay_dir, name, registry, registry_overlay)
|
106
113
|
else:
|
107
114
|
# exists only in overlay, so create a deletion overlay
|
115
|
+
deleted.append(registry[name].source_path)
|
108
116
|
gen_registry_overlay(
|
109
117
|
ctx, overlay_dir, name, registry, registry_overlay, "deletion"
|
110
118
|
)
|
@@ -115,6 +123,8 @@ def check_registry(
|
|
115
123
|
ctx, overlay_dir, name, registry, registry_overlay, "addition"
|
116
124
|
)
|
117
125
|
|
126
|
+
return deleted
|
127
|
+
|
118
128
|
|
119
129
|
def gen_registry_overlay(
|
120
130
|
ctx: Context,
|
@@ -0,0 +1,8 @@
|
|
1
|
+
beet_observer/__init__.py,sha256=2a7c7z_oeF6m8073Y6AaZlA2Ki1lPLQrXIm7RssesGo,45
|
2
|
+
beet_observer/data_pack.py,sha256=6bsBYi7-uvqxEk4ZuYZrS9A68LbTBo1v9M8b9eEzBoo,10361
|
3
|
+
beet_observer/plugin.py,sha256=Be1jA_8ScChb0ZtwZ1voQY-sG4YmOaEhiGo41KGF2xk,5412
|
4
|
+
beet_observer/resource_pack.py,sha256=2GMUrNv0fF7-a0RWZ46sA7ipDt7s5z4yE3laPv2eXO8,6477
|
5
|
+
beet_observer-0.7.3.dist-info/LICENSE,sha256=oBbP6j7sgG9darFSRZxV7iO8yPR1aZiDspSK3mcLpXI,1062
|
6
|
+
beet_observer-0.7.3.dist-info/METADATA,sha256=lLvfQOV4UBpOMKqvyV1aOPHdCXyQh6fc7z3_ETYJb9w,674
|
7
|
+
beet_observer-0.7.3.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
8
|
+
beet_observer-0.7.3.dist-info/RECORD,,
|
@@ -1,8 +0,0 @@
|
|
1
|
-
beet_observer/__init__.py,sha256=JcF4rPyJxqAn0u-uUEv2tLL9azWoXI9PVD-uGE3sZnQ,45
|
2
|
-
beet_observer/data_pack.py,sha256=0qvnIwXlP_A_I1DAnvloW9ryaUZh2Qm1VF-Qux6IxBc,9973
|
3
|
-
beet_observer/plugin.py,sha256=NXLMkfsxxlnJbR51eM4TGOf1vCR30rNYSr6l4djqnT8,2973
|
4
|
-
beet_observer/resource_pack.py,sha256=hwFlwQiRUFg1V9Zy-U4gVUOvZxqEzyqHgoBdwzqoAXc,6211
|
5
|
-
beet_observer-0.7.2.dist-info/LICENSE,sha256=oBbP6j7sgG9darFSRZxV7iO8yPR1aZiDspSK3mcLpXI,1062
|
6
|
-
beet_observer-0.7.2.dist-info/METADATA,sha256=KleELV6Buct3KDzBcBamAMwVbKhEec4wSgs6UmewNBo,674
|
7
|
-
beet_observer-0.7.2.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
8
|
-
beet_observer-0.7.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|