def get_metafile(self, metafile, _params=None): params = self.params if _params: params.update(_params) masterfile = metafile[self] if isinstance(masterfile, bool): raise Exception("Calling %s.get_metafile( %s )" % (self, metafile)) # FIXME : the same extraction was already performed on master.get_metafile() item, filelist = xml_filelist(masterfile) local_repodata = os.path.join(self.repo_path(), self.metadata_path(True)) primary, secondary = False, False _primary = os.path.join(local_repodata, item['href']) if os.path.isfile(_primary): if self.verify(_primary, item, params): primary = True if self.mode == "init": primary = _primary if not primary and self.mode != "keep": repolib.logger.warning( "No local primary file exist for %s. Downloading." % self) url = repolib.urljoin(self.metadata_path(True), item['href']) if self.downloadRawFile(url, _primary): if self.verify(_primary, item, params): primary = _primary else: os.unlink(_primary) _secondary = os.path.join(local_repodata, filelist['href']) if os.path.isfile(_secondary): if self.verify(_secondary, filelist, params): secondary = True if self.mode == "init": secondary = _secondary if not secondary and self.mode != "keep": repolib.logger.warning( "No local filelists file exist for %s. Downloading." % self) url = repolib.urljoin(self.metadata_path(True), filelist['href']) if self.downloadRawFile(url, _secondary): if self.verify(_secondary, filelist, params): secondary = _secondary else: os.unlink(_secondary) # Workarounds to detect booleans within output if False in (primary, secondary): return False if primary == secondary and isinstance(primary, bool): return primary return primary, secondary
def get_metafile( self , metafile , _params=None ) : params = self.params if _params : params.update( _params ) masterfile = metafile[self] if isinstance(masterfile,bool) : raise Exception( "Calling %s.get_metafile( %s )" % ( self , metafile ) ) # FIXME : the same extraction was already performed on master.get_metafile() item , filelist = xml_filelist( masterfile ) local_repodata = os.path.join( self.repo_path() , self.metadata_path(True) ) primary , secondary = False , False _primary = os.path.join( local_repodata , item['href'] ) if os.path.isfile( _primary ) : if self.verify( _primary , item , params ) : primary = True if self.mode == "init" : primary = _primary if not primary and self.mode != "keep" : repolib.logger.warning( "No local primary file exist for %s. Downloading." % self ) url = repolib.urljoin( self.metadata_path(True) , item['href'] ) if self.downloadRawFile( url , _primary ) : if self.verify( _primary , item , params ) : primary = _primary else: os.unlink( _primary ) _secondary = os.path.join( local_repodata , filelist['href'] ) if os.path.isfile( _secondary ) : if self.verify( _secondary , filelist , params ) : secondary = True if self.mode == "init" : secondary = _secondary if not secondary and self.mode != "keep" : repolib.logger.warning( "No local filelists file exist for %s. Downloading." % self ) url = repolib.urljoin( self.metadata_path(True) , filelist['href'] ) if self.downloadRawFile( url , _secondary ) : if self.verify( _secondary , filelist , params ) : secondary = _secondary else : os.unlink( _secondary ) # Workarounds to detect booleans within output if False in ( primary , secondary ) : return False if primary == secondary and isinstance(primary,bool) : return primary return primary , secondary
def handler(req): local_path = req.filename subpath = local_path.replace(req.hlist.directory, "", 1) remote_url = req.get_options().get("source_url") if not remote_url.endswith("/"): remote_url += "/" req.log_error("Fix configuration, source_url should have a trailing '/'", apache.APLOG_INFO) if req.used_path_info: local_path += req.path_info remote_url = repolib.urljoin(remote_url, subpath + req.path_info) return get_file(req, local_path, remote_url)
def handler(req): local_path = req.filename subpath = local_path.replace(req.hlist.directory, "", 1) remote_url = req.get_options().get('source_url') if not remote_url.endswith('/'): remote_url += "/" req.log_error( "Fix configuration, source_url should have a trailing '/'", apache.APLOG_INFO) if req.used_path_info: local_path += req.path_info remote_url = repolib.urljoin(remote_url, subpath + req.path_info) return get_file(req, local_path, remote_url)
def downloadRawFile ( self , remote , local=None ) : """Downloads a remote file to the local system. remote - path relative to repository base local - Optional local name for the file Returns the local file name or False if errors""" remote = repolib.urljoin( self.base_url() , remote ) if not local : (handle, fname) = tempfile.mkstemp() else : fname = local handle = os.open( fname , os.O_WRONLY | os.O_TRUNC | os.O_CREAT ) if not repolib.download( remote , handle ) : os.unlink(fname) return False return fname
def downloadRawFile(self, remote, local=None): """Downloads a remote file to the local system. remote - path relative to repository base local - Optional local name for the file Returns the local file name or False if errors""" remote = repolib.urljoin(self.base_url(), remote) if not local: (handle, fname) = tempfile.mkstemp() else: fname = local handle = os.open(fname, os.O_WRONLY | os.O_TRUNC | os.O_CREAT) if not repolib.download(remote, handle): os.unlink(fname) return False return fname