Ejemplo n.º 1
0
def check_transfer(source, target, tl):
    source_size = fsize(source)
    target_size = fsize(target)
    if not source_size == target_size:
        tl.adderr(
            "Size of source file (%d bytes) and size of target file (%d bytes) are not equal"
            % (source_size, target_size))
    if not ChecksumFile(source).get(
            ChecksumAlgorithm.SHA256) == ChecksumFile(target).get(
                ChecksumAlgorithm.SHA256):
        tl.adderr("Checksums of source %s and target %s are not equal" %
                  (source, target))
Ejemplo n.º 2
0
def copy_file(source,
              target,
              progress_reporter=default_reporter,
              total_bytes_read=0,
              bytes_total=-1):
    with open(target, 'wb') as target_file:
        for chunk in FileBinaryDataChunks(source, 65536,
                                          progress_reporter).chunks(
                                              total_bytes_read,
                                              total_bytes_read):
            target_file.write(chunk)
        target_file.close()
        total_bytes_read += fsize(source)
    return total_bytes_read
Ejemplo n.º 3
0
def read_ipfc(request, ip_sub_file_path):
    # only allow reading from session working directory (ip_sub_file_path must begin with uuid)
    file_path = os.path.join(config_path_work, ip_sub_file_path)
    if not os.path.exists(file_path):
        return HttpResponseNotFound("File not found %s vs %s" %
                                    (ip_sub_file_path, file_path))
    elif not os.path.isfile(file_path):
        return HttpResponseBadRequest("Not a file")
    else:
        file_size = fsize(file_path)
        if file_size <= config_max_filesize_viewer:
            mime = get_mime_type(file_path)
            print "MIME" + mime
            file_content = None
            if get_mime_type(file_path) == "image/png" or get_mime_type(
                    file_path) == "image/jpg":
                file_content = read_file_content(file_path)
                file_content = "data:" + mime + ";base64," + base64.b64encode(
                    file_content)
            elif get_mime_type(file_path) == "image/tiff" or get_mime_type(
                    file_path) == "image/gif":
                from pgmagick.api import Image
                img = Image(file_path)
                uuid = randomutils.getUniqueID()
                img.write('/tmp/%s.png' % uuid)
                print '/tmp/%s.png' % uuid
                file_content = "data:" + mime + ";base64," + base64.b64encode(
                    read_file_content('/tmp/%s.png' % uuid))
            elif get_mime_type(file_path) == "application/pdf":
                uuid = randomutils.getUniqueID()
                html_file = ('/tmp/%s.html' % uuid)
                pdftohtml_cmd = CliCommand.get("pdftohtml", {
                    'pdf_file': file_path,
                    'html_file': html_file
                })
                out = check_output(pdftohtml_cmd)
                file_content = read_file_content(html_file)
            else:
                file_content = read_file_content(file_path)
            return HttpResponse(file_content)
        else:
            return HttpResponseForbidden(
                "Size of requested file exceeds limit (file size %d > %d)" %
                (file_size, config_max_filesize_viewer))
Ejemplo n.º 4
0
def read_ipfc(request, ip_sub_file_path):
    # TODO: Direct access to the working area file system is not always possible from the frontent. It is therefore necessary to read the file content from a backend service.
    file_path = os.path.join(config_path_work, ip_sub_file_path)
    logger.debug("Read directory content from directory: " + file_path)
    if not os.path.exists(file_path):
        return HttpResponseNotFound("File not found %s vs %s" %
                                    (ip_sub_file_path, file_path))
    elif not os.path.isfile(file_path):
        return HttpResponseBadRequest("Not a file")
    else:
        file_size = fsize(file_path)
        if file_size <= config_max_filesize_viewer:
            mime = get_mime_type(file_path)
            logger.debug("MIME" + mime)
            file_content = read_file_content(file_path)
            return HttpResponse(file_content, content_type=mime)
        else:
            return HttpResponseForbidden(
                "Size of requested file exceeds limit (file size %d > %d)" %
                (file_size, config_max_filesize_viewer))
Ejemplo n.º 5
0
 def source_size(self):
     if self.source_available():
         return fsize(self.source)
     else:
         return -1