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/sync.py CHANGED
@@ -1,6 +1,6 @@
1
- import os
1
+ from __future__ import annotations
2
2
 
3
- from .helpers import normalize_model_parameter
3
+ import os
4
4
 
5
5
  from . import client as raw
6
6
  from . import asset as asset_module
@@ -11,32 +11,33 @@ from . import files as files_module
11
11
  from . import shot as shot_module
12
12
  from . import task as task_module
13
13
 
14
+ from .client import KitsuClient
14
15
  from .helpers import normalize_model_parameter, validate_date_format
15
16
 
16
17
  default = raw.default_client
17
18
 
18
19
 
19
20
  def get_last_events(
20
- limit=20000,
21
- project=None,
22
- after=None,
23
- before=None,
24
- only_files=False,
25
- name=None,
26
- client=default,
27
- ):
21
+ limit: int = 20000,
22
+ project: str | dict | None = None,
23
+ after: str | None = None,
24
+ before: str | None = None,
25
+ only_files: bool = False,
26
+ name: str | None = None,
27
+ client: KitsuClient = default,
28
+ ) -> list[dict]:
28
29
  """
29
30
  Get last events that occured on the machine.
30
31
 
31
32
  Args:
32
33
  limit (int): Number of events to retrieve.
33
- project (dict/id): Get only events related to this project.
34
- after (dict/id): Get only events occuring after given date.
35
- before (dict/id): Get only events occuring before given date.
34
+ project (str / dict): Get only events related to this project.
35
+ after (str): Get only events occuring after given date.
36
+ before (str): Get only events occuring before given date.
36
37
  only_files (bool): Get only events related to files.
37
38
 
38
39
  Returns:
39
- dict: Last events matching criterions.
40
+ list[dict]: Last events matching criterions.
40
41
  """
41
42
  path = "/data/events/last"
42
43
  params = {"limit": limit, "only_files": only_files}
@@ -52,7 +53,9 @@ def get_last_events(
52
53
  return raw.get(path, params=params, client=client)
53
54
 
54
55
 
55
- def import_entities(entities, client=default):
56
+ def import_entities(
57
+ entities: list[dict], client: KitsuClient = default
58
+ ) -> list[dict]:
56
59
  """
57
60
  Import entities from another instance to target instance (keep id and audit
58
61
  dates).
@@ -61,12 +64,14 @@ def import_entities(entities, client=default):
61
64
  entities (list): Entities to import.
62
65
 
63
66
  Returns:
64
- dict: Entities created.
67
+ list[dict]: Entities created.
65
68
  """
66
69
  return raw.post("import/kitsu/entities", entities, client=client)
67
70
 
68
71
 
69
- def import_tasks(tasks, client=default):
72
+ def import_tasks(
73
+ tasks: list[dict], client: KitsuClient = default
74
+ ) -> list[dict]:
70
75
  """
71
76
  Import tasks from another instance to target instance (keep id and audit
72
77
  dates).
@@ -75,12 +80,14 @@ def import_tasks(tasks, client=default):
75
80
  tasks (list): Tasks to import.
76
81
 
77
82
  Returns:
78
- dict: Tasks created.
83
+ list[dict]: Tasks created.
79
84
  """
80
85
  return raw.post("import/kitsu/tasks", tasks, client=client)
81
86
 
82
87
 
83
- def import_entity_links(links, client=default):
88
+ def import_entity_links(
89
+ links: list[dict], client: KitsuClient = default
90
+ ) -> list[dict]:
84
91
  """
85
92
  Import enitity links from another instance to target instance (keep id and
86
93
  audit dates).
@@ -94,11 +101,14 @@ def import_entity_links(links, client=default):
94
101
  return raw.post("import/kitsu/entity-links", links, client=client)
95
102
 
96
103
 
97
- def get_model_list_diff(source_list, target_list, id_field="id"):
104
+ def get_model_list_diff(
105
+ source_list: list[dict], target_list: list[dict], id_field: str = "id"
106
+ ) -> tuple[list[dict], list[dict]]:
98
107
  """
99
108
  Args:
100
109
  source_list (list): List of models to compare.
101
110
  target_list (list): List of models for which we want a diff.
111
+ id_field (str): the model field to use as an ID for comparison.
102
112
 
103
113
  Returns:
104
114
  tuple: Two lists, one containing the missing models in the target list
@@ -120,7 +130,9 @@ def get_model_list_diff(source_list, target_list, id_field="id"):
120
130
  return (missing, unexpected)
121
131
 
122
132
 
123
- def get_link_list_diff(source_list, target_list):
133
+ def get_link_list_diff(
134
+ source_list: list[dict], target_list: list[dict]
135
+ ) -> tuple[list[dict], list[dict]]:
124
136
  """
125
137
  Args:
126
138
  source_list (list): List of links to compare.
@@ -132,7 +144,7 @@ def get_link_list_diff(source_list, target_list):
132
144
  Links are identified by their in ID and their out ID.
133
145
  """
134
146
 
135
- def get_link_key(l):
147
+ def get_link_key(l: dict) -> str:
136
148
  return l["entity_in_id"] + "-" + l["entity_out_id"]
137
149
 
138
150
  missing = []
@@ -148,7 +160,9 @@ def get_link_list_diff(source_list, target_list):
148
160
  return (missing, unexpected)
149
161
 
150
162
 
151
- def get_id_map_by_name(source_list, target_list):
163
+ def get_id_map_by_name(
164
+ source_list: list[dict], target_list: list[dict]
165
+ ) -> dict:
152
166
  """
153
167
  Args:
154
168
  source_list (list): List of links to compare.
@@ -170,7 +184,9 @@ def get_id_map_by_name(source_list, target_list):
170
184
  return link_map
171
185
 
172
186
 
173
- def get_id_map_by_id(source_list, target_list, field="name"):
187
+ def get_id_map_by_id(
188
+ source_list: list[dict], target_list: list[dict], field: str = "name"
189
+ ) -> dict:
174
190
  """
175
191
  Args:
176
192
  source_list (list): List of links to compare.
@@ -192,7 +208,7 @@ def get_id_map_by_id(source_list, target_list, field="name"):
192
208
  return link_map
193
209
 
194
210
 
195
- def is_changed(source_model, target_model):
211
+ def is_changed(source_model: dict, target_model: dict) -> bool:
196
212
  """
197
213
  Args:
198
214
  source_model (dict): Model from the source API.
@@ -207,7 +223,9 @@ def is_changed(source_model, target_model):
207
223
  return source_date > target_date
208
224
 
209
225
 
210
- def get_sync_department_id_map(source_client, target_client):
226
+ def get_sync_department_id_map(
227
+ source_client: KitsuClient, target_client: KitsuClient
228
+ ) -> dict:
211
229
  """
212
230
  Args:
213
231
  source_client (KitsuClient): client to get data from source API
@@ -221,7 +239,9 @@ def get_sync_department_id_map(source_client, target_client):
221
239
  return get_id_map_by_id(departments_source, departments_target)
222
240
 
223
241
 
224
- def get_sync_asset_type_id_map(source_client, target_client):
242
+ def get_sync_asset_type_id_map(
243
+ source_client: KitsuClient, target_client: KitsuClient
244
+ ) -> dict:
225
245
  """
226
246
  Args:
227
247
  source_client (KitsuClient): client to get data from source API
@@ -235,7 +255,9 @@ def get_sync_asset_type_id_map(source_client, target_client):
235
255
  return get_id_map_by_id(asset_types_source, asset_types_target)
236
256
 
237
257
 
238
- def get_sync_project_id_map(source_client, target_client):
258
+ def get_sync_project_id_map(
259
+ source_client: KitsuClient, target_client: KitsuClient
260
+ ) -> dict:
239
261
  """
240
262
  Args:
241
263
  source_client (KitsuClient): client to get data from source API
@@ -249,7 +271,9 @@ def get_sync_project_id_map(source_client, target_client):
249
271
  return get_id_map_by_id(projects_source, projects_target)
250
272
 
251
273
 
252
- def get_sync_task_type_id_map(source_client, target_client):
274
+ def get_sync_task_type_id_map(
275
+ source_client: KitsuClient, target_client: KitsuClient
276
+ ) -> dict:
253
277
  """
254
278
  Args:
255
279
  source_client (KitsuClient): client to get data from source API
@@ -263,7 +287,9 @@ def get_sync_task_type_id_map(source_client, target_client):
263
287
  return get_id_map_by_id(task_types_source, task_types_target)
264
288
 
265
289
 
266
- def get_sync_task_status_id_map(source_client, target_client):
290
+ def get_sync_task_status_id_map(
291
+ source_client: KitsuClient, target_client: KitsuClient
292
+ ) -> dict:
267
293
  """
268
294
  Args:
269
295
  source_client (KitsuClient): client to get data from source API
@@ -278,7 +304,9 @@ def get_sync_task_status_id_map(source_client, target_client):
278
304
  return get_id_map_by_id(task_statuses_source, task_statuses_target)
279
305
 
280
306
 
281
- def get_sync_person_id_map(source_client, target_client):
307
+ def get_sync_person_id_map(
308
+ source_client: KitsuClient, target_client: KitsuClient
309
+ ) -> dict:
282
310
  """
283
311
  Args:
284
312
  source_client (KitsuClient): client to get data from source API
@@ -292,7 +320,12 @@ def get_sync_person_id_map(source_client, target_client):
292
320
  return get_id_map_by_id(persons_source, persons_target, field="email")
293
321
 
294
322
 
295
- def push_assets(project_source, project_target, client_source, client_target):
323
+ def push_assets(
324
+ project_source: dict,
325
+ project_target: dict,
326
+ client_source: KitsuClient,
327
+ client_target: KitsuClient,
328
+ ) -> list[dict]:
296
329
  """
297
330
  Copy assets from source to target and preserve audit fields (`id`,
298
331
  `created_at`, and `updated_at`).
@@ -300,8 +333,8 @@ def push_assets(project_source, project_target, client_source, client_target):
300
333
  Args:
301
334
  project_source (dict): The project to get assets from
302
335
  project_target (dict): The project to push assets to
303
- source_client (KitsuClient): client to get data from source API
304
- target_client (KitsuClient): client to push data to target API
336
+ client_source (KitsuClient): client to get data from source API
337
+ client_target (KitsuClient): client to push data to target API
305
338
 
306
339
  Returns:
307
340
  list: Pushed assets
@@ -320,8 +353,11 @@ def push_assets(project_source, project_target, client_source, client_target):
320
353
 
321
354
 
322
355
  def push_episodes(
323
- project_source, project_target, client_source, client_target
324
- ):
356
+ project_source: dict,
357
+ project_target: dict,
358
+ client_source: KitsuClient,
359
+ client_target: KitsuClient,
360
+ ) -> list[dict]:
325
361
  """
326
362
  Copy episodes from source to target and preserve audit fields (`id`,
327
363
  `created_at`, and `updated_at`)
@@ -329,8 +365,8 @@ def push_episodes(
329
365
  Args:
330
366
  project_source (dict): The project to get episodes from
331
367
  project_target (dict): The project to push episodes to
332
- source_client (KitsuClient): client to get data from source API
333
- target_client (KitsuClient): client to push data to target API
368
+ client_source (KitsuClient): client to get data from source API
369
+ client_target (KitsuClient): client to push data to target API
334
370
 
335
371
  Returns:
336
372
  list: Pushed episodes
@@ -344,8 +380,11 @@ def push_episodes(
344
380
 
345
381
 
346
382
  def push_sequences(
347
- project_source, project_target, client_source, client_target
348
- ):
383
+ project_source: dict,
384
+ project_target: dict,
385
+ client_source: KitsuClient,
386
+ client_target: KitsuClient,
387
+ ) -> list[dict]:
349
388
  """
350
389
  Copy sequences from source to target and preserve audit fields (`id`,
351
390
  `created_at`, and `updated_at`)
@@ -353,8 +392,8 @@ def push_sequences(
353
392
  Args:
354
393
  project_source (dict): The project to get sequences from
355
394
  project_target (dict): The project to push sequences to
356
- source_client (KitsuClient): client to get data from source API
357
- target_client (KitsuClient): client to push data to target API
395
+ client_source (KitsuClient): client to get data from source API
396
+ client_target (KitsuClient): client to push data to target API
358
397
 
359
398
  Returns:
360
399
  list: Pushed sequences
@@ -367,7 +406,12 @@ def push_sequences(
367
406
  return import_entities(sequences, client=client_target)
368
407
 
369
408
 
370
- def push_shots(project_source, project_target, client_source, client_target):
409
+ def push_shots(
410
+ project_source: dict,
411
+ project_target: dict,
412
+ client_source: KitsuClient,
413
+ client_target: KitsuClient,
414
+ ) -> list[dict]:
371
415
  """
372
416
  Copy shots from source to target and preserve audit fields (`id`,
373
417
  `created_at`, and `updated_at`).
@@ -375,8 +419,8 @@ def push_shots(project_source, project_target, client_source, client_target):
375
419
  Args:
376
420
  project_source (dict): The project to get shots from
377
421
  project_target (dict): The project to push shots to
378
- source_client (KitsuClient): client to get data from source API
379
- target_client (KitsuClient): client to push data to target API
422
+ client_source (KitsuClient): client to get data from source API
423
+ client_target (KitsuClient): client to push data to target API
380
424
 
381
425
  Returns:
382
426
  list: Pushed shots
@@ -390,8 +434,11 @@ def push_shots(project_source, project_target, client_source, client_target):
390
434
 
391
435
 
392
436
  def push_entity_links(
393
- project_source, project_target, client_source, client_target
394
- ):
437
+ project_source: dict,
438
+ project_target: dict,
439
+ client_source: KitsuClient,
440
+ client_target: KitsuClient,
441
+ ) -> list[dict]:
395
442
  """
396
443
  Copy entity links (breakdown, concepts) from source to target and preserve
397
444
  audit fields (`id`, `created_at`, and `updated_at`).
@@ -399,8 +446,8 @@ def push_entity_links(
399
446
  Args:
400
447
  project_source (dict): The project to get assets from
401
448
  project_target (dict): The project to push assets to
402
- source_client (KitsuClient): client to get data from source API
403
- target_client (KitsuClient): client to push data to target API
449
+ client_source (KitsuClient): client to get data from source API
450
+ client_target (KitsuClient): client to push data to target API
404
451
 
405
452
  Returns:
406
453
  list: Pushed entity links
@@ -412,8 +459,11 @@ def push_entity_links(
412
459
 
413
460
 
414
461
  def push_project_entities(
415
- project_source, project_target, client_source, client_target
416
- ):
462
+ project_source: dict,
463
+ project_target: dict,
464
+ client_source: KitsuClient,
465
+ client_target: KitsuClient,
466
+ ) -> dict:
417
467
  """
418
468
  Copy assets, episodes, sequences, shots and entity links from source to
419
469
  target and preserve audit fields (`id`, `created_at`, and `updated_at`).
@@ -421,19 +471,29 @@ def push_project_entities(
421
471
  Args:
422
472
  project_source (dict): The project to get assets from
423
473
  project_target (dict): The project to push assets to
424
- source_client (KitsuClient): client to get data from source API
425
- target_client (KitsuClient): client to push data to target API
474
+ client_source (KitsuClient): client to get data from source API
475
+ client_target (KitsuClient): client to push data to target API
426
476
 
427
477
  Returns:
428
478
  dict: Pushed data
429
479
  """
430
- assets = push_assets(project_source, project_target)
480
+ assets = push_assets(
481
+ project_source, project_target, client_source, client_target
482
+ )
431
483
  episodes = []
432
484
  if project_source["production_type"] == "tvshow":
433
- episodes = push_episodes(project_source, project_target)
434
- sequences = push_sequences(project_source, project_target)
435
- shots = push_shots(project_source, project_target)
436
- entity_links = push_entity_links(project_source, project_target)
485
+ episodes = push_episodes(
486
+ project_source, project_target, client_source, client_target
487
+ )
488
+ sequences = push_sequences(
489
+ project_source, project_target, client_source, client_target
490
+ )
491
+ shots = push_shots(
492
+ project_source, project_target, client_source, client_target
493
+ )
494
+ entity_links = push_entity_links(
495
+ project_source, project_target, client_source, client_target
496
+ )
437
497
  return {
438
498
  "assets": assets,
439
499
  "episodes": episodes,
@@ -444,12 +504,12 @@ def push_project_entities(
444
504
 
445
505
 
446
506
  def push_tasks(
447
- project_source,
448
- project_target,
449
- default_status,
450
- client_source,
451
- client_target,
452
- ):
507
+ project_source: dict,
508
+ project_target: dict,
509
+ default_status: str | dict,
510
+ client_source: KitsuClient,
511
+ client_target: KitsuClient,
512
+ ) -> list[dict]:
453
513
  """
454
514
  Copy tasks from source to target and preserve audit fields (`id`,
455
515
  `created_at`, and `updated_at`)
@@ -458,13 +518,13 @@ def push_tasks(
458
518
  Args:
459
519
  project_source (dict): The project to get assets from
460
520
  project_target (dict): The project to push assets to
461
- source_client (KitsuClient): client to get data from source API
462
- target_client (KitsuClient): client to push data to target API
521
+ default_status (str / dict): The default status for the pushed tasks
522
+ client_source (KitsuClient): client to get data from source API
523
+ client_target (KitsuClient): client to push data to target API
463
524
 
464
525
  Returns:
465
526
  list: Pushed entity links
466
527
  """
467
-
468
528
  default_status_id = normalize_model_parameter(default_status)["id"]
469
529
  task_type_map = get_sync_task_type_id_map(client_source, client_target)
470
530
  person_map = get_sync_person_id_map(client_source, client_target)
@@ -484,7 +544,11 @@ def push_tasks(
484
544
  return import_tasks(tasks, client=client_target)
485
545
 
486
546
 
487
- def push_tasks_comments(project_source, client_source, client_target):
547
+ def push_tasks_comments(
548
+ project_source: dict,
549
+ client_source: KitsuClient,
550
+ client_target: KitsuClient,
551
+ ) -> list[dict]:
488
552
  """
489
553
  Create a new comment into target api for each comment in source project
490
554
  but preserve only `created_at` field.
@@ -492,14 +556,12 @@ def push_tasks_comments(project_source, client_source, client_target):
492
556
 
493
557
  Args:
494
558
  project_source (dict): The project to get assets from
495
- project_target (dict): The project to push assets to
496
- source_client (KitsuClient): client to get data from source API
497
- target_client (KitsuClient): client to push data to target API
559
+ client_source (KitsuClient): client to get data from source API
560
+ client_target (KitsuClient): client to push data to target API
498
561
 
499
562
  Returns:
500
563
  list: Created comments
501
564
  """
502
-
503
565
  task_status_map = get_sync_task_status_id_map(client_source, client_target)
504
566
  person_map = get_sync_person_id_map(client_source, client_target)
505
567
  tasks = task_module.all_tasks_for_project(
@@ -513,18 +575,23 @@ def push_tasks_comments(project_source, client_source, client_target):
513
575
 
514
576
 
515
577
  def push_task_comments(
516
- task_status_map, person_map, task, client_source, client_target
517
- ):
578
+ task_status_map: dict,
579
+ person_map: dict,
580
+ task: str | dict,
581
+ client_source: KitsuClient,
582
+ client_target: KitsuClient,
583
+ ) -> list[dict]:
518
584
  """
519
585
  Create a new comment into target api for each comment in source task
520
586
  but preserve only `created_at` field.
521
587
  Attachments and previews are created too.
522
588
 
523
589
  Args:
524
- project_source (dict): The project to get assets from
525
- project_target (dict): The project to push assets to
526
- source_client (KitsuClient): client to get data from source API
527
- target_client (KitsuClient): client to push data to target API
590
+ task_status_map (dict): A mapping of source TaskStatus IDs to target IDs.
591
+ person_map (dict): A mapping of source Person IDs to target IDs.
592
+ task (str / dict): The task to push comments for
593
+ client_source (KitsuClient): client to get data from source API
594
+ client_target (KitsuClient): client to push data to target API
528
595
 
529
596
  Returns:
530
597
  list: Created comments
@@ -546,28 +613,33 @@ def push_task_comments(
546
613
 
547
614
 
548
615
  def push_task_comment(
549
- task_status_map,
550
- person_map,
551
- task,
552
- comment,
553
- client_source,
554
- client_target,
555
- author_id=None,
556
- tmp_path="/tmp/zou/sync/",
557
- ):
616
+ task_status_map: dict,
617
+ person_map: dict,
618
+ task: str | dict,
619
+ comment: dict,
620
+ client_source: KitsuClient,
621
+ client_target: KitsuClient,
622
+ author_id: str | None = None,
623
+ tmp_path: str = "/tmp/zou/sync/",
624
+ ) -> dict:
558
625
  """
559
626
  Create a new comment into target api for each comment in source task
560
627
  but preserve only `created_at` field.
561
628
  Attachments and previews are created too.
562
629
 
563
630
  Args:
564
- project_source (dict): The project to get assets from
565
- project_target (dict): The project to push assets to
566
- source_client (KitsuClient): client to get data from source API
567
- target_client (KitsuClient): client to push data to target API
631
+ task_status_map (dict): A mapping of source TaskStatus IDs to target IDs.
632
+ person_map (dict): A mapping of source Person IDs to target IDs.
633
+ task (str / dict): The task to push the comment for.
634
+ comment (dict): The comment to push.
635
+ client_source (KitsuClient): client to get data from source API
636
+ client_target (KitsuClient): client to push data to target API
637
+ author_id (str): The ID of the Person to set as the comment author.
638
+ tmp_path (str): The local path on disk to download the attachment files
639
+ for syncing.
568
640
 
569
641
  Returns:
570
- list: Created comments
642
+ dict: The source comment.
571
643
  """
572
644
  attachments = []
573
645
  for attachment_id in comment["attachment_files"]:
@@ -612,9 +684,7 @@ def push_task_comment(
612
684
  )
613
685
 
614
686
  task_status = {"id": task_status_map[comment["task_status_id"]]}
615
- if author_id is not None:
616
- author_id = author_id
617
- else:
687
+ if author_id is None:
618
688
  author_id = person_map[comment["person_id"]]
619
689
  person = {"id": author_id}
620
690
 
@@ -652,11 +722,11 @@ def push_task_comment(
652
722
  return comment
653
723
 
654
724
 
655
- def convert_id_list(ids, model_map):
725
+ def convert_id_list(ids: list[str], model_map: dict) -> list:
656
726
  """
657
727
  Args:
658
728
  ids (list): Ids to convert.
659
- model_map (dict): Map matching ids to another value.c
729
+ model_map (dict): Map matching ids to another value.
660
730
 
661
731
  Returns:
662
732
  list: Ids converted through given model map.