beet-observer 0.7.1__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 +38 -27
- beet_observer/plugin.py +64 -11
- beet_observer/resource_pack.py +32 -23
- {beet_observer-0.7.1.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.1.dist-info/RECORD +0 -8
- {beet_observer-0.7.1.dist-info → beet_observer-0.7.3.dist-info}/LICENSE +0 -0
- {beet_observer-0.7.1.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,14 +7,16 @@ 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
|
-
|
13
|
-
|
14
|
-
|
15
|
-
`
|
16
|
-
`
|
12
|
+
Generates overlays between two datapacks. \n
|
13
|
+
Returns a list of deleted files from the source pack.
|
14
|
+
|
15
|
+
Keyword arguments: \n
|
16
|
+
`ctx` -- the build context \n
|
17
|
+
`ctx_overlay` -- the overlay context \n
|
18
|
+
`overlay_dir` -- the directory of the overlay \n
|
19
|
+
`ignore` -- a list of overlays to ignore (existing overlays that should not be touched) \n
|
17
20
|
"""
|
18
21
|
# create list of all datapack file types
|
19
22
|
file_types: list[tuple[NamespaceProxy[Any], NamespaceProxy[Any]]] = [
|
@@ -107,8 +110,9 @@ def gen_dp_overlays(
|
|
107
110
|
),
|
108
111
|
]
|
109
112
|
# for each file type, check for required overlays
|
113
|
+
deleted: list[PosixPath] = []
|
110
114
|
for registry, registry_overlay in file_types:
|
111
|
-
check_registry(ctx,
|
115
|
+
deleted.extend(check_registry(ctx, overlay_dir, registry, registry_overlay))
|
112
116
|
|
113
117
|
# get pack.mcmeta overlay entries
|
114
118
|
mcmeta: dict[str, dict[str, list[dict[str, Any]]]] = ctx.data.mcmeta.data.copy()
|
@@ -153,24 +157,28 @@ def gen_dp_overlays(
|
|
153
157
|
if len(entries) > 0:
|
154
158
|
ctx.data.mcmeta.data.update({"overlays": {"entries": entries}})
|
155
159
|
|
160
|
+
return deleted
|
161
|
+
|
156
162
|
|
157
163
|
def check_registry(
|
158
164
|
ctx: Context,
|
159
|
-
ctx_overlay: 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.
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
`
|
170
|
-
`overlay_dir` -- the directory of the overlay
|
171
|
-
`registry` -- the namespace proxy from the build context
|
172
|
-
`registry_overlay` -- the namespace proxy from the overlay context
|
170
|
+
Generates overlays for each namespace proxy. \n
|
171
|
+
Returns a list of deleted files from the source pack.
|
172
|
+
|
173
|
+
Keyword arguments: \n
|
174
|
+
`ctx` -- the build context \n
|
175
|
+
`overlay_dir` -- the directory of the overlay \n
|
176
|
+
`registry` -- the namespace proxy from the build context \n
|
177
|
+
`registry_overlay` -- the namespace proxy from the overlay context \n
|
173
178
|
"""
|
179
|
+
# prepare cache deletion list
|
180
|
+
deleted: list[PosixPath] = []
|
181
|
+
|
174
182
|
# check each file in the build pack
|
175
183
|
for name in list(registry):
|
176
184
|
if name in registry_overlay:
|
@@ -178,6 +186,7 @@ def check_registry(
|
|
178
186
|
gen_registry_overlay(ctx, overlay_dir, name, registry, registry_overlay)
|
179
187
|
else:
|
180
188
|
# exists only in overlay, so create a deletion overlay
|
189
|
+
deleted.append(registry[name].source_path)
|
181
190
|
gen_registry_overlay(
|
182
191
|
ctx, overlay_dir, name, registry, registry_overlay, "deletion"
|
183
192
|
)
|
@@ -188,6 +197,8 @@ def check_registry(
|
|
188
197
|
ctx, overlay_dir, name, registry, registry_overlay, "addition"
|
189
198
|
)
|
190
199
|
|
200
|
+
return deleted
|
201
|
+
|
191
202
|
|
192
203
|
def gen_registry_overlay(
|
193
204
|
ctx: Context,
|
@@ -198,15 +209,15 @@ def gen_registry_overlay(
|
|
198
209
|
type: str = "",
|
199
210
|
) -> None:
|
200
211
|
"""
|
201
|
-
Checks if two
|
202
|
-
|
203
|
-
Keyword arguments
|
204
|
-
`ctx` -- the build context
|
205
|
-
`overlay_dir` -- the directory of the generated overlay
|
206
|
-
`name` -- the name of the file
|
207
|
-
`registry` -- the namespace proxy from the build context
|
208
|
-
`registry_overlay` -- the namespace proxy from the overlay context
|
209
|
-
`type` -- either "deletion" or "addition" (default: `""`)
|
212
|
+
Checks if two files have the same contents and generate an overlay if they don't.
|
213
|
+
|
214
|
+
Keyword arguments: \n
|
215
|
+
`ctx` -- the build context \n
|
216
|
+
`overlay_dir` -- the directory of the generated overlay \n
|
217
|
+
`name` -- the name of the file \n
|
218
|
+
`registry` -- the namespace proxy from the build context \n
|
219
|
+
`registry_overlay` -- the namespace proxy from the overlay context \n
|
220
|
+
`type`(optional) -- either "deletion" or "addition" (default: `""`) \n
|
210
221
|
"""
|
211
222
|
if type == "deletion":
|
212
223
|
# move file from build pack to overlay in build pack
|
beet_observer/plugin.py
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
+
from pathlib import PosixPath
|
2
|
+
|
1
3
|
from beet import Context, run_beet
|
2
4
|
|
3
|
-
from .data_pack import
|
4
|
-
from .resource_pack import
|
5
|
+
from .data_pack import gen_dp_overlays
|
6
|
+
from .resource_pack import gen_rp_overlays
|
5
7
|
|
6
8
|
|
7
9
|
def beet_default(ctx: Context):
|
8
10
|
if "observer" not in ctx.meta:
|
9
11
|
return
|
10
12
|
|
11
|
-
#
|
13
|
+
# check cache
|
12
14
|
cache = ctx.cache["observer"]
|
13
15
|
cached_dp = False
|
14
16
|
cached_rp = False
|
@@ -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
|
@@ -45,10 +87,15 @@ def beet_default(ctx: Context):
|
|
45
87
|
"rp"
|
46
88
|
]
|
47
89
|
# save current overlays
|
48
|
-
|
90
|
+
save_dp: list[str] = []
|
91
|
+
save_rp: list[str] = []
|
49
92
|
for overlay in ctx.data.overlays:
|
50
|
-
|
93
|
+
save_dp.append(overlay)
|
94
|
+
for overlay in ctx.assets.overlays:
|
95
|
+
save_rp.append(overlay)
|
51
96
|
# loop through all overlays
|
97
|
+
deleted_dp: list[PosixPath] = []
|
98
|
+
deleted_rp: list[PosixPath] = []
|
52
99
|
for overlay in ctx.meta["observer"]["overlays"]:
|
53
100
|
# get pack
|
54
101
|
if overlay["process"].startswith("https://"):
|
@@ -67,12 +114,18 @@ def beet_default(ctx: Context):
|
|
67
114
|
rp_dir = overlay["directory"]
|
68
115
|
# compare build pack and overlay pack
|
69
116
|
if not cached_dp and ctx.data:
|
70
|
-
gen_dp_overlays(ctx, ctx_overlay, dp_dir,
|
117
|
+
deleted_dp = gen_dp_overlays(ctx, ctx_overlay, dp_dir, save_dp)
|
71
118
|
if not cached_rp and ctx.assets:
|
72
|
-
gen_rp_overlays(ctx, ctx_overlay, rp_dir,
|
119
|
+
deleted_rp = gen_rp_overlays(ctx, ctx_overlay, rp_dir, save_rp)
|
73
120
|
|
74
121
|
# save to cache
|
75
122
|
if not cached_dp and ctx.data:
|
76
|
-
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")
|
77
127
|
if not cached_rp and ctx.assets:
|
78
|
-
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,14 +6,15 @@ 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
|
|
12
|
-
Keyword arguments
|
13
|
-
`ctx` -- the build context
|
14
|
-
`ctx_overlay` -- the overlay context
|
15
|
-
`overlay_dir` -- the directory of the overlay
|
13
|
+
Keyword arguments: \n
|
14
|
+
`ctx` -- the build context \n
|
15
|
+
`ctx_overlay` -- the overlay context \n
|
16
|
+
`overlay_dir` -- the directory of the overlay \n
|
17
|
+
`ignore` -- a list of overlays to ignore (existing overlays that should not be touched) \n
|
16
18
|
"""
|
17
19
|
# create list of all resource pack file types
|
18
20
|
file_types: list[tuple[NamespaceProxy[Any], NamespaceProxy[Any]]] = [
|
@@ -35,8 +37,9 @@ def gen_rp_overlays(
|
|
35
37
|
(ctx.assets.atlases, ctx_overlay.assets.atlases),
|
36
38
|
]
|
37
39
|
# for each file type, check for required overlays
|
40
|
+
deleted: list[PosixPath] = []
|
38
41
|
for registry, registry_overlay in file_types:
|
39
|
-
check_registry(ctx,
|
42
|
+
deleted.extend(check_registry(ctx, overlay_dir, registry, registry_overlay))
|
40
43
|
|
41
44
|
# get pack.mcmeta overlay entries
|
42
45
|
mcmeta: dict[str, dict[str, list[dict[str, Any]]]] = ctx.assets.mcmeta.data.copy()
|
@@ -81,24 +84,27 @@ def gen_rp_overlays(
|
|
81
84
|
if len(entries) > 0:
|
82
85
|
ctx.assets.mcmeta.data.update({"overlays": {"entries": entries}})
|
83
86
|
|
87
|
+
return deleted
|
88
|
+
|
84
89
|
|
85
90
|
def check_registry(
|
86
91
|
ctx: Context,
|
87
|
-
ctx_overlay: 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
|
|
95
|
-
Keyword arguments
|
96
|
-
`ctx` -- the build context
|
97
|
-
`
|
98
|
-
`
|
99
|
-
`
|
100
|
-
`registry_overlay` -- the namespace proxy from the overlay context</br>
|
99
|
+
Keyword arguments: \n
|
100
|
+
`ctx` -- the build context \n
|
101
|
+
`overlay_dir` -- the directory of the overlay \n
|
102
|
+
`registry` -- the namespace proxy from the build context \n
|
103
|
+
`registry_overlay` -- the namespace proxy from the overlay context \n
|
101
104
|
"""
|
105
|
+
# prepare cache deletion list
|
106
|
+
deleted: list[PosixPath] = []
|
107
|
+
|
102
108
|
# check each file in the build pack
|
103
109
|
for name in list(registry):
|
104
110
|
if name in registry_overlay:
|
@@ -106,6 +112,7 @@ def check_registry(
|
|
106
112
|
gen_registry_overlay(ctx, overlay_dir, name, registry, registry_overlay)
|
107
113
|
else:
|
108
114
|
# exists only in overlay, so create a deletion overlay
|
115
|
+
deleted.append(registry[name].source_path)
|
109
116
|
gen_registry_overlay(
|
110
117
|
ctx, overlay_dir, name, registry, registry_overlay, "deletion"
|
111
118
|
)
|
@@ -116,6 +123,8 @@ def check_registry(
|
|
116
123
|
ctx, overlay_dir, name, registry, registry_overlay, "addition"
|
117
124
|
)
|
118
125
|
|
126
|
+
return deleted
|
127
|
+
|
119
128
|
|
120
129
|
def gen_registry_overlay(
|
121
130
|
ctx: Context,
|
@@ -126,15 +135,15 @@ def gen_registry_overlay(
|
|
126
135
|
type: str = "",
|
127
136
|
) -> None:
|
128
137
|
"""
|
129
|
-
Checks if two
|
130
|
-
|
131
|
-
Keyword arguments
|
132
|
-
`ctx` -- the build context
|
133
|
-
`overlay_dir` -- the directory of the generated overlay
|
134
|
-
`name` -- the name of the file
|
135
|
-
`registry` -- the namespace proxy from the build context
|
136
|
-
`registry_overlay` -- the namespace proxy from the overlay context
|
137
|
-
`type` -- either "deletion" or "addition" (default: `""`)
|
138
|
+
Checks if two files have the same contents and generate an overlay if they don't.
|
139
|
+
|
140
|
+
Keyword arguments: \n
|
141
|
+
`ctx` -- the build context \n
|
142
|
+
`overlay_dir` -- the directory of the generated overlay \n
|
143
|
+
`name` -- the name of the file \n
|
144
|
+
`registry` -- the namespace proxy from the build context \n
|
145
|
+
`registry_overlay` -- the namespace proxy from the overlay context \n
|
146
|
+
`type`(optional) -- either "deletion" or "addition" (default: `""`) \n
|
138
147
|
"""
|
139
148
|
if type == "deletion":
|
140
149
|
# move file from build pack to overlay in build pack
|
@@ -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=1XpNKUm-Hk_yCgkuoqDBACiacdZ1uf9I3C1WAHMucuE,45
|
2
|
-
beet_observer/data_pack.py,sha256=YIkMDaR1j6FU-ukC5UibCaweRQ-TEvd_w1sZZTbE5Ww,9972
|
3
|
-
beet_observer/plugin.py,sha256=mtGBtJNCiUHkSGiAoRl7li0oIlZBQ-cuDS91bubDaPs,2835
|
4
|
-
beet_observer/resource_pack.py,sha256=anQw0EdCF780j9rVMM1ycQAqQzEFpg_8I_h6T5Xoguo,6210
|
5
|
-
beet_observer-0.7.1.dist-info/LICENSE,sha256=oBbP6j7sgG9darFSRZxV7iO8yPR1aZiDspSK3mcLpXI,1062
|
6
|
-
beet_observer-0.7.1.dist-info/METADATA,sha256=_c2AXX_DL1MmeoqYuYMHpg4xWWTkhKkRuwtlid4-2zc,674
|
7
|
-
beet_observer-0.7.1.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
8
|
-
beet_observer-0.7.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|