Beispiel #1
0
def secure_force_copy_file(sfile, dfile):
    if os.path.isfile(sfile):
        shutil.copy2(sfile, dfile)
        from earkcore.fixity.ChecksumFile import get_sha256_hash
        if not os.path.exists(dfile) or not get_sha256_hash(
                sfile) == get_sha256_hash(dfile):
            raise IOError(
                "File copy operation failed  (checksums are not equal comparing %s and %s)."
                % (sfile, dfile))
Beispiel #2
0
 def addFile(self, file_name, mets_filegroup):
     # reload(sys)
     # sys.setdefaultencoding('utf8')
     file_url = "file://./%s" % os.path.relpath(file_name, self.root_path)
     file_mimetype, _ = self.mime.guess_type(file_url)
     file_checksum = get_sha256_hash(file_name)
     file_size = os.path.getsize(file_name)
     file_cdate = get_file_ctime_iso_date_str(file_name,
                                              DT_ISO_FMT_SEC_PREC)
     file_id = "ID" + uuid.uuid4().__str__()
     mets_file = M.file({
         "MIMETYPE": file_mimetype,
         "CHECKSUMTYPE": "SHA-256",
         "CREATED": file_cdate,
         "CHECKSUM": file_checksum,
         "USE": "Datafile",
         "ID": file_id,
         "SIZE": file_size
     })
     mets_filegroup.append(mets_file)
     # _,fname = os.path.split(file_name)
     mets_FLocat = M.FLocat({
         q(XLINK_NS, 'href'): file_url,
         "LOCTYPE": "URL",
         q(XLINK_NS, 'type'): 'simple'
     })
     mets_file.append(mets_FLocat)
     return file_id
Beispiel #3
0
 def make_mdref(self, path, file, id, mdtype):
     mimetype, _ = self.mime.guess_type(os.path.join(path, file))
     rel_path = "file://./%s" % os.path.relpath(os.path.join(path, file),
                                                self.root_path)
     mets_mdref = {
         "LOCTYPE": "URL",
         "MIMETYPE": mimetype,
         "CREATED": current_timestamp(),
         q(XLINK_NS, "type"): "simple",
         q(XLINK_NS, "href"): rel_path,
         "CHECKSUMTYPE": "SHA-256",
         "CHECKSUM": get_sha256_hash(os.path.join(path, file)),
         "ID": id,
         "MDTYPE": mdtype
     }
     return mets_mdref