Exemplo n.º 1
0
def show_diff(request, project, label, package=''):
    label = unescape(label)
    record = Record.objects.get(label=label, project__id=project)
    if package:
        dependency = record.dependencies.get(name=package)
    else:
        package = "Main script"
        dependency = record
    return render_to_response("show_diff.html", {'label': label,
                                                 'project_name': project,
                                                 'package': package,
                                                 'parent_version': dependency.version,
                                                 'diff': dependency.diff})
Exemplo n.º 2
0
def record_detail(request, project, label):
    if label != 'nolabel':
        label = unescape(label)
        record = Record.objects.get(label=label, project__id=project)
    if request.method == 'POST':
        if request.POST.has_key(
                'delete'
        ):  # in this version the page record_detail doesn't have delete option
            record.delete()
            return HttpResponseRedirect('..')
        elif request.POST.has_key(
                'show_args'
        ):  # user clicks the link <parameters> in record_list.html
            parameter_set = record.parameters.to_sumatra()
            return HttpResponse(parameter_set)
        elif request.POST.has_key(
                'show_script'):  # retrieve script code from the repo
            digest = request.POST.get('digest', False)
            path = request.POST.get('path', False)
            path = str(path).encode("string_escape")
            wc = get_working_copy(path)
            file_content = wc.content(digest)
            return HttpResponse(file_content)
        elif request.POST.has_key('compare_records'):
            labels = request.POST.getlist('records[]')
            records = Record.objects.filter(project__id=project)
            records = records.filter(
                label__in=labels[:2])  # by now we take only two records
            for record in records:
                if record.script_arguments == '<parameters>':
                    record.script_arguments = record.parameters.to_sumatra()
            dic = {'records': records}
            return render_to_response('comparison_framework.html', dic)
        else:
            form = RecordUpdateForm(request.POST, instance=record)
            if form.is_valid():
                form.save()
    else:
        form = RecordUpdateForm(instance=record)
    # data_store = get_data_store(record.datastore.type, eval(record.datastore.parameters)) doesn't get used?
    parameter_set = record.parameters.to_sumatra()
    if hasattr(parameter_set, "as_dict"):
        parameter_set = parameter_set.as_dict()
    return render_to_response(
        'record_detail.html', {
            'record': record,
            'project_name': project,
            'parameters': parameter_set,
            'form': form
        })
Exemplo n.º 3
0
def show_diff(request, project, label, package=''):
    label = unescape(label)
    record = Record.objects.get(label=label, project__id=project)
    if package:
        dependency = record.dependencies.get(name=package)
    else:
        package = "Main script"
        dependency = record
    return render_to_response(
        "show_diff.html", {
            'label': label,
            'project_name': project,
            'package': package,
            'parent_version': dependency.version,
            'diff': dependency.diff
        })
Exemplo n.º 4
0
def download_file(request, project, label):
    label = unescape(label)
    path = request.GET['path']
    digest = request.GET['digest']
    data_key = DataKey(path, digest)
    record = Record.objects.get(label=label, project__id=project)
    data_store = get_data_store(record.datastore.type, eval(record.datastore.parameters))

    mimetype, encoding = mimetypes.guess_type(path)
    try:
        content = data_store.get_content(data_key)
    except (IOError, KeyError):
        raise Http404
    dir, fname = os.path.split(path)
    response = HttpResponse(content_type=mimetype)
    response['Content-Disposition'] = 'attachment; filename=%s' % fname
    response.write(content)
    return response
Exemplo n.º 5
0
def download_file(request, project, label):
    label = unescape(label)
    path = request.GET['path']
    digest = request.GET['digest']
    data_key = DataKey(path, digest)
    record = Record.objects.get(label=label, project__id=project)
    data_store = get_data_store(record.datastore.type,
                                eval(record.datastore.parameters))

    mimetype, encoding = mimetypes.guess_type(path)
    try:
        content = data_store.get_content(data_key)
    except (IOError, KeyError):
        raise Http404
    dir, fname = os.path.split(path)
    response = HttpResponse(content_type=mimetype)
    response['Content-Disposition'] = 'attachment; filename=%s' % fname
    response.write(content)
    return response
Exemplo n.º 6
0
def record_detail(request, project, label):
    if label != 'nolabel':
        label = unescape(label)
        record = Record.objects.get(label=label, project__id=project)
    if request.method == 'POST':
        if request.POST.has_key('delete'):  # in this version the page record_detail doesn't have delete option
            record.delete()
            return HttpResponseRedirect('..')
        elif request.POST.has_key('show_args'):  # user clicks the link <parameters> in record_list.html
            parameter_set = record.parameters.to_sumatra()
            return HttpResponse(parameter_set)
        elif request.POST.has_key('show_script'):  # retrieve script code from the repo
            digest = request.POST.get('digest', False)
            path = request.POST.get('path', False)
            path = str(path).encode("string_escape")
            wc = get_working_copy(path)
            file_content = wc.content(digest)
            return HttpResponse(file_content)
        elif request.POST.has_key('compare_records'):
            labels = request.POST.getlist('records[]')
            records = Record.objects.filter(project__id=project)
            records = records.filter(label__in=labels[:2])  # by now we take only two records
            for record in records:
                if record.script_arguments == '<parameters>':
                    record.script_arguments = record.parameters.to_sumatra()
            dic = {'records': records}
            return render_to_response('comparison_framework.html', dic)
        else:
            form = RecordUpdateForm(request.POST, instance=record)
            if form.is_valid():
                form.save()
    else:
        form = RecordUpdateForm(instance=record)
    # data_store = get_data_store(record.datastore.type, eval(record.datastore.parameters)) doesn't get used?
    parameter_set = record.parameters.to_sumatra()
    if hasattr(parameter_set, "as_dict"):
        parameter_set = parameter_set.as_dict()
    return render_to_response('record_detail.html', {'record': record,
                                                     'project_name': project,
                                                     'parameters': parameter_set,
                                                     'form': form
                                                     })
Exemplo n.º 7
0
def show_image(request, project, label):
    label = unescape(label)
    path = request.GET['path']
    digest = request.GET['digest']
    type = request.GET.get('type', 'output')
    data_key = DataKey(path, digest)
    mimetype, encoding = mimetypes.guess_type(path)
    if mimetype in ("image/png", "image/jpeg", "image/gif", "image/x-png"):
        record = Record.objects.get(label=label, project__id=project)
        if type == 'output':
            data_store = get_data_store(record.datastore.type, eval(record.datastore.parameters))
        else:
            data_store = get_data_store(record.input_datastore.type, eval(record.input_datastore.parameters))
        try:
            content = data_store.get_content(data_key)
        except (IOError, KeyError):
            raise Http404
        return HttpResponse(content, content_type=mimetype)
    else:
        return HttpResponse(content_type="image/png")  # should return a placeholder image?
Exemplo n.º 8
0
def show_image(request, project, label):
    label = unescape(label)
    path = request.GET['path']
    digest = request.GET['digest']
    type = request.GET.get('type', 'output')
    data_key = DataKey(path, digest)
    mimetype, encoding = mimetypes.guess_type(path)
    if mimetype in ("image/png", "image/jpeg", "image/gif", "image/x-png"):
        record = Record.objects.get(label=label, project__id=project)
        if type == 'output':
            data_store = get_data_store(record.datastore.type,
                                        eval(record.datastore.parameters))
        else:
            data_store = get_data_store(
                record.input_datastore.type,
                eval(record.input_datastore.parameters))
        try:
            content = data_store.get_content(data_key)
        except (IOError, KeyError):
            raise Http404
        return HttpResponse(content, content_type=mimetype)
    else:
        return HttpResponse(
            content_type="image/png")  # should return a placeholder image?
Exemplo n.º 9
0
def show_file(request, project, label):
    if request.POST.has_key('show_args'):  # retrieve the content of the input file
        name = request.POST.get('name', False)
        if os.name == 'posix':
            arg_file = open(os.getcwd() + '/' + name, 'r')
        else:
            arg_file = open(os.getcwd() + '\\' + name, 'r')
        f_content = arg_file.read()
        arg_file.close()
        return HttpResponse(f_content)
    label = unescape(label)
    path = request.GET['path']
    digest = request.GET['digest']
    type = request.GET.get('type', 'output')
    show_script = request.GET.get('show_script', False)
    data_key = DataKey(path, digest)
    if 'truncate' in request.GET:
        if request.GET['truncate'].lower() == 'false':
            max_display_length = None
        else:
            max_display_length = int(request.GET['truncate']) * 1024
    else:
        max_display_length = DEFAULT_MAX_DISPLAY_LENGTH

    record = Record.objects.get(label=label, project__id=project)
    if type == 'output':
        data_store = get_data_store(record.datastore.type, eval(record.datastore.parameters))
    else:
        data_store = get_data_store(record.input_datastore.type, eval(record.input_datastore.parameters))
    truncated = False
    mimetype, encoding = mimetypes.guess_type(path)
    try:
        if mimetype == "text/csv":
            content = data_store.get_content(data_key, max_length=max_display_length)
            if max_display_length is not None and len(content) >= max_display_length:
                truncated = True

                # dump the last truncated line (if any)
                content = content.rpartition('\n')[0]

            lines = content.splitlines()
            reader = csv.reader(lines)

            return render_to_response("show_csv.html",
                                      {'path': path, 'label': label,
                                       'digest': digest,
                                       'project_name': project,
                                       'reader': reader,
                                       'truncated': truncated,
                                       'mimetype': mimetype
                                       })

        elif encoding == 'gzip':
            import gzip
            with gzip.open(data_store.root + os.path.sep + path, 'r') as gf:
                content = gf.read()
            if 'csv' in path:
                lines = content.splitlines()
                if truncated:
                    lines = [lines[0]] + lines[-min(100, len(lines)):]
                reader = csv.reader(lines)
                return render_to_response("show_csv.html",
                                          {'path': path,
                                           'label': label,
                                           'digest': digest,
                                           'project_name': project,
                                           'reader': reader,
                                           'truncated': truncated,
                                           'mimetype': mimetype
                                           })
            else:
                return render_to_response("show_file.html",
                                          {'path': path,
                                           'label': label,
                                           'content': content,
                                           'project_name': project,
                                           'truncated': truncated,
                                           'digest': digest,
                                           'mimetype': mimetype
                                           })
        elif mimetype is None or mimetype.split("/")[0] == "text":
            content = data_store.get_content(data_key, max_length=max_display_length)
            if max_display_length is not None and len(content) >= max_display_length:
                truncated = True
            return render_to_response("show_file.html",
                                      {'path': path,
                                       'label': label,
                                       'digest': digest,
                                       'project_name': project,
                                       'content': content,
                                       'truncated': truncated,
                                       'mimetype': mimetype
                                       })
        elif mimetype in ("image/png", "image/jpeg", "image/gif", "image/x-png"):  # need to check digests match
            return render_to_response("show_image.html",
                                      {'path': path,
                                       'label': label,
                                       'digest': digest,
                                       'mimetype': mimetype,
                                       'project_name': project,
                                       'type': type})
        elif mimetype == 'application/zip':
            import zipfile
            if zipfile.is_zipfile(path):
                zf = zipfile.ZipFile(path, 'r')
                contents = zf.namelist()
                zf.close()
                return render_to_response("show_file.html",
                                          {'path': path,
                                           'label': label,
                                           'digest': digest,
                                           'content': "\n".join(contents),
                                           'project_name': project,
                                           'mimetype': mimetype
                                           })
            else:
                raise IOError("Not a valid zip file")
        else:
            return render_to_response("show_file.html",
                                      {'path': path,
                                       'label': label,
                                       'project_name': project,
                                       'digest': digest,
                                       'mimetype': mimetype,
                                       'content': "Can't display this file (mimetype assumed to be %s)" % mimetype
                                       })
    except (IOError, KeyError), e:
        return render_to_response("show_file.html",
                                  {'path': path,
                                   'label': label,
                                   'project_name': project,
                                   'digest': digest,
                                   'content': "File not found.",
                                   'errmsg': e
                                   })