예제 #1
0
def task_list(request):
    """List available fabric tasks."""
    fabfile_path = settings.FABADMIN_FABFILE
    filename = os.path.split(fabfile_path)[1]
    module = os.path.splitext(filename)[0]
    fabfile = __import__(module)
    _, new_style, classic, default = load_tasks_from_module(fabfile)
    tasks = []
    for task_group in [new_style, classic, default]:
        if task_group:
            for task in task_group.values():
                tasks.append(Task(task))
    task_choices = [NullTask()] + tasks
    output = ""
    if request.method == "POST":
        fabfile_form = FabfileForm(request.POST, tasks=task_choices)
        if fabfile_form.is_valid():
            cleaned_data = fabfile_form.cleaned_data
            task = cleaned_data['task']
            arguments = cleaned_data['arguments']
            args = ['fab', '-f', fabfile_path, task + ":" + arguments]
            process = subprocess.Popen(
                args, shell=False, stdout=subprocess.PIPE
            )
            converter = Ansi2HTMLConverter()
            shell_output = process.communicate()[0]
            output = converter.convert(shell_output, False)
    else:
        fabfile_form = FabfileForm(tasks=task_choices)
    return render_to_response("fabadmin/task_list.html", {
        'tasks': tasks,
        'fabfile_form': fabfile_form,
        'ADMIN_MEDIA_PREFIX': settings.ADMIN_MEDIA_PREFIX,
        'output': output
    }, RequestContext(request, {}))
예제 #2
0
def task_list(request):
    """List available fabric tasks."""
    fabfile_path = settings.FABADMIN_FABFILE
    filename = os.path.split(fabfile_path)[1]
    module = os.path.splitext(filename)[0]
    fabfile = __import__(module)
    _, new_style, classic, default = load_tasks_from_module(fabfile)
    tasks = {}
    def _add_group(task_group, group_name):
        if task_group:
            for name, task in task_group.items():
                if isinstance(task, dict):
                    if group_name:
                        name = "%s.%s" % (group_name, name)
                    _add_group(task, name)
                else:
                    t = Task(task, group_name)
                    if not t.name in tasks:
                        print "adding task: %s" % t.name
                        tasks[t.name] = t
                    else:
                        print "skipping task: %s" % t.name
    
    for task_group in [new_style, classic, default]:
        _add_group(new_style, None)
    
    task_names = tasks.keys()
    task_names.sort()
    tasks = [tasks[n] for n in task_names]
    
    task_choices = [NullTask()] + tasks
    output = ""
    if request.method == "POST":
        fabfile_form = FabfileForm(request.POST, tasks=task_choices)
        if fabfile_form.is_valid():
            cleaned_data = fabfile_form.cleaned_data
            task_str = cleaned_data['task']
            arguments = cleaned_data['arguments']
            if arguments:
                task_str = "%s:%s" % (task_str, arguments)
            args = ['fab', '-f', fabfile_path, task_str]
            process = subprocess.Popen(
                args, shell=False, stdout=subprocess.PIPE
            )
            converter = Ansi2HTMLConverter()
            shell_output = process.communicate()[0]
            output = converter.convert(shell_output, False)
    else:
        fabfile_form = FabfileForm(tasks=task_choices)
    return render_to_response("fabadmin/task_list.html", {
        'tasks': tasks,
        'fabfile_form': fabfile_form,
        'ADMIN_MEDIA_PREFIX': settings.ADMIN_MEDIA_PREFIX,
        'output': output
    }, RequestContext(request, {}))