flyte
5/22/2015 - 4:32 PM

Returns a JSON list of Jenkins plugins as keys and a boolean value representing their enabled status.

Returns a JSON list of Jenkins plugins as keys and a boolean value representing their enabled status.

import json
import os
import argparse


PLUGIN_EXTENSIONS = ("hpi", "jpi")


def plugin_name(path):
    file_name = os.path.basename(path)
    return file_name.split(".")[0]


def is_disabled(path):
    _, ext = os.path.splitext(path)
    return ext.lower() == ".disabled"


def is_plugin(path):
    _, ext = os.path.splitext(path)
    return ext.lower()[1:] in PLUGIN_EXTENSIONS


if __name__ == "__main__":
    p = argparse.ArgumentParser()
    p.add_argument("plugin_dir", help="The directory in which jenkins plugins reside")
    args = p.parse_args()

    items = os.listdir(args.plugin_dir)

    plugins = [plugin_name(x) for x in filter(is_plugin, items)]
    disabled_plugins = [plugin_name(x) for x in filter(is_disabled, items)]

    ret = {}

    for plugin in plugins:
        ret[plugin] = plugin not in disabled_plugins

    print json.dumps(ret, indent=2)