Fix to still use with keyword with Python 2.6

Also add imports for Python 2.6 usage.
This commit is contained in:
Laurent Bachelier 2012-01-25 01:47:06 +01:00
commit adb7b95796
2 changed files with 8 additions and 6 deletions

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>. # along with weboob. If not, see <http://www.gnu.org/licenses/>.
from __future__ import with_statement
from datetime import datetime from datetime import datetime
import tarfile import tarfile
@ -24,6 +25,7 @@ import os
import shutil import shutil
import sys import sys
from copy import copy from copy import copy
from contextlib import closing
from weboob.core.repositories import Repository from weboob.core.repositories import Repository
@ -106,9 +108,8 @@ class WeboobRepos(ReplApplication):
continue continue
print 'Create archive for %s' % name print 'Create archive for %s' % name
tar = tarfile.open(tarname, 'w:gz') with closing(tarfile.open(tarname, 'w:gz')) as tar:
tar.add(module_path, arcname=name, exclude=self._archive_excludes) tar.add(module_path, arcname=name, exclude=self._archive_excludes)
tar.close()
# Copy icon. # Copy icon.
icon_path = os.path.join(module_path, 'favicon.png') icon_path = os.path.join(module_path, 'favicon.png')

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>. # along with weboob. If not, see <http://www.gnu.org/licenses/>.
from __future__ import with_statement
import tarfile import tarfile
import posixpath import posixpath
@ -25,6 +26,7 @@ import re
import sys import sys
import os import os
from datetime import datetime from datetime import datetime
from contextlib import closing
from .modules import Module from .modules import Module
from weboob.tools.log import getLogger from weboob.tools.log import getLogger
@ -499,9 +501,8 @@ class Repositories(object):
progress.progress(0.7, 'Setting up module...') progress.progress(0.7, 'Setting up module...')
# Extract module from tarball. # Extract module from tarball.
tar = tarfile.open('', 'r:gz', fp) with closing(tarfile.open('', 'r:gz', fp)) as tar:
tar.extractall(self.modules_dir) tar.extractall(self.modules_dir)
tar.close()
self.versions.set(info.name, info.version) self.versions.set(info.name, info.version)