示例#1
0
def browse_file(request, file_id, sector):
    SECTOR_SIZE = 512
    
    file = get_object_or_404(DataFile, pk=file_id)

    from caso.collect.rpc import local_name

    f = open(local_name(file.file_name), 'rb')
    f.seek( int(sector) * SECTOR_SIZE )

    data = f.read(SECTOR_SIZE)
    
    str_bytes = ""
    real_bytes = ""
    for i in range(0, SECTOR_SIZE):
        if(i%16 == 0):
            str_bytes += " --- "
            str_bytes += real_bytes
            real_bytes = ""
            str_bytes += "\n%4d: " % (i)
            
        b = data[i]
        str_bytes += "%02x " % (ord(b))
        if((b in string.printable) and not (b in string.whitespace)):
            real_bytes += b
        else:
            real_bytes += " "

    str_bytes += " --- "
    str_bytes += real_bytes


    d = {}
    d['bytes'] = str_bytes
    d['case'] = file.case_project
    d['file_id'] = file_id
    d['file'] = file
    d['sector'] = sector
    if(int(sector)>0):
        d['prev_sector'] = int(sector)-1
        d['has_prev_sector'] = True
    else:
        d['has_prev_sector'] = False
    if(file.file_size > int(sector)*SECTOR_SIZE ):
        d['next_sector'] = int(sector)+1
        d['has_next_sector'] = True
    else:
        d['has_next_sector'] = False

    return render_to_response('collect/a_browse_file.html', d)
示例#2
0
def get_file(request, file_id):
    file = get_object_or_404(DataFile, pk=file_id)

    from django.core.servers.basehttp import FileWrapper
    from caso.collect.rpc import local_name

    f = open(local_name(file.file_name), 'rb')
    
    fw = FileWrapper(f)
    
    response = HttpResponse(fw, mimetype='application/octet-stream')
    response['Content-Disposition'] = 'attachment; filename=%s' % urllib.quote(file.file_name)
    f.seek(0, os.SEEK_END)
    response['Content-Length'] = f.tell()
    f.seek(0, os.SEEK_SET)
    return response