Example #1
0
def import_config(request, type):
    # do import if we're importing
    if request.method == 'POST' and 'import' in request.POST:
        content_types = {
            'status': status_content_type,
            'steps': step_content_type,
            'scheduler': scheduler_content_type,
        }
        module = request.POST['import']
        path = '.'.join(module.split('.')[:-1])
        name = request.POST['import'].split('.')[-1]
        introspected = introspect_module(path=path)
        imported_config = introspected[name]
        new_config = Config.objects.create(name=name, module=module,
                                         content_type=content_types[type])
        new_config.save()
        try:
            for req in imported_config[1]:
                ConfigParam.objects.create(type=new_config, name=req,
                                           required=True).save()
            for opt, default in imported_config[2].items():
                ConfigParam.objects.create(type=new_config, name=opt,
                                           default=str(default)).save()
        except Exception, e:
            new_config.delete()
            raise e

        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))
Example #2
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))
Example #3
0
def config_importer(module, type):
    content_types = {
        'status': status_content_type,
        'steps': step_content_type,
        'scheduler': scheduler_content_type,
    }
    path = '.'.join(module.split('.')[:-1])
    name = module.split('.')[-1]
    introspected = introspect_module(path=path)
    imported_config = introspected[name]
    new_config = Config(name=name, module=module,
                        content_type=content_types[type])
    new_config.save()
    try:
        for req in imported_config[1]:
            ConfigParam(type=new_config, name=req,
                        required=True).save()
        for opt, default in imported_config[2].items():
            ConfigParam(type=new_config, name=opt,
                        default=pickle.dumps(default)).save()
    except Exception, e:
        new_config.delete()
        raise e
Example #4
0
            new_config.delete()
            raise e

        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, }