Added support for (De)Activation of pages and added a better error for
missing nodes
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
from .connection import Connection
|
from .connection import Connection, CrxException, CrxNodeNotFound
|
||||||
from .simplenode import SimpleNode
|
from .simplenode import SimpleNode
|
||||||
from .util import get_simple_con
|
from .util import get_simple_con
|
||||||
|
|
||||||
__version__ = (1, 0, 0, 0)
|
__version__ = (1, 0, 0, 0)
|
||||||
|
|
||||||
__all__ = ["Connection", "SimpleNode", "get_simple_con"]
|
__all__ = ["Connection", "CrxException", "CrxNodeNotFound", "SimpleNode", "get_simple_con"]
|
||||||
|
|||||||
@@ -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_SERVER_ROOT = '/crx/server/crx.default/jcr:root/'
|
||||||
CRX_QUERY = '/crx/de/query.jsp'
|
CRX_QUERY = '/crx/de/query.jsp'
|
||||||
WCM_REFERENCES = '/bin/wcm/references.json'
|
WCM_REFERENCES = '/bin/wcm/references.json'
|
||||||
|
WCM_REPLICATE = '/bin/replicate.json'
|
||||||
|
|
||||||
CREATE_ASSET = '.createasset.html'
|
CREATE_ASSET = '.createasset.html'
|
||||||
|
|
||||||
@@ -40,6 +41,12 @@ class CrxException(ValueError):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class CrxNodeNotFound(CrxException):
|
||||||
|
def __init__(self, path: str, response: requests.Response):
|
||||||
|
self.path = path
|
||||||
|
self.response = response
|
||||||
|
|
||||||
|
|
||||||
class Connection:
|
class Connection:
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
host: str = 'localhost',
|
host: str = 'localhost',
|
||||||
@@ -47,12 +54,14 @@ class Connection:
|
|||||||
protocol: str = 'http',
|
protocol: str = 'http',
|
||||||
root: str = CRX_SERVER_ROOT,
|
root: str = CRX_SERVER_ROOT,
|
||||||
query: str = CRX_QUERY,
|
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._host = f'{protocol}://{host}:{port}'
|
||||||
self._data_root = self._host + root
|
self._data_root = self._host + root
|
||||||
self._query_path = self._host + query
|
self._query_path = self._host + query
|
||||||
self._image_references = self._host + image_references
|
self._image_references = self._host + image_references
|
||||||
|
self._wcm_replicate = self._host + wcm_replicate
|
||||||
|
|
||||||
self._session = requests.session()
|
self._session = requests.session()
|
||||||
|
|
||||||
@@ -149,6 +158,9 @@ class Connection:
|
|||||||
except requests.exceptions.RequestException as exception:
|
except requests.exceptions.RequestException as exception:
|
||||||
raise CrxException() # todo more specific exceptions
|
raise CrxException() # todo more specific exceptions
|
||||||
|
|
||||||
|
if response.status_code == 404:
|
||||||
|
raise CrxNodeNotFound(path, response)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data = response.json()
|
data = response.json()
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@@ -168,6 +180,18 @@ class Connection:
|
|||||||
"""
|
"""
|
||||||
return SimpleNode(path, self.get_node_raw(path), self)
|
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:
|
def download_binary(self, path: str) -> bytes:
|
||||||
"""
|
"""
|
||||||
Download the binary data of a node. (usually jcr:data).
|
Download the binary data of a node. (usually jcr:data).
|
||||||
|
|||||||
Reference in New Issue
Block a user