diff --git a/Crx/__init__.py b/Crx/__init__.py index 59583c3..314e0c2 100644 --- a/Crx/__init__.py +++ b/Crx/__init__.py @@ -1,7 +1,7 @@ -from .connection import Connection, CrxException, CrxNodeNotFound +from .connection import Connection, CrxException, CrxNodeNotFound, CrxCantDeleteAsset from .simplenode import SimpleNode from .util import get_simple_con __version__ = (1, 0, 0, 0) -__all__ = ["Connection", "CrxException", "CrxNodeNotFound", "SimpleNode", "get_simple_con"] +__all__ = ["Connection", "CrxException", "CrxNodeNotFound", "SimpleNode", "get_simple_con", "CrxCantDeleteAsset"] diff --git a/Crx/connection.py b/Crx/connection.py index 13b6294..e5ca877 100644 --- a/Crx/connection.py +++ b/Crx/connection.py @@ -20,6 +20,9 @@ Download: http://app30-prd-asd.sbnl.vancis.nl:4502/crx/server/crx.default/jcr:root/content/dam/beeldbank/vrouw-direct-naar.jpg/jcr:content/renditions/original/jcr:content/jcr:data OR download.jsp?path=%2Fcontent%2Fdam%2Fbeeldbank%2Fvrouw-direct-naar.jpg%2Fjcr%3Acontent%2Frenditions%2Foriginal%2Fjcr%3Acontent%2Fjcr%3Adata&index=0 + +Delete asset via trash +/bin/wcmcommand --data "path="%"2Fcontent"%"2Fdam"%"2Flandelijk"%"2Fjeugdbibliotheek15-18"%"2F615.swf&_charset_=utf-8&cmd=deletePage&force=true" """ CRX_SERVER_ROOT = '/crx/server/crx.default/jcr:root/' @@ -28,6 +31,7 @@ CRX_QUERY = '/crx/de/query.jsp' PACKMGR_EXEC = '/crx/packmgr/service/exec.json' PACKMGR_UPDATE = '/crx/packmgr/update.jsp' +WCM_COMMAND = '/bin/wcmcommand' WCM_REFERENCES = '/bin/wcm/references.json' WCM_PAGE_REFERENCES = '/libs/wcm/core/content/reference.json' WCM_REPLICATE = '/bin/replicate.json' @@ -56,6 +60,12 @@ class CrxNodeNotFound(CrxException): self.response = response +class CrxCantDeleteAsset(CrxException): + def __init__(self, response_body: str, message: str): + super(CrxCantDeleteAsset, self).__init__(message) + self.response = response_body + + class Connection: def __init__(self, host: str = 'localhost', @@ -177,6 +187,26 @@ class Connection: resp = self._session.post(url, files=files) resp.raise_for_status() + def delete_asset(self, dam_path: str, force: bool = False): + """ + Delete an asset to the trash. If force is False (default) don't delete it if it has remaining references + + Args: + dam_path: The path of the asset to delete + force: Whether or not to force delete it. + + Returns: + True when the asset has been deleted + + Raises CrxCantDeleteAsset: + When the asset can't be deleted (for example, insufficient rights or remaining references without force) + """ + url: str = self._host + WCM_COMMAND + response = self._session.post(url, data={'path': dam_path, 'cmd': 'deletePage', 'force': json.dumps(force)}) + if not response.ok: + raise CrxCantDeleteAsset(response.text, response.reason) + return True + def get_node_raw(self, path: str): """ Get the raw JSON dictionary of a node.