From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <gentoo-commits+bounces-655523-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 385E613894D for <garchives@archives.gentoo.org>; Sun, 5 Jan 2014 17:56:51 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 990ACE0AB8; Sun, 5 Jan 2014 17:56:50 +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 2B355E0AB8 for <gentoo-commits@lists.gentoo.org>; Sun, 5 Jan 2014 17:56:49 +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 CE68633F69C for <gentoo-commits@lists.gentoo.org>; Sun, 5 Jan 2014 17:56:48 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 51CEEE54AB for <gentoo-commits@lists.gentoo.org>; Sun, 5 Jan 2014 17:56:47 +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: <1388938715.d217db2bc76e4c1a2e75685b4a00e25f7d8142a8.dol-sen@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: bin/ X-VCS-Repository: proj/portage X-VCS-Files: bin/chpathtool.py X-VCS-Directories: bin/ X-VCS-Committer: dol-sen X-VCS-Committer-Name: Brian Dolbec X-VCS-Revision: d217db2bc76e4c1a2e75685b4a00e25f7d8142a8 X-VCS-Branch: master Date: Sun, 5 Jan 2014 17:56:47 +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: 4534573a-223d-44b4-bdaf-aeb6ef0971c4 X-Archives-Hash: 56c70a8eed4d2243b39e7ffa1cc7c5c8 commit: d217db2bc76e4c1a2e75685b4a00e25f7d8142a8 Author: Tom Wijsman <tomwij <AT> gentoo <DOT> org> AuthorDate: Sun Dec 29 02:21:48 2013 +0000 Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com> CommitDate: Sun Jan 5 16:18:35 2014 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=d217db2b Make use of optparse to fix argument parsing for Python 2.6 in bin/chpathtool.py. --- bin/chpathtool.py | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/bin/chpathtool.py b/bin/chpathtool.py index aa3b7d4..0cb5d64 100755 --- a/bin/chpathtool.py +++ b/bin/chpathtool.py @@ -13,6 +13,12 @@ import sys from portage.util._argparse import ArgumentParser +# Argument parsing compatibility for Python 2.6 using optparse. +if sys.hexversion < 0x2070000: + from optparse import OptionParser + +from optparse import OptionError + CONTENT_ENCODING = 'utf_8' FS_ENCODING = 'utf_8' @@ -147,15 +153,36 @@ def chpath_inplace_symlink(filename, st, old, new): def main(argv): parser = ArgumentParser(description=__doc__) - parser.add_argument('location', default=None, - help='root directory (e.g. $D)') - parser.add_argument('old', default=None, - help='original build prefix (e.g. /)') - parser.add_argument('new', default=None, - help='new install prefix (e.g. $EPREFIX)') - opts = parser.parse_args(argv) - - location, old, new = opts.location, opts.old, opts.new + try: + parser.add_argument('location', default=None, + help='root directory (e.g. $D)') + parser.add_argument('old', default=None, + help='original build prefix (e.g. /)') + parser.add_argument('new', default=None, + help='new install prefix (e.g. $EPREFIX)') + opts = parser.parse_args(argv) + + location, old, new = opts.location, opts.old, opts.new + except OptionError: + # Argument parsing compatibility for Python 2.6 using optparse. + if sys.hexversion < 0x2070000: + parser = OptionParser(description=__doc__, + usage="usage: %prog [-h] location old new\n\n" + \ + " location: root directory (e.g. $D)\n" + \ + " old: original build prefix (e.g. /)\n" + \ + " new: new install prefix (e.g. $EPREFIX)") + + (opts, args) = parser.parse_args() + + if len(args) != 3: + parser.print_usage() + print("%s: error: expected 3 arguments, got %i" + % (__file__, len(args))) + return + + location, old, new = args[0:3] + else: + raise is_text_file = IsTextFile()