Remove Photo.filepath and real_filepath in favor of real_path.
This commit is contained in:
		
							parent
							
								
									42728d5d67
								
							
						
					
					
						commit
						606a66cbf9
					
				
					 4 changed files with 18 additions and 17 deletions
				
			
		|  | @ -49,10 +49,11 @@ def album_zip_filenames(album, recursive=True): | ||||||
|     for (album, directory) in directories.items(): |     for (album, directory) in directories.items(): | ||||||
|         photos = album.get_photos() |         photos = album.get_photos() | ||||||
|         for photo in photos: |         for photo in photos: | ||||||
|             if photo.real_filepath in arcnames: |             filepath = photo.real_path.absolute_path | ||||||
|  |             if filepath in arcnames: | ||||||
|                 continue |                 continue | ||||||
|             photo_name = '%s - %s' % (photo.id, photo.basename) |             photo_name = '%s - %s' % (photo.id, photo.basename) | ||||||
|             arcnames[photo.real_filepath] = os.path.join(directory, photo_name) |             arcnames[filepath] = os.path.join(directory, photo_name) | ||||||
| 
 | 
 | ||||||
|     return arcnames |     return arcnames | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -544,13 +544,13 @@ class Photo(ObjectBase): | ||||||
|         if isinstance(db_row, (list, tuple)): |         if isinstance(db_row, (list, tuple)): | ||||||
|             db_row = dict(zip(constants.SQL_COLUMNS['photos'], db_row)) |             db_row = dict(zip(constants.SQL_COLUMNS['photos'], db_row)) | ||||||
| 
 | 
 | ||||||
|         self.real_filepath = helpers.remove_path_badchars(db_row['filepath'], allowed=':\\/') |         self.real_path = db_row['filepath'] | ||||||
|         self.real_path = pathclass.Path(self.real_filepath) |         self.real_path = helpers.remove_path_badchars(self.real_path, allowed=':\\/') | ||||||
|  |         self.real_path = pathclass.Path(self.real_path) | ||||||
| 
 | 
 | ||||||
|         self.id = db_row['id'] |         self.id = db_row['id'] | ||||||
|         self.created = db_row['created'] |         self.created = db_row['created'] | ||||||
|         self.author_id = db_row['author_id'] |         self.author_id = db_row['author_id'] | ||||||
|         self.filepath = db_row['override_filename'] or self.real_path.absolute_path |  | ||||||
|         self.basename = db_row['override_filename'] or self.real_path.basename |         self.basename = db_row['override_filename'] or self.real_path.basename | ||||||
|         self.extension = db_row['extension'] |         self.extension = db_row['extension'] | ||||||
|         self.tagged_at = db_row['tagged_at'] |         self.tagged_at = db_row['tagged_at'] | ||||||
|  | @ -573,7 +573,7 @@ class Photo(ObjectBase): | ||||||
|         else: |         else: | ||||||
|             self.bitrate = None |             self.bitrate = None | ||||||
| 
 | 
 | ||||||
|         self.mimetype = helpers.get_mimetype(self.real_filepath) |         self.mimetype = helpers.get_mimetype(self.real_path.basename) | ||||||
|         if self.mimetype is None: |         if self.mimetype is None: | ||||||
|             self.simple_mimetype = None |             self.simple_mimetype = None | ||||||
|         else: |         else: | ||||||
|  | @ -694,9 +694,9 @@ class Photo(ObjectBase): | ||||||
|         return_filepath = None |         return_filepath = None | ||||||
| 
 | 
 | ||||||
|         if self.simple_mimetype == 'image': |         if self.simple_mimetype == 'image': | ||||||
|             self.photodb.log.debug('Thumbnailing %s' % self.real_filepath) |             self.photodb.log.debug('Thumbnailing %s' % self.real_path.absolute_path) | ||||||
|             try: |             try: | ||||||
|                 image = PIL.Image.open(self.real_filepath) |                 image = PIL.Image.open(self.real_path.absolute_path) | ||||||
|             except (OSError, ValueError): |             except (OSError, ValueError): | ||||||
|                 pass |                 pass | ||||||
|             else: |             else: | ||||||
|  | @ -728,7 +728,7 @@ class Photo(ObjectBase): | ||||||
| 
 | 
 | ||||||
|         elif self.simple_mimetype == 'video' and constants.ffmpeg: |         elif self.simple_mimetype == 'video' and constants.ffmpeg: | ||||||
|             #print('video') |             #print('video') | ||||||
|             probe = constants.ffmpeg.probe(self.real_filepath) |             probe = constants.ffmpeg.probe(self.real_path.absolute_path) | ||||||
|             try: |             try: | ||||||
|                 if probe.video: |                 if probe.video: | ||||||
|                     size = helpers.fit_into_bounds( |                     size = helpers.fit_into_bounds( | ||||||
|  | @ -747,7 +747,7 @@ class Photo(ObjectBase): | ||||||
|                         else: |                         else: | ||||||
|                             timestamp = 2 |                             timestamp = 2 | ||||||
|                     constants.ffmpeg.thumbnail( |                     constants.ffmpeg.thumbnail( | ||||||
|                         self.real_filepath, |                         self.real_path.absolute_path, | ||||||
|                         outfile=hopeful_filepath, |                         outfile=hopeful_filepath, | ||||||
|                         quality=2, |                         quality=2, | ||||||
|                         size=size, |                         size=size, | ||||||
|  | @ -851,7 +851,7 @@ class Photo(ObjectBase): | ||||||
|         ''' |         ''' | ||||||
|         Load the file's height, width, etc as appropriate for this type of file. |         Load the file's height, width, etc as appropriate for this type of file. | ||||||
|         ''' |         ''' | ||||||
|         self.bytes = os.path.getsize(self.real_filepath) |         self.bytes = self.real_path.size | ||||||
|         self.width = None |         self.width = None | ||||||
|         self.height = None |         self.height = None | ||||||
|         self.area = None |         self.area = None | ||||||
|  | @ -862,7 +862,7 @@ class Photo(ObjectBase): | ||||||
| 
 | 
 | ||||||
|         if self.simple_mimetype == 'image': |         if self.simple_mimetype == 'image': | ||||||
|             try: |             try: | ||||||
|                 image = PIL.Image.open(self.real_filepath) |                 image = PIL.Image.open(self.real_path.absolute_path) | ||||||
|             except (OSError, ValueError): |             except (OSError, ValueError): | ||||||
|                 self.photodb.log.debug('Failed to read image data for {photo:r}'.format(photo=self)) |                 self.photodb.log.debug('Failed to read image data for {photo:r}'.format(photo=self)) | ||||||
|             else: |             else: | ||||||
|  | @ -872,7 +872,7 @@ class Photo(ObjectBase): | ||||||
| 
 | 
 | ||||||
|         elif self.simple_mimetype == 'video' and constants.ffmpeg: |         elif self.simple_mimetype == 'video' and constants.ffmpeg: | ||||||
|             try: |             try: | ||||||
|                 probe = constants.ffmpeg.probe(self.real_filepath) |                 probe = constants.ffmpeg.probe(self.real_path.absolute_path) | ||||||
|                 if probe and probe.video: |                 if probe and probe.video: | ||||||
|                     self.duration = probe.format.duration or probe.video.duration |                     self.duration = probe.format.duration or probe.video.duration | ||||||
|                     self.width = probe.video.video_width |                     self.width = probe.video.video_width | ||||||
|  | @ -882,7 +882,7 @@ class Photo(ObjectBase): | ||||||
| 
 | 
 | ||||||
|         elif self.simple_mimetype == 'audio' and constants.ffmpeg: |         elif self.simple_mimetype == 'audio' and constants.ffmpeg: | ||||||
|             try: |             try: | ||||||
|                 probe = constants.ffmpeg.probe(self.real_filepath) |                 probe = constants.ffmpeg.probe(self.real_path.absolute_path) | ||||||
|                 if probe and probe.audio: |                 if probe and probe.audio: | ||||||
|                     self.duration = probe.audio.duration |                     self.duration = probe.audio.duration | ||||||
|             except Exception: |             except Exception: | ||||||
|  |  | ||||||
|  | @ -314,7 +314,7 @@ class PDBPhotoMixin: | ||||||
|             photos = self.get_photos_by_recent() |             photos = self.get_photos_by_recent() | ||||||
| 
 | 
 | ||||||
|         for photo in photos: |         for photo in photos: | ||||||
|             if os.path.exists(photo.real_filepath): |             if photo.real_path.exists: | ||||||
|                 continue |                 continue | ||||||
|             photo.delete(commit=False) |             photo.delete(commit=False) | ||||||
|         if commit: |         if commit: | ||||||
|  |  | ||||||
|  | @ -49,11 +49,11 @@ def get_file(photo_id): | ||||||
| 
 | 
 | ||||||
|         download_as = etiquette.helpers.remove_path_badchars(download_as) |         download_as = etiquette.helpers.remove_path_badchars(download_as) | ||||||
|         download_as = urllib.parse.quote(download_as) |         download_as = urllib.parse.quote(download_as) | ||||||
|         response = flask.make_response(common.send_file(photo.real_filepath)) |         response = flask.make_response(common.send_file(photo.real_path.absolute_path)) | ||||||
|         response.headers['Content-Disposition'] = 'attachment; filename*=UTF-8\'\'%s' % download_as |         response.headers['Content-Disposition'] = 'attachment; filename*=UTF-8\'\'%s' % download_as | ||||||
|         return response |         return response | ||||||
|     else: |     else: | ||||||
|         return common.send_file(photo.real_filepath, override_mimetype=photo.mimetype) |         return common.send_file(photo.real_path.absolute_path, override_mimetype=photo.mimetype) | ||||||
| 
 | 
 | ||||||
| @site.route('/thumbnail/<photo_id>') | @site.route('/thumbnail/<photo_id>') | ||||||
| def get_thumbnail(photo_id): | def get_thumbnail(photo_id): | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue