accsyn-python-api 3.2.3__py3-none-any.whl → 3.3.1__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.
accsyn_api/_version.py CHANGED
@@ -1,4 +1,4 @@
1
1
  # :coding: utf-8
2
2
  # :copyright: Copyright (c) 2015-2023 accsyn/HDR AB
3
3
 
4
- __version__ = "3.2.3-0"
4
+ __version__ = "3.3.1-0"
accsyn_api/session.py CHANGED
@@ -86,7 +86,7 @@ UNIQUE_ENTITY_TYPES = [
86
86
  "engine",
87
87
  "queue",
88
88
  ]
89
- # Entity types were code is unique and can be used to find the entity by code
89
+ # Entity types were code is unique and can be used to find the entity by its API identifier (code)
90
90
 
91
91
 
92
92
  class JSONEncoder(json.JSONEncoder):
@@ -124,26 +124,27 @@ class JSONDecoder(json.JSONDecoder):
124
124
  newlist.append(recursive_decode(i))
125
125
  d[key] = newlist
126
126
  elif Session._is_str(d[key]):
127
- if re.match(
128
- "^[0-9]{2,4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:" "[0-9]{2}$",
127
+ dt = None
128
+ if d[key].startswith("ObjectId:"):
129
+ d[key] = d[key].replace("ObjectId:", "") # Just treat as string
130
+ elif re.match(
131
+ "^[0-9]{2,4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}$",
129
132
  str(Session._safely_printable(d[key])),
130
133
  ):
131
134
  if len(d[key].split("-")[0]) == 4:
132
135
  dt = datetime.datetime.strptime(d[key], "%Y-%m-%dT%H:%M:%S")
133
136
  else:
134
137
  dt = datetime.datetime.strptime(d[key], "%y-%m-%dT%H:%M:%S")
135
- # Backend sends UTC, convert to local timezone
136
- dt = dt.replace(tzinfo=datetime.timezone.utc)
137
- d[key] = dt.astimezone()
138
138
  # With millis
139
139
  elif re.match(
140
- "^[0-9]{2,4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:" "[0-9]{2}:[0-9]{2}.[0-9]{3}$",
140
+ "^[0-9]{2,4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}$",
141
141
  str(Session._safely_printable(d[key])),
142
142
  ):
143
143
  if len(d[key].split("-")[0]) == 4:
144
144
  dt = datetime.datetime.strptime(d[key], "%Y-%m-%dT%H:%M:%S.%f")
145
145
  else:
146
146
  dt = datetime.datetime.strptime(d[key], "%y-%m-%dT%H:%M:%S.%f")
147
+ if dt is not None:
147
148
  # Backend sends UTC, convert to local timezone
148
149
  dt = dt.replace(tzinfo=datetime.timezone.utc)
149
150
  d[key] = dt.astimezone()
@@ -394,6 +395,7 @@ class Session(object):
394
395
  data: Union[str, Dict[str, Any], List[Dict[str, Any]]],
395
396
  entityid: Optional[str] = None,
396
397
  allow_duplicates: Optional[bool] = None,
398
+ replace_duplicates: Optional[bool] = None,
397
399
  ) -> Union[Dict[str, Any], List[Dict[str, Any]]]:
398
400
  """
399
401
  Create a new accsyn entity.
@@ -401,7 +403,8 @@ class Session(object):
401
403
  :param entitytype: The type of entity to create (job, share, acl)
402
404
  :param data: The entity data as a dictionary.
403
405
  :param entityid: For creating sub entities (tasks), this is the parent (job) id.
404
- :param allow_duplicates: (jobs and tasks) Allow duplicates to be created.
406
+ :param allow_duplicates: (jobs and tasks) Allow duplicate tasks (same uri), will ignore the provided task and retry the existing task instead.
407
+ :param replace_duplicates: (jobs and tasks) Do not retry the existing task, replace duplicate tasks (same uri) with the new one instead.
405
408
  :return: The created entity data, as dictionary.
406
409
  """
407
410
  entitytype = (entitytype or "").lower().strip()
@@ -428,7 +431,7 @@ class Session(object):
428
431
  data = dict(tasks=data)
429
432
  if entitytype == "file":
430
433
  uri = "add"
431
- if allow_duplicates is not None and entitytype in [
434
+ if entitytype in [
432
435
  "transfer",
433
436
  "compute",
434
437
  "delivery",
@@ -437,7 +440,10 @@ class Session(object):
437
440
  "job",
438
441
  "task",
439
442
  ]:
440
- data["allow_duplicates"] = allow_duplicates
443
+ if allow_duplicates is not None:
444
+ data["allow_duplicates"] = allow_duplicates
445
+ if replace_duplicates is not None:
446
+ data["replace_duplicates"] = replace_duplicates
441
447
  d = self._event(
442
448
  "POST",
443
449
  f"{entitytype}/{uri}",
@@ -574,6 +580,7 @@ class Session(object):
574
580
  def find_one(
575
581
  self,
576
582
  query: str,
583
+ entityid: Optional[str] = None,
577
584
  attributes: Optional[List[str]] = None,
578
585
  finished: Optional[bool] = None,
579
586
  inactive: Optional[bool] = None,
@@ -584,6 +591,7 @@ class Session(object):
584
591
  Return a single entity.
585
592
 
586
593
  :param query: The query, a string on accsyn query format.
594
+ :param entityid: The parent entity ID, required for sub entities "task" and "file".
587
595
  :param attributes: The attributes to return, default is to return all attributes with access.
588
596
  :param finished: (job) Search among finished/aborted jobs.
589
597
  :param inactive: (user,share) Search among inactive entities.
@@ -596,6 +604,7 @@ class Session(object):
596
604
  ), "Invalid query type supplied, must be of string type!"
597
605
  return self.find(
598
606
  query,
607
+ entityid=entityid,
599
608
  attributes=attributes,
600
609
  finished=finished,
601
610
  inactive=inactive or offline,
@@ -1530,41 +1539,116 @@ class Session(object):
1530
1539
  def get_setting(
1531
1540
  self,
1532
1541
  name: Optional[str] = None,
1533
- scope: str = 'workspace',
1534
- entity_id: Optional[str] = None,
1542
+ entitytype: str = 'workspace',
1543
+ entityid: Optional[str] = None,
1535
1544
  integration: Optional[str] = None,
1536
1545
  data: Optional[Dict[str, Any]] = None,
1537
1546
  ) -> Optional[Any]:
1538
- '''Retrive *name* setting for the given *scope* (workspace, job, share..), for optional *entity_id* or *integration* (ftrack,..)'''
1539
- evt_data = dict(scope=scope, name=name)
1540
- if entity_id:
1541
- evt_data['ident'] = entity_id
1547
+ """
1548
+ Retrive *name* setting value for the given *entitytype* (workspace, job, volume, user, queue, ...) and
1549
+ *entityid* or *integration* (ftrack,..).
1550
+
1551
+ :param name: Setting name.
1552
+ :param entitytype: Entity type (workspace, job, volume, user, queue, ...).
1553
+ :param entityid: Entity ID (None for workspace entity type).
1554
+ :param integration: Integration name (ftrack, ..).
1555
+ :param data: Additional data to include in the request.
1556
+ :return: Setting value.
1557
+ """
1558
+ evt_data = dict(entitytype=entitytype, name=name)
1542
1559
  if integration:
1543
1560
  evt_data['integration'] = integration
1544
1561
  if evt_data:
1545
1562
  evt_data['data'] = data
1546
- response = self._event("GET", "setting", evt_data)
1563
+ response = self._event("GET", "setting", evt_data, entityid=entityid)
1547
1564
  return response.get("result")
1548
1565
 
1566
+ def get_settings(
1567
+ self,
1568
+ entitytype: Optional[str] = None,
1569
+ entityid: Optional[str] = None,
1570
+ recursive: bool = False,
1571
+ upstream: bool = False,
1572
+ omit_defaults: bool = True,
1573
+ share: Optional[str] = None,
1574
+ ) -> Dict[str, Any]:
1575
+ """
1576
+ Return settings JSON for an entity.
1577
+
1578
+ :param entitytype: Optional entity type (workspace, job, volume, user, queue, ...), defaults to 'workspace'.
1579
+ :param entityid: Optional entity ID, defaults to None.
1580
+ :param recursive: Include recursive settings lookup (for share trees, etc).
1581
+ :param upstream: Include inherited/upstream/default settings.
1582
+ :param omit_defaults: Omit unchanged defaults from response.
1583
+ :param share: Optional share ID/code used by some settings lookups.
1584
+ :return: Settings as a JSON-compatible dictionary.
1585
+ """
1586
+ if entitytype:
1587
+ entitytype = entitytype.lower().strip()
1588
+ payload: Dict[str, Any] = dict(
1589
+ entitytype=entitytype,
1590
+ recursive=recursive,
1591
+ upstream=upstream,
1592
+ omit_defaults=omit_defaults,
1593
+ )
1594
+ if share:
1595
+ payload["share"] = share
1596
+ response = self._event("GET", "setting", payload, entityid=entityid)
1597
+ return cast(Dict[str, Any], response.get("result") or {})
1598
+
1549
1599
  def set_setting(
1550
1600
  self,
1601
+ entitytype: str,
1551
1602
  name: str,
1552
- value: Any,
1553
- scope: str = 'workspace',
1554
- entity_id: Optional[str] = None,
1555
- integration: Optional[str] = None,
1556
- data: Optional[Dict[str, Any]] = None,
1557
- ) -> Optional[Any]:
1558
- '''Set the setting identified by *name* to *value* for *entity_id* within *scope*.'''
1559
- evt_data = dict(scope=scope, name=name, value=value)
1560
- if entity_id:
1561
- evt_data['ident'] = entity_id
1562
- if integration:
1563
- evt_data['integration'] = integration
1564
- if evt_data:
1565
- evt_data['data'] = data
1566
- response = self._event("PUT", "setting", evt_data)
1567
- return response.get("result")
1603
+ value: any,
1604
+ entityid: Optional[str] = None,
1605
+ ) -> bool:
1606
+ """
1607
+ Set a setting for an entity.
1608
+
1609
+ .. versionchanged:: 3.2
1610
+ Simplified to a single signature: ``set_setting(entitytype, entityid, name, value)``.
1611
+ Legacy compatibility argument patterns were removed.
1612
+
1613
+ :param entitytype: Entity type (workspace, job, volume, user, queue, ...)
1614
+ :param name: Setting name.
1615
+ :param value: Setting value, must be of string type. Dictionaries are supported, but must be converted to JSON string first. Serialise dates to ISO 8601 strings.
1616
+ :param entityid: Optional entity ID (None for workspace entity type, otherwise required).
1617
+ :return: True if setting was updated.
1618
+ """
1619
+ assert 0 < len(entitytype or "") and Session._is_str(
1620
+ entitytype
1621
+ ), "Invalid entity type supplied, must be of string type!"
1622
+ assert 0 < len(name or "") and Session._is_str(name), "Invalid name supplied, must be of string type!"
1623
+ assert value is not None and isinstance(value, str), "Invalid value supplied, must be of string type!"
1624
+ entitytype = entitytype.lower().strip()
1625
+ payload: Dict[str, Any] = dict(entitytype=entitytype, name=name, value=value)
1626
+ response = self._event("PUT", "setting", payload, entityid=entityid)
1627
+ return bool(response.get("result"))
1628
+
1629
+ def delete_setting(
1630
+ self,
1631
+ entitytype: str,
1632
+ name: str,
1633
+ entityid: Optional[str] = None,
1634
+ ) -> bool:
1635
+ """
1636
+ Delete a setting for an entity.
1637
+
1638
+ :param entitytype: Entity type (workspace, job, volume, user, queue, ...)
1639
+ :param name: Setting name.
1640
+ :param entityid: Optional entity ID (None for workspace entity type, otherwise required).
1641
+ :return: True if setting was deleted.
1642
+ """
1643
+ assert 0 < len(entitytype or "") and Session._is_str(
1644
+ entitytype
1645
+ ), "Invalid entity type supplied, must be of string type!"
1646
+ assert 0 < len(name or "") and Session._is_str(name), "Invalid name supplied, must be of string type!"
1647
+ entitytype = entitytype.lower().strip()
1648
+ payload: Dict[str, Any] = dict(entitytype=entitytype, name=name)
1649
+ response = self._event("DELETE", "setting", payload, entityid=entityid)
1650
+ return bool(response.get("result"))
1651
+
1568
1652
 
1569
1653
  # Misc
1570
1654
  def get_api_key(self) -> str:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: accsyn-python-api
3
- Version: 3.2.3
3
+ Version: 3.3.1
4
4
  Summary: A Python API for accsyn programmable fast and secure data delivery software
5
5
  Home-page: https://accsyn.com
6
6
  License: Apache-2.0
@@ -31,7 +31,7 @@ Description-Content-Type: text/markdown
31
31
  # accsyn-python-api
32
32
  Official accsyn fast and secure file delivery Python API
33
33
 
34
- Python API support can be found [here](https://support.accsyn.com/workflows/python-api).
34
+ Python API support can be found [here](https://support.accsyn.com/developer/python-api).
35
35
 
36
36
 
37
37
  Changelog:
@@ -0,0 +1,8 @@
1
+ accsyn_api/__init__.py,sha256=vSGlQJ7mqd5eE2vElmJ_hnvRy61FkMqFpUXyhhVapTY,121
2
+ accsyn_api/_devtools.py,sha256=nDhD_LKrgGvJXaXxP0RRPMugOLJKMxQkjr8K4gXyOKg,848
3
+ accsyn_api/_version.py,sha256=Rb8h7-M-5CBkSuIeh1jk_0CXv51zdiyw-2QugO9fnNc,94
4
+ accsyn_api/session.py,sha256=bpOvNJFPOz47SwO2UE_tt4_AW82gk3vstKwo0dZLABM,87273
5
+ accsyn_python_api-3.3.1.dist-info/METADATA,sha256=iHzMZc1ySfce_qLRapS6sF8-p00iiA_Xy8YcPGrJ75Q,4685
6
+ accsyn_python_api-3.3.1.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
7
+ accsyn_python_api-3.3.1.dist-info/entry_points.txt,sha256=i6jv25cTq1_QzeTlRV6MYIzsyfikRe1Bk4ETWkyXVqU,50
8
+ accsyn_python_api-3.3.1.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- accsyn_api/__init__.py,sha256=vSGlQJ7mqd5eE2vElmJ_hnvRy61FkMqFpUXyhhVapTY,121
2
- accsyn_api/_devtools.py,sha256=nDhD_LKrgGvJXaXxP0RRPMugOLJKMxQkjr8K4gXyOKg,848
3
- accsyn_api/_version.py,sha256=Nm3n1tMFKQjofLlU_RQbM0p_oJ7fajVDDlq4WQS6hFY,94
4
- accsyn_api/session.py,sha256=RPC11utsqWMLhe0YPwUi9QeIKJXLBzexLoNfFZOQoqc,83231
5
- accsyn_python_api-3.2.3.dist-info/METADATA,sha256=YZOsoFck-rpLJ__FAeQL3fQ_hNvjA6ZSm6yGnFsKJTI,4685
6
- accsyn_python_api-3.2.3.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
7
- accsyn_python_api-3.2.3.dist-info/entry_points.txt,sha256=i6jv25cTq1_QzeTlRV6MYIzsyfikRe1Bk4ETWkyXVqU,50
8
- accsyn_python_api-3.2.3.dist-info/RECORD,,