From: "Zac Medico" <zmedico@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/emaint/modules/logs/, pym/portage/emaint/
Date: Fri, 2 Aug 2013 20:20:51 +0000 (UTC) [thread overview]
Message-ID: <1375474691.42b0a6e898172c375d4d47c3346b25dac2333bf0.zmedico@gentoo> (raw)
commit: 42b0a6e898172c375d4d47c3346b25dac2333bf0
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Fri Aug 2 20:18:11 2013 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Fri Aug 2 20:18:11 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=42b0a6e8
emaint: remove callback usage
This will simplify conversion to argparse.
---
pym/portage/emaint/defaults.py | 4 +-
pym/portage/emaint/main.py | 60 ++++++++++-------------------
pym/portage/emaint/modules/logs/__init__.py | 8 +---
3 files changed, 25 insertions(+), 47 deletions(-)
diff --git a/pym/portage/emaint/defaults.py b/pym/portage/emaint/defaults.py
index d9d83ff..ee0dc11 100644
--- a/pym/portage/emaint/defaults.py
+++ b/pym/portage/emaint/defaults.py
@@ -1,16 +1,18 @@
-# Copyright 2005-2012 Gentoo Foundation
+# Copyright 2005-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# parser option data
CHECK = {"short": "-c", "long": "--check",
"help": "Check for problems (a default option for most modules)",
'status': "Checking %s for problems",
+ 'action': 'store_true',
'func': 'check'
}
FIX = {"short": "-f", "long": "--fix",
"help": "Attempt to fix problems (a default option for most modules)",
'status': "Attempting to fix %s",
+ 'action': 'store_true',
'func': 'fix'
}
diff --git a/pym/portage/emaint/main.py b/pym/portage/emaint/main.py
index 5775ce1..4b6d666 100644
--- a/pym/portage/emaint/main.py
+++ b/pym/portage/emaint/main.py
@@ -30,36 +30,16 @@ class OptionItem(object):
self.help = opt['help']
self.status = opt['status']
self.func = opt['func']
- self.action = opt.get('action', "callback")
+ self.action = opt.get('action', 'store')
self.type = opt.get('type', None)
self.dest = opt.get('dest', None)
- self.callback = opt.get('callback', self._exclusive)
- self.callback_kwargs = opt.get('callback_kwargs', {"var":"action"})
-
def _exclusive(self, option, *args, **kw):
"""Generic check for the 2 default options
"""
- var = kw.get("var", None)
- if var is None:
- raise ValueError("var not specified to exclusive()")
if getattr(self.parser, var, ""):
raise OptionValueError("%s and %s are exclusive options"
% (getattr(self.parser, var), option))
- setattr(self.parser, var, str(option))
-
- def check_action(self, action):
- """Checks if 'action' is the same as this option
-
- @type action: string
- @param action: the action to compare
- @rtype: boolean
- """
- if action == self.action:
- return True
- elif action == '/'.join([self.short, self.long]):
- return True
- return False
def usage(module_controller):
@@ -172,24 +152,27 @@ def emaint_main(myargv):
parser_options.append(OptionItem(desc[opt], parser))
for opt in parser_options:
parser.add_option(opt.short, opt.long, help=opt.help, action=opt.action,
- type=opt.type, dest=opt.dest,
- callback=opt.callback, callback_kwargs=opt.callback_kwargs)
-
- parser.action = None
+ type=opt.type, dest=opt.dest)
(options, args) = parser.parse_args(args=myargv)
- #print('options', options, '\nargs', args, '\naction', parser.action)
if len(args) != 1:
parser.error("Incorrect number of arguments")
if args[0] not in module_names:
parser.error("%s target is not a known target" % args[0])
- if parser.action:
- action = parser.action
- else:
- action = "-c/--check"
- long_action = action.split('/')[1].lstrip('-')
- #print("DEBUG: action = ", action, long_action)
+
+ func = status = long_action = None
+ for opt in parser_options:
+ if opt.long == '--check':
+ # Default action
+ status = opt.status
+ func = opt.func
+ long_action = 'check'
+ elif opt.status and getattr(options, opt.long.lstrip("-"), False):
+ status = opt.status
+ func = opt.func
+ long_action = opt.long.lstrip('-')
+ break
if args[0] == "all":
tasks = []
@@ -200,15 +183,12 @@ def emaint_main(myargv):
elif long_action in module_controller.get_functions(args[0]):
tasks = [module_controller.get_class(args[0] )]
else:
- print("\nERROR: module '%s' does not have option '%s'\n" %(args[0], action))
- print(module_opts(module_controller, args[0]))
+ portage.util.writemsg(
+ "\nERROR: module '%s' does not have option '--%s'\n\n" %
+ (args[0], long_action), noiselevel=-1)
+ portage.util.writemsg(module_opts(module_controller, args[0]),
+ noiselevel=-1)
sys.exit(1)
- func = status = None
- for opt in parser_options:
- if opt.check_action(action):
- status = opt.status
- func = opt.func
- break
# need to pass the parser options dict to the modules
# so they are available if needed.
diff --git a/pym/portage/emaint/modules/logs/__init__.py b/pym/portage/emaint/modules/logs/__init__.py
index 6f62d03..c5204b7 100644
--- a/pym/portage/emaint/modules/logs/__init__.py
+++ b/pym/portage/emaint/modules/logs/__init__.py
@@ -20,17 +20,15 @@ module_spec = {
"help": "Cleans out logs more than 7 days old (cleanlogs only)" + \
" module-options: -t, -p",
'status': "Cleaning %s",
- 'func': 'clean'
+ 'action': 'store_true',
+ 'func': 'clean',
},
'time': {
"short": "-t", "long": "--time",
"help": "(cleanlogs only): -t, --time Delete logs older than NUM of days",
'status': "",
- 'action': 'store',
'type': 'int',
'dest': 'NUM',
- 'callback': None,
- 'callback_kwargs': None,
'func': 'clean'
},
'pretend': {
@@ -39,8 +37,6 @@ module_spec = {
'status': "",
'action': 'store_true',
'dest': 'pretend',
- 'callback': None,
- 'callback_kwargs': None,
'func': 'clean'
}
}
next reply other threads:[~2013-08-02 20:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-02 20:20 Zac Medico [this message]
-- strict thread matches above, loose matches on Subject: below --
2013-08-02 21:49 [gentoo-commits] proj/portage:master commit in: pym/portage/emaint/modules/logs/, pym/portage/emaint/ Zac Medico
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=1375474691.42b0a6e898172c375d4d47c3346b25dac2333bf0.zmedico@gentoo \
--to=zmedico@gentoo.org \
--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