public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Brian Dolbec" <brian.dolbec@gmail.com>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/mirrorselect:master commit in: mirrorselect/
Date: Tue, 15 Oct 2013 03:51:22 +0000 (UTC)	[thread overview]
Message-ID: <1381808932.e5e82eb4ec1517144bf25d7ffc48b86109f60150.dol-sen@gentoo> (raw)

commit:     e5e82eb4ec1517144bf25d7ffc48b86109f60150
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Tue Oct 15 03:48:52 2013 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Tue Oct 15 03:48:52 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/mirrorselect.git;a=commit;h=e5e82eb4

Add country and region filtering in the xml parsing.

Move protocol filtering to the new xml filtering system.

---
 mirrorselect/main.py          | 10 ++++++++++
 mirrorselect/mirrorparser3.py | 21 +++++++++++++++++++--
 mirrorselect/selectors.py     |  8 +-------
 3 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/mirrorselect/main.py b/mirrorselect/main.py
index 3f90694..5ba9116 100755
--- a/mirrorselect/main.py
+++ b/mirrorselect/main.py
@@ -271,6 +271,16 @@ class MirrorSelect(object):
 		group.add_option(
 			"-6", "--ipv6", action="store_true", default=False,
 			help="only use IPv6")
+		group.add_option(
+			"-c", "--country", action="store", default=None,
+			help="only use mirrors from the specified country "
+			"NOTE: Names with a space must be quoted "
+			"eg.:  -c 'South Korea'")
+		group.add_option(
+			"-R", "--region", action="store", default=None,
+			help="only use mirrors from the specified region"
+			"NOTE: Names with a space must be quoted"
+			"eg.:  -r 'North America'")
 
 		group = parser.add_option_group("Other options")
 		group.add_option(

diff --git a/mirrorselect/mirrorparser3.py b/mirrorselect/mirrorparser3.py
index e34f9c2..976ff17 100644
--- a/mirrorselect/mirrorparser3.py
+++ b/mirrorselect/mirrorparser3.py
@@ -35,7 +35,15 @@ MIRRORS_3_XML = 'http://www.gentoo.org/main/en/mirrors3.xml'
 MIRRORS_RSYNC_DATA = 'http://www.gentoo.org/main/en/mirrors-rsync-data.xml'
 
 class MirrorParser3:
-	def __init__(self):
+	def __init__(self, options=None):
+		self.filters = {}
+		for opt in ["country", "region"]:
+			value = getattr(options, opt)
+			if value is not None:
+				self.filters[opt] = value
+		for opt in ["ftp", "http"]:
+			if getattr(options, opt):
+				self.filters["proto"] = opt
 		self._reset()
 
 	def _reset(self):
@@ -51,7 +59,7 @@ class MirrorParser3:
 						name = e.text
 					if e.tag == 'uri':
 						uri = e.text
-						self._dict[uri] = {
+						data = {
 							"name": name,
 							"country": mirrorgroup.get("countryname"),
 							"region": mirrorgroup.get("region"),
@@ -59,6 +67,15 @@ class MirrorParser3:
 							"ipv6": e.get("ipv6"),
 							"proto": e.get("protocol"),
 							}
+						if len(self.filters):
+							good = True
+							for f in self.filters:
+								if data[f] != self.filters[f]:
+									good = False
+							if good:
+								self._dict[uri] = data
+						else:
+							self._dict[uri] = data
 
 	def tuples(self):
 		return [(url, args) for url, args in list(self._dict.items())]

diff --git a/mirrorselect/selectors.py b/mirrorselect/selectors.py
index 38ca07a..a603a47 100644
--- a/mirrorselect/selectors.py
+++ b/mirrorselect/selectors.py
@@ -58,19 +58,13 @@ class Extractor(object):
 
 	def __init__(self, list_url, options, output):
 		self.output = output
-		parser = MirrorParser3()
+		parser = MirrorParser3(options)
 		self.hosts = []
 
 		hosts = self.getlist(parser, list_url)
 		self.output.write('Extractor(): fetched mirrors.xml,'
 				' %s hosts before filtering\n' % len(hosts), 2)
 
-		if not options.rsync:
-			if options.ftp:
-				hosts = self.restrict_protocall('ftp', hosts)
-			if options.http:
-				hosts = self.restrict_protocall('http', hosts)
-
 		self.hosts = hosts
 
 	def restrict_protocall(self, prot, hosts):


             reply	other threads:[~2013-10-15  3:51 UTC|newest]

Thread overview: 86+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-15  3:51 Brian Dolbec [this message]
  -- strict thread matches above, loose matches on Subject: below --
2024-05-28  3:48 [gentoo-commits] proj/mirrorselect:master commit in: mirrorselect/ Sam James
2023-08-07  0:23 Sam James
2023-08-07  0:14 Sam James
2023-08-07  0:14 Sam James
2023-08-07  0:14 Sam James
2023-08-06 23:30 Sam James
2023-08-06 23:30 Sam James
2023-07-06  8:05 Sam James
2022-05-31 18:39 Brian Dolbec
2022-05-31 18:39 Brian Dolbec
2022-05-31 18:39 Brian Dolbec
2022-05-31 18:39 Brian Dolbec
2022-05-31  4:08 Brian Dolbec
2022-05-31  4:08 Brian Dolbec
2022-05-31  2:22 Brian Dolbec
2022-05-31  2:22 Brian Dolbec
2022-05-30 23:12 Brian Dolbec
2022-05-30 23:12 Brian Dolbec
2020-06-03 19:05 Brian Dolbec
2019-07-17  5:06 Zac Medico
2019-05-27 17:52 Zac Medico
2019-05-27 17:22 Zac Medico
2019-02-13  8:22 Zac Medico
2019-02-13  8:09 Zac Medico
2019-02-13  5:51 Zac Medico
2018-05-26 15:43 Brian Dolbec
2017-02-21  4:44 Zac Medico
2017-02-21  3:19 Brian Dolbec
2017-02-21  3:19 Brian Dolbec
2016-11-15  1:16 Zac Medico
2015-01-27 18:20 Brian Dolbec
2015-01-27  4:38 Brian Dolbec
2015-01-27  4:38 Brian Dolbec
2014-05-28 21:08 Brian Dolbec
2014-05-28 19:44 Brian Dolbec
2014-05-05  2:04 Brian Dolbec
2014-05-05  2:04 Brian Dolbec
2014-05-05  2:04 Brian Dolbec
2014-03-02  7:44 [gentoo-commits] proj/mirrorselect:ssl " Brian Dolbec
2014-03-02  7:44 ` [gentoo-commits] proj/mirrorselect:master " Brian Dolbec
2014-03-02  7:44 Brian Dolbec
2014-03-02  7:44 Brian Dolbec
2014-03-02  7:44 Brian Dolbec
2014-03-02  7:44 Brian Dolbec
2014-03-02  7:44 Brian Dolbec
2014-03-02  7:44 Brian Dolbec
2014-03-02  7:44 Brian Dolbec
2014-01-31 15:44 [gentoo-commits] proj/mirrorselect:ssl " Brian Dolbec
2014-03-02  7:44 ` [gentoo-commits] proj/mirrorselect:master " Brian Dolbec
2013-10-20 18:19 [gentoo-commits] proj/mirrorselect:ssl " Brian Dolbec
2014-03-02  7:44 ` [gentoo-commits] proj/mirrorselect:master " Brian Dolbec
2013-10-19  9:06 Brian Dolbec
2013-10-19  9:06 Brian Dolbec
2013-10-19  9:06 Brian Dolbec
2013-10-18 14:26 Brian Dolbec
2013-10-18  6:46 Brian Dolbec
2013-10-18  6:46 Brian Dolbec
2013-10-18  6:46 Brian Dolbec
2013-10-18  6:46 Brian Dolbec
2013-10-17 14:26 Brian Dolbec
2013-10-17  6:57 Brian Dolbec
2013-10-17  3:16 Brian Dolbec
2013-10-17  3:16 Brian Dolbec
2013-10-17  3:16 Brian Dolbec
2013-10-16  9:17 Brian Dolbec
2013-10-16  8:36 Brian Dolbec
2013-10-16  8:36 Brian Dolbec
2013-10-16  8:36 Brian Dolbec
2013-10-16  8:36 Brian Dolbec
2013-10-15 22:43 Brian Dolbec
2013-10-15 14:39 Brian Dolbec
2013-10-15 14:39 Brian Dolbec
2013-10-15 14:39 Brian Dolbec
2013-10-15  7:27 Brian Dolbec
2013-10-15  3:51 Brian Dolbec
2013-03-10 13:07 Brian Dolbec
2012-12-16  2:38 Brian Dolbec
2012-12-15 21:25 Brian Dolbec
2012-11-15  3:53 Brian Dolbec
2012-11-15  3:44 Brian Dolbec
2012-11-14 20:28 Paul Varner
2012-11-12 21:41 Brian Dolbec
2012-11-12 20:37 Brian Dolbec
2012-11-12 15:56 Brian Dolbec
2012-11-12  7:46 Brian Dolbec
2012-11-12  7:46 Brian Dolbec
2012-11-12  7:46 Brian Dolbec
2012-11-12  7:46 Brian Dolbec

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1381808932.e5e82eb4ec1517144bf25d7ffc48b86109f60150.dol-sen@gentoo \
    --to=brian.dolbec@gmail.com \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox