From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-636490-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	by finch.gentoo.org (Postfix) with ESMTP id CF9CA138202
	for <garchives@archives.gentoo.org>; Fri, 18 Oct 2013 06:46:23 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id 4EC8FE0B71;
	Fri, 18 Oct 2013 06:46:20 +0000 (UTC)
Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183])
	(using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id 9840BE0B71
	for <gentoo-commits@lists.gentoo.org>; Fri, 18 Oct 2013 06:46:19 +0000 (UTC)
Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163])
	(using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id 60EF333F023
	for <gentoo-commits@lists.gentoo.org>; Fri, 18 Oct 2013 06:46:17 +0000 (UTC)
Received: from localhost.localdomain (localhost [127.0.0.1])
	by hornbill.gentoo.org (Postfix) with ESMTP id 8742EE5308
	for <gentoo-commits@lists.gentoo.org>; Fri, 18 Oct 2013 06:46:16 +0000 (UTC)
From: "Brian Dolbec" <brian.dolbec@gmail.com>
To: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: 8bit
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Brian Dolbec" <brian.dolbec@gmail.com>
Message-ID: <1382061987.db2455365da647e2e03961724667d9fe4f95850c.dol-sen@gentoo>
Subject: [gentoo-commits] proj/mirrorselect:master commit in: mirrorselect/
X-VCS-Repository: proj/mirrorselect
X-VCS-Files: mirrorselect/configs.py
X-VCS-Directories: mirrorselect/
X-VCS-Committer: dol-sen
X-VCS-Committer-Name: Brian Dolbec
X-VCS-Revision: db2455365da647e2e03961724667d9fe4f95850c
X-VCS-Branch: master
Date: Fri, 18 Oct 2013 06:46:16 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Archives-Salt: 09fe8f96-6ee5-45b5-ab63-5414bbd65d3d
X-Archives-Hash: 3294fd8195cba446e2a3d93d96813bc6

commit:     db2455365da647e2e03961724667d9fe4f95850c
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Fri Oct 18 02:06:27 2013 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Fri Oct 18 02:06:27 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/mirrorselect.git;a=commit;h=db245536

get_filesystem_mirrors() cleanup & fixes

Fix py3 string.letters error
Unwrap function in try: except:, narrow it to only lex.get_token()
Cleanup sloppy/redundant code.
Thanks to Arfrever's help.

---
 mirrorselect/configs.py | 78 ++++++++++++++++++++++++++++---------------------
 1 file changed, 44 insertions(+), 34 deletions(-)

diff --git a/mirrorselect/configs.py b/mirrorselect/configs.py
index 8a83287..9fa4f2c 100644
--- a/mirrorselect/configs.py
+++ b/mirrorselect/configs.py
@@ -40,6 +40,12 @@ import string
 import sys
 
 
+try: # py2
+	letters = string.letters
+except AttributeError: # py3
+	letters = string.ascii_letters
+
+
 def get_make_conf_path(EPREFIX):
 		# try the newer make.conf location
 		config_path = EPREFIX + '/etc/portage/make.conf'
@@ -120,6 +126,16 @@ def get_filesystem_mirrors(output, config_path, sync=False):
 		make.conf variable target
 	@rtype list
 	"""
+
+	def get_token(lex):
+		'''internal function for getting shlex tokens
+		'''
+		try:
+			val = lex.get_token()
+		except ValueError:
+			val = None
+		return val
+
 	fsmirrors = []
 
 	if sync:
@@ -134,42 +150,36 @@ def get_filesystem_mirrors(output, config_path, sync=False):
 		return fsmirrors
 
 	""" Search for 'var' in make.conf and extract value """
-	try:
-		lex = shlex.shlex(f, posix=True)
-		lex.wordchars = string.digits+string.letters+"~!@#$%*_\:;?,./-+{}"
-		lex.quotes = "\"'"
-		while 1:
-			key = lex.get_token()
-			#output.write('get_filesystem_mirrors(): processing key = %s\n' % key, 2)
-
-			if key == var:
-				equ = lex.get_token()
-
-				if (equ == ''):
-					break
-				elif (equ != '='):
-					break
-
-				val = lex.get_token()
-				if val is None:
-					break
-
-				""" Look for mounted filesystem in value """
-				mirrorlist = val.rsplit()
-				output.write('get_filesystem_mirrors(): mirrorlist = %s\n' % mirrorlist, 2)
-				p = re.compile('rsync://|http://|ftp://', re.IGNORECASE)
-				for mirror in mirrorlist:
-					if (p.match(mirror) == None):
-						if os.access(mirror, os.F_OK):
-							output.write('get_filesystem_mirrors(): found file system mirror = %s\n' % mirror, 2)
-							fsmirrors.append(mirror)
-						else:
-							output.write('get_filesystem_mirrors(): ignoring non-accessible mirror = %s\n' % mirror, 2)
+	lex = shlex.shlex(f, posix=True)
+	lex.wordchars = string.digits+letters+"~!@#$%*_\:;?,./-+{}"
+	lex.quotes = "\"'"
+	p = re.compile('rsync://|http://|ftp://', re.IGNORECASE)
+	while 1:
+		key = get_token(lex)
+		#output.write('get_filesystem_mirrors(): processing key = %s\n' % key, 2)
+
+		if key == var:
+			equ = get_token(lex)
+			if (equ != '='):
 				break
-			elif key is None:
+
+			val = get_token(lex)
+			if val is None:
 				break
-	except Exception:
-		fsmirrors = []
+
+			""" Look for mounted filesystem in value """
+			mirrorlist = val.rsplit()
+			output.write('get_filesystem_mirrors(): mirrorlist = %s\n' % mirrorlist, 2)
+			for mirror in mirrorlist:
+				if (p.match(mirror) == None):
+					if os.access(mirror, os.F_OK):
+						output.write('get_filesystem_mirrors(): found file system mirror = %s\n' % mirror, 2)
+						fsmirrors.append(mirror)
+					else:
+						output.write('get_filesystem_mirrors(): ignoring non-accessible mirror = %s\n' % mirror, 2)
+			break
+		elif key is None:
+			break
 
 	output.write('get_filesystem_mirrors(): fsmirrors = %s\n' % fsmirrors, 2)
 	return fsmirrors