@@ -302,7 +302,7 @@ def _setOperatingContext(self, project_name):
302302 result = self .agent .get ('Project' , fetch = "Name" , workspace = self ._currentWorkspace , project = None )
303303
304304 if not result or result .resultCount == 0 :
305- problem = "No Projects found in the Workspace '%s'" % self ._defaultWorkspace
305+ problem = "No accessible Projects found in the Workspace '%s'" % self ._defaultWorkspace
306306 raise RallyRESTAPIError (problem )
307307
308308 try :
@@ -311,27 +311,40 @@ def _setOperatingContext(self, project_name):
311311 problem = "Unable to obtain Project Name values for projects in the '%s' Workspace"
312312 raise RallyRESTAPIError (problem % self ._defaultWorkspace )
313313
314- match_for_default_project = [project for project in projects if project .Name == self ._defaultProject ]
315- match_for_named_project = [project for project in projects if project .Name == project_name ]
314+ # does the project_name contain a ' // ' path element separator token?
315+ # if so, then we have to sidebar process this
316+ if ' // ' in project_name :
317+ target_project = self .__findMultiElementPathToProject (project_name )
318+ if not target_project :
319+ problem = "No such accessible multi-element-path Project: %s found in the Workspace '%s'"
320+ raise RallyRESTAPIError (problem % (project_name , self ._currentWorkspace ))
321+ # have to set:
322+ # self._defaultProject, self._currentProject
323+ # self._workspace_ref, self._project_ref
324+ # self.defaultContext, self.operatingContext
316325
317- if project_name :
318- if not match_for_named_project :
319- problem = "The current Workspace '%s' does not contain a Project with the name of '%s'"
320- raise RallyRESTAPIError (problem % (self ._currentWorkspace , project_name ))
321- else :
322- project = match_for_named_project [0 ]
323- proj_ref = project ._ref
324- self ._defaultProject = project .Name
325- self ._currentProject = project .Name
326326 else :
327- if not match_for_default_project :
328- problem = "The current Workspace '%s' does not contain a Project with the name of '%s'"
329- raise RallyRESTAPIError (problem % (self ._currentWorkspace , project_name ))
327+ match_for_default_project = [project for project in projects if project .Name == self ._defaultProject ]
328+ match_for_named_project = [project for project in projects if project .Name == project_name ]
329+
330+ if project_name :
331+ if not match_for_named_project :
332+ problem = "The current Workspace '%s' does not contain an accessible Project with the name of '%s'"
333+ raise RallyRESTAPIError (problem % (self ._currentWorkspace , project_name ))
334+ else :
335+ project = match_for_named_project [0 ]
336+ proj_ref = project ._ref
337+ self ._defaultProject = project .Name
338+ self ._currentProject = project .Name
330339 else :
331- project = match_for_default_project [0 ]
332- proj_ref = project ._ref
333- self ._defaultProject = project .Name
334- self ._currentProject = project .Name
340+ if not match_for_default_project :
341+ problem = "The current Workspace '%s' does not contain a Project with the name of '%s'"
342+ raise RallyRESTAPIError (problem % (self ._currentWorkspace , project_name ))
343+ else :
344+ project = match_for_default_project [0 ]
345+ proj_ref = project ._ref
346+ self ._defaultProject = project .Name
347+ self ._currentProject = project .Name
335348##
336349## print(" Default Workspace : %s" % self._defaultWorkspace)
337350## print(" Default Project : %s" % self._defaultProject)
@@ -341,6 +354,7 @@ def _setOperatingContext(self, project_name):
341354 if not self ._projects :
342355 self ._projects = {self ._defaultWorkspace : [self ._defaultProject ]}
343356 if not self ._workspace_ref :
357+ wksp_name , wkspace_ref = self .getWorkspace ()
344358 short_ref = "/" .join (wkspace_ref .split ('/' )[- 2 :]) # we only need the 'workspace/<oid>' part to be a valid ref
345359 self ._workspace_ref = {self ._defaultWorkspace : short_ref }
346360 if not self ._project_ref :
@@ -365,6 +379,38 @@ def _setOperatingContext(self, project_name):
365379## print(" completed _setOperatingContext processing...")
366380##
367381
382+ def __findMultiElementPathToProject (self , project_name ):
383+ """
384+ Given a project_name in BaseProject // NextLevelProject // TargetProjectName form,
385+ determine the existence/accessiblity of each successive path from the BaseProject
386+ on towards the full path ending with TargetProjectName.
387+ If found return a pyral entity for the TargetProject which will include the ObjectID (oid)
388+ after setting an attribute for FullProjectPath with the value of project_name.
389+ """
390+ proj_path_elements = project_name .split (' // ' )
391+ base_path_element = proj_path_elements [0 ]
392+ result = self .agent .get ('Project' , fetch = "Name" , workspace = self ._currentWorkspace , project = base_path_element )
393+ if not result or result .errors or result .resultCount != 1 :
394+ problem = "No such accessible base Project found in the Workspace '%s'" % project_name
395+ raise RallyRESTAPIError (problem )
396+ base_project = result .next ()
397+ parent = base_project
398+ project_path = base_project .Name
399+
400+ for proj_path_element in proj_path_elements [1 :]:
401+ project_path .append (proj_path_element )
402+ criteria = ['Name = ""' % proj_path_element , 'Parent = %s' % parent ._ref ]
403+ result = self .agent .get ('Project' , fetch = "Name" , query = criteria , workspace = self ._currentWorkspace , project = parent )
404+ if not result or result .errors or result .resultCount != 1 :
405+ problem = "No such accessible Project found: '%s'" % ' // ' .join (project_path )
406+ raise RallyRESTAPIError (problem )
407+ path_el = result .next ()
408+ if ' // ' .join (project_path ) != project_name :
409+ raise RallyRESTAPIError ()
410+ return path_el
411+
412+
413+
368414 def _getDefaults (self , user_response ):
369415 """
370416 We have to circumvent the normal machinery as this is part of setting up the
0 commit comments