From adb7b95796350ed4654ea92e8883699d8ed9e7cc Mon Sep 17 00:00:00 2001 From: Laurent Bachelier Date: Wed, 25 Jan 2012 01:47:06 +0100 Subject: [PATCH] Fix to still use with keyword with Python 2.6 Also add imports for Python 2.6 usage. --- weboob/applications/weboobrepos/weboobrepos.py | 7 ++++--- weboob/core/repositories.py | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/weboob/applications/weboobrepos/weboobrepos.py b/weboob/applications/weboobrepos/weboobrepos.py index dbf60405..788be829 100644 --- a/weboob/applications/weboobrepos/weboobrepos.py +++ b/weboob/applications/weboobrepos/weboobrepos.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Affero General Public License # along with weboob. If not, see . +from __future__ import with_statement from datetime import datetime import tarfile @@ -24,6 +25,7 @@ import os import shutil import sys from copy import copy +from contextlib import closing from weboob.core.repositories import Repository @@ -106,9 +108,8 @@ class WeboobRepos(ReplApplication): continue print 'Create archive for %s' % name - tar = tarfile.open(tarname, 'w:gz') - tar.add(module_path, arcname=name, exclude=self._archive_excludes) - tar.close() + with closing(tarfile.open(tarname, 'w:gz')) as tar: + tar.add(module_path, arcname=name, exclude=self._archive_excludes) # Copy icon. icon_path = os.path.join(module_path, 'favicon.png') diff --git a/weboob/core/repositories.py b/weboob/core/repositories.py index 318b98ad..a5ab6346 100644 --- a/weboob/core/repositories.py +++ b/weboob/core/repositories.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Affero General Public License # along with weboob. If not, see . +from __future__ import with_statement import tarfile import posixpath @@ -25,6 +26,7 @@ import re import sys import os from datetime import datetime +from contextlib import closing from .modules import Module from weboob.tools.log import getLogger @@ -499,9 +501,8 @@ class Repositories(object): progress.progress(0.7, 'Setting up module...') # Extract module from tarball. - tar = tarfile.open('', 'r:gz', fp) - tar.extractall(self.modules_dir) - tar.close() + with closing(tarfile.open('', 'r:gz', fp)) as tar: + tar.extractall(self.modules_dir) self.versions.set(info.name, info.version)