mirror of
				https://github.com/zulip/zulip.git
				synced 2025-10-31 03:53:50 +00:00 
			
		
		
		
	python: Reformat with Black, except quotes.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
		
				
					committed by
					
						 Tim Abbott
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							5028c081cb
						
					
				
				
					commit
					11741543da
				
			| @@ -13,12 +13,14 @@ from zerver.models import Attachment, RealmEmoji, UserProfile | ||||
|  | ||||
| s3backend = S3UploadBackend() | ||||
|  | ||||
|  | ||||
| def transfer_uploads_to_s3(processes: int) -> None: | ||||
|     # TODO: Eventually, we'll want to add realm icon and logo | ||||
|     transfer_avatars_to_s3(processes) | ||||
|     transfer_message_files_to_s3(processes) | ||||
|     transfer_emoji_to_s3(processes) | ||||
|  | ||||
|  | ||||
| def _transfer_avatar_to_s3(user: UserProfile) -> None: | ||||
|     avatar_path = user_avatar_path(user) | ||||
|     file_path = os.path.join(settings.LOCAL_UPLOADS_DIR, "avatars", avatar_path) + ".original" | ||||
| @@ -29,6 +31,7 @@ def _transfer_avatar_to_s3(user: UserProfile) -> None: | ||||
|     except FileNotFoundError: | ||||
|         pass | ||||
|  | ||||
|  | ||||
| def transfer_avatars_to_s3(processes: int) -> None: | ||||
|     users = list(UserProfile.objects.all()) | ||||
|     if processes == 1: | ||||
| @@ -41,16 +44,24 @@ def transfer_avatars_to_s3(processes: int) -> None: | ||||
|             for out in p.imap_unordered(_transfer_avatar_to_s3, users): | ||||
|                 pass | ||||
|  | ||||
|  | ||||
| def _transfer_message_files_to_s3(attachment: Attachment) -> None: | ||||
|     file_path = os.path.join(settings.LOCAL_UPLOADS_DIR, "files", attachment.path_id) | ||||
|     try: | ||||
|         with open(file_path, 'rb') as f: | ||||
|             guessed_type = guess_type(attachment.file_name)[0] | ||||
|             upload_image_to_s3(s3backend.uploads_bucket, attachment.path_id, guessed_type, attachment.owner, f.read()) | ||||
|             upload_image_to_s3( | ||||
|                 s3backend.uploads_bucket, | ||||
|                 attachment.path_id, | ||||
|                 guessed_type, | ||||
|                 attachment.owner, | ||||
|                 f.read(), | ||||
|             ) | ||||
|             logging.info("Uploaded message file in path %s", file_path) | ||||
|     except FileNotFoundError:  # nocoverage | ||||
|         pass | ||||
|  | ||||
|  | ||||
| def transfer_message_files_to_s3(processes: int) -> None: | ||||
|     attachments = list(Attachment.objects.all()) | ||||
|     if processes == 1: | ||||
| @@ -63,6 +74,7 @@ def transfer_message_files_to_s3(processes: int) -> None: | ||||
|             for out in p.imap_unordered(_transfer_message_files_to_s3, attachments): | ||||
|                 pass | ||||
|  | ||||
|  | ||||
| def _transfer_emoji_to_s3(realm_emoji: RealmEmoji) -> None: | ||||
|     if not realm_emoji.file_name or not realm_emoji.author: | ||||
|         return  # nocoverage | ||||
| @@ -78,6 +90,7 @@ def _transfer_emoji_to_s3(realm_emoji: RealmEmoji) -> None: | ||||
|     except FileNotFoundError:  # nocoverage | ||||
|         pass | ||||
|  | ||||
|  | ||||
| def transfer_emoji_to_s3(processes: int) -> None: | ||||
|     realm_emojis = list(RealmEmoji.objects.filter()) | ||||
|     if processes == 1: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user