Gentoo Archives: gentoo-commits

From: "André Erdmann" <dywi@×××××××.de>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/R_overlay:master commit in: /, roverlay/
Date: Thu, 02 Aug 2012 15:14:54
Message-Id: 1343920149.dbd601765440a1f735ead40c89c2c02d64c07af3.dywi@gentoo
1 commit: dbd601765440a1f735ead40c89c2c02d64c07af3
2 Author: André Erdmann <dywi <AT> mailerd <DOT> de>
3 AuthorDate: Thu Aug 2 15:09:09 2012 +0000
4 Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
5 CommitDate: Thu Aug 2 15:09:09 2012 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=dbd60176
7
8 main script, argutil: command_map
9
10 ---
11 roverlay.py | 4 ++--
12 roverlay/argutil.py | 38 ++++++++++++++++++++++----------------
13 2 files changed, 24 insertions(+), 18 deletions(-)
14
15 diff --git a/roverlay.py b/roverlay.py
16 index 3297325..bd250ea 100755
17 --- a/roverlay.py
18 +++ b/roverlay.py
19 @@ -62,8 +62,8 @@ COMMAND_DESCRIPTION = {
20
21 commands, config_file, additional_config, extra_opts = \
22 roverlay.argutil.parse_argv (
23 - CMD_DESC=COMMAND_DESCRIPTION,
24 - DEFAULT_CONFIG="R-overlay.conf"
25 + command_map=COMMAND_DESCRIPTION,
26 + default_config_file="R-overlay.conf"
27 )
28
29 OPTION = extra_opts.get
30
31 diff --git a/roverlay/argutil.py b/roverlay/argutil.py
32 index 4cefdbd..813a7d7 100644
33 --- a/roverlay/argutil.py
34 +++ b/roverlay/argutil.py
35 @@ -3,13 +3,13 @@ import os.path
36 import argparse
37 import roverlay
38
39 -def get_parser ( CMD_DESC, DEFAULT_CONFIG ):
40 +def get_parser ( command_map, default_config_file, default_command='create' ):
41
42 def is_fs_file ( value ):
43 f = os.path.abspath ( value )
44 if not os.path.isfile ( f ):
45 raise argparse.ArgumentTypeError (
46 - "%r is not a file." % value
47 + "{!r} is not a file.".format ( value )
48 )
49 return f
50
51 @@ -17,7 +17,7 @@ def get_parser ( CMD_DESC, DEFAULT_CONFIG ):
52 d = os.path.abspath ( value )
53 if not os.path.isdir ( d ):
54 raise argparse.ArgumentTypeError (
55 - "%r is not a directory." % value
56 + "{!r} is not a directory.".format ( value )
57 )
58 return d
59
60 @@ -25,7 +25,7 @@ def get_parser ( CMD_DESC, DEFAULT_CONFIG ):
61 d = os.path.abspath ( value )
62 if os.path.exists ( d ) and not os.path.isdir ( d ):
63 raise argparse.ArgumentTypeError (
64 - "%r cannot be a directory." % value
65 + "{!r} cannot be a directory.".format ( value )
66 )
67 return d
68
69 @@ -40,7 +40,13 @@ def get_parser ( CMD_DESC, DEFAULT_CONFIG ):
70 roverlay.description_str, roverlay.license_str,
71 )),
72 epilog = 'Known commands:\n' + '\n'.join (
73 - ( ( '* ' + c ).ljust(17) + ' - ' + d for (c,d) in CMD_DESC.items() )
74 + (
75 + # '* <space> <command> - <command description>'
76 + '* {cmd} - {desc}'.format (
77 + cmd = i [0].ljust ( 15 ),
78 + desc = i [1]
79 + ) for i in command_map.items()
80 + )
81 ),
82 add_help=True,
83 formatter_class=argparse.RawDescriptionHelpFormatter,
84 @@ -60,18 +66,17 @@ def get_parser ( CMD_DESC, DEFAULT_CONFIG ):
85
86 arg (
87 'commands',
88 - # fixme: CMD_DESC is "unknown", but default is set to a specific command
89 - default='create',
90 - help="action to perform. choices are " + ', '.join (CMD_DESC.keys()) + \
91 + default=default_command,
92 + help="action to perform. choices are " + ', '.join (command_map.keys()) + \
93 ". defaults to %(default)s.",
94 nargs="*",
95 - choices=CMD_DESC.keys(),
96 + choices=command_map.keys(),
97 metavar="command"
98 )
99
100 arg (
101 '-c', '--config',
102 - default=DEFAULT_CONFIG,
103 + default=default_config_file,
104 help="config file",
105 type=is_fs_file_or_void, metavar="<file>"
106 )
107 @@ -205,7 +210,7 @@ def get_parser ( CMD_DESC, DEFAULT_CONFIG ):
108 return parser
109 # --- end of get_parser (...) ---
110
111 -def parse_argv ( *args, **kw ):
112 +def parse_argv ( command_map, **kw ):
113 """Parses sys.argv and returns the result as tuple
114 (<commands to run>, <config file>,
115 <dict for config>, <extra options as dict>).
116 @@ -229,7 +234,7 @@ def parse_argv ( *args, **kw ):
117 pos = pos [k]
118
119
120 - p = get_parser ( *args, **kw ).parse_args()
121 + p = get_parser ( command_map=command_map, **kw ).parse_args()
122
123 given = lambda kw : hasattr ( p, kw )
124
125 @@ -264,13 +269,14 @@ def parse_argv ( *args, **kw ):
126 doconf ( p.distroot, 'distfiles.root' )
127
128 if given ( 'distdirs' ):
129 + if given ( 'distroot' ):
130 + raise Exception ( "--distdir and --disroot are mutually exclusive!" )
131 +
132 doconf ( (), 'REPO.config_files' )
133 extra ['distdirs'] = frozenset ( p.distdirs )
134 extra ['nosync'] = True
135 - # FIXME: COMMANDS are unknown here (theoretically)
136 - commands.append ( "create" )
137 - # FIXME:
138 - # distdir implies --nosync, but LocalRepo doesn't care about that ( sync() is nosync() )
139 + if 'create' in command_map:
140 + commands.append ( "create" )
141
142 if given ( 'deprule_file' ):
143 doconf ( p.deprule_file, 'DEPRES.SIMPLE_RULES.files' )