def test_static(self):
     Decsync(".tests/decsync", "sync-type", "collection",
             "app-id").set_entry(["info"], "name", "Foo")
     self.assertEqual(
         Decsync.get_static_info(".tests/decsync", "sync-type",
                                 "collection", "name"), "Foo")
     self.assertEqual(
         Decsync.get_static_info(".tests/decsync", "sync-type",
                                 "collection", "color"), None)
     self.assertEqual(
         Decsync.list_collections(".tests/decsync", "sync-type"),
         ["collection"])
     Decsync.get_app_id("app", id=12345)
     Decsync.get_app_id("app")
Example #2
0
    def __init__(self, storage_, path, filesystem_path=None):
        super().__init__(storage_, path, filesystem_path=filesystem_path)
        attributes = _get_attributes_from_path(path)
        if len(attributes) == 2:
            decsync_dir = self._storage.decsync_dir
            sync_type = attributes[1].split("-")[0]
            if sync_type not in ["contacts", "calendars", "tasks", "memos"]:
                raise RuntimeError("Unknown sync type " + sync_type)
            collection = attributes[1][len(sync_type) + 1:]
            own_app_id = Decsync.get_app_id("Radicale")
            self.decsync = Decsync(decsync_dir, sync_type, collection,
                                   own_app_id)

            def info_listener(path, datetime, key, value, extra):
                if key == "name":
                    extra._set_meta_key("D:displayname",
                                        value,
                                        update_decsync=False)
                elif key == "deleted":
                    if value:
                        extra.delete(update_decsync=False)
                elif key == "color":
                    extra._set_meta_key("ICAL:calendar-color",
                                        value,
                                        update_decsync=False)
                else:
                    raise ValueError("Unknown info key " + key)

            self.decsync.add_listener(["info"], info_listener)

            def resources_listener(path, datetime, key, value, extra):
                if len(path) != 1:
                    raise ValueError("Invalid path " + str(path))
                uid = path[0]
                href = extra.get_href(uid)
                if value is None:
                    if extra._get(href) is not None:
                        extra.delete(href, update_decsync=False)
                else:
                    vobject_item = vobject.readOne(value)
                    if sync_type == "contacts":
                        tag = "VADDRESSBOOK"
                    else:
                        tag = "VCALENDAR"
                    radicale_item.check_and_sanitize_items([vobject_item],
                                                           tag=tag)
                    item = radicale_item.Item(collection=extra,
                                              vobject_item=vobject_item,
                                              uid=uid)
                    item.prepare()
                    extra.upload(href, item, update_decsync=False)

            self.decsync.add_listener(["resources"], resources_listener)

            self.load_hrefs(sync_type)