... |
... |
@@ -165,24 +165,29 @@ class WorkspaceProjectCache(): |
165
|
165
|
|
166
|
166
|
# get()
|
167
|
167
|
#
|
168
|
|
- # Returns a WorkspaceProject for a given directory, loading one from disk if present
|
169
|
|
- # and caching it.
|
|
168
|
+ # Returns a WorkspaceProject for a given directory, retrieving from the cache if
|
|
169
|
+ # present, and searching the filesystem for the file and loading it if not.
|
170
|
170
|
#
|
171
|
171
|
# Args:
|
172
|
172
|
# directory (str): The directory to search for a WorkspaceProject.
|
173
|
173
|
#
|
174
|
174
|
# Returns:
|
175
|
175
|
# (WorkspaceProject): The WorkspaceProject that was found for that directory.
|
|
176
|
+ # or (NoneType): None, if no WorkspaceProject can be found.
|
176
|
177
|
#
|
177
|
178
|
def get(self, directory):
|
178
|
|
- # NOTE: Later, this will load any WorkspaceProject found from directory
|
179
|
179
|
try:
|
180
|
180
|
workspace_project = self._projects[directory]
|
181
|
181
|
except KeyError:
|
182
|
|
- workspace_project = WorkspaceProject.load(directory)
|
183
|
|
- if not workspace_project:
|
184
|
|
- workspace_project = WorkspaceProject(directory)
|
185
|
|
- self._projects[directory] = workspace_project
|
|
182
|
+ found_dir = WorkspaceProject.search_for_dir(directory)
|
|
183
|
+ if found_dir:
|
|
184
|
+ try:
|
|
185
|
+ workspace_project = self._projects[found_dir]
|
|
186
|
+ except KeyError:
|
|
187
|
+ workspace_project = WorkspaceProject.load(found_dir)
|
|
188
|
+ self._projects[found_dir] = workspace_project
|
|
189
|
+ else:
|
|
190
|
+ workspace_project = None
|
186
|
191
|
|
187
|
192
|
return workspace_project
|
188
|
193
|
|
... |
... |
@@ -201,6 +206,9 @@ class WorkspaceProjectCache(): |
201
|
206
|
#
|
202
|
207
|
def add(self, directory, project_path='', element_name=''):
|
203
|
208
|
workspace_project = self.get(directory)
|
|
209
|
+ if not workspace_project:
|
|
210
|
+ workspace_project = WorkspaceProject(directory)
|
|
211
|
+ self._projects[directory] = workspace_project
|
204
|
212
|
if project_path:
|
205
|
213
|
workspace_project._add_project(project_path, element_name)
|
206
|
214
|
return workspace_project
|
... |
... |
@@ -223,6 +231,9 @@ class WorkspaceProjectCache(): |
223
|
231
|
# NOTE: project_path and element_name will only be used when I implement
|
224
|
232
|
# multiple owners of a workspace
|
225
|
233
|
workspace_project = self.get(directory)
|
|
234
|
+ if not workspace_project:
|
|
235
|
+ raise LoadError(LoadErrorReason.MISSING_FILE,
|
|
236
|
+ "Failed to find a {} file to remove".format(WORKSPACE_PROJECT_FILE))
|
226
|
237
|
path = workspace_project._get_filename()
|
227
|
238
|
try:
|
228
|
239
|
os.unlink(path)
|