def _get_orphan_exercise_repository_list(self, repositoryListIn): repoPathList = os.listdir(config.get("local_repo_root_dir")) repoUsedPath = [] repositoryList = [] for repo in repositoryListIn: repoUsedPath.append(repo.get_local_path()) for repoPath in repoPathList: path = os.path.join(config.get("local_repo_root_dir"), repoPath) if path not in repoUsedPath: repository = ExerciseRepository() repository.init_from_path(path) repository.set_type("orphan") repositoryList.append(repository) return repositoryList
def _get_orphan_exercise_repository_list(self, repositoryListIn): repoPathList = os.listdir(config.get("local_repo_root_dir")) repoUsedPath = [] repositoryList = [] for repo in repositoryListIn: repoUsedPath.append(repo.get_local_path()) for repoPath in repoPathList: path = os.path.join(config.get("local_repo_root_dir"), repoPath) if path not in repoUsedPath: repository = ExerciseRepository() repository.init_from_path(path) repository.set_type("orphan") repositoryList.append(repository) return repositoryList
def _get_local_exercise_repository_list(self): """Build and return the list of local repository. In fact, this list will contain at maximum 2 repositories. A local personnal repository is added to the list if a directory named 'local' exist in the repo root directory. A local system repository is added to the list if a directory named 'system_repo' is found in the perroquet data files. The local system repository is special because it is composed by 2 path : a system path for common data and a path for personnal data as progress """ repositoryList = [] # Build potential local repository path localRepoPath = os.path.join(config.get("local_repo_root_dir"), "local") # Test local repository existance if os.path.isdir(localRepoPath): # Repository found so Initialize it from the path and set it as local repository = ExerciseRepository() repository.init_from_path(localRepoPath) repository.set_type("local") repositoryList.append(repository) systemRepoPath = os.path.join(config.get("system_repo_root_dir"), "system") print "system repo path "+systemRepoPath #Test systemrepository existance if os.path.isdir(systemRepoPath): print "system repo found" # Repository found so Initialize it from the path and set it as local repository = ExerciseRepository() repository.set_system(True); repository.init_from_path(systemRepoPath) repository.set_type("local") repositoryList.append(repository) return repositoryList
def _get_distant_exercise_repository_list(self): """Build and return a list of distant and offline repositories. There is one repository initialized for each url found in the config files. If the url is reachable, a distant repository is initialized, else an offline repository is created. """ #Get the list of files containing url list repositoryPathList = config.get("repository_source_list") repositoryList = [] offlineRepoList = [] #Fetch repository urls file for path in repositoryPathList: f = open(path, 'r') #Fetch urls of repo description for line in f: line = line.rstrip() if line and line[0] == "#": #Comment line continue req = urllib2.Request(line) try: #try to download the file headers handle = urllib2.urlopen(req) except IOError: #if the download failed store the url in a list of #offline urls self.logger.error("Fail to connection to repository '" + line + "'") offlineRepoList.append(line) except ValueError: self.logger.exception("Unknown url type '" + line + "'") offlineRepoList.append(line) else: #if the download success, init a repository from the #downloaded file and regenerate the tree self.logger.debug("init distant repo") repository = ExerciseRepository() repository.parse_distant_repository_file(handle) repository.set_url(line) repositoryList.append(repository) repository.generate_description() #if the list of url is not empty, add a list of offline repository if len(offlineRepoList) > 0: repoPathList = os.listdir(config.get("local_repo_root_dir")) for repoPath in repoPathList: #for eaach directory in the repo root path analyse the #description file. If the url of this repo match with one #of offline url, then init an offline repository from this #path repository = ExerciseRepository() repoDescriptionPath = os.path.join(config.get("local_repo_root_dir"), repoPath, "repository.xml") if not os.path.isfile(repoDescriptionPath): continue f = open(repoDescriptionPath, 'r') dom = parse(f) repository.parse_description(dom) self.logger.debug("test offline url : " + repository.get_url()) if repository.get_url() in offlineRepoList: self.logger.info("add url : " + repository.get_url()) repository = ExerciseRepository() repository.init_from_path(os.path.join(config.get("local_repo_root_dir"), repoPath)) repository.set_type("offline") repositoryList.append(repository) return repositoryList
def _get_local_exercise_repository_list(self): """Build and return the list of local repository. In fact, this list will contain at maximum 2 repositories. A local personnal repository is added to the list if a directory named 'local' exist in the repo root directory. A local system repository is added to the list if a directory named 'system_repo' is found in the perroquet data files. The local system repository is special because it is composed by 2 path : a system path for common data and a path for personnal data as progress """ repositoryList = [] # Build potential local repository path localRepoPath = os.path.join(config.get("local_repo_root_dir"), "local") # Test local repository existance if os.path.isdir(localRepoPath): # Repository found so Initialize it from the path and set it as local repository = ExerciseRepository() repository.init_from_path(localRepoPath) repository.set_type("local") repositoryList.append(repository) systemRepoPath = os.path.join(config.get("system_repo_root_dir"), "system") print "system repo path " + systemRepoPath #Test systemrepository existance if os.path.isdir(systemRepoPath): print "system repo found" # Repository found so Initialize it from the path and set it as local repository = ExerciseRepository() repository.set_system(True) repository.init_from_path(systemRepoPath) repository.set_type("local") repositoryList.append(repository) return repositoryList
def _get_distant_exercise_repository_list(self): """Build and return a list of distant and offline repositories. There is one repository initialized for each url found in the config files. If the url is reachable, a distant repository is initialized, else an offline repository is created. """ #Get the list of files containing url list repositoryPathList = config.get("repository_source_list") repositoryList = [] offlineRepoList = [] #Fetch repository urls file for path in repositoryPathList: f = open(path, 'r') #Fetch urls of repo description for line in f: line = line.rstrip() if line and line[0] == "#": #Comment line continue req = urllib2.Request(line) try: #try to download the file headers handle = urllib2.urlopen(req) except IOError: #if the download failed store the url in a list of #offline urls self.logger.error("Fail to connection to repository '" + line + "'") offlineRepoList.append(line) except ValueError: self.logger.exception("Unknown url type '" + line + "'") offlineRepoList.append(line) else: #if the download success, init a repository from the #downloaded file and regenerate the tree self.logger.debug("init distant repo") repository = ExerciseRepository() repository.parse_distant_repository_file(handle) repository.set_url(line) repositoryList.append(repository) repository.generate_description() #if the list of url is not empty, add a list of offline repository if len(offlineRepoList) > 0: repoPathList = os.listdir(config.get("local_repo_root_dir")) for repoPath in repoPathList: #for eaach directory in the repo root path analyse the #description file. If the url of this repo match with one #of offline url, then init an offline repository from this #path repository = ExerciseRepository() repoDescriptionPath = os.path.join( config.get("local_repo_root_dir"), repoPath, "repository.xml") if not os.path.isfile(repoDescriptionPath): continue f = open(repoDescriptionPath, 'r') dom = parse(f) repository.parse_description(dom) self.logger.debug("test offline url : " + repository.get_url()) if repository.get_url() in offlineRepoList: self.logger.info("add url : " + repository.get_url()) repository = ExerciseRepository() repository.init_from_path( os.path.join(config.get("local_repo_root_dir"), repoPath)) repository.set_type("offline") repositoryList.append(repository) return repositoryList