Code cleanup and refactoring

This commit is contained in:
Tuna Celik
2020-08-17 02:14:04 +02:00
parent 5253a464ab
commit 389a6b9906
5 changed files with 41 additions and 31 deletions

View File

@@ -21,7 +21,7 @@ from http import client
from xml.etree import ElementTree as ET
from radicale import app, httputils, storage, xmlutils
from radicale.hook.rabbitmq import QueueItem, QueueItemTypes
from radicale.hook import HookNotificationItem, HookNotificationItemTypes
def xml_delete(base_prefix, path, collection, href=None):
@@ -66,10 +66,14 @@ class ApplicationDeleteMixin:
if isinstance(item, storage.BaseCollection):
xml_answer = xml_delete(base_prefix, path, item)
for item in item.get_all():
self._hook.notify(QueueItem(QueueItemTypes.DELETE, item.uid))
hook_notification_item = \
HookNotificationItem(HookNotificationItemTypes.DELETE, item.uid)
self._hook.notify(hook_notification_item)
else:
xml_answer = xml_delete(
base_prefix, path, item.collection, item.href)
self._hook.notify(QueueItem(QueueItemTypes.DELETE, item.uid))
hook_notification_item = \
HookNotificationItem(HookNotificationItemTypes.DELETE, item.uid)
self._hook.notify(hook_notification_item)
headers = {"Content-Type": "text/xml; charset=%s" % self._encoding}
return client.OK, headers, self._write_xml_content(xml_answer)

View File

@@ -29,7 +29,7 @@ from radicale import app, httputils
from radicale import item as radicale_item
from radicale import pathutils, rights, storage, xmlutils
from radicale.log import logger
from radicale.hook.rabbitmq import QueueItem, QueueItemTypes
from radicale.hook import HookNotificationItem, HookNotificationItemTypes
MIMETYPE_TAGS = {value: key for key, value in xmlutils.MIMETYPES.items()}
@@ -195,7 +195,9 @@ class ApplicationPutMixin:
etag = self._storage.create_collection(
path, prepared_items, props).etag
for item in prepared_items:
self._hook.notify(QueueItem(QueueItemTypes.UPSERT, item.serialize()))
hook_notification_item = \
HookNotificationItem(HookNotificationItemTypes.UPSERT, item.serialize())
self._hook.notify(hook_notification_item)
except ValueError as e:
logger.warning(
"Bad PUT request on %r: %s", path, e, exc_info=True)
@@ -211,7 +213,9 @@ class ApplicationPutMixin:
href = posixpath.basename(pathutils.strip_path(path))
try:
etag = parent_item.upload(href, prepared_item).etag
self._hook.notify(QueueItem(QueueItemTypes.UPSERT, prepared_item.serialize()))
hook_notification_item = \
HookNotificationItem(HookNotificationItemTypes.UPSERT, prepared_item.serialize())
self._hook.notify(hook_notification_item)
except ValueError as e:
logger.warning(
"Bad PUT request on %r: %s", path, e, exc_info=True)