Kaydet (Commit) fcf2f8a4 authored tarafından Faik Uygur's avatar Faik Uygur

* mirrors:// support added.

----

mirrors.conf example:

faik@iago ~ $ cat /etc/pisi/mirrors.conf
# Sourceforge mirrors
sourceforge      http://pardus.dl.sourceforge.net/sourceforge
sourceforge      http://easynews.dl.sourceforge.net/sourceforge

# Gnu mirrors
gnu              ftp://mirrors.hbi.co.jp/gnu
gnu              ftp://core.ring.gr.jp/pub/GNU
gnu              ftp://mirror.aarnet.edu.au/pub/gnu

# Local mirrors
local            http://192.168.3.8

----

pspec.xml line example:

<Archive ... >mirrors://sourceforge/cracklib/cracklib-2.8.9.tar.gz</Archive>

----

Output example:

Kaynak system.base bileşeninin parçası
Kaynak mirrors://sourceforge/cracklib/cracklib-2.8.9.tar.gz adresinden indiriliyor
Fetching source from mirror: http://pardus.dl.sourceforge.net/sourceforge/cracklib/cracklib-2.8.9.tar.gz
Fetching source from mirror: http://easynews.dl.sourceforge.net/sourceforge/cracklib/cracklib-2.8.9.tar.gz
cracklib-2.8.9.tar.gz          (562.0 KB)100%     72.42 KB/s [00:00:00] [bitti]
Kaynak arşivi saklandı:  /var/cache/pisi/archives/cracklib-2.8.9.tar.gz
Arşiv açılıyor... açıldı (/var/tmp/pisi/cracklib-2.8.9-3/work)
üst f3de0da0
......@@ -78,6 +78,7 @@ class Constants:
self.__c.metadata_xml = "metadata.xml"
self.__c.install_tar = "install.tar"
self.__c.install_tar_lzma = "install.tar.lzma"
self.__c.mirrors_conf = "/etc/pisi/mirrors.conf"
#file/directory permissions
self.__c.umask = 0022
......
# -*- coding: utf-8 -*-
#
# Copyright (C) 2006, TUBITAK/UEKAE
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# Please read the COPYING file.
import os.path
import pisi.context as ctx
from pisi import Error
import gettext
__trans = gettext.translation('pisi', fallback=True)
_ = __trans.ugettext
class Mirrors:
def __init__(self, config=ctx.const.mirrors_conf):
self.mirrors = {}
self._parse(config)
def get_mirrors(self, name):
if self.mirrors.has_key(name):
return list(self.mirrors[name])
return None
def _add_mirror(self, name, url):
if self.mirrors.has_key(name):
self.mirrors[name].append(url)
else:
self.mirrors[name] = [url]
def _parse(self, config):
if os.path.exists(config):
for line in open(config, "r").readlines():
if not line.startswith('#') and not line == '\n':
mirror = line.strip().split()
if len(mirror) == 2:
(name, url) = mirror
self._add_mirror(name, url)
else:
raise Error(_('Mirrors file %s does not exist. Could not resolve mirrors://') % config)
......@@ -28,6 +28,7 @@ import pisi.context as ctx
from pisi.archive import Archive
from pisi.uri import URI
from pisi.fetcher import fetch_url
from pisi.mirrors import Mirrors
class Error(pisi.Error):
pass
......@@ -44,21 +45,48 @@ class SourceArchive:
def fetch(self, interactive=True):
if not self.is_cached(interactive):
if interactive:
progress = ctx.ui.Progress
self.progress = ctx.ui.Progress
else:
progress = None
self.progress = None
try:
fetch_url(self.url, ctx.config.archives_dir(), progress)
if self.url.get_uri().startswith("mirrors://"):
self.fetch_from_mirror()
else:
fetch_url(self.url, ctx.config.archives_dir(), self.progress)
except pisi.fetcher.FetchError:
# if archive can not be reached from the url, try the fallback
# address.
if ctx.config.values.build.fallback:
archive = basename(self.url.get_uri())
src = join(ctx.config.values.build.fallback, archive)
fetch_url(src, ctx.config.archives_dir(), progress)
self.fetch_from_fallback()
else:
raise
def fetch_from_fallback(self):
archive = basename(self.url.get_uri())
src = join(ctx.config.values.build.fallback, archive)
ctx.ui.warning(_('Trying fallback address: %s') % src)
fetch_url(src, ctx.config.archives_dir(), self.progress)
def fetch_from_mirror(self):
uri = self.url.get_uri()
sep = uri[len("mirrors://"):].split("/")
name = sep.pop(0)
archive = "/".join(sep)
mirrors = Mirrors().get_mirrors(name)
if not mirrors:
raise Error(_("%s mirrors are not defined.") % name)
for mirror in mirrors:
try:
url = join(mirror, archive)
ctx.ui.warning(_('Fetching source from mirror: %s') % url)
fetch_url(url, ctx.config.archives_dir(), self.progress)
return
except pisi.fetcher.FetchError:
pass
raise pisi.fetcher.FetchError(_('Could not fetch source from %s mirrors.') % name);
def is_cached(self, interactive=True):
if not access(self.archiveFile, R_OK):
return False
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment