From a08411375db4363fcf9ae3999ef98a4a4c6c307c Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sun, 27 Oct 2013 16:44:44 +0000 Subject: Minor refactorisation of exiftool.py --- MAT/exiftool.py | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/MAT/exiftool.py b/MAT/exiftool.py index 9803aa9..86a5be9 100644 --- a/MAT/exiftool.py +++ b/MAT/exiftool.py @@ -1,15 +1,12 @@ -''' - Care about images with help of the amazing (perl) library Exiftool. +''' Care about images with help of the amazing (perl) library Exiftool. ''' -import subprocess import parser -import shutil +import subprocess class ExiftoolStripper(parser.GenericParser): - ''' - A generic stripper class using exiftool as backend + ''' A generic stripper class using exiftool as backend ''' def __init__(self, filename, parser, mime, backup, is_writable, **kwargs): @@ -21,35 +18,30 @@ class ExiftoolStripper(parser.GenericParser): self._set_allowed() def _set_allowed(self): - ''' - Set the allowed/harmless list of metadata + ''' Virtual method. Set the allowed/harmless list of metadata ''' raise NotImplementedError def remove_all(self): - ''' - Remove all metadata with help of exiftool + ''' Remove all metadata with help of exiftool ''' try: if self.backup: self.create_backup_copy() # Note: '-All=' must be followed by a known exiftool option. - subprocess.call(['exiftool', '-m', '-all=', + return subprocess.call(['exiftool', '-m', '-all=', '-adobe=', '-overwrite_original', self.filename], stdout=open('/dev/null')) - return True except: return False def is_clean(self): + ''' Check if the file is clean with the help of exiftool ''' - Check if the file is clean with help of exiftool - ''' - return self.get_meta() == {} + return not self.get_meta() def get_meta(self): - ''' - Return every harmful meta with help of exiftool. + ''' Return every harmful meta with help of exiftool. Exiftool output looks like this: field name : value field name : value @@ -57,7 +49,7 @@ class ExiftoolStripper(parser.GenericParser): output = subprocess.Popen(['exiftool', self.filename], stdout=subprocess.PIPE).communicate()[0] meta = {} - for i in output.split('\n')[:-1]: + for i in output.split('\n')[:-1]: # chop last char ('\n') key = i.split(':')[0].strip() if key not in self.allowed: meta[key] = i.split(':')[1].strip() # add the field name to the metadata set @@ -65,8 +57,7 @@ class ExiftoolStripper(parser.GenericParser): class JpegStripper(ExiftoolStripper): - ''' - Care about jpeg files with help + ''' Care about jpeg files with help of exiftool ''' def _set_allowed(self): @@ -76,8 +67,7 @@ class JpegStripper(ExiftoolStripper): class PngStripper(ExiftoolStripper): - ''' - Care about png files with help + ''' Care about png files with help of exiftool ''' def _set_allowed(self): -- cgit v1.3