Skip to content

Commit

Permalink
Improve handling disconnected wrt models
Browse files Browse the repository at this point in the history
Workspaces and workspace models are refreshed each time we get to
disconnected state.
  • Loading branch information
pieterhijma committed Sep 30, 2024
1 parent 9cabe9d commit 90a1765
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 44 deletions.
13 changes: 0 additions & 13 deletions Workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ def roleNames(self):

def upload(self, fileName, fileId=None, message=""):
# Default action is to not upload anything
logger.debug("WorkspaceModel.upload()")
pass

def isEmptyDirectory(self, index):
Expand Down Expand Up @@ -286,7 +285,6 @@ def getFileNames(self):
return [fi.name for fi in localDirs + localFiles]

def createDir(self, dir):
logger.debug("WorkspaceModel.createDir()")
fullPath = Utils.joinPath(self.getFullPath(), dir)
if not os.path.exists(fullPath):
os.makedirs(fullPath)
Expand Down Expand Up @@ -405,7 +403,6 @@ def refreshModel(self, firstCall=True):
that reflect the status of the server and local file system.
"""
logger.debug("ServerWorkspaceModel.refreshModel()")

self.clearModel()

Expand Down Expand Up @@ -474,7 +471,6 @@ def updateFileNotFound(localFileItem):
# self.uploadUntrackedFiles()

def data(self, index, role=Qt.DisplayRole):
# logger.debug("ServerWorkspaceModel.data()")
if not index.isValid():
return None
file_item = self.files[index.row()]
Expand Down Expand Up @@ -524,18 +520,14 @@ def getServerThumbnail(self, fileId):
return None

def openDirectory(self, index):
logger.debug("ServerWorkspaceModel.openDirectory()")

file_item = self.files[index.row()]
self.subPath = Utils.joinPath(self.subPath, file_item.name)
# push the directory to the stack
if file_item.serverFileDict.get("_id"):
# the server knows about this directory
logger.debug(" pushing serverFileDict to the currentDirectory")
self.currentDirectory.append(file_item.serverFileDict)
else:
# the server needs to know about this directory
logger.debug(" creating a directory")
id = None
fancy_handle(lambda: self.createDir(file_item.name))
# ignore the result
Expand Down Expand Up @@ -577,7 +569,6 @@ def deleteDirectory(self, index):
It assumes that the directory is empty. It should not call
refreshModel because it is combined with a call to super().
"""
logger.debug("ServerWorkspaceModel.deleteDirectory()")
super().deleteDirectory(index, NO_REFRESH)
fileItem = self.files[index.row()]
if fileItem.serverFileDict and "_id" in fileItem.serverFileDict:
Expand All @@ -600,15 +591,13 @@ def deleteDirectory(self, index):

def deleteFileLocally(self, index):
"""Delete a file on the local filesystem."""
logger.debug("ServerWorkspaceModel.deleteFileLocally()")
super().deleteFile(index)

def deleteFile(self, index):
"""Delete a file from the server.
This function assumes that the files have been removed locally.
"""
logger.debug("ServerWorkspaceModel.deleteFile()")
file_item = self.files[index.row()]

id = file_item.serverFileDict["_id"]
Expand Down Expand Up @@ -724,7 +713,6 @@ def upload(
self.apiClient.createModel(fileId)

def openParentFolder(self):
logger.debug("ServerWorkspaceModel.openParentFolder()")
self.subPath = os.path.dirname(self.subPath)
self.currentDirectory.pop()
self.refreshModel()
Expand All @@ -743,7 +731,6 @@ def summarizeWorkspace(self):
return {k: self.workspace[k] for k in ("_id", "name", "refName", "open")}

def createDir(self, nameDirectory):
logger.debug("ServerWorkspaceModel.createDir()")
# raises an APIClientException
currentDir = self.currentDirectory[-1]
workspace = self.summarizeWorkspace()
Expand Down
46 changes: 15 additions & 31 deletions WorkspaceView.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
import uuid
import base64
import webbrowser

# import logging

import random
import math

Expand Down Expand Up @@ -51,9 +48,6 @@
APIClient,
APIClientException,
APIClientAuthenticationException,
# APIClientConnectionError,
# APIClientTierException,
# APIClientRequestException,
ConnStatus,
APICallResult,
fancy_handle,
Expand Down Expand Up @@ -854,14 +848,6 @@ def setWorkspaceModel(self):
self.currentWorkspaceModel = ServerWorkspaceModel(
self.current_workspace, apiClient=self.api
)
# subPath = ""
# if hasattr(self, "currentWorkspaceModel") and self.currentWorkspaceModel:
# subPath = self.currentWorkspaceModel.subPath
# self.currentWorkspaceModel = LocalWorkspaceModel(
# self.current_workspace, subPath=subPath
# )
# I probably need to do something with the subpath

self.setWorkspaceNameLabel()
self.form.fileList.setModel(self.currentWorkspaceModel)
self.switchView()
Expand Down Expand Up @@ -999,7 +985,6 @@ def openFile(self, index):
throws an APIClientException
"""
logger.debug("openFile")
wsm = self.currentWorkspaceModel
fileItem = wsm.data(index)
if fileItem.is_folder:
Expand Down Expand Up @@ -1182,6 +1167,8 @@ def trySetVersion():
else:
refreshUI()

self.handle_api_call(trySetVersion, "Failed to download version.")

def updateThumbnail(self, fileItem):
fileName = fileItem.name
path = self.currentWorkspaceModel.getFullPath()
Expand Down Expand Up @@ -1740,22 +1727,18 @@ def uploadFile(
Interacts with the API.
"""

def tryUpload():
wsm = self.currentWorkspaceModel
if fileId:
# updating an existing version
wsm.upload(fileName, fileId, message)
else:
# initial commit
wsm.upload(fileName)
wsm.refreshModel()
if self.form.versionsComboBox.isVisible():
model = self.form.versionsComboBox.model()
model.refreshModel(fileItem)
self.form.versionsComboBox.setCurrentIndex(model.getCurrentIndex())
logger.debug("versionComboBox setCurrentIndex")

tryUpload()
wsm = self.currentWorkspaceModel
if fileId:
# updating an existing version
wsm.upload(fileName, fileId, message)
else:
# initial commit
wsm.upload(fileName)
wsm.refreshModel()
if self.form.versionsComboBox.isVisible():
model = self.form.versionsComboBox.model()
model.refreshModel(fileItem)
self.form.versionsComboBox.setCurrentIndex(model.getCurrentIndex())

def enterCommitMessage(self):
dialog = EnterCommitMessageDialog()
Expand Down Expand Up @@ -2042,6 +2025,7 @@ def showOndselSignUpPage(self):
def refreshModel(self):
if self.current_workspace is not None:
self.currentWorkspaceModel.refreshModel()
self.hideLinkVersionDetails()
else:
self.workspacesModel.refreshModel()

Expand Down

0 comments on commit 90a1765

Please sign in to comment.