public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "André Erdmann" <dywi@mailerd.de>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/R_overlay:master commit in: /, roverlay/
Date: Thu,  2 Aug 2012 15:14:18 +0000 (UTC)	[thread overview]
Message-ID: <1343920149.dbd601765440a1f735ead40c89c2c02d64c07af3.dywi@gentoo> (raw)

commit:     dbd601765440a1f735ead40c89c2c02d64c07af3
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Thu Aug  2 15:09:09 2012 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Thu Aug  2 15:09:09 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=dbd60176

main script, argutil: command_map

---
 roverlay.py         |    4 ++--
 roverlay/argutil.py |   38 ++++++++++++++++++++++----------------
 2 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/roverlay.py b/roverlay.py
index 3297325..bd250ea 100755
--- a/roverlay.py
+++ b/roverlay.py
@@ -62,8 +62,8 @@ COMMAND_DESCRIPTION = {
 
 commands, config_file, additional_config, extra_opts = \
 	roverlay.argutil.parse_argv (
-		CMD_DESC=COMMAND_DESCRIPTION,
-		DEFAULT_CONFIG="R-overlay.conf"
+		command_map=COMMAND_DESCRIPTION,
+		default_config_file="R-overlay.conf"
 	)
 
 OPTION = extra_opts.get

diff --git a/roverlay/argutil.py b/roverlay/argutil.py
index 4cefdbd..813a7d7 100644
--- a/roverlay/argutil.py
+++ b/roverlay/argutil.py
@@ -3,13 +3,13 @@ import os.path
 import argparse
 import roverlay
 
-def get_parser ( CMD_DESC, DEFAULT_CONFIG ):
+def get_parser ( command_map, default_config_file, default_command='create' ):
 
 	def is_fs_file ( value ):
 		f = os.path.abspath ( value )
 		if not os.path.isfile ( f ):
 			raise argparse.ArgumentTypeError (
-				"%r is not a file." % value
+				"{!r} is not a file.".format ( value )
 			)
 		return f
 
@@ -17,7 +17,7 @@ def get_parser ( CMD_DESC, DEFAULT_CONFIG ):
 		d = os.path.abspath ( value )
 		if not os.path.isdir ( d ):
 			raise argparse.ArgumentTypeError (
-				"%r is not a directory." % value
+				"{!r} is not a directory.".format ( value )
 			)
 		return d
 
@@ -25,7 +25,7 @@ def get_parser ( CMD_DESC, DEFAULT_CONFIG ):
 		d = os.path.abspath ( value )
 		if os.path.exists ( d ) and not os.path.isdir ( d ):
 			raise argparse.ArgumentTypeError (
-				"%r cannot be a directory." % value
+				"{!r} cannot be a directory.".format ( value )
 			)
 		return d
 
@@ -40,7 +40,13 @@ def get_parser ( CMD_DESC, DEFAULT_CONFIG ):
 			roverlay.description_str, roverlay.license_str,
 		)),
 		epilog = 'Known commands:\n' + '\n'.join (
-			( ( '* ' + c ).ljust(17) + ' - ' + d for (c,d) in CMD_DESC.items() )
+			(
+				# '* <space> <command> - <command description>'
+				'* {cmd} - {desc}'.format (
+					cmd  = i [0].ljust ( 15 ),
+					desc = i [1]
+				) for i in command_map.items()
+			)
 		),
 		add_help=True,
 		formatter_class=argparse.RawDescriptionHelpFormatter,
@@ -60,18 +66,17 @@ def get_parser ( CMD_DESC, DEFAULT_CONFIG ):
 
 	arg (
 		'commands',
-		# fixme: CMD_DESC is "unknown", but default is set to a specific command
-		default='create',
-		help="action to perform. choices are " + ', '.join (CMD_DESC.keys()) + \
+		default=default_command,
+		help="action to perform. choices are " + ', '.join (command_map.keys()) + \
 			". defaults to %(default)s.",
 		nargs="*",
-		choices=CMD_DESC.keys(),
+		choices=command_map.keys(),
 		metavar="command"
 	)
 
 	arg (
 		'-c', '--config',
-		default=DEFAULT_CONFIG,
+		default=default_config_file,
 		help="config file",
 		type=is_fs_file_or_void, metavar="<file>"
 	)
@@ -205,7 +210,7 @@ def get_parser ( CMD_DESC, DEFAULT_CONFIG ):
 	return parser
 # --- end of get_parser (...) ---
 
-def parse_argv ( *args, **kw ):
+def parse_argv ( command_map, **kw ):
 	"""Parses sys.argv and returns the result as tuple
 	(<commands to run>, <config file>,
 	<dict for config>, <extra options as dict>).
@@ -229,7 +234,7 @@ def parse_argv ( *args, **kw ):
 				pos = pos [k]
 
 
-	p = get_parser ( *args, **kw ).parse_args()
+	p = get_parser ( command_map=command_map, **kw ).parse_args()
 
 	given = lambda kw : hasattr ( p, kw )
 
@@ -264,13 +269,14 @@ def parse_argv ( *args, **kw ):
 		doconf ( p.distroot, 'distfiles.root' )
 
 	if given ( 'distdirs' ):
+		if given ( 'distroot' ):
+			raise Exception ( "--distdir and --disroot are mutually exclusive!" )
+
 		doconf ( (), 'REPO.config_files' )
 		extra ['distdirs'] = frozenset ( p.distdirs )
 		extra ['nosync']   = True
-		# FIXME: COMMANDS are unknown here (theoretically)
-		commands.append ( "create" )
-		# FIXME:
-		# distdir implies --nosync, but LocalRepo doesn't care about that ( sync() is nosync() )
+		if 'create' in command_map:
+			commands.append ( "create" )
 
 	if given ( 'deprule_file' ):
 		doconf ( p.deprule_file, 'DEPRES.SIMPLE_RULES.files' )


             reply	other threads:[~2012-08-02 15:14 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-02 15:14 André Erdmann [this message]
  -- strict thread matches above, loose matches on Subject: below --
2024-08-23  7:28 [gentoo-commits] proj/R_overlay:master commit in: /, roverlay/ Benda XU
2014-08-23 19:03 André Erdmann
2014-07-29 20:26 André Erdmann
2014-08-23 19:03 ` André Erdmann
2013-09-23 15:30 André Erdmann
2013-08-19 15:42 André Erdmann
2013-08-09 10:18 André Erdmann
2013-07-11 17:11 André Erdmann
2013-04-25 16:44 André Erdmann
2013-02-09 20:45 André Erdmann
2013-02-05 17:48 André Erdmann
2013-01-28 23:54 André Erdmann
2013-01-09 19:15 André Erdmann
2012-08-20 14:04 André Erdmann
2012-07-30 15:53 André Erdmann
2012-07-06 22:19 André Erdmann
2012-07-05 16:00 André Erdmann

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=1343920149.dbd601765440a1f735ead40c89c2c02d64c07af3.dywi@gentoo \
    --to=dywi@mailerd.de \
    --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