def read(self, request, text): return serve(request=request, path='/virtual/', document_root=config.get_repo_dir(), show_indexes=True, show_virtuals=True)
def getVirtualRepoDir(self, reponame=''): virtual_path=config.get_repo_dir() + '/virtual/' if not os.path.exists(virtual_path): os.makedirs(virtual_path) if '..' in reponame: raise ValueError('reponame is not allowed to contain ..') repo_path=virtual_path+reponame return repo_path
def getStaticRepoDir(self, reponame=''): static_path = config.get_repo_dir() + '/static/' if not os.path.exists(static_path): os.makedirs(static_path) if '..' in reponame: raise ValueError('Repository name {0} is not allowed. String ".." forbidden in repository name.'.format(reponame)) repo_path = static_path + reponame return repo_path
def read(self, request, reponame, rpm = '/'): virtual_reponame = reponame path_relative_to_repository = rpm virtual_repo_dir = self.repoConfigService.getVirtualRepoDir(virtual_reponame) if not os.path.exists(virtual_repo_dir): resp = rc.NOT_FOUND resp.content = 'Virtual Repository does not exists!' return resp repoConfig = self.repoConfigService.getConfig(virtual_reponame) absoluteDestinationRepoPath = config.get_repo_dir() + repoConfig.destination return serve(request, path_relative_to_repository, absoluteDestinationRepoPath, True)
def createVirtualRepo(self, virtual_reponame, destination_relative_to_repodir): destination = config.get_repo_dir() + '/' + destination_relative_to_repodir destination = self.removeTrailingSlashIfPresent(destination) logging.info("check if " + destination + " exists") if not os.path.exists(destination): raise RepoNotFoundException() if self.is_virtual_repository_path(destination): destination_reponame = destination_relative_to_repodir[len('virtual/'):] static_destination = self.getConfig(destination_reponame).destination else:#destination is static -> no need to check for repo.yaml just take destination as is static_destination = '/' + destination_relative_to_repodir path_to_virtual_repo = self.getVirtualRepoDir(virtual_reponame) self.create_virtual_repo_skeleton(path_to_virtual_repo) return self.writeConfig(virtual_reponame, static_destination)
def read(self, request, reponame, rpm='/'): virtual_reponame = reponame path_relative_to_repository = rpm virtual_repo_dir = self.repoConfigService.getVirtualRepoDir( virtual_reponame) if not os.path.exists(virtual_repo_dir): resp = rc.NOT_FOUND resp.content = 'Virtual Repository does not exists!' return resp repoConfig = self.repoConfigService.getConfig(virtual_reponame) if re.match('^https?://.*', repoConfig.destination): return HttpResponseRedirect(repoConfig.destination + rpm) else: absoluteDestinationRepoPath = config.get_repo_dir( ) + repoConfig.destination return serve(request, path_relative_to_repository, absoluteDestinationRepoPath, True)
def create(self, request, reponame): full_path_to_repo = self.repoConfigService.getStaticRepoDir(reponame) if not os.path.exists(full_path_to_repo): resp = rc.NOT_FOUND resp.content = 'Repository %s not found' % full_path_to_repo return resp try: self.repoConfigService.doCreateRepo(full_path_to_repo, reponame) except: resp = rc.BAD_REQUEST resp.content = 'createrepo has finished with Error' return resp resp = rc.CREATED resp.content = config.get_repo_dir() return resp
def createVirtualRepo(self, virtual_reponame, destination_relative_to_repodir): if re.match('^https?://.*', destination_relative_to_repodir): if destination_relative_to_repodir.endswith('/'): static_destination = destination_relative_to_repodir[:-1] else: static_destination = destination_relative_to_repodir else: destination = config.get_repo_dir() + '/' + destination_relative_to_repodir destination = self.removeTrailingSlashIfPresent(destination) if not os.path.exists(destination): raise RepoNotFoundException() if self.is_virtual_repository_path(destination): destination_reponame = destination_relative_to_repodir[len('virtual/'):] static_destination = self.getConfig(destination_reponame).destination else:#destination is static -> no need to check for repo.yaml just take destination as is static_destination = '/' + destination_relative_to_repodir self.create_virtual_repo_skeleton(virtual_reponame) return self.writeConfig(virtual_reponame, static_destination)
def getRepoDir(self): return config.get_repo_dir()
def is_virtual_repository_path(self, destination): #the path is relative to the project directory virtual_repo_path_prefix = config.get_repo_dir() + "/virtual" return destination.startswith(virtual_repo_path_prefix)
def assert_metadata_generated(self, repo_name): repo_dir = config.get_repo_dir() metadata_dir = repo_dir + Constants.PATH_TO_STATIC_REPO_RELATIVE_TO_PROJECT_DIR + repo_name + Constants.GENERATE_REPO_DATA_POSTFIX self.assertTrue(os.path.exists(metadata_dir)) self.assertTrue(os.path.exists(metadata_dir + Constants.PRIMARY_XML)) self.assert_package_count(metadata_dir, 1)
def getVirtualRepoDir(self, reponame=''): virtual_path=config.get_repo_dir() + '/virtual/' if not os.path.exists(virtual_path): os.makedirs(virtual_path) repo_path=virtual_path+reponame return repo_path
def getStaticRepoDir(self, reponame=''): static_path=config.get_repo_dir() + '/static/' repo_path=static_path+reponame if not os.path.exists(static_path): os.makedirs(static_path) return repo_path
def read(self, request, text): return serve(request=request, path='/virtual/', document_root=config.get_repo_dir(), show_indexes=True, parent_dir_type=ParentDirType.VIRTUAL)