示例#1
0
    async def _transactions_factory(device,
                                    backend_cmds,
                                    local_storage,
                                    cls=SyncTransactions):
        def _get_workspace_entry():
            return workspace_entry

        workspace_entry = WorkspaceEntry.new("test")
        workspace_manifest = LocalWorkspaceManifest.new_placeholder(
            device.device_id, id=workspace_entry.id, now=datetime(2000, 1, 1))
        async with local_storage.lock_entry_id(workspace_entry.id):
            await local_storage.set_manifest(workspace_entry.id,
                                             workspace_manifest)

        remote_devices_manager = remote_devices_manager_factory(device)
        remote_loader = RemoteLoader(
            device,
            workspace_entry.id,
            _get_workspace_entry,
            backend_cmds,
            remote_devices_manager,
            local_storage,
        )

        return cls(
            workspace_entry.id,
            _get_workspace_entry,
            device,
            local_storage,
            remote_loader,
            event_bus,
        )
示例#2
0
    async def workspace_create(self, name: AnyEntryName) -> EntryID:
        """
        Raises: Nothing !
        """
        name = EntryName(name)
        workspace_entry = WorkspaceEntry.new(name)
        workspace_manifest = LocalWorkspaceManifest.new_placeholder(
            self.device.device_id, id=workspace_entry.id)
        async with self._update_user_manifest_lock:
            user_manifest = self.get_user_manifest()
            user_manifest = user_manifest.evolve_workspaces_and_mark_updated(
                workspace_entry)
            await self._create_workspace(workspace_entry.id,
                                         workspace_manifest)
            await self.set_user_manifest(user_manifest)
            self.event_bus.send(ClientEvent.FS_ENTRY_UPDATED,
                                id=self.user_manifest_id)
            self.event_bus.send(ClientEvent.FS_WORKSPACE_CREATED,
                                new_entry=workspace_entry)

        return workspace_entry.id