This patch allows the usage of plugins on cli. Majority of the changes are just a re-ordering of existing code.
Cheers, Christos
Christos Triantafyllidis (3): Added support for plugins at client Added plugin configuration in client conf file Passing options variable to plugins
cli/koji | 91 +++++++++++++++++++++++++++++++++++++---------------------- cli/koji.conf | 8 ++++++ 2 files changed, 65 insertions(+), 34 deletions(-)
--- cli/koji | 90 ++++++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 56 insertions(+), 34 deletions(-)
diff --git a/cli/koji b/cli/koji index 47d9691..3df29d3 100755 --- a/cli/koji +++ b/cli/koji @@ -38,6 +38,7 @@ import base64 import errno import koji import koji.util +import koji.plugin import fnmatch from koji.util import md5_constructor import logging @@ -152,40 +153,6 @@ def get_options(): parser.add_option("--help-commands", action="store_true", default=False, help=_("list commands")) (options, args) = parser.parse_args()
- if options.help_commands: - list_commands() - sys.exit(0) - if not args: - list_commands() - sys.exit(0) - - aliases = { - 'cancel-task' : 'cancel', - 'cxl' : 'cancel', - 'list-commands' : 'help', - 'move-pkg': 'move-build', - 'move': 'move-build', - 'latest-pkg': 'latest-build', - 'tag-pkg': 'tag-build', - 'tag': 'tag-build', - 'untag-pkg': 'untag-build', - 'untag': 'untag-build', - } - cmd = args[0] - cmd = aliases.get(cmd, cmd) - if cmd.lower() in greetings: - cmd = "moshimoshi" - cmd = cmd.replace('-', '_') - if globals().has_key('anon_handle_' + cmd): - if not options.force_auth: - options.noauth = True - cmd = 'anon_handle_' + cmd - elif globals().has_key('handle_' + cmd): - cmd = 'handle_' + cmd - else: - list_commands() - parser.error('Unknown command: %s' % args[0]) - assert False # load local config defaults = { 'server' : 'http://localhost/kojihub', @@ -206,6 +173,8 @@ def get_options(): 'cert': '~/.koji/client.crt', 'ca': '~/.koji/clientca.crt', 'serverca': '~/.koji/serverca.crt', + 'plugin_path': None, + 'plugins': None, 'authtype': None } #note: later config files override earlier ones @@ -282,6 +251,59 @@ def get_options(): else: warn("Warning: The pkgurl option is obsolete, please use topurl instead")
+ + if options.plugins: + tracker = koji.plugin.PluginTracker(path=options.plugin_path.split(':')) + for name in options.plugins.split(): + try: + tracker.load(name) + for v in vars(tracker.plugins[name]).itervalues(): + if callable(v): + if getattr(v, 'exported', False): + if hasattr(v, 'export_alias'): + name = getattr(v, 'export_alias') + else: + name = v.__name__ + globals()[name] = v + except Exception: + error(''.join(traceback.format_exception(*sys.exc_info()))) + + + if options.help_commands: + list_commands() + sys.exit(0) + if not args: + list_commands() + sys.exit(0) + + aliases = { + 'cancel-task' : 'cancel', + 'cxl' : 'cancel', + 'list-commands' : 'help', + 'move-pkg': 'move-build', + 'move': 'move-build', + 'latest-pkg': 'latest-build', + 'tag-pkg': 'tag-build', + 'tag': 'tag-build', + 'untag-pkg': 'untag-build', + 'untag': 'untag-build', + } + cmd = args[0] + cmd = aliases.get(cmd, cmd) + if cmd.lower() in greetings: + cmd = "moshimoshi" + cmd = cmd.replace('-', '_') + if globals().has_key('anon_handle_' + cmd): + if not options.force_auth: + options.noauth = True + cmd = 'anon_handle_' + cmd + elif globals().has_key('handle_' + cmd): + cmd = 'handle_' + cmd + else: + list_commands() + parser.error('Unknown command: %s' % args[0]) + assert False + return options, cmd, args[1:]
def ensure_connection(session):
--- cli/koji.conf | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/cli/koji.conf b/cli/koji.conf index 01ac7ee..1baa906 100644 --- a/cli/koji.conf +++ b/cli/koji.conf @@ -29,3 +29,11 @@
;certificate of the CA that issued the HTTP server certificate ;serverca = ~/.koji/serverca.crt + +; Client plugins + +; The path where plugins are found +; plugin_path = /usr/lib/koji-cli-plugins +; A space-separated list of plugins to load +; plugins = +
--- cli/koji | 1 + 1 file changed, 1 insertion(+)
diff --git a/cli/koji b/cli/koji index 3df29d3..0b33797 100755 --- a/cli/koji +++ b/cli/koji @@ -257,6 +257,7 @@ def get_options(): for name in options.plugins.split(): try: tracker.load(name) + tracker.plugins[name].options = options for v in vars(tracker.plugins[name]).itervalues(): if callable(v): if getattr(v, 'exported', False):
buildsys@lists.fedoraproject.org