From aec34378a69f4e38c39c703a6baa6d1f09deed5f Mon Sep 17 00:00:00 2001 From: jvoisin Date: Wed, 17 Jul 2013 12:58:20 +0200 Subject: Minor refactoring --- MAT/exiftool.py | 2 +- MAT/mutagenstripper.py | 3 +-- MAT/parser.py | 12 ++++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/MAT/exiftool.py b/MAT/exiftool.py index 1cae352..d2d177c 100644 --- a/MAT/exiftool.py +++ b/MAT/exiftool.py @@ -32,7 +32,7 @@ class ExiftoolStripper(parser.GenericParser): ''' try: if self.backup: - shutil.copy2(self.filename, self.filename + '.bak') + self.create_backup_copy() # Note: '-All=' must be followed by a known exiftool option. process = subprocess.Popen( ['exiftool', '-m', '-all=', '-adobe=', '-overwrite_original', self.filename ], diff --git a/MAT/mutagenstripper.py b/MAT/mutagenstripper.py index 34f5705..9d82a30 100644 --- a/MAT/mutagenstripper.py +++ b/MAT/mutagenstripper.py @@ -15,8 +15,7 @@ class MutagenStripper(parser.GenericParser): def remove_all(self): if self.backup: - shutil.copy2(self.filename, self.filename + '.bak') - + self.create_backup_copy() self.mfile.delete() self.mfile.save() return True diff --git a/MAT/parser.py b/MAT/parser.py index 2dda074..e956164 100644 --- a/MAT/parser.py +++ b/MAT/parser.py @@ -7,6 +7,7 @@ import hachoir_editor import os import tempfile +import shutil import mat @@ -38,6 +39,12 @@ class GenericParser(object): _, output = tempfile.mkstemp() self.output = hachoir_core.cmd_line.unicodeFilename(output) + def __del__(self): + ''' Remove tempfile if it was not used + ''' + if os.path.exists(self.output): + mat.secure_remove(self.output) + def is_clean(self): ''' Check if the file is clean from harmful metadatas @@ -116,6 +123,11 @@ class GenericParser(object): ''' raise NotImplementedError + def create_backup_copy(self): + ''' Create a backup copy + ''' + shutil.copy2(self.filename, self.filename + '.bak') + def do_backup(self): ''' Keep a backup of the file if asked. -- cgit v1.3