Exemple #1
0
def import_config(request, type):
    # do import if we're importing
    if request.method == "POST" and "import" in request.POST:
        config_importer(request.POST["import"], type)

        if "path" in request.POST:
            path = request.POST["path"]
        else:
            path = None
        return HttpResponseRedirect("%s?path=%s" % (reverse("loki.views.import_config", args=[type]), path))

    # not importing so get configs in the db and configs from the path
    configs = [mod[0] for mod in Config.objects.values_list("module")]
    path = "buildbot.%s" % type
    if request.method == "GET" and "path" in request.GET:
        path = request.GET["path"]
    introspected = introspect_module(path=path)

    # calculate which introspected configs are already in the db
    del_classes = []
    for config in introspected:
        if introspected[config][0] in configs:
            del_classes.append(config)

    # remove the existing configs from the displayed list.
    for del_class in del_classes:
        del introspected[del_class]

    # render
    context = {"path": path, "type": type, "classes": introspected}
    return render_to_response("loki/import.html", context, context_instance=RequestContext(request))