Ayon-Python-Api 0.1.8__tar.gz → 0.1.9__tar.gz

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.
Files changed (26) hide show
  1. {ayon-python-api-0.1.8/ayon_python_api.egg-info → ayon-python-api-0.1.9}/PKG-INFO +1 -1
  2. {ayon-python-api-0.1.8 → ayon-python-api-0.1.9}/ayon_api/__init__.py +8 -0
  3. {ayon-python-api-0.1.8 → ayon-python-api-0.1.9}/ayon_api/server.py +67 -61
  4. {ayon-python-api-0.1.8 → ayon-python-api-0.1.9}/ayon_api/server_api.py +63 -3
  5. {ayon-python-api-0.1.8 → ayon-python-api-0.1.9}/ayon_api/version.py +1 -1
  6. {ayon-python-api-0.1.8 → ayon-python-api-0.1.9/ayon_python_api.egg-info}/PKG-INFO +1 -1
  7. ayon-python-api-0.1.9/ayon_python_api.egg-info/dependency_links.txt +1 -0
  8. ayon-python-api-0.1.9/ayon_python_api.egg-info/requires.txt +4 -0
  9. {ayon-python-api-0.1.8 → ayon-python-api-0.1.9}/pyproject.toml +3 -3
  10. {ayon-python-api-0.1.8 → ayon-python-api-0.1.9}/setup.py +2 -3
  11. ayon-python-api-0.1.8/ayon_python_api.egg-info/dependency_links.txt +0 -1
  12. ayon-python-api-0.1.8/ayon_python_api.egg-info/requires.txt +0 -2
  13. {ayon-python-api-0.1.8 → ayon-python-api-0.1.9}/LICENSE +0 -0
  14. {ayon-python-api-0.1.8 → ayon-python-api-0.1.9}/README.md +0 -0
  15. {ayon-python-api-0.1.8 → ayon-python-api-0.1.9}/ayon_api/constants.py +0 -0
  16. {ayon-python-api-0.1.8 → ayon-python-api-0.1.9}/ayon_api/entity_hub.py +0 -0
  17. {ayon-python-api-0.1.8 → ayon-python-api-0.1.9}/ayon_api/events.py +0 -0
  18. {ayon-python-api-0.1.8 → ayon-python-api-0.1.9}/ayon_api/exceptions.py +0 -0
  19. {ayon-python-api-0.1.8 → ayon-python-api-0.1.9}/ayon_api/graphql.py +0 -0
  20. {ayon-python-api-0.1.8 → ayon-python-api-0.1.9}/ayon_api/graphql_queries.py +0 -0
  21. {ayon-python-api-0.1.8 → ayon-python-api-0.1.9}/ayon_api/operations.py +0 -0
  22. {ayon-python-api-0.1.8 → ayon-python-api-0.1.9}/ayon_api/thumbnails.py +0 -0
  23. {ayon-python-api-0.1.8 → ayon-python-api-0.1.9}/ayon_api/utils.py +0 -0
  24. {ayon-python-api-0.1.8 → ayon-python-api-0.1.9}/ayon_python_api.egg-info/SOURCES.txt +0 -0
  25. {ayon-python-api-0.1.8 → ayon-python-api-0.1.9}/ayon_python_api.egg-info/top_level.txt +0 -0
  26. {ayon-python-api-0.1.8 → ayon-python-api-0.1.9}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ayon-python-api
3
- Version: 0.1.8
3
+ Version: 0.1.9
4
4
  Summary: AYON Python API
5
5
  Home-page: https://github.com/ynput/ayon-python-api
6
6
  Author: ynput.io
@@ -12,6 +12,10 @@ from .server_api import (
12
12
 
13
13
  init_service,
14
14
 
15
+ is_connection_created,
16
+ close_connection,
17
+ change_token,
18
+ set_environments,
15
19
  get_server_api_connection,
16
20
 
17
21
  get_base_url,
@@ -116,6 +120,10 @@ __all__ = (
116
120
  "ServiceContext",
117
121
  "init_service",
118
122
 
123
+ "is_connection_created",
124
+ "close_connection",
125
+ "change_token",
126
+ "set_environments",
119
127
  "get_server_api_connection",
120
128
 
121
129
  "get_base_url",
@@ -607,7 +607,7 @@ class ServerAPIBase(object):
607
607
  ):
608
608
  if value is not None:
609
609
  kwargs[key] = value
610
- response = self.put(
610
+ response = self.patch(
611
611
  "events/{}".format(event_id),
612
612
  **kwargs
613
613
  )
@@ -1016,8 +1016,7 @@ class ServerAPIBase(object):
1016
1016
  if details:
1017
1017
  endpoint += "?details=1"
1018
1018
  response = self.get(endpoint)
1019
- if response.status != 200:
1020
- raise ServerError(response.text)
1019
+ response.raise_for_status()
1021
1020
  return response.data
1022
1021
 
1023
1022
  def download_addon_private_file(
@@ -1233,8 +1232,7 @@ class ServerAPIBase(object):
1233
1232
  result = self.get(
1234
1233
  "addons/{}/{}/settings".format(addon_name, addon_version)
1235
1234
  )
1236
- if result.status != 200:
1237
- raise ServerError(result.text)
1235
+ result.raise_for_status()
1238
1236
  return result.data
1239
1237
 
1240
1238
  def get_addon_project_settings(
@@ -1245,8 +1243,7 @@ class ServerAPIBase(object):
1245
1243
  addon_name, addon_version, project_name
1246
1244
  )
1247
1245
  )
1248
- if result.status != 200:
1249
- raise ServerError(result.text)
1246
+ result.raise_for_status()
1250
1247
  return result.data
1251
1248
 
1252
1249
  def get_addon_settings(self, addon_name, addon_version, project_name=None):
@@ -1287,7 +1284,7 @@ class ServerAPIBase(object):
1287
1284
  returned if 'None' is passed.
1288
1285
 
1289
1286
  Returns:
1290
- List[Dict[str, Any]]: List of available projects.
1287
+ Generator[Dict[str, Any]]: Available projects.
1291
1288
  """
1292
1289
 
1293
1290
  for project_name in self.get_project_names(active, library):
@@ -1350,8 +1347,7 @@ class ServerAPIBase(object):
1350
1347
  ]))
1351
1348
 
1352
1349
  response = self.get("projects{}".format(query), **query_keys)
1353
- # TODO check status
1354
- response.status
1350
+ response.raise_for_status()
1355
1351
  data = response.data
1356
1352
  project_names = []
1357
1353
  if data:
@@ -1375,7 +1371,7 @@ class ServerAPIBase(object):
1375
1371
  on entity will have 'None' value.
1376
1372
 
1377
1373
  Returns:
1378
- List[Dict[str, Any]]: List of queried projects.
1374
+ Generator[Dict[str, Any]]: Queried projects.
1379
1375
  """
1380
1376
 
1381
1377
  if fields is None:
@@ -1484,11 +1480,11 @@ class ServerAPIBase(object):
1484
1480
  if 'None' is passed.
1485
1481
 
1486
1482
  Returns:
1487
- Iterable[dict[str, Any]]: Queried folder entities.
1483
+ Generator[dict[str, Any]]: Queried folder entities.
1488
1484
  """
1489
1485
 
1490
1486
  if not project_name:
1491
- return []
1487
+ return
1492
1488
 
1493
1489
  filters = {
1494
1490
  "projectName": project_name
@@ -1496,25 +1492,25 @@ class ServerAPIBase(object):
1496
1492
  if folder_ids is not None:
1497
1493
  folder_ids = set(folder_ids)
1498
1494
  if not folder_ids:
1499
- return []
1495
+ return
1500
1496
  filters["folderIds"] = list(folder_ids)
1501
1497
 
1502
1498
  if folder_paths is not None:
1503
1499
  folder_paths = set(folder_paths)
1504
1500
  if not folder_paths:
1505
- return []
1501
+ return
1506
1502
  filters["folderPaths"] = list(folder_paths)
1507
1503
 
1508
1504
  if folder_names is not None:
1509
1505
  folder_names = set(folder_names)
1510
1506
  if not folder_names:
1511
- return []
1507
+ return
1512
1508
  filters["folderNames"] = list(folder_names)
1513
1509
 
1514
1510
  if parent_ids is not None:
1515
1511
  parent_ids = set(parent_ids)
1516
1512
  if not parent_ids:
1517
- return []
1513
+ return
1518
1514
  if None in parent_ids:
1519
1515
  # Replace 'None' with '"root"' which is used during GraphQl
1520
1516
  # query for parent ids filter for folders without folder
@@ -1575,7 +1571,7 @@ class ServerAPIBase(object):
1575
1571
  own_attributes=False
1576
1572
  ):
1577
1573
  if not project_name:
1578
- return []
1574
+ return
1579
1575
 
1580
1576
  filters = {
1581
1577
  "projectName": project_name
@@ -1584,25 +1580,25 @@ class ServerAPIBase(object):
1584
1580
  if task_ids is not None:
1585
1581
  task_ids = set(task_ids)
1586
1582
  if not task_ids:
1587
- return []
1583
+ return
1588
1584
  filters["taskIds"] = list(task_ids)
1589
1585
 
1590
1586
  if task_names is not None:
1591
1587
  task_names = set(task_names)
1592
1588
  if not task_names:
1593
- return []
1589
+ return
1594
1590
  filters["taskNames"] = list(task_names)
1595
1591
 
1596
1592
  if task_types is not None:
1597
1593
  task_types = set(task_types)
1598
1594
  if not task_types:
1599
- return []
1595
+ return
1600
1596
  filters["taskTypes"] = list(task_types)
1601
1597
 
1602
1598
  if folder_ids is not None:
1603
1599
  folder_ids = set(folder_ids)
1604
1600
  if not folder_ids:
1605
- return []
1601
+ return
1606
1602
  filters["folderIds"] = list(folder_ids)
1607
1603
 
1608
1604
  if not fields:
@@ -1760,6 +1756,20 @@ class ServerAPIBase(object):
1760
1756
  for folder in folders
1761
1757
  }
1762
1758
 
1759
+ def _filter_subset(
1760
+ self, project_name, subset, active, own_attributes, use_rest
1761
+ ):
1762
+ if active is not None and subset["active"] is not active:
1763
+ return None
1764
+
1765
+ if use_rest:
1766
+ subset = self.get_rest_subset(project_name, subset["id"])
1767
+
1768
+ if own_attributes:
1769
+ fill_own_attribs(subset)
1770
+
1771
+ return subset
1772
+
1763
1773
  def get_subsets(
1764
1774
  self,
1765
1775
  project_name,
@@ -1772,24 +1782,24 @@ class ServerAPIBase(object):
1772
1782
  own_attributes=False
1773
1783
  ):
1774
1784
  if not project_name:
1775
- return []
1785
+ return
1776
1786
 
1777
1787
  if subset_ids is not None:
1778
1788
  subset_ids = set(subset_ids)
1779
1789
  if not subset_ids:
1780
- return []
1790
+ return
1781
1791
 
1782
1792
  filter_subset_names = None
1783
1793
  if subset_names is not None:
1784
1794
  filter_subset_names = set(subset_names)
1785
1795
  if not filter_subset_names:
1786
- return []
1796
+ return
1787
1797
 
1788
1798
  filter_folder_ids = None
1789
1799
  if folder_ids is not None:
1790
1800
  filter_folder_ids = set(folder_ids)
1791
1801
  if not filter_folder_ids:
1792
- return []
1802
+ return
1793
1803
 
1794
1804
  # This will disable 'folder_ids' and 'subset_names' filters
1795
1805
  # - maybe could be enhanced in future?
@@ -1803,7 +1813,7 @@ class ServerAPIBase(object):
1803
1813
  filter_subset_names |= set(names)
1804
1814
 
1805
1815
  if not filter_subset_names or not filter_folder_ids:
1806
- return []
1816
+ return
1807
1817
 
1808
1818
  # Convert fields and add minimum required fields
1809
1819
  if fields:
@@ -1847,35 +1857,30 @@ class ServerAPIBase(object):
1847
1857
  parsed_data = query.query(self)
1848
1858
 
1849
1859
  subsets = parsed_data.get("project", {}).get("subsets", [])
1850
- if active is not None or own_attributes:
1851
- _subsets = []
1852
- for subset in subsets:
1853
- if active is not None and subset["active"] is not active:
1854
- continue
1855
-
1856
- if use_rest:
1857
- subset = self.get_rest_subset(project_name, subset["id"])
1858
-
1859
- if own_attributes:
1860
- fill_own_attribs(subset)
1861
- _subsets.append(subset)
1862
- subsets = _subsets
1863
-
1864
1860
  # Filter subsets by 'names_by_folder_ids'
1865
1861
  if names_by_folder_ids:
1866
1862
  subsets_by_folder_id = collections.defaultdict(list)
1867
1863
  for subset in subsets:
1868
- folder_id = subset["folderId"]
1869
- subsets_by_folder_id[folder_id].append(subset)
1864
+ filtered_subset = self._filter_subset(
1865
+ project_name, subset, active, own_attributes, use_rest
1866
+ )
1867
+ if filtered_subset is not None:
1868
+ folder_id = filtered_subset["folderId"]
1869
+ subsets_by_folder_id[folder_id].append(filtered_subset)
1870
1870
 
1871
- filtered_subsets = []
1872
1871
  for folder_id, names in names_by_folder_ids.items():
1873
1872
  for folder_subset in subsets_by_folder_id[folder_id]:
1874
1873
  if folder_subset["name"] in names:
1875
- filtered_subsets.append(subset)
1876
- subsets = filtered_subsets
1874
+ yield folder_subset
1875
+
1876
+ else:
1877
+ for subset in subsets:
1878
+ filtered_subset = self._filter_subset(
1879
+ project_name, subset, active, own_attributes, use_rest
1880
+ )
1881
+ if filtered_subset is not None:
1882
+ yield filtered_subset
1877
1883
 
1878
- return list(subsets)
1879
1884
 
1880
1885
  def get_subset_by_id(
1881
1886
  self,
@@ -1972,7 +1977,7 @@ class ServerAPIBase(object):
1972
1977
  if 'None' is passed.
1973
1978
 
1974
1979
  Returns:
1975
- List[Dict[str, Any]]: Queried version entities.
1980
+ Generator[Dict[str, Any]]: Queried version entities.
1976
1981
  """
1977
1982
 
1978
1983
  if not fields:
@@ -1999,24 +2004,24 @@ class ServerAPIBase(object):
1999
2004
  if version_ids is not None:
2000
2005
  version_ids = set(version_ids)
2001
2006
  if not version_ids:
2002
- return []
2007
+ return
2003
2008
  filters["versionIds"] = list(version_ids)
2004
2009
 
2005
2010
  if subset_ids is not None:
2006
2011
  subset_ids = set(subset_ids)
2007
2012
  if not subset_ids:
2008
- return []
2013
+ return
2009
2014
  filters["subsetIds"] = list(subset_ids)
2010
2015
 
2011
2016
  # TODO versions can't be used as fitler at this moment!
2012
2017
  if versions is not None:
2013
2018
  versions = set(versions)
2014
2019
  if not versions:
2015
- return []
2020
+ return
2016
2021
  filters["versions"] = list(versions)
2017
2022
 
2018
2023
  if not hero and not standard:
2019
- return []
2024
+ return
2020
2025
 
2021
2026
  queries = []
2022
2027
  # Add filters based on 'hero' and 'standard'
@@ -2285,7 +2290,7 @@ class ServerAPIBase(object):
2285
2290
  passed.
2286
2291
 
2287
2292
  Returns:
2288
- List[Dict[str, Any]]: Queried representation entities.
2293
+ Generator[Dict[str, Any]]: Queried representation entities.
2289
2294
  """
2290
2295
 
2291
2296
  if not fields:
@@ -2310,7 +2315,7 @@ class ServerAPIBase(object):
2310
2315
  if representation_ids is not None:
2311
2316
  representation_ids = set(representation_ids)
2312
2317
  if not representation_ids:
2313
- return []
2318
+ return
2314
2319
  filters["representationIds"] = list(representation_ids)
2315
2320
 
2316
2321
  version_ids_filter = None
@@ -2323,18 +2328,18 @@ class ServerAPIBase(object):
2323
2328
  representaion_names_filter |= set(names)
2324
2329
 
2325
2330
  if not version_ids_filter or not representaion_names_filter:
2326
- return []
2331
+ return
2327
2332
 
2328
2333
  else:
2329
2334
  if representation_names is not None:
2330
2335
  representaion_names_filter = set(representation_names)
2331
2336
  if not representaion_names_filter:
2332
- return []
2337
+ return
2333
2338
 
2334
2339
  if version_ids is not None:
2335
2340
  version_ids_filter = set(version_ids)
2336
2341
  if not version_ids_filter:
2337
- return []
2342
+ return
2338
2343
 
2339
2344
  if version_ids_filter:
2340
2345
  filters["versionIds"] = list(version_ids_filter)
@@ -2459,19 +2464,19 @@ class ServerAPIBase(object):
2459
2464
  if task_ids is not None:
2460
2465
  task_ids = set(task_ids)
2461
2466
  if not task_ids:
2462
- return []
2467
+ return
2463
2468
  filters["taskIds"] = list(task_ids)
2464
2469
 
2465
2470
  if paths is not None:
2466
2471
  paths = set(paths)
2467
2472
  if not paths:
2468
- return []
2473
+ return
2469
2474
  filters["paths"] = list(paths)
2470
2475
 
2471
2476
  if workfile_ids is not None:
2472
2477
  workfile_ids = set(workfile_ids)
2473
2478
  if not workfile_ids:
2474
- return []
2479
+ return
2475
2480
  filters["workfileIds"] = list(workfile_ids)
2476
2481
 
2477
2482
  if not fields:
@@ -2849,4 +2854,5 @@ class ServerAPIBase(object):
2849
2854
  operation_id,
2850
2855
  json.dumps(body_by_id[operation_id], indent=4),
2851
2856
  op_result["error"],
2852
- ))
2857
+ ))
2858
+
@@ -68,6 +68,27 @@ class GlobalContext:
68
68
 
69
69
  _connection = None
70
70
 
71
+ @classmethod
72
+ def is_connection_created(cls):
73
+ return cls._connection is not None
74
+
75
+ @classmethod
76
+ def change_token(cls, url, token):
77
+ ServerAPI.set_environments(url, token)
78
+ if cls._connection is None:
79
+ return
80
+
81
+ if cls._connection.get_base_url() == url:
82
+ cls._connection.set_token(token)
83
+ else:
84
+ cls.close_connection()
85
+
86
+ @classmethod
87
+ def close_connection(cls):
88
+ if cls._connection is not None:
89
+ cls._connection.close_session()
90
+ cls._connection = None
91
+
71
92
  @classmethod
72
93
  def get_server_api_connection(cls):
73
94
  if cls._connection is None:
@@ -150,8 +171,7 @@ class ServiceContext:
150
171
  cls.service_name = service_name or socket.gethostname()
151
172
 
152
173
  # Make sure required environments for ServerAPI are set
153
- os.environ["AYON_SERVER_URL"] = cls.server_url
154
- os.environ["AYON_TOKEN"] = cls.token
174
+ ServerAPI.set_environments(cls.server_url, cls.token)
155
175
 
156
176
  if connect:
157
177
  print("Connecting to server \"{}\"".format(server_url))
@@ -164,6 +184,46 @@ def init_service(*args, **kwargs):
164
184
  ServiceContext.init_service(*args, **kwargs)
165
185
 
166
186
 
187
+ def is_connection_created():
188
+ """Is global connection created.
189
+
190
+ Returns:
191
+ bool: True if connection was connected.
192
+ """
193
+
194
+ return GlobalContext.is_connection_created()
195
+
196
+
197
+ def close_connection():
198
+ """Close global connection if is connected."""
199
+
200
+ GlobalContext.close_connection()
201
+
202
+
203
+ def change_token(url, token):
204
+ """Change connection token for url.
205
+
206
+ This function can be also used to change url.
207
+
208
+ Args:
209
+ url (str): Server url.
210
+ token (str): API key token.
211
+ """
212
+
213
+ GlobalContext.change_token(url, token)
214
+
215
+
216
+ def set_environments(url, token):
217
+ """Set global environments for global connection.
218
+
219
+ Args:
220
+ url (Union[str, None]): Url to server or None to unset environments.
221
+ token (Union[str, None]): API key token to be used for connection.
222
+ """
223
+
224
+ ServerAPI.set_environments(url, token)
225
+
226
+
167
227
  def get_server_api_connection():
168
228
  """Access to global scope object of ServerAPI.
169
229
 
@@ -244,7 +304,7 @@ def get_event(*args, **kwargs):
244
304
 
245
305
  def dispatch_event(*args, **kwargs):
246
306
  con = get_server_api_connection()
247
- return con.get_event(*args, **kwargs)
307
+ return con.dispatch_event(*args, **kwargs)
248
308
 
249
309
 
250
310
  def update_event(*args, **kwargs):
@@ -1,2 +1,2 @@
1
1
  """Package declaring Python API for Ayon server."""
2
- __version__ = "0.1.8"
2
+ __version__ = "0.1.9"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ayon-python-api
3
- Version: 0.1.8
3
+ Version: 0.1.9
4
4
  Summary: AYON Python API
5
5
  Home-page: https://github.com/ynput/ayon-python-api
6
6
  Author: ynput.io
@@ -0,0 +1,4 @@
1
+ requests>=2.27.1
2
+ six>=1.15
3
+ Unidecode>=1.3.6
4
+ appdirs<2,>=1
@@ -1,14 +1,14 @@
1
1
  [tool.poetry]
2
2
  name = "ayon_api"
3
- version = "0.1.8"
3
+ version = "0.1.9"
4
4
  description = "Python api for AYON server"
5
5
  authors = ["ynput.io <info@ynput.io>"]
6
6
 
7
7
  [tool.poetry.dependencies]
8
8
  requests = "^2.28.1"
9
9
  six = "^1.15"
10
- unidecode = "^1.3"
11
- appdirs = { git = "https://github.com/ActiveState/appdirs.git", branch = "master" }
10
+ Unidecode = "^1.3"
11
+ appdirs = "^1.4"
12
12
 
13
13
  [tool.poetry.dev-dependencies]
14
14
  pytest = "^5.2"
@@ -30,9 +30,8 @@ setup(
30
30
  install_requires=[
31
31
  "requests >= 2.27.1",
32
32
  "six >= 1.15",
33
- ],
34
- dependency_links=[
35
- "appdirs @ git+https://github.com/ActiveState/appdirs.git@master"
33
+ "Unidecode >= 1.3.6",
34
+ "appdirs >=1, <2",
36
35
  ],
37
36
  keywords=["AYON", "ynput", "OpenPype", "vfx"],
38
37
  )
@@ -1 +0,0 @@
1
- appdirs @ git+https://github.com/ActiveState/appdirs.git@master
@@ -1,2 +0,0 @@
1
- requests>=2.27.1
2
- six>=1.15
File without changes