public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-portage-dev] [PATCH] Make use of optparse to fix argument parsing for Python 2.6 in bin/chpathtool.py.
@ 2013-12-29  1:54 Tom Wijsman
  2013-12-29  2:21 ` Tom Wijsman
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Wijsman @ 2013-12-29  1:54 UTC (permalink / raw
  To: gentoo-portage-dev

---
 bin/chpathtool.py | 43 ++++++++++++++++++++++++++++++++-----------
 1 file changed, 32 insertions(+), 11 deletions(-)

diff --git a/bin/chpathtool.py b/bin/chpathtool.py
index aa3b7d4..692a338 100755
--- a/bin/chpathtool.py
+++ b/bin/chpathtool.py
@@ -11,7 +11,11 @@ import os
 import stat
 import sys
 
-from portage.util._argparse import ArgumentParser
+if sys.hexversion < 0x2070000:
+	# Argument parsing compatibility for Python 2.6 using optparse.
+	from optparse import OptionParser
+else:
+	from portage.util._argparse import ArgumentParser
 
 CONTENT_ENCODING = 'utf_8'
 FS_ENCODING = 'utf_8'
@@ -145,17 +149,34 @@ def chpath_inplace_symlink(filename, st, old, new):
 		os.lchown(filename, st.st_uid, st.st_gid)
 
 def main(argv):
+	if sys.hexversion < 0x2070000:
+		# Argument parsing compatibility for Python 2.6 using optparse.
+		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
 
-	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
+		location, old, new = args[0:3]
+	else:
+		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
 
 	is_text_file = IsTextFile()
 
-- 
1.8.5.2



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-12-29 15:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-29  1:54 [gentoo-portage-dev] [PATCH] Make use of optparse to fix argument parsing for Python 2.6 in bin/chpathtool.py Tom Wijsman
2013-12-29  2:21 ` Tom Wijsman
2013-12-29 15:34   ` Sebastian Luther
2013-12-29 15:51     ` Tom Wijsman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox