diff options
-rw-r--r-- | g_octave/description.py | 2 | ||||
-rw-r--r-- | g_octave/svn/client.py | 38 | ||||
-rw-r--r-- | g_octave/svn/description.py | 2 | ||||
-rw-r--r-- | g_octave/svn/revisions.py | 9 | ||||
-rw-r--r-- | g_octave/svn/utils.py | 6 |
5 files changed, 32 insertions, 25 deletions
diff --git a/g_octave/description.py b/g_octave/description.py index d3850ab..c8b3260 100644 --- a/g_octave/description.py +++ b/g_octave/description.py @@ -60,7 +60,7 @@ class Description(object): # current key key = None - with open(file, 'r') as fp: + with open(file, 'r', encoding='iso-8859-1') as fp: for line in fp: line_splited = line.split(':') diff --git a/g_octave/svn/client.py b/g_octave/svn/client.py index 4fae4fd..46bb45a 100644 --- a/g_octave/svn/client.py +++ b/g_octave/svn/client.py @@ -11,17 +11,27 @@ :license: GPL-2, see LICENSE for more details. """ +from __future__ import print_function, absolute_import + import os import pysvn import re import shutil import subprocess import sys -import urllib2 + +from g_octave.compat import py3k + +if py3k: + import urllib.request as url_request, urllib.error as url_error +else: + import urllib2 + url_request = urllib2 + url_error = urllib2 from contextlib import closing -import revisions +from . import revisions from g_octave import config class SvnClient: @@ -59,7 +69,7 @@ class SvnClient: for package_c in pkg_cache: if re.match(r'%s\-[0-9\.]+' % package, package_c) is not None: tarball_exist = True - if current_revision is None or current_revision > old_revision or not tarball_exist: + if current_revision is None or old_revision is None or current_revision > old_revision or not tarball_exist: self._revisions.set(category, package, current_revision) updated.append((category, package)) return updated @@ -67,13 +77,13 @@ class SvnClient: def _list_packages(self, category): try: if self._verbose: - print 'Listing packages from: ' + category + print('Listing packages from: ' + category) pkg_list = self._client.list( self.url + '/' + category + '/', depth = pysvn.depth.immediates ) - except pysvn.ClientError, err: - print >> sys.stderr, 'Error: ' + str(err) + except pysvn.ClientError as err: + print('Error: ' + str(err), file=sys.stderr) tmp = {} for props, lock in pkg_list: filename = props.repos_path.split('/')[-1] @@ -90,13 +100,13 @@ class SvnClient: os.makedirs(current_dir) try: if self._verbose: - print 'Fetching DESCRIPTION from: %s/%s' % (category, pkg) - fp = urllib2.urlopen( + print('Fetching DESCRIPTION from: %s/%s' % (category, pkg)) + fp = url_request.urlopen( self.url + '/' + category + '/' + pkg + '/DESCRIPTION' ) - with open(os.path.join(current_dir, 'DESCRIPTION'), 'w') as fp_: + with open(os.path.join(current_dir, 'DESCRIPTION'), 'wb') as fp_: shutil.copyfileobj(fp, fp_) - except urllib2.URLError: + except url_error.URLError: pass def checkout_package(self, category, name, dest, stable=True): @@ -117,9 +127,9 @@ class SvnClient: autogen = os.path.join(dest, 'src', 'autogen.sh') self.download_file('packages/package_Makefile.in', os.path.join(dest, 'Makefile')) self.download_file('packages/package_configure.in', configure) - os.chmod(configure, 0755) + os.chmod(configure, 0o755) if os.path.exists(autogen): - os.chmod(autogen, 0755) + os.chmod(autogen, 0o755) if subprocess.call( 'cd %s && ./autogen.sh' % os.path.dirname(autogen), shell=True @@ -127,6 +137,6 @@ class SvnClient: raise RuntimeError('Failed to run autogen.sh') def download_file(self, src, dest): - with closing(urllib2.urlopen(self.url + '/' + src)) as fp: + with closing(url_request.urlopen(self.url + '/' + src)) as fp: with open(dest, 'wb') as fp_: - fp_.write(fp.read()) + shutil.copyfileobj(fp, fp_) diff --git a/g_octave/svn/description.py b/g_octave/svn/description.py index 08c5260..1cb760c 100644 --- a/g_octave/svn/description.py +++ b/g_octave/svn/description.py @@ -21,7 +21,7 @@ from g_octave import description, exception class SvnDescription(description.Description): def __init__(self, category, package): - self._svn = client.SvnClient() + self._svn = client.SvnClient(create_revisions=False) temp_desc = config_file = tempfile.mkstemp()[1] try: self._svn.download_file( diff --git a/g_octave/svn/revisions.py b/g_octave/svn/revisions.py index cc4e234..647756a 100644 --- a/g_octave/svn/revisions.py +++ b/g_octave/svn/revisions.py @@ -13,6 +13,8 @@ import json +from g_octave.compat import open + class Revisions(object): def __init__(self, json_file): @@ -53,10 +55,3 @@ class Revisions(object): revisions[category][package] = value if not self._dump_json(revisions): raise RuntimeError('Failed to save JSON file.') - - -if __name__ == '__main__': - a = Revisions('/tmp/file.json') - a.set('main', 'fuuuu', 1234) - print a.get() - diff --git a/g_octave/svn/utils.py b/g_octave/svn/utils.py index 10ecb28..83e32f9 100644 --- a/g_octave/svn/utils.py +++ b/g_octave/svn/utils.py @@ -10,6 +10,8 @@ :license: GPL-2, see LICENSE for more details. """ +from __future__ import print_function + import sys import tarfile @@ -23,5 +25,5 @@ def create_tarball(src_dir, tarball_file, arcname): try: with closing(tarfile.open(tarball_file, 'w:gz')) as tar: tar.add(src_dir, arcname=arcname, recursive=True, exclude=exclude) - except tarfile.TarError, err: - print >> sys.stderr, 'Failed to create the tarball: %s' % err + except tarfile.TarError as err: + print('Failed to create the tarball: %s' % err, file=sys.stderr) |