diff options
author | Ben Sturmfels <ben@sturm.com.au> | 2021-03-05 23:12:19 +1100 |
---|---|---|
committer | Ben Sturmfels <ben@sturm.com.au> | 2021-03-05 23:12:19 +1100 |
commit | dec47c7102cf0aa3a4debf002928db8e460c0d71 (patch) | |
tree | 47631fc15c7af172aa699506adf3d76d3a71976c /mediagoblin/processing | |
parent | 5f3a782fef4855e10b7259624a14d8afb0f7be93 (diff) | |
download | mediagoblin-dec47c7102cf0aa3a4debf002928db8e460c0d71.tar.lz mediagoblin-dec47c7102cf0aa3a4debf002928db8e460c0d71.tar.xz mediagoblin-dec47c7102cf0aa3a4debf002928db8e460c0d71.zip |
Apply `pyupgrade --py3-plus` to remove Python 2 compatibility code.
Diffstat (limited to 'mediagoblin/processing')
-rw-r--r-- | mediagoblin/processing/__init__.py | 40 | ||||
-rw-r--r-- | mediagoblin/processing/task.py | 18 |
2 files changed, 29 insertions, 29 deletions
diff --git a/mediagoblin/processing/__init__.py b/mediagoblin/processing/__init__.py index 2897b5e7..f9289d14 100644 --- a/mediagoblin/processing/__init__.py +++ b/mediagoblin/processing/__init__.py @@ -35,7 +35,7 @@ from mediagoblin.tools.translate import lazy_pass_to_ugettext as _ _log = logging.getLogger(__name__) -class ProgressCallback(object): +class ProgressCallback: def __init__(self, entry): self.entry = entry @@ -53,11 +53,11 @@ class ProgressCallback(object): def create_pub_filepath(entry, filename): return mgg.public_store.get_unique_filepath( ['media_entries', - six.text_type(entry.id), + str(entry.id), filename]) -class FilenameBuilder(object): +class FilenameBuilder: """Easily slice and dice filenames. Initialize this class with an original file path, then use the fill() @@ -90,7 +90,7 @@ class FilenameBuilder(object): -class MediaProcessor(object): +class MediaProcessor: """A particular processor for this media type. While the ProcessingManager handles all types of MediaProcessing @@ -192,7 +192,7 @@ class ProcessingManagerDoesNotExist(ProcessingKeyError): pass -class ProcessingManager(object): +class ProcessingManager: """Manages all the processing actions available for a media type Specific processing actions, MediaProcessor subclasses, are added @@ -290,7 +290,7 @@ def get_processing_manager_for_type(media_type): manager_class = hook_handle(('reprocess_manager', media_type)) if not manager_class: raise ProcessingManagerDoesNotExist( - "A processing manager does not exist for {0}".format(media_type)) + "A processing manager does not exist for {}".format(media_type)) manager = manager_class() return manager @@ -331,19 +331,19 @@ def mark_entry_failed(entry_id, exc): # metadata the user might have supplied. atomic_update(mgg.database.MediaEntry, {'id': entry_id}, - {u'state': u'failed', - u'fail_error': six.text_type(exc.exception_path), - u'fail_metadata': exc.metadata}) + {'state': 'failed', + 'fail_error': str(exc.exception_path), + 'fail_metadata': exc.metadata}) else: _log.warn("No idea what happened here, but it failed: %r", exc) # Looks like no, let's record it so that admin could ask us about the # reason atomic_update(mgg.database.MediaEntry, {'id': entry_id}, - {u'state': u'failed', - u'fail_error': u'Unhandled exception: {0}'.format( - six.text_type(exc)), - u'fail_metadata': {}}) + {'state': 'failed', + 'fail_error': 'Unhandled exception: {}'.format( + str(exc)), + 'fail_metadata': {}}) def get_process_filename(entry, workbench, acceptable_files): @@ -391,7 +391,7 @@ def store_public(entry, keyname, local_file, target_name=None, try: mgg.public_store.copy_local_to_storage(local_file, target_filepath) except Exception as e: - _log.error(u'Exception happened: {0}'.format(e)) + _log.error('Exception happened: {}'.format(e)) raise PublicStoreFail(keyname=keyname) # raise an error if the file failed to copy if not mgg.public_store.file_exists(target_filepath): @@ -400,7 +400,7 @@ def store_public(entry, keyname, local_file, target_name=None, entry.media_files[keyname] = target_filepath -def copy_original(entry, orig_filename, target_name, keyname=u"original"): +def copy_original(entry, orig_filename, target_name, keyname="original"): store_public(entry, keyname, orig_filename, target_name) @@ -413,16 +413,16 @@ class BaseProcessingFail(Exception): and provide the exception_path and general_message applicable to this error. """ - general_message = u'' + general_message = '' @property def exception_path(self): - return u"%s:%s" % ( + return "{}:{}".format( self.__class__.__module__, self.__class__.__name__) def __init__(self, message=None, **metadata): if message is not None: - super(BaseProcessingFail, self).__init__(message) + super().__init__(message) metadata['message'] = message self.metadata = metadata @@ -431,7 +431,7 @@ class BadMediaFail(BaseProcessingFail): Error that should be raised when an inappropriate file was given for the media type specified. """ - general_message = _(u'Invalid file given for media type.') + general_message = _('Invalid file given for media type.') class PublicStoreFail(BaseProcessingFail): @@ -446,4 +446,4 @@ class ProcessFileNotFound(BaseProcessingFail): Error that should be raised when an acceptable file for processing is not found. """ - general_message = _(u'An acceptable processing file was not found') + general_message = _('An acceptable processing file was not found') diff --git a/mediagoblin/processing/task.py b/mediagoblin/processing/task.py index bedfd32d..c62293e8 100644 --- a/mediagoblin/processing/task.py +++ b/mediagoblin/processing/task.py @@ -38,7 +38,7 @@ def handle_push_urls(feed_url): Retry 3 times every 2 minutes if run in separate process before failing.""" if not mgg.app_config["push_urls"]: return # Nothing to do - _log.debug('Notifying Push servers for feed {0}'.format(feed_url)) + _log.debug('Notifying Push servers for feed {}'.format(feed_url)) hubparameters = { 'hub.mode': 'publish', 'hub.url': feed_url} @@ -57,7 +57,7 @@ def handle_push_urls(feed_url): return handle_push_urls.retry(exc=exc, throw=False) except Exception as e: # All retries failed, Failure is no tragedy here, probably. - _log.warn('Failed to notify PuSH server for feed {0}. ' + _log.warn('Failed to notify PuSH server for feed {}. ' 'Giving up.'.format(feed_url)) return False @@ -95,18 +95,18 @@ class ProcessMedia(celery.Task): with processor_class(manager, entry) as processor: # Initial state change has to be here because # the entry.state gets recorded on processor_class init - entry.state = u'processing' + entry.state = 'processing' entry.save() - _log.debug('Processing {0}'.format(entry)) + _log.debug('Processing {}'.format(entry)) try: processor.process(**reprocess_info) except Exception as exc: if processor.entry_orig_state == 'processed': _log.error( - 'Entry {0} failed to process due to the following' - ' error: {1}'.format(entry.id, exc)) + 'Entry {} failed to process due to the following' + ' error: {}'.format(entry.id, exc)) _log.info( 'Setting entry.state back to "processed"') pass @@ -115,7 +115,7 @@ class ProcessMedia(celery.Task): # We set the state to processed and save the entry here so there's # no need to save at the end of the processing stage, probably ;) - entry.state = u'processed' + entry.state = 'processed' entry.save() # Notify the PuSH servers as async task @@ -130,7 +130,7 @@ class ProcessMedia(celery.Task): except ImportError as exc: _log.error( - 'Entry {0} failed to process due to an import error: {1}'\ + 'Entry {} failed to process due to an import error: {}'\ .format( entry.title, exc)) @@ -140,7 +140,7 @@ class ProcessMedia(celery.Task): except Exception as exc: _log.error('An unhandled exception was raised while' - + ' processing {0}'.format( + + ' processing {}'.format( entry)) mark_entry_failed(entry.id, exc) |