From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id B7121138247 for ; Sun, 29 Dec 2013 02:22:14 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id DA53EE0AFE; Sun, 29 Dec 2013 02:22:11 +0000 (UTC) Received: from gerard.telenet-ops.be (gerard.telenet-ops.be [195.130.132.48]) by pigeon.gentoo.org (Postfix) with ESMTP id 0E869E0AF6 for ; Sun, 29 Dec 2013 02:22:10 +0000 (UTC) Received: from localhost.localdomain ([94.226.55.127]) by gerard.telenet-ops.be with bizsmtp id 7EN91n00K2khLEN0HEN9Yu; Sun, 29 Dec 2013 03:22:10 +0100 From: Tom Wijsman To: gentoo-portage-dev@lists.gentoo.org Subject: [gentoo-portage-dev] [PATCH] Make use of optparse to fix argument parsing for Python 2.6 in bin/chpathtool.py. Date: Sun, 29 Dec 2013 03:21:48 +0100 Message-Id: <1388283708-11119-1-git-send-email-tomwij@gentoo.org> X-Mailer: git-send-email 1.8.5.2 In-Reply-To: <1388282061-10347-1-git-send-email-tomwij@gentoo.org> References: <1388282061-10347-1-git-send-email-tomwij@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-portage-dev@lists.gentoo.org Reply-to: gentoo-portage-dev@lists.gentoo.org X-Archives-Salt: 29acea80-b54c-41a5-8349-780c42f149fa X-Archives-Hash: 56bdd1664b6ec1dd5f0e3bdffc0dab8d --- 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() -- 1.8.5.2