示例#1
0
    def discover(self,
                 path,
                 depth="0",
                 child_context_manager=(
                     lambda path, href=None: contextlib.ExitStack())):
        collections = list(super().discover(path, depth,
                                            child_context_manager))
        for collection in collections:
            yield collection

        if depth == "0":
            return

        attributes = _get_attributes_from_path(path)

        if len(attributes) == 0:
            return
        elif len(attributes) == 1:
            username = attributes[0]
            known_paths = [collection.path for collection in collections]
            for sync_type in ["contacts", "calendars", "tasks", "memos"]:
                for collection in Decsync.list_collections(
                        self.decsync_dir, sync_type):
                    child_path = "/%s/%s-%s/" % (username, sync_type,
                                                 collection)
                    if pathutils.strip_path(child_path) in known_paths:
                        continue
                    if Decsync.get_static_info(self.decsync_dir, sync_type,
                                               collection, "deleted") == True:
                        continue

                    props = {}
                    if sync_type == "contacts":
                        props["tag"] = "VADDRESSBOOK"
                    else:
                        props["tag"] = "VCALENDAR"
                        if sync_type == "calendars":
                            props[
                                "C:supported-calendar-component-set"] = "VEVENT"
                        elif sync_type == "tasks":
                            props[
                                "C:supported-calendar-component-set"] = "VTODO"
                        elif sync_type == "memos":
                            props[
                                "C:supported-calendar-component-set"] = "VJOURNAL"
                        else:
                            raise RuntimeError("Unknown sync type " +
                                               sync_type)
                    child = super().create_collection(child_path, props=props)
                    child.decsync.init_stored_entries()
                    child.decsync.execute_stored_entries_for_path_exact(
                        ["info"], child)
                    child.decsync.execute_stored_entries_for_path_prefix(
                        ["resources"], child)
                    yield child
        elif len(attributes) == 2:
            return
        else:
            raise ValueError("Invalid number of attributes")
 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")
示例#3
0
    def discover(cls, path, depth="0"):
        collections = list(super().discover(path, depth))
        for collection in collections:
            yield collection

        if depth == "0":
            return

        attributes = _get_attributes_from_path(path)

        if len(attributes) == 0:
            return
        elif len(attributes) == 1:
            known_paths = [collection.path for collection in collections]
            for sync_type in ["contacts", "calendars"]:
                for collection in Decsync.list_collections(
                        cls.decsync_dir, sync_type):
                    child_path = storage.sanitize_path(path + "/" + sync_type +
                                                       "-" +
                                                       collection).strip("/")
                    if child_path in known_paths:
                        continue
                    if Decsync.get_static_info(cls.decsync_dir, sync_type,
                                               collection, "deleted") == True:
                        continue

                    props = {}
                    if sync_type == "contacts":
                        props["tag"] = "VADDRESSBOOK"
                    elif sync_type == "calendars":
                        props["tag"] = "VCALENDAR"
                        props["C:supported-calendar-component-set"] = "VEVENT"
                    else:
                        raise RuntimeError("Unknown sync type " + sync_type)
                    child = super().create_collection(child_path, props=props)
                    child.decsync.init_stored_entries()
                    child.decsync.execute_stored_entries_for_path(["info"],
                                                                  child)
                    child.decsync.execute_stored_entries_for_path(
                        ["resources"], child)
                    yield child
        elif len(attributes) == 2:
            return
        else:
            raise ValueError("Invalid number of attributes")