gazu 1.0.2__py2.py3-none-any.whl → 1.1.0__py2.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.
- gazu/__version__.py +1 -1
- gazu/asset.py +157 -51
- gazu/cache.py +25 -17
- gazu/casting.py +178 -25
- gazu/client.py +124 -71
- gazu/concept.py +35 -17
- gazu/context.py +41 -15
- gazu/edit.py +36 -17
- gazu/encoder.py +3 -1
- gazu/entity.py +47 -18
- gazu/events.py +27 -22
- gazu/files.py +616 -220
- gazu/helpers.py +13 -5
- gazu/person.py +194 -86
- gazu/playlist.py +107 -53
- gazu/project.py +207 -92
- gazu/py.typed +0 -0
- gazu/scene.py +57 -17
- gazu/search.py +10 -3
- gazu/shot.py +195 -76
- gazu/sorting.py +4 -1
- gazu/sync.py +167 -97
- gazu/task.py +544 -186
- gazu/user.py +127 -63
- {gazu-1.0.2.dist-info → gazu-1.1.0.dist-info}/METADATA +2 -1
- gazu-1.1.0.dist-info/RECORD +31 -0
- gazu-1.0.2.dist-info/RECORD +0 -30
- {gazu-1.0.2.dist-info → gazu-1.1.0.dist-info}/WHEEL +0 -0
- {gazu-1.0.2.dist-info → gazu-1.1.0.dist-info}/licenses/LICENSE +0 -0
- {gazu-1.0.2.dist-info → gazu-1.1.0.dist-info}/top_level.txt +0 -0
gazu/__version__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "1.0
|
|
1
|
+
__version__ = "1.1.0"
|
gazu/asset.py
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import requests
|
|
4
|
+
|
|
1
5
|
from .helpers import normalize_model_parameter
|
|
2
6
|
|
|
3
7
|
from . import client as raw
|
|
@@ -7,13 +11,16 @@ from .sorting import sort_by_name
|
|
|
7
11
|
|
|
8
12
|
from .cache import cache
|
|
9
13
|
|
|
14
|
+
from .client import KitsuClient
|
|
15
|
+
|
|
10
16
|
from .shot import get_episode
|
|
11
17
|
|
|
18
|
+
|
|
12
19
|
default = raw.default_client
|
|
13
20
|
|
|
14
21
|
|
|
15
22
|
@cache
|
|
16
|
-
def all_assets_for_open_projects(client=default):
|
|
23
|
+
def all_assets_for_open_projects(client: KitsuClient = default) -> list[dict]:
|
|
17
24
|
"""
|
|
18
25
|
Returns:
|
|
19
26
|
list: Assets stored in the database for open projects.
|
|
@@ -25,7 +32,9 @@ def all_assets_for_open_projects(client=default):
|
|
|
25
32
|
|
|
26
33
|
|
|
27
34
|
@cache
|
|
28
|
-
def all_assets_for_project(
|
|
35
|
+
def all_assets_for_project(
|
|
36
|
+
project: str | dict, client: KitsuClient = default
|
|
37
|
+
) -> list[dict]:
|
|
29
38
|
"""
|
|
30
39
|
Args:
|
|
31
40
|
project (str / dict): The project dict or the project ID.
|
|
@@ -43,7 +52,9 @@ def all_assets_for_project(project, client=default):
|
|
|
43
52
|
|
|
44
53
|
|
|
45
54
|
@cache
|
|
46
|
-
def all_assets_for_episode(
|
|
55
|
+
def all_assets_for_episode(
|
|
56
|
+
episode: str | dict, client: KitsuClient = default
|
|
57
|
+
) -> list[dict]:
|
|
47
58
|
"""
|
|
48
59
|
Args:
|
|
49
60
|
episode (str / dict): The episode dict or the episode ID.
|
|
@@ -59,7 +70,9 @@ def all_assets_for_episode(episode, client=default):
|
|
|
59
70
|
|
|
60
71
|
|
|
61
72
|
@cache
|
|
62
|
-
def all_assets_for_shot(
|
|
73
|
+
def all_assets_for_shot(
|
|
74
|
+
shot: str | dict, client: KitsuClient = default
|
|
75
|
+
) -> list[dict]:
|
|
63
76
|
"""
|
|
64
77
|
Args:
|
|
65
78
|
shot (str / dict): The shot dict or the shot ID.
|
|
@@ -73,7 +86,9 @@ def all_assets_for_shot(shot, client=default):
|
|
|
73
86
|
|
|
74
87
|
|
|
75
88
|
@cache
|
|
76
|
-
def all_assets_for_project_and_type(
|
|
89
|
+
def all_assets_for_project_and_type(
|
|
90
|
+
project: str | dict, asset_type: str | dict, client: KitsuClient = default
|
|
91
|
+
) -> list[dict]:
|
|
77
92
|
"""
|
|
78
93
|
Args:
|
|
79
94
|
project (str / dict): The project dict or the project ID.
|
|
@@ -95,7 +110,12 @@ def all_assets_for_project_and_type(project, asset_type, client=default):
|
|
|
95
110
|
|
|
96
111
|
|
|
97
112
|
@cache
|
|
98
|
-
def get_asset_by_name(
|
|
113
|
+
def get_asset_by_name(
|
|
114
|
+
project: str | dict,
|
|
115
|
+
name: str,
|
|
116
|
+
asset_type: str | dict | None = None,
|
|
117
|
+
client: KitsuClient = default,
|
|
118
|
+
) -> dict | None:
|
|
99
119
|
"""
|
|
100
120
|
Args:
|
|
101
121
|
project (str / dict): The project dict or the project ID.
|
|
@@ -121,7 +141,7 @@ def get_asset_by_name(project, name, asset_type=None, client=default):
|
|
|
121
141
|
|
|
122
142
|
|
|
123
143
|
@cache
|
|
124
|
-
def get_asset(asset_id, client=default):
|
|
144
|
+
def get_asset(asset_id: str, client: KitsuClient = default) -> dict:
|
|
125
145
|
"""
|
|
126
146
|
Args:
|
|
127
147
|
asset_id (str): ID of claimed asset.
|
|
@@ -133,7 +153,7 @@ def get_asset(asset_id, client=default):
|
|
|
133
153
|
|
|
134
154
|
|
|
135
155
|
@cache
|
|
136
|
-
def get_asset_url(asset, client=default):
|
|
156
|
+
def get_asset_url(asset: str | dict, client: KitsuClient = default) -> str:
|
|
137
157
|
"""
|
|
138
158
|
Args:
|
|
139
159
|
asset (str / dict): The asset dict or the asset ID.
|
|
@@ -163,15 +183,15 @@ def get_asset_url(asset, client=default):
|
|
|
163
183
|
|
|
164
184
|
|
|
165
185
|
def new_asset(
|
|
166
|
-
project,
|
|
167
|
-
asset_type,
|
|
168
|
-
name,
|
|
169
|
-
description=None,
|
|
170
|
-
extra_data={},
|
|
171
|
-
episode=None,
|
|
172
|
-
is_shared=False,
|
|
173
|
-
client=default,
|
|
174
|
-
):
|
|
186
|
+
project: str | dict,
|
|
187
|
+
asset_type: str | dict,
|
|
188
|
+
name: str,
|
|
189
|
+
description: str | None = None,
|
|
190
|
+
extra_data: dict = {},
|
|
191
|
+
episode: str | dict = None,
|
|
192
|
+
is_shared: bool = False,
|
|
193
|
+
client: KitsuClient = default,
|
|
194
|
+
) -> dict:
|
|
175
195
|
"""
|
|
176
196
|
Create a new asset in the database for given project and asset type.
|
|
177
197
|
|
|
@@ -210,7 +230,7 @@ def new_asset(
|
|
|
210
230
|
return asset
|
|
211
231
|
|
|
212
232
|
|
|
213
|
-
def update_asset(asset, client=default):
|
|
233
|
+
def update_asset(asset: dict, client: KitsuClient = default) -> dict:
|
|
214
234
|
"""
|
|
215
235
|
Save given asset data into the API. It assumes that the asset already
|
|
216
236
|
exists.
|
|
@@ -223,13 +243,15 @@ def update_asset(asset, client=default):
|
|
|
223
243
|
return raw.put("data/entities/%s" % asset["id"], asset, client=client)
|
|
224
244
|
|
|
225
245
|
|
|
226
|
-
def update_asset_data(
|
|
246
|
+
def update_asset_data(
|
|
247
|
+
asset: str | dict, data: dict = {}, client: KitsuClient = default
|
|
248
|
+
) -> dict:
|
|
227
249
|
"""
|
|
228
250
|
Update the metadata for the provided asset. Keys that are not provided are
|
|
229
251
|
not changed.
|
|
230
252
|
|
|
231
253
|
Args:
|
|
232
|
-
asset (
|
|
254
|
+
asset (str / dict): The asset dict or ID to save in database.
|
|
233
255
|
data (dict): Free field to set metadata of any kind.
|
|
234
256
|
|
|
235
257
|
Returns:
|
|
@@ -242,12 +264,20 @@ def update_asset_data(asset, data={}, client=default):
|
|
|
242
264
|
return update_asset(updated_asset, client=client)
|
|
243
265
|
|
|
244
266
|
|
|
245
|
-
def remove_asset(
|
|
267
|
+
def remove_asset(
|
|
268
|
+
asset: str | dict, force: bool = False, client: KitsuClient = default
|
|
269
|
+
) -> str:
|
|
246
270
|
"""
|
|
247
271
|
Remove given asset from database.
|
|
248
272
|
|
|
273
|
+
If the Asset has tasks linked to it, this will by default mark the
|
|
274
|
+
Asset as canceled. Deletion can be forced regardless of task links
|
|
275
|
+
with the `force` parameter.
|
|
276
|
+
|
|
249
277
|
Args:
|
|
250
|
-
asset (dict): Asset to remove.
|
|
278
|
+
asset (str / dict): Asset to remove.
|
|
279
|
+
force (bool): Whether to force deletion of the asset regardless of
|
|
280
|
+
whether it has links to tasks.
|
|
251
281
|
"""
|
|
252
282
|
asset = normalize_model_parameter(asset)
|
|
253
283
|
path = "data/assets/%s" % asset["id"]
|
|
@@ -258,7 +288,7 @@ def remove_asset(asset, force=False, client=default):
|
|
|
258
288
|
|
|
259
289
|
|
|
260
290
|
@cache
|
|
261
|
-
def all_asset_types(client=default):
|
|
291
|
+
def all_asset_types(client: KitsuClient = default) -> list[dict]:
|
|
262
292
|
"""
|
|
263
293
|
Returns:
|
|
264
294
|
list: Asset types stored in the database.
|
|
@@ -267,7 +297,9 @@ def all_asset_types(client=default):
|
|
|
267
297
|
|
|
268
298
|
|
|
269
299
|
@cache
|
|
270
|
-
def all_asset_types_for_project(
|
|
300
|
+
def all_asset_types_for_project(
|
|
301
|
+
project: str | dict, client: KitsuClient = default
|
|
302
|
+
) -> list[dict]:
|
|
271
303
|
"""
|
|
272
304
|
Args:
|
|
273
305
|
project (str / dict): The project dict or the project ID.
|
|
@@ -281,7 +313,9 @@ def all_asset_types_for_project(project, client=default):
|
|
|
281
313
|
|
|
282
314
|
|
|
283
315
|
@cache
|
|
284
|
-
def all_asset_types_for_shot(
|
|
316
|
+
def all_asset_types_for_shot(
|
|
317
|
+
shot: str | dict, client: KitsuClient = default
|
|
318
|
+
) -> list[dict]:
|
|
285
319
|
"""
|
|
286
320
|
Args:
|
|
287
321
|
shot (str / dict): The shot dict or the shot ID.
|
|
@@ -294,10 +328,10 @@ def all_asset_types_for_shot(shot, client=default):
|
|
|
294
328
|
|
|
295
329
|
|
|
296
330
|
@cache
|
|
297
|
-
def get_asset_type(asset_type_id, client=default):
|
|
331
|
+
def get_asset_type(asset_type_id: str, client: KitsuClient = default) -> dict:
|
|
298
332
|
"""
|
|
299
333
|
Args:
|
|
300
|
-
asset_type_id (str
|
|
334
|
+
asset_type_id (str): ID of claimed asset type.
|
|
301
335
|
|
|
302
336
|
Returns:
|
|
303
337
|
dict: Asset Type matching given ID.
|
|
@@ -307,26 +341,30 @@ def get_asset_type(asset_type_id, client=default):
|
|
|
307
341
|
|
|
308
342
|
|
|
309
343
|
@cache
|
|
310
|
-
def get_asset_type_by_name(
|
|
344
|
+
def get_asset_type_by_name(
|
|
345
|
+
name: str, client: KitsuClient = default
|
|
346
|
+
) -> dict | None:
|
|
311
347
|
"""
|
|
312
348
|
Args:
|
|
313
349
|
name (str): name of asset type.
|
|
314
350
|
|
|
315
351
|
Returns:
|
|
316
|
-
dict: Asset Type matching given name
|
|
352
|
+
dict | None: Asset Type matching given name, or None if no asset type
|
|
353
|
+
exists with that name.
|
|
317
354
|
"""
|
|
318
355
|
return raw.fetch_first("entity-types", {"name": name}, client=client)
|
|
319
356
|
|
|
320
357
|
|
|
321
|
-
def new_asset_type(name, client=default):
|
|
358
|
+
def new_asset_type(name: str, client: KitsuClient = default) -> dict:
|
|
322
359
|
"""
|
|
323
|
-
Create a new asset type in the database
|
|
360
|
+
Create a new asset type in the database, or return the existing asset
|
|
361
|
+
type if one already exists with that name.
|
|
324
362
|
|
|
325
363
|
Args:
|
|
326
364
|
name (str): The name of asset type to create.
|
|
327
365
|
|
|
328
366
|
Returns:
|
|
329
|
-
(dict):
|
|
367
|
+
(dict): The created (or already existing) asset type.
|
|
330
368
|
"""
|
|
331
369
|
data = {"name": name}
|
|
332
370
|
asset_type = raw.fetch_first("entity-types", {"name": name}, client=client)
|
|
@@ -335,7 +373,7 @@ def new_asset_type(name, client=default):
|
|
|
335
373
|
return asset_type
|
|
336
374
|
|
|
337
375
|
|
|
338
|
-
def update_asset_type(asset_type, client=default):
|
|
376
|
+
def update_asset_type(asset_type: dict, client: KitsuClient = default) -> dict:
|
|
339
377
|
"""
|
|
340
378
|
Save given asset type data into the API. It assumes that the asset type
|
|
341
379
|
already exists.
|
|
@@ -348,12 +386,14 @@ def update_asset_type(asset_type, client=default):
|
|
|
348
386
|
return raw.put(path, data, client=client)
|
|
349
387
|
|
|
350
388
|
|
|
351
|
-
def remove_asset_type(
|
|
389
|
+
def remove_asset_type(
|
|
390
|
+
asset_type: str | dict, client: KitsuClient = default
|
|
391
|
+
) -> str:
|
|
352
392
|
"""
|
|
353
393
|
Remove given asset type from database.
|
|
354
394
|
|
|
355
395
|
Args:
|
|
356
|
-
asset_type (dict): Asset type to remove.
|
|
396
|
+
asset_type (str / dict): Asset type to remove.
|
|
357
397
|
"""
|
|
358
398
|
asset_type = normalize_model_parameter(asset_type)
|
|
359
399
|
path = "data/asset-types/%s" % asset_type["id"]
|
|
@@ -361,7 +401,9 @@ def remove_asset_type(asset_type, client=default):
|
|
|
361
401
|
|
|
362
402
|
|
|
363
403
|
@cache
|
|
364
|
-
def get_asset_instance(
|
|
404
|
+
def get_asset_instance(
|
|
405
|
+
asset_instance_id: str, client: KitsuClient = default
|
|
406
|
+
) -> dict:
|
|
365
407
|
"""
|
|
366
408
|
Args:
|
|
367
409
|
asset_instance_id (str): ID of claimed asset instance.
|
|
@@ -373,7 +415,9 @@ def get_asset_instance(asset_instance_id, client=default):
|
|
|
373
415
|
|
|
374
416
|
|
|
375
417
|
@cache
|
|
376
|
-
def all_shot_asset_instances_for_asset(
|
|
418
|
+
def all_shot_asset_instances_for_asset(
|
|
419
|
+
asset: str | dict, client: KitsuClient = default
|
|
420
|
+
) -> list[dict]:
|
|
377
421
|
"""
|
|
378
422
|
Args:
|
|
379
423
|
asset (str / dict): The asset dict or the asset ID.
|
|
@@ -386,7 +430,9 @@ def all_shot_asset_instances_for_asset(asset, client=default):
|
|
|
386
430
|
return raw.fetch_all(path, client=client)
|
|
387
431
|
|
|
388
432
|
|
|
389
|
-
def enable_asset_instance(
|
|
433
|
+
def enable_asset_instance(
|
|
434
|
+
asset_instance: str | dict, client: KitsuClient = default
|
|
435
|
+
) -> dict:
|
|
390
436
|
"""
|
|
391
437
|
Set active flag of given asset instance to True.
|
|
392
438
|
|
|
@@ -399,7 +445,9 @@ def enable_asset_instance(asset_instance, client=default):
|
|
|
399
445
|
return raw.put(path, data, client=client)
|
|
400
446
|
|
|
401
447
|
|
|
402
|
-
def disable_asset_instance(
|
|
448
|
+
def disable_asset_instance(
|
|
449
|
+
asset_instance: str | dict, client: KitsuClient = default
|
|
450
|
+
) -> dict:
|
|
403
451
|
"""
|
|
404
452
|
Set active flag of given asset instance to False.
|
|
405
453
|
|
|
@@ -413,7 +461,9 @@ def disable_asset_instance(asset_instance, client=default):
|
|
|
413
461
|
|
|
414
462
|
|
|
415
463
|
@cache
|
|
416
|
-
def all_scene_asset_instances_for_asset(
|
|
464
|
+
def all_scene_asset_instances_for_asset(
|
|
465
|
+
asset: str | dict, client: KitsuClient = default
|
|
466
|
+
) -> list[str]:
|
|
417
467
|
"""
|
|
418
468
|
Args:
|
|
419
469
|
asset (str / dict): The asset dict or the asset ID.
|
|
@@ -427,7 +477,9 @@ def all_scene_asset_instances_for_asset(asset, client=default):
|
|
|
427
477
|
|
|
428
478
|
|
|
429
479
|
@cache
|
|
430
|
-
def all_asset_instances_for_shot(
|
|
480
|
+
def all_asset_instances_for_shot(
|
|
481
|
+
shot: str | dict, client: KitsuClient = default
|
|
482
|
+
) -> list[str]:
|
|
431
483
|
"""
|
|
432
484
|
Args:
|
|
433
485
|
shot (str / dict): The shot dict or the shot ID.
|
|
@@ -440,7 +492,9 @@ def all_asset_instances_for_shot(shot, client=default):
|
|
|
440
492
|
|
|
441
493
|
|
|
442
494
|
@cache
|
|
443
|
-
def all_asset_instances_for_asset(
|
|
495
|
+
def all_asset_instances_for_asset(
|
|
496
|
+
asset: str | dict, client: KitsuClient = default
|
|
497
|
+
) -> list[str]:
|
|
444
498
|
"""
|
|
445
499
|
Args:
|
|
446
500
|
asset (str / dict): The asset dict or the asset ID.
|
|
@@ -454,15 +508,18 @@ def all_asset_instances_for_asset(asset, client=default):
|
|
|
454
508
|
|
|
455
509
|
|
|
456
510
|
def new_asset_asset_instance(
|
|
457
|
-
asset
|
|
458
|
-
|
|
511
|
+
asset: str | dict,
|
|
512
|
+
asset_to_instantiate: str | dict,
|
|
513
|
+
description: str | None = None,
|
|
514
|
+
client: KitsuClient = default,
|
|
515
|
+
) -> dict:
|
|
459
516
|
"""
|
|
460
517
|
Creates a new asset instance for given asset. The instance number is
|
|
461
518
|
automatically generated (increment highest number).
|
|
462
519
|
|
|
463
520
|
Args:
|
|
464
521
|
asset (str / dict): The asset dict or the shot ID.
|
|
465
|
-
|
|
522
|
+
asset_to_instantiate (str / dict): The asset instance dict or ID.
|
|
466
523
|
description (str): Additional information (optional)
|
|
467
524
|
|
|
468
525
|
Returns:
|
|
@@ -482,7 +539,21 @@ def new_asset_asset_instance(
|
|
|
482
539
|
)
|
|
483
540
|
|
|
484
541
|
|
|
485
|
-
def import_assets_with_csv(
|
|
542
|
+
def import_assets_with_csv(
|
|
543
|
+
project: str | dict, csv_file_path: str, client: KitsuClient = default
|
|
544
|
+
) -> list[dict]:
|
|
545
|
+
"""
|
|
546
|
+
Import the Assets from a previously exported CSV file into the given
|
|
547
|
+
project.
|
|
548
|
+
|
|
549
|
+
Args:
|
|
550
|
+
project (str | dict): The project to import the Assets into, as an ID
|
|
551
|
+
string or model dict.
|
|
552
|
+
csv_file_path (str): The path on disk to the CSV file.
|
|
553
|
+
|
|
554
|
+
Returns:
|
|
555
|
+
list[dict]: the Asset dicts created by the import.
|
|
556
|
+
"""
|
|
486
557
|
project = normalize_model_parameter(project)
|
|
487
558
|
return raw.upload(
|
|
488
559
|
"import/csv/projects/%s/assets" % project["id"],
|
|
@@ -492,8 +563,33 @@ def import_assets_with_csv(project, csv_file_path, client=default):
|
|
|
492
563
|
|
|
493
564
|
|
|
494
565
|
def export_assets_with_csv(
|
|
495
|
-
project
|
|
496
|
-
|
|
566
|
+
project: str | dict,
|
|
567
|
+
csv_file_path: str,
|
|
568
|
+
episode: str | dict | None = None,
|
|
569
|
+
assigned_to: str | dict | None = None,
|
|
570
|
+
client: KitsuClient = default,
|
|
571
|
+
) -> requests.Response:
|
|
572
|
+
"""
|
|
573
|
+
Export the Assets data for a project to a CSV file on disk.
|
|
574
|
+
|
|
575
|
+
Args:
|
|
576
|
+
project (str | dict):
|
|
577
|
+
The ID or dict for the project to export.
|
|
578
|
+
csv_file_path (str):
|
|
579
|
+
The path on disk to write the file to. If the path already exists
|
|
580
|
+
it will be overwritten.
|
|
581
|
+
episode (str | dict | None):
|
|
582
|
+
Only export Assets that are linked to the given Episode, which can
|
|
583
|
+
be provided as an ID string or model dict. If None, all assets will
|
|
584
|
+
be exported.
|
|
585
|
+
assigned_to (str | dict | None):
|
|
586
|
+
Only export Assets that have one or more Tasks assigned to the
|
|
587
|
+
given Person, specified as an ID string or model dict. If None,
|
|
588
|
+
no filtering is put in place.
|
|
589
|
+
|
|
590
|
+
Returns:
|
|
591
|
+
(requests.Response): the response from the API server.
|
|
592
|
+
"""
|
|
497
593
|
project = normalize_model_parameter(project)
|
|
498
594
|
episode = normalize_model_parameter(episode)
|
|
499
595
|
assigned_to = normalize_model_parameter(assigned_to)
|
|
@@ -511,13 +607,21 @@ def export_assets_with_csv(
|
|
|
511
607
|
|
|
512
608
|
|
|
513
609
|
@cache
|
|
514
|
-
def get_episode_from_asset(
|
|
610
|
+
def get_episode_from_asset(
|
|
611
|
+
asset: dict, client: KitsuClient = default
|
|
612
|
+
) -> dict | None:
|
|
515
613
|
"""
|
|
614
|
+
Return the Episode that the given Asset is linked to.
|
|
615
|
+
|
|
616
|
+
If the Asset isn't linked to a particular Episode (i.e it's part of the
|
|
617
|
+
"Main Pack"), None will be returned.
|
|
618
|
+
|
|
516
619
|
Args:
|
|
517
620
|
asset (dict): The asset dict.
|
|
518
621
|
|
|
519
622
|
Returns:
|
|
520
|
-
dict: Episode which is parent of given asset
|
|
623
|
+
dict: Episode which is parent of given asset, or None if not part of
|
|
624
|
+
an episode.
|
|
521
625
|
"""
|
|
522
626
|
if asset["parent_id"] is None:
|
|
523
627
|
return None
|
|
@@ -526,7 +630,9 @@ def get_episode_from_asset(asset, client=default):
|
|
|
526
630
|
|
|
527
631
|
|
|
528
632
|
@cache
|
|
529
|
-
def get_asset_type_from_asset(
|
|
633
|
+
def get_asset_type_from_asset(
|
|
634
|
+
asset: dict, client: KitsuClient = default
|
|
635
|
+
) -> dict:
|
|
530
636
|
"""
|
|
531
637
|
Args:
|
|
532
638
|
asset (dict): The asset dict.
|
gazu/cache.py
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
1
3
|
import copy
|
|
2
4
|
import datetime
|
|
3
5
|
import json
|
|
4
6
|
|
|
5
7
|
from functools import wraps
|
|
8
|
+
from typing import Any, Callable
|
|
9
|
+
from typing_extensions import Literal # Python 3.7 compatibility.
|
|
6
10
|
|
|
7
11
|
cache_settings = {"enabled": False}
|
|
8
12
|
cached_functions = []
|
|
9
13
|
|
|
10
14
|
|
|
11
|
-
def enable():
|
|
15
|
+
def enable() -> Literal[True]:
|
|
12
16
|
"""
|
|
13
17
|
Enable caching on all decorated functions.
|
|
14
18
|
"""
|
|
@@ -16,7 +20,7 @@ def enable():
|
|
|
16
20
|
return cache_settings["enabled"]
|
|
17
21
|
|
|
18
22
|
|
|
19
|
-
def disable():
|
|
23
|
+
def disable() -> Literal[False]:
|
|
20
24
|
"""
|
|
21
25
|
Disable caching on all decorated functions.
|
|
22
26
|
"""
|
|
@@ -24,7 +28,7 @@ def disable():
|
|
|
24
28
|
return cache_settings["enabled"]
|
|
25
29
|
|
|
26
30
|
|
|
27
|
-
def clear_all():
|
|
31
|
+
def clear_all() -> None:
|
|
28
32
|
"""
|
|
29
33
|
Clear all cached functions.
|
|
30
34
|
"""
|
|
@@ -32,7 +36,7 @@ def clear_all():
|
|
|
32
36
|
function.clear_cache()
|
|
33
37
|
|
|
34
38
|
|
|
35
|
-
def remove_oldest_entry(memo, maxsize):
|
|
39
|
+
def remove_oldest_entry(memo: dict, maxsize: int) -> Any:
|
|
36
40
|
"""
|
|
37
41
|
Remove the oldest cache entry if there is more value stored than allowed.
|
|
38
42
|
|
|
@@ -54,7 +58,7 @@ def remove_oldest_entry(memo, maxsize):
|
|
|
54
58
|
return oldest_entry
|
|
55
59
|
|
|
56
60
|
|
|
57
|
-
def get_cache_key(args, kwargs):
|
|
61
|
+
def get_cache_key(args: Any, kwargs: Any) -> str:
|
|
58
62
|
"""
|
|
59
63
|
Serialize arguments to get a cache key. It will be used to store function
|
|
60
64
|
results.
|
|
@@ -75,7 +79,9 @@ def get_cache_key(args, kwargs):
|
|
|
75
79
|
return json.dumps([args, kwargscopy])
|
|
76
80
|
|
|
77
81
|
|
|
78
|
-
def insert_value(
|
|
82
|
+
def insert_value(
|
|
83
|
+
function: Callable, cache_store: dict, args: Any, kwargs: Any
|
|
84
|
+
) -> Any:
|
|
79
85
|
"""
|
|
80
86
|
Serialize function call arguments and store function result in given cache
|
|
81
87
|
store.
|
|
@@ -97,7 +103,7 @@ def insert_value(function, cache_store, args, kwargs):
|
|
|
97
103
|
return get_value(cache_store, key)
|
|
98
104
|
|
|
99
105
|
|
|
100
|
-
def get_value(cache_store, key):
|
|
106
|
+
def get_value(cache_store: dict, key: str) -> Any:
|
|
101
107
|
"""
|
|
102
108
|
It generates a deep copy of the requested value. It's needed because if a
|
|
103
109
|
pointer is returned, the value can be changed. Which leads to a modified
|
|
@@ -110,7 +116,7 @@ def get_value(cache_store, key):
|
|
|
110
116
|
return copy.deepcopy(value)
|
|
111
117
|
|
|
112
118
|
|
|
113
|
-
def is_cache_enabled(state):
|
|
119
|
+
def is_cache_enabled(state: dict) -> bool:
|
|
114
120
|
"""
|
|
115
121
|
Args:
|
|
116
122
|
state: The state describing the cache state.
|
|
@@ -121,7 +127,7 @@ def is_cache_enabled(state):
|
|
|
121
127
|
return cache_settings["enabled"] and state["enabled"]
|
|
122
128
|
|
|
123
129
|
|
|
124
|
-
def is_cache_expired(memo, state, key):
|
|
130
|
+
def is_cache_expired(memo: dict, state: dict, key: str) -> bool:
|
|
125
131
|
"""
|
|
126
132
|
Check if cache is expired (outdated) for given wrapper state and cache key.
|
|
127
133
|
|
|
@@ -140,7 +146,9 @@ def is_cache_expired(memo, state, key):
|
|
|
140
146
|
return expire > 0 and date_to_check < datetime.datetime.now()
|
|
141
147
|
|
|
142
148
|
|
|
143
|
-
def cache(
|
|
149
|
+
def cache(
|
|
150
|
+
function: Callable, maxsize: int = 300, expire: int = 120
|
|
151
|
+
) -> Callable:
|
|
144
152
|
"""
|
|
145
153
|
Decorator that generate cache wrapper and that adds cache feature to
|
|
146
154
|
target function. A max cache size and and expiration time (in seconds) can
|
|
@@ -156,10 +164,10 @@ def cache(function, maxsize=300, expire=120):
|
|
|
156
164
|
|
|
157
165
|
statistics = {"hits": 0, "misses": 0, "expired_hits": 0}
|
|
158
166
|
|
|
159
|
-
def clear_cache():
|
|
167
|
+
def clear_cache() -> None:
|
|
160
168
|
cache_store.clear()
|
|
161
169
|
|
|
162
|
-
def get_cache_infos():
|
|
170
|
+
def get_cache_infos() -> dict:
|
|
163
171
|
size = {"current_size": len(cache_store)}
|
|
164
172
|
infos = {}
|
|
165
173
|
for d in [state, statistics, size]:
|
|
@@ -167,20 +175,20 @@ def cache(function, maxsize=300, expire=120):
|
|
|
167
175
|
|
|
168
176
|
return infos
|
|
169
177
|
|
|
170
|
-
def set_expire(new_expire):
|
|
178
|
+
def set_expire(new_expire: int) -> None:
|
|
171
179
|
state["expire"] = new_expire
|
|
172
180
|
|
|
173
|
-
def set_max_size(maxsize):
|
|
181
|
+
def set_max_size(maxsize: int) -> None:
|
|
174
182
|
state["maxsize"] = maxsize
|
|
175
183
|
|
|
176
|
-
def enable_cache():
|
|
184
|
+
def enable_cache() -> None:
|
|
177
185
|
state["enabled"] = True
|
|
178
186
|
|
|
179
|
-
def disable_cache():
|
|
187
|
+
def disable_cache() -> None:
|
|
180
188
|
state["enabled"] = False
|
|
181
189
|
|
|
182
190
|
@wraps(function)
|
|
183
|
-
def wrapper(*args, **kwargs):
|
|
191
|
+
def wrapper(*args: Any, **kwargs: Any) -> Any:
|
|
184
192
|
if is_cache_enabled(state):
|
|
185
193
|
key = get_cache_key(args, kwargs)
|
|
186
194
|
|