| |
@@ -65,20 +65,40 @@
|
| |
globals()[name] = v
|
| |
|
| |
|
| |
- def load_plugins(options, path):
|
| |
- """Load plugins specified by our configuration plus system plugins. Order
|
| |
- is that system plugins are first, so they can be overridden by
|
| |
- user-specified ones with same name."""
|
| |
+ def load_plugins(plugin_paths):
|
| |
+ """Load plugins specified by input paths, ~/.koji/plugins, system plugins.
|
| |
+ Loading order is descending, so they can be overridden by user-specified
|
| |
+ ones.
|
| |
+ Notice that:
|
| |
+ - plugin file should end with .py extension
|
| |
+ - non-directory is not acceptable by plugin_paths
|
| |
+ - all plugin files and the exported handlers inside will be loaded, and
|
| |
+ handler with the same name will override the one has already been loaded
|
| |
+ before"""
|
| |
+
|
| |
logger = logging.getLogger('koji.plugins')
|
| |
- if os.path.exists(path):
|
| |
- tracker = koji.plugin.PluginTracker(path=path)
|
| |
- for name in sorted(os.listdir(path)):
|
| |
- if not name.endswith('.py'):
|
| |
- continue
|
| |
- name = name[:-3]
|
| |
- logger.info('Loading plugin: %s', name)
|
| |
- tracker.load(name)
|
| |
- register_plugin(tracker.get(name))
|
| |
+ paths = []
|
| |
+ # first, always load plugins from koji_cli_plugins module
|
| |
+ paths.append(
|
| |
+ '%s/lib/python%s.%s/site-packages/koji_cli_plugins' %
|
| |
+ (sys.prefix, sys.version_info[0], sys.version_info[1]))
|
| |
+ # second, always load plugins from ~/.koji/plugins
|
| |
+ paths.append(os.path.expanduser('~/.koji/plugins'))
|
| |
+ # finally, update plugin_paths to the list
|
| |
+ if plugin_paths:
|
| |
+ if not isinstance(plugin_paths, (list, tuple)):
|
| |
+ plugin_paths = plugin_paths.split(':')
|
| |
+ paths.extend([os.path.expanduser(p) for p in reversed(plugin_paths)])
|
| |
+ tracker = koji.plugin.PluginTracker()
|
| |
+ for path in paths:
|
| |
+ if os.path.exists(path) and os.path.isdir(path):
|
| |
+ for name in sorted(os.listdir(path)):
|
| |
+ fullname = os.path.join(path, name)
|
| |
+ if not (os.path.isfile(fullname) and name.endswith('.py')):
|
| |
+ continue
|
| |
+ name = name[:-3]
|
| |
+ logger.info('Loading plugin: %s', fullname)
|
| |
+ register_plugin(tracker.load(name, path=path, reload=True))
|
| |
|
| |
|
| |
def get_options():
|
| |
@@ -124,6 +144,8 @@
|
| |
parser.add_option("--weburl", help=_("url of the Koji web interface"))
|
| |
parser.add_option("--topurl", help=_("url for Koji file access"))
|
| |
parser.add_option("--pkgurl", help=SUPPRESS_HELP)
|
| |
+ parser.add_option("--plugin-paths", metavar='PATHS',
|
| |
+ help=_("specify additional plugin paths (colon separated)"))
|
| |
parser.add_option("--help-commands", action="store_true", default=False, help=_("list commands"))
|
| |
(options, args) = parser.parse_args()
|
| |
|
| |
@@ -163,9 +185,7 @@
|
| |
else:
|
| |
warn("Warning: The pkgurl option is obsolete, please use topurl instead")
|
| |
|
| |
- plugins_path = '%s/lib/python%s.%s/site-packages/koji_cli_plugins' % \
|
| |
- (sys.prefix, sys.version_info[0], sys.version_info[1])
|
| |
- load_plugins(options, plugins_path)
|
| |
+ load_plugins(options.plugin_paths)
|
| |
|
| |
if options.help_commands:
|
| |
list_commands()
|
| |
--plugin-paths
in cli argumentsfixes: #887