Ejemplo n.º 1
0
def examinezip(request,
               tarpath,
               fpath=None,
               document_root=None,
               show_indexes=False):

    if fpath:
        # Got a valid fpath (inside the zipfile)
        zippath = document_root + zippath + "/" + fpath
    else:
        # No valid fpath (zipfile itself)
        zippath = document_root + zippath

    if fpath == None:
        try:
            t = loader.get_template(
                '/u/savagev/valtest/realtest/templates/data/static/directory_index.html'
            )
        except TemplateDoesNotExist:
            t = loader.get_template(
                '/u/kamwoods/Sudoc/svp/realtest/templates/data/static/directory_index.html'
            )

        zip = zipfile.open(tarpath, 'r')

        files = []
        for zipinfo in zip:
            f = zippath.split('/')[-1] + '/' + zipinfo.filename
            filefp = os.path.join(zippath, f)
            mimetype = mimefinder.find_type(filefp)
            fmodtime = zipinfo.date_time
            if not tarinfo.file_size == 0:
                fgsize = static.greek(zipinfo.file_size)
            else:
                fgsize = "-"

            files.append([
                "-",
                "",
                mimetype,
                f,
                fmodtime,
                fgsize,
            ])

        zip.close()

        c = Context({
            'directory': zippath + '/',
            'file_list': files,
            'hinst': request.session['hinst'],
            'hexe': request.session['hexe'],
            'hdriver': request.session['hdriver'],
            'hlib': request.session['hlib'],
            'hetc': request.session['hetc'],
            'user': request.user.username,
        })

        return HttpResponse(t.render(c))
Ejemplo n.º 2
0
def examinezip(request, tarpath, fpath=None, document_root=None, show_indexes=False):

    if fpath:
        # Got a valid fpath (inside the zipfile)
        zippath = document_root + zippath + "/" + fpath
    else:
        # No valid fpath (zipfile itself)
        zippath = document_root + zippath

    if fpath == None:
        try:
            t = loader.get_template('/u/savagev/valtest/realtest/templates/data/static/directory_index.html')
        except TemplateDoesNotExist:
            t = loader.get_template('/u/kamwoods/Sudoc/svp/realtest/templates/data/static/directory_index.html')

        zip = zipfile.open(tarpath, 'r')

        files = []
        for zipinfo in zip:
            f = zippath.split('/')[-1] +'/'+ zipinfo.filename
            filefp = os.path.join(zippath, f)
            mimetype = mimefinder.find_type(filefp)
            fmodtime = zipinfo.date_time
            if not tarinfo.file_size == 0:
                fgsize = static.greek(zipinfo.file_size)
            else:
                fgsize = "-"

            files.append(["-",
                          "",
                          mimetype,
                          f,
                          fmodtime,
                          fgsize,])

        zip.close()

        c = Context({
            'directory' : zippath+'/',
            'file_list' : files,
            'hinst': request.session['hinst'],
            'hexe': request.session['hexe'],
            'hdriver': request.session['hdriver'],
            'hlib': request.session['hlib'],
            'hetc': request.session['hetc'],
            'user': request.user.username,
        })

        return HttpResponse(t.render(c))
Ejemplo n.º 3
0
def examinetar(request, tarpath, fpath=None, document_root=None, show_indexes=False):

    if fpath:
        # Got a valid fpath (inside the tarfile)
        tarpath = document_root + tarpath + "/" + fpath
    else:
        # No valid fpath (tarfile itself)
        tarpath = document_root + tarpath

    if fpath == None:
        try:
            t = loader.get_template('/u/savagev/valtest/realtest/templates/data/static/directory_index.html')
        except TemplateDoesNotExist:
            t = loader.get_template('/u/kamwoods/Sudoc/svp/realtest/templates/data/static/directory_index.html')

        tar = tarfile.open(tarpath, 'r')
    
        files = []
        for tarinfo in tar:
            f = tarpath.split('/')[-1] +'/'+ tarinfo.name
            filefp = os.path.join(tarpath, f)
            mimetype = mimefinder.find_type(filefp)
            fmodtime = tarinfo.mtime
            if not tarinfo.isdir():
                fgsize = static.greek(tarinfo.size)
            else:
                fgsize = "-"

            files.append(["-",
                          "",
                          mimetype,
                          f,
                          fmodtime,
                          fgsize,])

        tar.close()
    
        c = Context({
            'directory' : tarpath+'/',
            'file_list' : files,
            'hinst': request.session['hinst'],
            'hexe': request.session['hexe'],
            'hdriver': request.session['hdriver'],
            'hlib': request.session['hlib'],
            'hetc': request.session['hetc'],
            'user': request.user.username,
        }) 

        return HttpResponse(t.render(c))

    else:
        # Inside the tarfile (set up the appropriate path)
        tarmainpath = "/".join([x for x in tarpath.split("/")[0:-1]])

        tar = tarfile.open(tarmainpath, 'r')
        tarredfile = tarpath.split('/')[-1]
        extractpath = '/tmp/' + tarredfile

        thefile = tar.extract(tarredfile, "/tmp")
        content = open(extractpath, 'rb').read()

        mimetype = mimetypes.guess_type(extractpath)[0]
        return HttpResponse(content, mimetype=mimetype)