コード例 #1
0
ファイル: s3.py プロジェクト: wcyn/aleph
 def load_file(self, content_hash, file_name=None):
     obj = self._locate_key(content_hash)
     if obj is not None:
         path = self._get_local_prefix(content_hash)
         try:
             os.makedirs(path)
         except:
             pass
         file_name = make_filename(file_name, default='data')
         path = os.path.join(path, file_name)
         self.bucket.download_file(obj.key, path)
         return path
コード例 #2
0
    def archive_file(self, file_path, content_hash=None):
        """Import the given file into the archive."""
        if content_hash is None:
            content_hash = checksum(file_path)

        if self._locate_key(content_hash):
            return content_hash

        archive_path = os.path.join(self.path, self._get_prefix(content_hash))
        try:
            os.makedirs(archive_path)
        except:
            pass
        file_name = make_filename(file_path, default='data')
        archive_path = os.path.join(archive_path, file_name)
        shutil.copy(file_path, archive_path)
        return content_hash
コード例 #3
0
 def file_name(self):
     """File name is a slugified version of the file title that is safe to
     use as part of a file system path."""
     return make_filename(self.file_title, default='data')