[ADD][WIP]Odoo storage plugin : implementation of correct init, discover, lock, get META and create methods

This commit is contained in:
Fabien BOURGEOIS 2018-05-09 11:07:05 +02:00
parent 34ab776f6d
commit f23010827e
1 changed files with 70 additions and 6 deletions

View File

@ -22,20 +22,39 @@ import threading
from contextlib import contextmanager from contextlib import contextmanager
from odoorpc import ODOO from odoorpc import ODOO
from odoorpc.error import RPCError from odoorpc.error import RPCError
from radicale.storage import Collection as RadicaleCollection from radicale.storage import BaseCollection
class Collection(RadicaleCollection): class Collection(BaseCollection):
""" BaseCollection implementation for Odoo Radicale Storage """ """ BaseCollection implementation for Odoo Radicale Storage """
odoo = False odoo = False
def __init__(self, path, principal=None, folder=None, filesystem_path=None): def __init__(self, path):
""" Init function """ """ Init function """
super(Collection, self).__init__(path, principal, folder, filesystem_path)
if not self.odoo: if not self.odoo:
self.odoo_connect() self.__class__.odoo_connect()
self.odoo_init() # self.odoo_init()
attributes = path.strip('/').split('/')
self.tag = None
self.props = {}
if 'odoo-contact' in attributes:
self.tag = 'VADDRESSBOOK'
self.content_suffix = '.vcf'
self.props.update({'tag': 'VADDRESSBOOK',
'D:displayname': 'Odoo contacts',
'CR:addressbook-description': 'Contacts form your Odoo account'})
elif 'odoo-calendar' in attributes:
self.tag = 'VCALENDAR'
self.content_suffix = '.ics'
self.props.update({'tag': 'VCALENDAR',
'D:displayname': 'Odoo calendar',
'C:calendar-description': 'Events form your Odoo calendar'})
self.path = path.strip('/')
self.owner = attributes[0]
self.is_principal = len(attributes) == 0
@classmethod @classmethod
def odoo_connect(cls): def odoo_connect(cls):
@ -83,3 +102,48 @@ class Collection(RadicaleCollection):
'C:calendar-description': 'Events form your Odoo calendar'} 'C:calendar-description': 'Events form your Odoo calendar'}
self.create_collection(calendar_path, props=props) self.create_collection(calendar_path, props=props)
self.logger.info('Collection creation for Odoo Sync : %s' % calendar_path) self.logger.info('Collection creation for Odoo Sync : %s' % calendar_path)
@classmethod
@contextmanager
def acquire_lock(cls, mode, user=None):
cls.user = user
yield
@classmethod
def discover(cls, path, depth="0"):
"""Discover a list of collections under the given ``path``.
``path`` is sanitized.
If ``depth`` is "0", only the actual object under ``path`` is
returned.
If ``depth`` is anything but "0", it is considered as "1" and direct
children are included in the result.
The root collection "/" must always exist.
"""
attributes = path.strip('/').split('/') or []
if path and not cls.user:
cls.user = attributes[0]
cls.logger.warning('Discover : %s (path), %s (depth), %s (cls.user), %s (attributes)' %
(path, depth, cls.user, attributes))
yield cls(path)
contact_path = '%s/odoo-contact' % path
calendar_path = '%s/odoo-calendar' % path
yield cls(contact_path)
yield cls(calendar_path)
def get_meta(self, key=None):
"""Get metadata value for collection """
if key == 'tag':
return self.tag
return self.props.get(key)
@classmethod
def create_collection(cls, href, collection=None, props=None):
""" Create collection implementation : only warns ATM """
cls.logger.error('Attemmpt to create a new collection for %s' % href)