Added support for (De)Activation of pages and added a better error for
missing nodes
This commit is contained in:
@@ -24,6 +24,7 @@ download.jsp?path=%2Fcontent%2Fdam%2Fbeeldbank%2Fvrouw-direct-naar.jpg%2Fjcr%3Ac
|
||||
CRX_SERVER_ROOT = '/crx/server/crx.default/jcr:root/'
|
||||
CRX_QUERY = '/crx/de/query.jsp'
|
||||
WCM_REFERENCES = '/bin/wcm/references.json'
|
||||
WCM_REPLICATE = '/bin/replicate.json'
|
||||
|
||||
CREATE_ASSET = '.createasset.html'
|
||||
|
||||
@@ -40,6 +41,12 @@ class CrxException(ValueError):
|
||||
pass
|
||||
|
||||
|
||||
class CrxNodeNotFound(CrxException):
|
||||
def __init__(self, path: str, response: requests.Response):
|
||||
self.path = path
|
||||
self.response = response
|
||||
|
||||
|
||||
class Connection:
|
||||
def __init__(self,
|
||||
host: str = 'localhost',
|
||||
@@ -47,12 +54,14 @@ class Connection:
|
||||
protocol: str = 'http',
|
||||
root: str = CRX_SERVER_ROOT,
|
||||
query: str = CRX_QUERY,
|
||||
image_references: str = WCM_REFERENCES):
|
||||
image_references: str = WCM_REFERENCES,
|
||||
wcm_replicate: str = WCM_REPLICATE):
|
||||
|
||||
self._host = f'{protocol}://{host}:{port}'
|
||||
self._data_root = self._host + root
|
||||
self._query_path = self._host + query
|
||||
self._image_references = self._host + image_references
|
||||
self._wcm_replicate = self._host + wcm_replicate
|
||||
|
||||
self._session = requests.session()
|
||||
|
||||
@@ -149,6 +158,9 @@ class Connection:
|
||||
except requests.exceptions.RequestException as exception:
|
||||
raise CrxException() # todo more specific exceptions
|
||||
|
||||
if response.status_code == 404:
|
||||
raise CrxNodeNotFound(path, response)
|
||||
|
||||
try:
|
||||
data = response.json()
|
||||
except ValueError:
|
||||
@@ -168,6 +180,18 @@ class Connection:
|
||||
"""
|
||||
return SimpleNode(path, self.get_node_raw(path), self)
|
||||
|
||||
def replicate(self, path: str, deactivate: bool = False):
|
||||
"""
|
||||
Replicate a page to the publish servers
|
||||
|
||||
Args:
|
||||
path: The page to replicate
|
||||
deactivate: Deactivate instead of activate
|
||||
"""
|
||||
command = 'deactivate' if deactivate else 'activate'
|
||||
resp = self._session.post(self._wcm_replicate, files={'path': path, 'cmd': command})
|
||||
resp.raise_for_status()
|
||||
|
||||
def download_binary(self, path: str) -> bytes:
|
||||
"""
|
||||
Download the binary data of a node. (usually jcr:data).
|
||||
|
||||
Reference in New Issue
Block a user