Example #1
0
    def set_global_config( self ):
        import ctx_cfg
        import ctx_common
        cfgFile = ctx_cfg.CFGFile( os.path.join( ctx_common.getUserCfgDir(), 'contexo.cfg' ))

        for p in ctx_common.assureList(cfgFile.getBConfPaths()):
            self.addGlobalPath( p, 'bconf' )

        for p in ctx_common.assureList(cfgFile.getCDefPaths()):
            self.addGlobalPath( p, 'cdef' )

        self.addGlobalPath( ctx_common.getUserCfgDir(), 'misc' )
        self.addGlobalPath( self.getRoot(), 'misc' )
Example #2
0
    def locateItem(self, item, path_sections):

        candidate_locations = list()
        tried_locations = list()

        path_sections = assureList( path_sections )

        for path_section in path_sections:
            # Always prioritize locating items from the RSpec repositories
            if path_section in REPO_PATH_SECTIONS and self.getRSpec() != None:
                for repo in self.getRSpec().getRepositories():
                    repo_candidates, repo_tried = repo.locateItem( item, path_section )
                    candidate_locations.extend( repo_candidates )
                    tried_locations.extend( repo_tried )

            if len(candidate_locations) == 1:
                infoMessage("Located '%s' at '%s'"%(item, candidate_locations[0]), 2)
                return candidate_locations[0]
            elif len(candidate_locations) > 1:
                userErrorExit("Multiple occurances of '%s' was found. Unable to determine which one to use: \n   %s"\
                               %(item, "\n   ".join(candidate_locations)))

        # Item not present in any repository, be clear to the user..
        if self.getRSpec() != None:
            if self.getAccessPolicy() == AP_NO_REMOTE_ACCESS:
                infoMessage("Item '%s' was not found in RSpec repositories.\nNote that the system is set to search for repository items in the local view only (%s).\nTrying system global locations."%(item, AP_FLAGS[self.getAccessPolicy()]), 2)
            elif self.getAccessPolicy() == AP_PREFER_REMOTE_ACCESS:
                infoMessage("Item '%s' was not found in RSpec repositories.\nNote that the system is set to search for repository items at the repository source location only (%s).\nTrying system global locations."%(item, AP_FLAGS[self.getAccessPolicy()]), 2)
            else:
                infoMessage("Item '%s' was not found in RSpec repositories.\nTrying system global locations."%(item), 2)

        for path_section in path_sections:
            # File was not found in RSpec repositories, look in view
            if path_section in SYSGLOBAL_PATH_SECTIONS:
                for path in self.getGlobalPaths(path_section):
                    tried_locations.append( path )
                    if os.path.isdir(path):
                        if item in os.listdir(path):
                            candidate_locations.append( os.path.join(path, item) )
                    else:
                        tried_locations[-1] = tried_locations[-1] + " (path not found)"
                        warningMessage("System global path '%s' doesn't exist"%(path))

            if len(candidate_locations) == 1:
                infoMessage("Located '%s' at '%s'"%(item, candidate_locations[0]), 2)
                return candidate_locations[0]
            elif len(candidate_locations) > 1:
                userErrorExit("Multiple occurances of '%s' was found. Unable to determine which one to use: \n   %s"\
                               %(item, "\n   ".join(candidate_locations)))


        userErrorExit("Unable to locate file '%s'. Attempted the following locations: \n   %s"\
                       %(item, "\n   ".join(tried_locations)))
Example #3
0
    def locateItem(self, item, path_sections):

        candidate_locations = list()
        tried_locations = list()

        path_sections = assureList( path_sections )

        for path_section in path_sections:
            # Always prioritize locating items from the RSpec repositories
            if path_section in REPO_PATH_SECTIONS and self.getRSpec() != None:
                for repo in self.getRSpec().getRepositories():
                    repo_candidates, repo_tried = repo.locateItem( item, path_section )
                    candidate_locations.extend( repo_candidates )
                    tried_locations.extend( repo_tried )

            if len(candidate_locations) == 1:
                infoMessage("Located '%s' at '%s'"%(item, candidate_locations[0]), 2)
                return candidate_locations[0]
            elif len(candidate_locations) > 1:
                userErrorExit("Multiple occurances of '%s' was found. Unable to determine which one to use: \n   %s"\
                               %(item, "\n   ".join(candidate_locations)))
            infoMessage("Item '%s' was not found in RSpec repositories.\nTrying system global locations."%(item), 2) 

        for path_section in path_sections:
            # File was not found in RSpec repositories, look in view
            if path_section in SYSGLOBAL_PATH_SECTIONS:
                for path in self.getGlobalPaths(path_section):
                    tried_locations.append( path )
                    if os.path.isdir(path):
                        if item in os.listdir(path):
                            candidate_locations.append( os.path.join(path, item) )
                    else:
                        tried_locations[-1] = tried_locations[-1] + " (path not found)"
                        warningMessage("System global path '%s' doesn't exist"%(path))

            if len(candidate_locations) == 1:
                infoMessage("Located '%s' at '%s'"%(item, candidate_locations[0]), 2)
                return candidate_locations[0]
            elif len(candidate_locations) > 1:
                userErrorExit("Multiple occurances of '%s' was found. Unable to determine which one to use: \n   %s"\
                               %(item, "\n   ".join(candidate_locations)))


        userErrorExit("Unable to locate file '%s'. Attempted the following locations: \n   %s"\
                       %(item, "\n   ".join(tried_locations)))