Beispiel #1
0
    def load_project(self,
                     profile_context: typing.Optional[ProfileContext]) -> None:
        """Read project.

        The profile context is used during testing.
        """
        if not self.project:  # the project from the document model
            project: typing.Optional[Project.Project] = None

            # create project if it doesn't exist
            project_storage_system = self.make_storage(profile_context)
            if project_storage_system:
                project_storage_system.load_properties()
                project = Project.Project(project_storage_system)

            if project:
                self.__document_model = DocumentModel.DocumentModel(
                    project, storage_cache=self.storage_cache)

                project.prepare_read_project()  # sets up the uuid, used next.

                self.update_item_context(project)
                project.about_to_be_inserted(self)
                self.notify_property_changed(
                    "project"
                )  # before reading, so document model has a chance to set up
                project.read_project()
            else:
                logging.getLogger("loader").warning(
                    f"Project could not be loaded {self}.")
Beispiel #2
0
 def read_project_uuid(
     self,
     profile_context: typing.Optional["MemoryProfileContext"] = None
 ) -> typing.Optional[uuid.UUID]:
     project_storage_system = self.make_storage(profile_context)
     if project_storage_system:
         project_storage_system.load_properties()
         with contextlib.closing(
                 Project.Project(project_storage_system)) as project:
             project.prepare_read_project()  # sets up the uuid, used next.
             return project.uuid
     return None
Beispiel #3
0
 def read_project_info(
         self, profile_context: typing.Optional[ProfileContext]) -> None:
     if not self.__has_project_info_been_read:
         try:
             project_storage_system = self.make_storage(profile_context)
         except Exception:
             project_storage_system = None
         if project_storage_system:
             project_storage_system.load_properties()
             with contextlib.closing(
                     Project.Project(project_storage_system)) as project:
                 if self.project_uuid != project.project_uuid:
                     self.project_uuid = project.project_uuid
                 self.__project_version = project.project_version
                 self.__project_state = project.project_state
                 self.__has_project_info_been_read = True
Beispiel #4
0
    def read_project(
        self,
        existing_projects: typing.Sequence[Project.Project],
        profile_context: typing.Optional["MemoryProfileContext"] = None
    ) -> None:
        """Read the project if it is active.

        The profile context is used during testing.
        """
        assert not self.__project
        if self.is_active:
            project_storage_system = self.make_storage(profile_context)
            if project_storage_system:
                project_storage_system.load_properties()
                self.__project = Project.Project(project_storage_system)
            else:
                logging.getLogger("loader").warning(
                    f"Project could not be loaded {self}.")
            # do not allow multiple projects to load with same uuid
            existing_project_uuids = {
                project.uuid
                for project in existing_projects
            }
            if self.__project:
                self.__project.prepare_read_project(
                )  # sets up the uuid, used next.
                if not self.__project.uuid in existing_project_uuids and self.__project.uuid == self.project_uuid:
                    self.update_item_context(self.__project)
                    self.__project.about_to_be_inserted(self)
                    self.notify_property_changed(
                        "project"
                    )  # before reading, so document model has a chance to set up
                    self.__project.read_project()
                else:
                    self.__project.close()
                    self.__project = None