import logging
log = logging.getLogger("pakfire")
-from config import Config
+from config import _Config
from urlgrabber.grabber import URLGrabber, URLGrabError
from urlgrabber.mirror import MirrorGroup
kwargs.update({
"quote" : 0,
"user_agent" : "pakfire/%s" % PAKFIRE_VERSION,
+
+ "ssl_verify_host" : False,
+ "ssl_verify_peer" : False,
})
- if isinstance(pakfire, Config):
+ if isinstance(pakfire, _Config):
config = pakfire
else:
config = pakfire.config
- if config.get("offline"):
+ if config.get("downloader", "offline"):
raise OfflineModeError, "Cannot use %s in offline mode." % self.__class__.__name__
# Set throttle setting.
- bandwidth_throttle = config.get("bandwidth_throttle")
+ bandwidth_throttle = config.get("downloader", "bandwidth_throttle")
if bandwidth_throttle:
try:
bandwidth_throttle = int(bandwidth_throttle)
kwargs.update({ "throttle" : bandwidth_throttle })
# Configure HTTP proxy.
- http_proxy = config.get("http_proxy")
+ http_proxy = config.get("downloader", "http_proxy")
if http_proxy:
kwargs.update({ "proxies" : { "http" : http_proxy }})
# a unicode string.
return URLGrabber.urlread(self, filename.encode("utf-8"), *args, **kwargs)
+ def urlopen(self, filename, *args, **kwargs):
+ # However, urlopen requires the filename to be an ordinary string object.
+ filename = str(filename)
+
+ return URLGrabber.urlopen(self, filename, *args, **kwargs)
+
class PackageDownloader(PakfireGrabber):
def __init__(self, pakfire, *args, **kwargs):
class MirrorList(object):
- def __init__(self, pakfire, repo):
+ def __init__(self, pakfire, repo, mirrorlist):
self.pakfire = pakfire
self.repo = repo
self.__mirrors = []
# Save URL to more mirrors.
- self.mirrorlist = repo.mirrorlist
+ self.mirrorlist = mirrorlist
- self.update(force=False)
+ @property
+ def base_mirror(self):
+ if not self.repo.baseurl:
+ return
+
+ return Mirror(self.repo.baseurl, preferred=False)
+
+ @property
+ def distro(self):
+ return self.repo.distro
@property
def cache(self):
return
log.debug("Updating mirrorlist for repository '%s' (force=%s)" % (self.repo.name, force))
-
- cache_filename = "mirrors/mirrorlist"
+ cache_filename = os.path.join("repodata", self.distro.sname, self.distro.release,
+ self.repo.name, self.distro.arch, "mirrors")
# Force the update if no mirrorlist is available.
if not self.cache.exists(cache_filename):
f.close()
# Read mirrorlist from cache and parse it.
+ self.forget_mirrors()
with self.cache.open(cache_filename) as f:
self.parse_mirrordata(f.read())
self.__mirrors.append(mirror)
+ def forget_mirrors(self):
+ self.__mirrors = []
+
+ if self.base_mirror:
+ self.__mirrors.append(self.base_mirror)
+
@property
def preferred(self):
"""
"""
Return a MirrorGroup object for the given grabber.
"""
+ # Make sure the mirrorlist is up to date.
+ self.update()
+
# A list of mirrors that is passed to MirrorGroup.
mirrors = []