def __init__(self, url, cache_dir, pkg_dir, proxy_addr="", proxy_user="", proxy_pass=""): self.url = url parts = url.rsplit('/dists/', 1) self.base_url = [parts[0]] # Make sure baseurl ends with / and urljoin will work correctly if self.base_url[0][-1] != '/': self.base_url[0] += '/' self.urls = self.base_url self.sslclientcert = self.sslclientkey = self.sslcacert = None self.proxy = proxy_addr self.proxy_username = proxy_user self.proxy_password = proxy_pass self.basecachedir = cache_dir if not os.path.isdir(self.basecachedir): fileutils.makedirs(self.basecachedir, user='******', group='apache') self.includepkgs = [] self.exclude = [] self.pkgdir = pkg_dir self.http_headers = {}
def setup_repo(self, repo): """Fetch repository metadata""" repo.cache = 0 repo.mirrorlist = self.url repo.baseurl = [self.url] repo.basecachedir = CACHE_DIR # base_persistdir have to be set before pkgdir if hasattr(repo, 'base_persistdir'): repo.base_persistdir = CACHE_DIR if (self.url.find("file://") < 0): pkgdir = os.path.join(CFG.MOUNT_POINT, CFG.PREPENDED_DIR, '1', 'stage') if not os.path.isdir(pkgdir): fileutils.makedirs(pkgdir, user='******', group='apache') else: pkgdir = self.url[7:] repo.pkgdir = pkgdir yb_cfg = self.yumbase.conf.cfg if not ((yb_cfg.has_section(self.name) and yb_cfg.has_option(self.name, 'proxy')) or (yb_cfg.has_section('main') and yb_cfg.has_option('main', 'proxy'))) and \ self.proxy_addr is not None: repo.proxy = "http://%s" % self.proxy_addr repo.proxy_username = self.proxy_user repo.proxy_password = self.proxy_pass warnings = YumWarnings() warnings.disable() try: repo.baseurlSetup() except: warnings.restore() raise warnings.restore() repo.setup(False) self.sack = self.repo.getPackageSack()
def __init__(self, url, cache_dir): self.url = url parts = url.split('/dists') self.base_url = parts[0] self.sslclientcert = self.sslclientkey = self.sslcacert = None self.basecachedir = cache_dir if not os.path.isdir(self.basecachedir): fileutils.makedirs(self.basecachedir, user='******', group='apache') self.includepkgs = [] self.exclude = []
def setup_repo(self, repo, no_mirrors, ca_cert_file, client_cert_file, client_key_file): """Fetch repository metadata""" repo.cache = 0 repo.mirrorlist = self.url repo.baseurl = [self.url] repo.basecachedir = os.path.join(CACHE_DIR, self.org) # base_persistdir have to be set before pkgdir if hasattr(repo, 'base_persistdir'): repo.base_persistdir = repo.basecachedir pkgdir = os.path.join(CFG.MOUNT_POINT, CFG.PREPENDED_DIR, self.org, 'stage') if not os.path.isdir(pkgdir): fileutils.makedirs(pkgdir, user='******', group='apache') repo.pkgdir = pkgdir repo.sslcacert = ca_cert_file repo.sslclientcert = client_cert_file repo.sslclientkey = client_key_file repo.proxy = None repo.proxy_username = None repo.proxy_password = None if "file://" in self.url: repo.copy_local = 1 if self.proxy_addr: repo.proxy = self.proxy_addr if '://' in self.proxy_addr else 'http://' + self.proxy_addr repo.proxy_username = self.proxy_user repo.proxy_password = self.proxy_pass # Do not try to expand baseurl to other mirrors if no_mirrors: repo.urls = repo.baseurl # Make sure baseurl ends with / and urljoin will work correctly if repo.urls[0][-1] != '/': repo.urls[0] += '/' else: warnings = YumWarnings() warnings.disable() try: repo.baseurlSetup() except: warnings.restore() raise warnings.restore() # if self.url is metalink it will be expanded into # real urls in repo.urls and also save this metalink # in begin of the url list ("for repolist -v ... or anything else wants to know the baseurl") # Remove it from the list, we don't need it to download content of repo repo.urls = [url for url in repo.urls if '?' not in url] repo.interrupt_callback = self.interrupt_callback repo.setup(0)
def setup_repo(self, repo, no_mirrors, ca_cert_file, client_cert_file, client_key_file): """Fetch repository metadata""" repo.metadata_expire=0 repo.mirrorlist = self.url repo.baseurl = [self.url] pkgdir = os.path.join(CFG.MOUNT_POINT, CFG.PREPENDED_DIR, self.org, 'stage') if not os.path.isdir(pkgdir): fileutils.makedirs(pkgdir, user='******', group='apache') repo.pkgdir = pkgdir repo.sslcacert = ca_cert_file repo.sslclientcert = client_cert_file repo.sslclientkey = client_key_file repo.proxy = None repo.proxy_username = None repo.proxy_password = None if self.proxy_addr: repo.proxy = self.proxy_addr if '://' in self.proxy_addr else 'http://' + self.proxy_addr repo.proxy_username = self.proxy_user repo.proxy_password = self.proxy_pass if no_mirrors: repo.mirrorlist = "" self.digest=hashlib.sha256(self.url.encode('utf8')).hexdigest()[:16] self.dnfbase.repos.add(repo) self.repoid = repo.id try: logger = logging.getLogger('dnf') logger.setLevel(logging.ERROR) self.yumbase.repos[self.repoid].load() logger.setLevel(logging.WARN) except RepoError: # Dnf bug workaround. Mirrorlist was provided but none worked. Fallback to baseurl and load again. # Remove once dnf is fixed and add detection if mirrors failed. logger.setLevel(logging.WARN) repo.mirrorlist = "" no_mirrors = True self.dnfbase.repos[self.repoid].load() # Do not try to expand baseurl to other mirrors if no_mirrors: self.dnfbase.repos[self.repoid].urls = repo.baseurl # Make sure baseurl ends with / and urljoin will work correctly if self.dnfbase.repos[self.repoid].urls[0][-1] != '/': self.dnfbase.repos[self.repoid].urls[0] += '/' else: self.dnfbase.repos[self.repoid].urls = self.clean_urls(self.dnfbase.repos[self.repoid]._repo.getMirrors()) # pylint: disable=W0212 self.dnfbase.repos[self.repoid].urls=[url for url in self.dnfbase.repos[self.repoid].urls if '?' not in url] self.dnfbase.repos[self.repoid].basecachedir = os.path.join(CACHE_DIR, self.org) repoXML = type('', (), {})() repoXML.repoData = {} self.dnfbase.repos[self.repoid].repoXML = repoXML
def setup_repo(self, repo, no_mirrors, ca_cert_file, client_cert_file, client_key_file): """Fetch repository metadata""" repo.cache = 0 repo.mirrorlist = self.url repo.baseurl = [self.url] repo.basecachedir = os.path.join(CACHE_DIR, self.org) # base_persistdir have to be set before pkgdir if hasattr(repo, 'base_persistdir'): repo.base_persistdir = repo.basecachedir pkgdir = os.path.join(CFG.MOUNT_POINT, CFG.PREPENDED_DIR, self.org, 'stage') if not os.path.isdir(pkgdir): fileutils.makedirs(pkgdir, user='******', group='apache') repo.pkgdir = pkgdir repo.sslcacert = ca_cert_file repo.sslclientcert = client_cert_file repo.sslclientkey = client_key_file repo.proxy = None repo.proxy_username = None repo.proxy_password = None if "file://" in self.url: repo.copy_local = 1 if self.proxy_addr: repo.proxy = "http://%s" % self.proxy_addr repo.proxy_username = self.proxy_user repo.proxy_password = self.proxy_pass # Do not try to expand baseurl to other mirrors if no_mirrors: repo.urls = repo.baseurl # Make sure baseurl ends with / and urljoin will work correctly if repo.urls[0][-1] != '/': repo.urls[0] += '/' else: warnings = YumWarnings() warnings.disable() try: repo.baseurlSetup() except: warnings.restore() raise warnings.restore() # if self.url is metalink it will be expanded into # real urls in repo.urls and also save this metalink # in begin of the url list ("for repolist -v ... or anything else wants to know the baseurl") # Remove it from the list, we don't need it to download content of repo repo.urls = [url for url in repo.urls if '?' not in url] repo.interrupt_callback = self.interrupt_callback repo.setup(0)
def __init__(self, root, url, org): self.root = root self.baseurl = [url] self.basecachedir = os.path.join(CACHE_DIR, org) self.pkgdir = os.path.join(CFG.MOUNT_POINT, CFG.PREPENDED_DIR, org, 'stage') self.urls = self.baseurl # Make sure baseurl ends with / and urljoin will work correctly if self.urls[0][-1] != '/': self.urls[0] += '/' # Make sure root paths are created if not os.path.isdir(self.root): fileutils.makedirs(self.root, user='******', group='www') if not os.path.isdir(self.pkgdir): fileutils.makedirs(self.pkgdir, user='******', group='www') self.is_configured = False
def setup_repo(self, repo, no_mirrors): """Fetch repository metadata""" repo.cache = 0 repo.mirrorlist = self.url repo.baseurl = [self.url] repo.basecachedir = os.path.join(CACHE_DIR, self.org) # base_persistdir have to be set before pkgdir if hasattr(repo, 'base_persistdir'): repo.base_persistdir = repo.basecachedir pkgdir = os.path.join(CFG.MOUNT_POINT, CFG.PREPENDED_DIR, self.org, 'stage') if not os.path.isdir(pkgdir): fileutils.makedirs(pkgdir, user='******', group='apache') repo.pkgdir = pkgdir repo.sslcacert = None repo.sslclientcert = None repo.sslclientkey = None repo.proxy = None repo.proxy_username = None repo.proxy_password = None if "file://" in self.url: repo.copy_local = 1 yb_cfg = self.yumbase.conf.cfg if not ((yb_cfg.has_section(self.name) and yb_cfg.has_option(self.name, 'proxy')) or (yb_cfg.has_section('main') and yb_cfg.has_option('main', 'proxy'))) and \ self.proxy_addr is not None: repo.proxy = "http://%s" % self.proxy_addr repo.proxy_username = self.proxy_user repo.proxy_password = self.proxy_pass # Do not try to expand baseurl to other mirrors if no_mirrors: repo.urls = repo.baseurl # Make sure baseurl ends with / and urljoin will work correctly if repo.urls[0][-1] != '/': repo.urls[0] += '/' else: warnings = YumWarnings() warnings.disable() try: repo.baseurlSetup() except: warnings.restore() raise warnings.restore() repo.setup(0)
def __init__(self, url, cache_dir, pkg_dir): self.url = url parts = url.split('/dists') self.base_url = [parts[0]] # Make sure baseurl ends with / and urljoin will work correctly if self.base_url[0][-1] != '/': self.base_url[0] += '/' self.urls = self.base_url self.sslclientcert = self.sslclientkey = self.sslcacert = None self.proxy = self.proxy_username = self.proxy_password = None self.basecachedir = cache_dir if not os.path.isdir(self.basecachedir): fileutils.makedirs(self.basecachedir, user='******', group='apache') self.includepkgs = [] self.exclude = [] self.pkgdir = pkg_dir
def setup_repo(self, repo, no_mirrors): """Fetch repository metadata""" repo.cache = 0 repo.mirrorlist = self.url repo.baseurl = [self.url] repo.basecachedir = os.path.join(CACHE_DIR, self.org) # base_persistdir have to be set before pkgdir if hasattr(repo, 'base_persistdir'): repo.base_persistdir = repo.basecachedir pkgdir = os.path.join(CFG.MOUNT_POINT, CFG.PREPENDED_DIR, self.org, 'stage') if not os.path.isdir(pkgdir): fileutils.makedirs(pkgdir, user='******', group='apache') repo.pkgdir = pkgdir repo.sslcacert = None repo.sslclientcert = None repo.sslclientkey = None repo.proxy = None repo.proxy_username = None repo.proxy_password = None if "file://" in self.url: repo.copy_local = 1 if self.proxy_addr: repo.proxy = "http://%s" % self.proxy_addr repo.proxy_username = self.proxy_user repo.proxy_password = self.proxy_pass # Do not try to expand baseurl to other mirrors if no_mirrors: repo.urls = repo.baseurl # Make sure baseurl ends with / and urljoin will work correctly if repo.urls[0][-1] != '/': repo.urls[0] += '/' else: warnings = YumWarnings() warnings.disable() try: repo.baseurlSetup() except: warnings.restore() raise warnings.restore() repo.interrupt_callback = self.interrupt_callback repo.setup(0)
def _safe_create(fname, user, group, mode): """ This function returns a file descriptor for the open file fname If the file is already there, it is truncated otherwise, all the directories up to it are created and the file is created as well. """ # There can be race conditions between the moment we check for the file # existence and when we actually create it, so retry if something fails tries = 5 while tries: tries = tries - 1 # we're really picky about what can we do if os.access(fname, os.F_OK): # file exists if not os.access(fname, os.R_OK | os.W_OK): raise UnreadableFileError() fd = os.open(fname, os.O_WRONLY | os.O_TRUNC) # We're done return fd # If directory does not exist, attempt to create it dirname = os.path.dirname(fname) if not os.path.isdir(dirname): try: #os.makedirs(dirname, 0755) makedirs(dirname, mode, user, group) except OSError, e: # There is a window between the moment we check the disk and # the one we try to create the directory # We double-check the file existance here if not (e.errno == EEXIST and os.path.isdir(dirname)): # If the exception was thrown on a parent dir # check the subdirectory to go through next loop. if os.path.isdir(e.filename): continue # Pass exception through raise except:
def _safe_create(fname, user, group, mode): """ This function returns a file descriptor for the open file fname If the file is already there, it is truncated otherwise, all the directories up to it are created and the file is created as well. """ # There can be race conditions between the moment we check for the file # existence and when we actually create it, so retry if something fails tries = 5 while tries: tries = tries - 1 # we're really picky about what can we do if os.access(fname, os.F_OK): # file exists if not os.access(fname, os.R_OK|os.W_OK): raise UnreadableFileError() fd = os.open(fname, os.O_WRONLY | os.O_TRUNC ) # We're done return fd # If directory does not exist, attempt to create it dirname = os.path.dirname(fname) if not os.path.isdir(dirname): try: #os.makedirs(dirname, 0755) makedirs(dirname, mode, user, group) except OSError, e: # There is a window between the moment we check the disk and # the one we try to create the directory # We double-check the file existance here if not (e.errno == EEXIST and os.path.isdir(dirname)): # If the exception was thrown on a parent dir # check the subdirectory to go through next loop. if os.path.isdir(e.filename): continue # Pass exception through raise except:
def setup_repo(self, repo): """Fetch repository metadata""" repo.cache = 0 repo.metadata_expire = 0 repo.mirrorlist = self.url repo.baseurl = [self.url] repo.basecachedir = CACHE_DIR # base_persistdir have to be set before pkgdir if hasattr(repo, 'base_persistdir'): repo.base_persistdir = CACHE_DIR if (self.url.find("file://") < 0): pkgdir = os.path.join(CFG.MOUNT_POINT, CFG.PREPENDED_DIR, '1', 'stage') if not os.path.isdir(pkgdir): fileutils.makedirs(pkgdir, user='******', group='apache') else: pkgdir = self.url[7:] repo.pkgdir = pkgdir yb_cfg = self.yumbase.conf.cfg if not ((yb_cfg.has_section(self.name) and yb_cfg.has_option(self.name, 'proxy')) or (yb_cfg.has_section('main') and yb_cfg.has_option('main', 'proxy'))) and \ self.proxy_addr is not None: repo.proxy = "http://%s" % self.proxy_addr repo.proxy_username = self.proxy_user repo.proxy_password = self.proxy_pass warnings = YumWarnings() warnings.disable() try: repo.baseurlSetup() except: warnings.restore() raise warnings.restore() repo.setup(False) self.sack = self.repo.getPackageSack()
def _safe_create(fname, user, group, mode): """ This function returns a file descriptor for the open file fname If the file is already there, it is truncated otherwise, all the directories up to it are created and the file is created as well. """ # There can be race conditions between the moment we check for the file # existence and when we actually create it, so retry if something fails tries = 5 while tries: tries = tries - 1 # we're really picky about what can we do if os.access(fname, os.F_OK): # file exists if not os.access(fname, os.R_OK | os.W_OK): raise UnreadableFileError() fd = os.open(fname, os.O_WRONLY | os.O_TRUNC) # We're done return fd # If directory does not exist, attempt to create it dirname = os.path.dirname(fname) if not os.path.isdir(dirname): try: #os.makedirs(dirname, 0755) makedirs(dirname, mode, user, group) except OSError: e = sys.exc_info()[1] # There is a window between the moment we check the disk and # the one we try to create the directory # We double-check the file existance here if not (e.errno == EEXIST and os.path.isdir(dirname)): # If the exception was thrown on a parent dir # check the subdirectory to go through next loop. if os.path.isdir(e.filename): continue # Pass exception through raise except: # Pass exception through raise # If we got here, it means the directory exists # file does not exist, attempt to create it # we pass most of the exceptions through try: fd = os.open(fname, os.O_WRONLY | os.O_CREAT | os.O_EXCL, int('0644', 8)) except OSError: e = sys.exc_info()[1] # The file may be already there if e.errno == EEXIST and os.access(fname, os.F_OK): # Retry continue # Pass exception through raise # If we got here, the file is created, so break out of the loop setPermsPath(fname, user, group, mode) return fd # Ran out of tries; something is fishy # (if we manage to create or truncate the file, we've returned from the # function already) raise RuntimeError("Attempt to create file %s failed" % fname)
def _safe_create(fname, user, group, mode): """ This function returns a file descriptor for the open file fname If the file is already there, it is truncated otherwise, all the directories up to it are created and the file is created as well. """ # There can be race conditions between the moment we check for the file # existence and when we actually create it, so retry if something fails tries = 5 while tries: tries = tries - 1 # we're really picky about what can we do if os.access(fname, os.F_OK): # file exists if not os.access(fname, os.R_OK | os.W_OK): raise UnreadableFileError() fd = os.open(fname, os.O_WRONLY | os.O_TRUNC) # We're done return fd # If directory does not exist, attempt to create it dirname = os.path.dirname(fname) if not os.path.isdir(dirname): try: #os.makedirs(dirname, 0755) makedirs(dirname, mode, user, group) except OSError: e = sys.exc_info()[1] # There is a window between the moment we check the disk and # the one we try to create the directory # We double-check the file existance here if not (e.errno == EEXIST and os.path.isdir(dirname)): # If the exception was thrown on a parent dir # check the subdirectory to go through next loop. if os.path.isdir(e.filename): continue # Pass exception through raise except: # Pass exception through raise # If we got here, it means the directory exists # file does not exist, attempt to create it # we pass most of the exceptions through try: fd = os.open(fname, os.O_WRONLY | os.O_CREAT | os.O_EXCL, int('0644', 8)) except OSError: e = sys.exc_info()[1] # The file may be already there if e.errno == EEXIST and os.access(fname, os.F_OK): # Retry continue # Pass exception through raise # If we got here, the file is created, so break out of the loop setPermsPath(fname, user, group, mode) return fd # Ran out of tries; something is fishy # (if we manage to create or truncate the file, we've returned from the # function already) raise RuntimeError("Attempt to create file %s failed" % fname)
def setup_repo(self, repo, no_mirrors, ca_cert_file, client_cert_file, client_key_file): """Fetch repository metadata""" repo.cache = 0 repo.mirrorlist = self.url repo.baseurl = [self.url] repo.basecachedir = os.path.join(CACHE_DIR, self.org) repo.setAttribute('_override_sigchecks', False) if self.insecure: repo.repo_gpgcheck = False else: repo.repo_gpgcheck = True # base_persistdir have to be set before pkgdir if hasattr(repo, 'base_persistdir'): repo.base_persistdir = repo.basecachedir pkgdir = os.path.join(CFG.MOUNT_POINT, CFG.PREPENDED_DIR, self.org, 'stage') if not os.path.isdir(pkgdir): fileutils.makedirs(pkgdir, user='******', group='www') repo.pkgdir = pkgdir repo.sslcacert = ca_cert_file repo.sslclientcert = client_cert_file repo.sslclientkey = client_key_file repo.proxy = None repo.proxy_username = None repo.proxy_password = None if "file://" in self.url: repo.copy_local = 1 if self.proxy_url is not None: repo.proxy = self.proxy_url repo.proxy_username = self.proxy_user repo.proxy_password = self.proxy_pass # Do not try to expand baseurl to other mirrors if no_mirrors: repo.urls = repo.baseurl # FIXME: SUSE # Make sure baseurl ends with / and urljoin will work correctly if repo.urls[0][-1] != '/': repo.urls[0] += '/' else: warnings = YumWarnings() warnings.disable() try: repo.baseurlSetup() except: warnings.restore() raise warnings.restore() # if self.url is metalink it will be expanded into # real urls in repo.urls and also save this metalink # in begin of the url list ("for repolist -v ... or anything else wants to know the baseurl") # Remove it from the list, we don't need it to download content of repo # # SUSE uses tokens which have ? and this must stay # #repo.urls = [url for url in repo.urls if '?' not in url] for burl in repo.baseurl: (scheme, netloc, path, query, fragid) = urlparse.urlsplit(burl) repo.gpgkey = [ urlparse.urlunsplit( (scheme, netloc, path + '/repodata/repomd.xml.key', query, fragid)) ] repo.setup(0, None, gpg_import_func=self.getKeyForRepo, confirm_func=self.askImportKey) # use a fix dir for repo metadata sig checks repo.gpgdir = GPG_DIR self.initgpgdir(repo.gpgdir)
def setup_repo(self, repo, no_mirrors, ca_cert_file, client_cert_file, client_key_file): """Fetch repository metadata""" repo.cache = 0 repo.mirrorlist = self.url repo.baseurl = [self.url] repo.basecachedir = os.path.join(CACHE_DIR, self.org) repo.setAttribute('_override_sigchecks', False) if self.insecure: repo.repo_gpgcheck = False else: repo.repo_gpgcheck = True # base_persistdir have to be set before pkgdir if hasattr(repo, 'base_persistdir'): repo.base_persistdir = repo.basecachedir pkgdir = os.path.join(CFG.MOUNT_POINT, CFG.PREPENDED_DIR, self.org, 'stage') if not os.path.isdir(pkgdir): fileutils.makedirs(pkgdir, user='******', group='www') repo.pkgdir = pkgdir repo.sslcacert = ca_cert_file repo.sslclientcert = client_cert_file repo.sslclientkey = client_key_file repo.proxy = None repo.proxy_username = None repo.proxy_password = None if "file://" in self.url: repo.copy_local = 1 if self.proxy_url is not None: repo.proxy = self.proxy_url repo.proxy_username = self.proxy_user repo.proxy_password = self.proxy_pass # Do not try to expand baseurl to other mirrors if no_mirrors: repo.urls = repo.baseurl # FIXME: SUSE # Make sure baseurl ends with / and urljoin will work correctly if repo.urls[0][-1] != '/': repo.urls[0] += '/' else: warnings = YumWarnings() warnings.disable() try: repo.baseurlSetup() except: warnings.restore() raise warnings.restore() # if self.url is metalink it will be expanded into # real urls in repo.urls and also save this metalink # in begin of the url list ("for repolist -v ... or anything else wants to know the baseurl") # Remove it from the list, we don't need it to download content of repo # # SUSE uses tokens which have ? and this must stay # #repo.urls = [url for url in repo.urls if '?' not in url] for burl in repo.baseurl: (scheme, netloc, path, query, fragid) = urlparse.urlsplit(burl) repo.gpgkey = [urlparse.urlunsplit((scheme, netloc, path + '/repodata/repomd.xml.key', query, fragid))] repo.setup(0, None, gpg_import_func=self.getKeyForRepo, confirm_func=self.askImportKey) # use a fix dir for repo metadata sig checks repo.gpgdir = GPG_DIR self.initgpgdir( repo.gpgdir )