[jhbuild/py3-flake8] CI: run python3-flake8
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [jhbuild/py3-flake8] CI: run python3-flake8
- Date: Thu, 12 Sep 2019 20:48:59 +0000 (UTC)
commit 5658628fec167fe69fdb923f525169f264ce9a0e
Author: Christoph Reiter <reiter christoph gmail com>
Date: Thu Sep 12 22:25:23 2019 +0200
CI: run python3-flake8
This adds a new compat.py module which abstracts away some py2/3 differences
to make flake8 pass in py2 mode and py3 mode.
No code was fully ported to Python 3 yet, only flake8 is more happy now.
.gitlab-ci.yml | 1 +
.gitlab-ci/Dockerfile | 2 +
jhbuild/commands/__init__.py | 20 ++++----
jhbuild/commands/extdeps.py | 40 ++++++++-------
jhbuild/commands/goalreport.py | 100 +++++++++++++++++++-------------------
jhbuild/commands/snapshot.py | 6 +--
jhbuild/commands/sysdeps.py | 62 +++++++++++------------
jhbuild/commands/twoninetynine.py | 2 +-
jhbuild/config.py | 1 +
jhbuild/frontends/autobuild.py | 38 +++++++++------
jhbuild/frontends/buildscript.py | 5 +-
jhbuild/frontends/gtkui.py | 9 ++--
jhbuild/frontends/terminal.py | 25 +++++-----
jhbuild/frontends/tinderbox.py | 7 +--
jhbuild/main.py | 11 +++--
jhbuild/modtypes/autotools.py | 6 +--
jhbuild/utils/Makefile.am | 1 +
jhbuild/utils/cmds.py | 7 +--
jhbuild/utils/compat.py | 55 +++++++++++++++++++++
jhbuild/utils/packagedb.py | 2 +-
jhbuild/utils/subprocess_win32.py | 4 +-
jhbuild/utils/sxml.py | 7 +--
jhbuild/utils/systeminstall.py | 4 +-
jhbuild/utils/unpack.py | 8 +--
jhbuild/versioncontrol/bzr.py | 3 +-
jhbuild/versioncontrol/darcs.py | 4 +-
jhbuild/versioncontrol/git.py | 2 +-
jhbuild/versioncontrol/svn.py | 4 +-
jhbuild/versioncontrol/tarball.py | 4 +-
scripts/changecvsroot.py | 10 ++--
scripts/hg-update.py | 8 +--
scripts/mk-tarball-moduleset.py | 6 ++-
tests/tests.py | 8 +--
33 files changed, 285 insertions(+), 187 deletions(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 560f04ac..3c6c71ae 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -12,6 +12,7 @@ test:
- make distcheck
- cd ..
- python2 -m flake8 .
+ - python3 -m flake8 .
- mkdir public
- cd public
- yelp-build html ../doc/C/index.docbook
diff --git a/.gitlab-ci/Dockerfile b/.gitlab-ci/Dockerfile
index 9b440f87..37a806ee 100644
--- a/.gitlab-ci/Dockerfile
+++ b/.gitlab-ci/Dockerfile
@@ -15,6 +15,8 @@ RUN apt update && apt install -y \
pkg-config \
python \
python-flake8 \
+ python3 \
+ python3-flake8 \
sudo \
trang \
yelp-tools
diff --git a/jhbuild/commands/__init__.py b/jhbuild/commands/__init__.py
index a42f5b28..56db2eba 100644
--- a/jhbuild/commands/__init__.py
+++ b/jhbuild/commands/__init__.py
@@ -17,6 +17,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+from __future__ import print_function
+
__metaclass__ = type
__all__ = [
'Command',
@@ -99,8 +101,8 @@ class BuildCommand(Command):
else:
return ''
- print _('Required packages:')
- print _(' System installed packages which are too old:')
+ print(_('Required packages:'))
+ print(_(' System installed packages which are too old:'))
have_too_old = False
for module, (req_version, installed_version, new_enough, systemmodule) in module_state.iteritems():
if (installed_version is not None) and (not new_enough) and systemmodule:
@@ -110,19 +112,19 @@ class BuildCommand(Command):
req_version,
installed_version)))
if not have_too_old:
- print _(' (none)')
+ print(_(' (none)'))
- print _(' No matching system package installed:')
+ print(_(' No matching system package installed:'))
have_missing = False
for module, (req_version, installed_version, new_enough, systemmodule) in module_state.iteritems():
if installed_version is None and (not new_enough) and systemmodule:
have_missing = True
- print (' %s %s' % (module.name,
- fmt_details(module.pkg_config,
- req_version,
- installed_version)))
+ print(' %s %s' % (module.name,
+ fmt_details(module.pkg_config,
+ req_version,
+ installed_version)))
if not have_missing:
- print _(' (none)')
+ print(_(' (none)'))
def print_help():
diff --git a/jhbuild/commands/extdeps.py b/jhbuild/commands/extdeps.py
index 8bf2d16a..cd13fb5a 100644
--- a/jhbuild/commands/extdeps.py
+++ b/jhbuild/commands/extdeps.py
@@ -17,12 +17,16 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+from __future__ import print_function
+
from optparse import make_option
import re
import socket
import sys
import time
+from jhbuild.utils.compat import cmp
+
try:
from cStringIO import StringIO
except ImportError:
@@ -104,9 +108,9 @@ class cmd_extdeps(Command):
title = _('External deps for GNOME %s') % gnome_ver
break
- print >> output, HTML_AT_TOP % {'title': title}
- print >> output, '<table>'
- print >> output, '<tbody>'
+ print(HTML_AT_TOP % {'title': title}, file=output)
+ print('<table>', file=output)
+ print('<tbody>', file=output)
module_list.sort(lambda x,y: cmp(x.name.lower(), y.name.lower()))
for mod in module_list:
@@ -131,31 +135,31 @@ class cmd_extdeps(Command):
if len(rdeps) > 5:
classes.append('many')
- print >> output, '<tr class="%s">' % ' '.join(classes)
- print >> output, '<th>%s</th>' % mod.name
+ print('<tr class="%s">' % ' '.join(classes), file=output)
+ print('<th>%s</th>' % mod.name, file=output)
version = mod.branch.version
if mod.branch.patches:
version = version + ' (%s)' % _('patched')
- print >> output, '<td class="version">%s</td>' % version
- print >> output, '<td class="url"><a href="%s">tarball</a></td>' % mod.branch.module
+ print('<td class="version">%s</td>' % version, file=output)
+ print('<td class="url"><a href="%s">tarball</a></td>' % mod.branch.module, file=output)
if len(rdeps) > 5:
rdeps = rdeps[:4] + [_('and %d others.') % (len(rdeps)-4)]
- print >> output, '<td class="rdeps">%s</td>' % ', '.join(rdeps)
- print >> output, '</tr>'
+ print('<td class="rdeps">%s</td>' % ', '.join(rdeps), file=output)
+ print('</tr>', file=output)
- print >> output, '</tbody>'
- print >> output, '</table>'
+ print('</tbody>', file=output)
+ print('</table>', file=output)
- print >> output, '<div id="footer">'
- print >> output, 'Generated:', time.strftime('%Y-%m-%d %H:%M:%S %z')
- print >> output, 'on ', socket.getfqdn()
- print >> output, '</div>'
+ print('<div id="footer">', file=output)
+ print('Generated:', time.strftime('%Y-%m-%d %H:%M:%S %z'), file=output)
+ print('on ', socket.getfqdn(), file=output)
+ print('</div>', file=output)
- print >> output, '</body>'
- print >> output, '</html>'
+ print('</body>', file=output)
+ print('</html>', file=output)
if output != sys.stdout:
- file(options.output, 'w').write(output.getvalue())
+ open(options.output, 'w').write(output.getvalue())
def compute_rdeps(self, module):
diff --git a/jhbuild/commands/goalreport.py b/jhbuild/commands/goalreport.py
index 59f59792..514665c2 100644
--- a/jhbuild/commands/goalreport.py
+++ b/jhbuild/commands/goalreport.py
@@ -17,6 +17,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+from __future__ import print_function
+
import os
import re
import socket
@@ -204,7 +206,7 @@ class SymbolsCheck(Check):
filenames = [x for x in filenames if \
os.path.splitext(x)[-1] in ('.c', '.cc', '.cpp', '.h', '.glade')]
for filename in filenames:
- for s in symbol_regex.findall(file(os.path.join(base, filename)).read()):
+ for s in symbol_regex.findall(open(os.path.join(base, filename)).read()):
deprecated_and_used[s] = True
except UnicodeDecodeError:
raise ExcludedModuleException()
@@ -257,7 +259,7 @@ class GrepCheck(Check):
filenames = [x for x in filenames if \
os.path.splitext(x)[-1] in ('.c', '.cc', '.cpp', '.h', '.glade')]
for filename in filenames:
- if self.grep in file(os.path.join(base, filename)).read():
+ if self.grep in open(os.path.join(base, filename)).read():
self.nb_occurences += 1
except UnicodeDecodeError:
raise ExcludedModuleException()
@@ -405,7 +407,7 @@ class cmd_goalreport(Command):
cachedir = os.path.join(os.environ['HOME'], '.cache','jhbuild')
if options.cache:
try:
- results = cPickle.load(file(os.path.join(cachedir, options.cache)))
+ results = cPickle.load(open(os.path.join(cachedir, options.cache)))
except:
pass
@@ -463,24 +465,24 @@ class cmd_goalreport(Command):
if not os.path.exists(cachedir):
os.makedirs(cachedir)
if options.cache:
- cPickle.dump(results, file(os.path.join(cachedir, options.cache), 'w'))
+ cPickle.dump(results, open(os.path.join(cachedir, options.cache), 'w'))
- print >> output, HTML_AT_TOP % {'title': self.title}
+ print(HTML_AT_TOP % {'title': self.title}, file=output)
if self.page_intro:
- print >> output, self.page_intro
- print >> output, '<table>'
- print >> output, '<thead>'
- print >> output, '<tr><td></td>'
+ print(self.page_intro, file=output)
+ print('<table>', file=output)
+ print('<thead>', file=output)
+ print('<tr><td></td>', file=output)
for check in self.checks:
- print >> output, '<th>%s</th>' % check.__name__
- print >> output, '<td></td></tr>'
+ print('<th>%s</th>' % check.__name__, file=output)
+ print('<td></td></tr>', file=output)
if [x for x in self.checks if x.header_note]:
- print >> output, '<tr><td></td>'
+ print('<tr><td></td>', file=output)
for check in self.checks:
- print >> output, '<td>%s</td>' % (check.header_note or '')
- print >> output, '</tr>'
- print >> output, '</thead>'
- print >> output, '<tbody>'
+ print('<td>%s</td>' % (check.header_note or ''), file=output)
+ print('</tr>', file=output)
+ print('</thead>', file=output)
+ print('<tbody>', file=output)
processed_modules = {'gnome-common': True}
suites = []
@@ -504,13 +506,13 @@ class cmd_goalreport(Command):
module_names = [x for x in metamodule.dependencies if x in results]
if not module_names:
continue
- print >> output, '<tr><td class="heading" colspan="%d">%s</td></tr>' % (
- 1+len(self.checks)+self.repeat_row_header, suite_label)
+ print('<tr><td class="heading" colspan="%d">%s</td></tr>' % (
+ 1+len(self.checks)+self.repeat_row_header, suite_label), file=output)
for module_name in module_names:
if module_name in not_other_module_names:
continue
r = results[module_name].get('results')
- print >> output, self.get_mod_line(module_name, r)
+ print(self.get_mod_line(module_name, r), file=output)
processed_modules[module_name] = True
not_other_module_names.extend(module_names)
@@ -519,8 +521,8 @@ class cmd_goalreport(Command):
x not in processed_modules and \
module_set.get_module(x).moduleset_name.startswith('gnome-external-deps')]
if external_deps:
- print >> output, '<tr><td class="heading" colspan="%d">%s</td></tr>' % (
- 1+len(self.checks)+self.repeat_row_header, 'External Dependencies')
+ print('<tr><td class="heading" colspan="%d">%s</td></tr>' % (
+ 1+len(self.checks)+self.repeat_row_header, 'External Dependencies'), file=output)
for module_name in sorted(external_deps):
if module_name not in results:
continue
@@ -529,52 +531,52 @@ class cmd_goalreport(Command):
version = module_set.get_module(module_name).branch.version
except:
version = None
- print >> output, self.get_mod_line(module_name, r, version_number=version)
+ print(self.get_mod_line(module_name, r, version_number=version), file=output)
other_module_names = [x for x in results.keys() if \
x not in processed_modules and x not in external_deps]
if other_module_names:
- print >> output, '<tr><td class="heading" colspan="%d">%s</td></tr>' % (
- 1+len(self.checks)+self.repeat_row_header, 'Others')
+ print('<tr><td class="heading" colspan="%d">%s</td></tr>' % (
+ 1+len(self.checks)+self.repeat_row_header, 'Others'), file=output)
for module_name in sorted(other_module_names):
if module_name not in results:
continue
r = results[module_name].get('results')
- print >> output, self.get_mod_line(module_name, r)
- print >> output, '</tbody>'
- print >> output, '<tfoot>'
+ print(self.get_mod_line(module_name, r), file=output)
+ print('</tbody>', file=output)
+ print('<tfoot>', file=output)
- print >> output, '<tr><td></td>'
+ print('<tr><td></td>', file=output)
for check in self.checks:
- print >> output, '<th>%s</th>' % check.__name__
- print >> output, '<td></td></tr>'
+ print('<th>%s</th>' % check.__name__, file=output)
+ print('<td></td></tr>', file=output)
- print >> output, self.get_stat_line(results, not_other_module_names)
- print >> output, '</tfoot>'
- print >> output, '</table>'
+ print(self.get_stat_line(results, not_other_module_names), file=output)
+ print('</tfoot>', file=output)
+ print('</table>', file=output)
if (options.bugfile and options.bugfile.startswith('http://')) or \
(options.falsepositivesfile and options.falsepositivesfile.startswith('http://')):
- print >> output, '<div id="data">'
- print >> output, '<p>The following data sources are used:</p>'
- print >> output, '<ul>'
+ print('<div id="data">', file=output)
+ print('<p>The following data sources are used:</p>', file=output)
+ print('<ul>', file=output)
if options.bugfile.startswith('http://'):
- print >> output, ' <li><a href="%s">Bugs</a></li>' % options.bugfile
+ print(' <li><a href="%s">Bugs</a></li>' % options.bugfile, file=output)
if options.falsepositivesfile.startswith('http://'):
- print >> output, ' <li><a href="%s">False positives</a></li>' % options.falsepositivesfile
- print >> output, '</ul>'
- print >> output, '</div>'
+ print(' <li><a href="%s">False positives</a></li>' % options.falsepositivesfile,
file=output)
+ print('</ul>', file=output)
+ print('</div>', file=output)
- print >> output, '<div id="footer">'
- print >> output, 'Generated:', time.strftime('%Y-%m-%d %H:%M:%S %z')
- print >> output, 'on ', socket.getfqdn()
- print >> output, '</div>'
+ print('<div id="footer">', file=output)
+ print('Generated:', time.strftime('%Y-%m-%d %H:%M:%S %z'), file=output)
+ print('on ', socket.getfqdn(), file=output)
+ print('</div>', file=output)
- print >> output, '</body>'
- print >> output, '</html>'
+ print('</body>', file=output)
+ print('</html>', file=output)
if output != sys.stdout:
- file(options.output, 'w').write(output.getvalue())
+ open(options.output, 'w').write(output.getvalue())
if output != sys.stdout and config.progress_bar:
sys.stdout.write('\n')
@@ -688,7 +690,7 @@ class cmd_goalreport(Command):
except Exception as e:
logging.warning('could not download %s: %s' % (filename, e))
return
- for line in file(filename):
+ for line in open(filename):
line = line.strip()
if not line:
continue
@@ -735,7 +737,7 @@ class cmd_goalreport(Command):
except Exception as e:
logging.warning('could not download %s: %s' % (filename, e))
return
- for line in file(filename):
+ for line in open(filename):
line = line.strip()
if not line:
continue
diff --git a/jhbuild/commands/snapshot.py b/jhbuild/commands/snapshot.py
index 050977ff..e9e26518 100644
--- a/jhbuild/commands/snapshot.py
+++ b/jhbuild/commands/snapshot.py
@@ -19,7 +19,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
+from __future__ import print_function
import urllib2
from optparse import make_option
@@ -55,7 +55,7 @@ class cmd_snapshot(Command):
+ [m.to_sxml() for m in checked_out_mods]
+ [m.to_sxml() for m in meta])
- print '<?xml version="1.0"?>\n'
- print sxml_to_string(x)
+ print('<?xml version="1.0"?>\n')
+ print(sxml_to_string(x))
register_command(cmd_snapshot)
diff --git a/jhbuild/commands/sysdeps.py b/jhbuild/commands/sysdeps.py
index 0abdf81d..d626d027 100644
--- a/jhbuild/commands/sysdeps.py
+++ b/jhbuild/commands/sysdeps.py
@@ -17,6 +17,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+from __future__ import print_function
+
from optparse import make_option
import logging
import os.path
@@ -81,7 +83,7 @@ class cmd_sysdeps(cmd_build):
if (isinstance(module, SystemModule) or isinstance(module.branch, TarballBranch) and
module.pkg_config is not None):
if module.pkg_config is not None:
- print 'pkgconfig:{0}'.format(module.pkg_config[:-3]) # remove .pc
+ print('pkgconfig:{0}'.format(module.pkg_config[:-3])) # remove .pc
if module.systemdependencies is not None:
for dep_type, value, altdeps in module.systemdependencies:
@@ -117,7 +119,7 @@ class cmd_sysdeps(cmd_build):
assert (module.pkg_config or module.systemdependencies)
if module.pkg_config is not None:
- print 'pkgconfig:{0}'.format(module.pkg_config[:-3]) # remove .pc
+ print('pkgconfig:{0}'.format(module.pkg_config[:-3])) # remove .pc
if module.systemdependencies is not None:
for dep_type, value, altdeps in module.systemdependencies:
@@ -131,7 +133,7 @@ class cmd_sysdeps(cmd_build):
return
- print _('System installed packages which are new enough:')
+ print(_('System installed packages which are new enough:'))
for module,(req_version, installed_version, new_enough, systemmodule) in module_state.iteritems():
if (installed_version is not None) and new_enough and (config.partial_build or systemmodule):
have_new_enough = True
@@ -140,63 +142,63 @@ class cmd_sysdeps(cmd_build):
req_version,
installed_version)))
if not have_new_enough:
- print _(' (none)')
+ print(_(' (none)'))
- print _('Required packages:')
- print _(' System installed packages which are too old:')
+ print(_('Required packages:'))
+ print(_(' System installed packages which are too old:'))
for module, (req_version, installed_version, new_enough, systemmodule) in module_state.iteritems():
if (installed_version is not None) and (not new_enough) and systemmodule:
have_too_old = True
- print (' %s %s' % (module.name,
- fmt_details(module.pkg_config,
- req_version,
- installed_version)))
+ print(' %s %s' % (module.name,
+ fmt_details(module.pkg_config,
+ req_version,
+ installed_version)))
if not have_too_old:
- print _(' (none)')
+ print(_(' (none)'))
- print _(' No matching system package installed:')
+ print(_(' No matching system package installed:'))
uninstalled = []
for module, (req_version, installed_version, new_enough, systemmodule) in module_state.iteritems():
if installed_version is None and (not new_enough) and systemmodule:
- print (' %s %s' % (module.name,
- fmt_details(module.pkg_config,
- req_version,
- installed_version)))
+ print(' %s %s' % (module.name,
+ fmt_details(module.pkg_config,
+ req_version,
+ installed_version)))
if module.pkg_config is not None:
uninstalled.append((module.name, 'pkgconfig', module.pkg_config[:-3])) # remove .pc
elif module.systemdependencies is not None:
for dep_type, value, altdeps in module.systemdependencies:
uninstalled.append((module.name, dep_type, value))
if len(uninstalled) == 0:
- print _(' (none)')
+ print(_(' (none)'))
have_too_old = False
if config.partial_build:
- print _('Optional packages: (JHBuild will build the missing packages)')
- print _(' System installed packages which are too old:')
+ print(_('Optional packages: (JHBuild will build the missing packages)'))
+ print(_(' System installed packages which are too old:'))
for module, (req_version, installed_version, new_enough, systemmodule) in
module_state.iteritems():
if (installed_version is not None) and (not new_enough) and (not systemmodule):
have_too_old = True
- print (' %s %s' % (module.name,
- fmt_details(module.pkg_config,
- req_version,
- installed_version)))
+ print(' %s %s' % (module.name,
+ fmt_details(module.pkg_config,
+ req_version,
+ installed_version)))
if not have_too_old:
- print _(' (none)')
+ print(_(' (none)'))
- print _(' No matching system package installed:')
+ print(_(' No matching system package installed:'))
for module,(req_version, installed_version, new_enough, systemmodule) in
module_state.iteritems():
if installed_version is None and (not new_enough) and (not systemmodule):
- print (' %s %s' % (module.name,
- fmt_details(module.pkg_config,
- req_version,
- installed_version)))
+ print(' %s %s' % (module.name,
+ fmt_details(module.pkg_config,
+ req_version,
+ installed_version)))
if module.pkg_config is not None:
uninstalled.append((module.name, 'pkgconfig', module.pkg_config[:-3])) # remove .pc
if len(uninstalled) == 0:
- print _(' (none)')
+ print(_(' (none)'))
if options.install:
installer = SystemInstall.find_best()
diff --git a/jhbuild/commands/twoninetynine.py b/jhbuild/commands/twoninetynine.py
index 4fbeb5b8..c3ad4908 100644
--- a/jhbuild/commands/twoninetynine.py
+++ b/jhbuild/commands/twoninetynine.py
@@ -131,7 +131,7 @@ class GObjectIntrospectionSupport(Check):
if not gir_file and 'Makefile.am' in filenames:
# if there is no .gir, we may simply be in an unbuilt module,
# let's look up for a .gir target in the Makefile.am
- makefile_am = file(os.path.join(base, 'Makefile.am')).read()
+ makefile_am = open(os.path.join(base, 'Makefile.am')).read()
if re.findall(r'^[A-Za-z0-9.\-\$\(\)_]+\.gir:', makefile_am, re.MULTILINE):
gir_file = True
if pkg_config and gir_file:
diff --git a/jhbuild/config.py b/jhbuild/config.py
index 3c31ee2b..dcde3168 100644
--- a/jhbuild/config.py
+++ b/jhbuild/config.py
@@ -32,6 +32,7 @@ import __builtin__
from jhbuild.environment import setup_env, setup_env_defaults, addpath
from jhbuild.errors import FatalError
from jhbuild.utils import sysid
+from jhbuild.utils.compat import execfile
if sys.platform.startswith('win'):
# For munging paths for MSYS's benefit
diff --git a/jhbuild/frontends/autobuild.py b/jhbuild/frontends/autobuild.py
index e44af9a2..12cbb59c 100644
--- a/jhbuild/frontends/autobuild.py
+++ b/jhbuild/frontends/autobuild.py
@@ -17,6 +17,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+from __future__ import print_function
+
import os
import time
import subprocess
@@ -25,6 +27,7 @@ import locale
import socket
from jhbuild.utils import cmds
+from jhbuild.utils.compat import text_type, string_types
from jhbuild.errors import CommandError
import buildscript
@@ -44,7 +47,7 @@ def fix_encoding(string):
s = 'VERY BORKEN ENCODING'
for encoding in [charset, 'utf-8', 'iso-8859-15']:
try:
- s = unicode(string, encoding)
+ s = text_type(string, encoding)
except:
continue
break
@@ -60,21 +63,24 @@ class ServerProxy(xmlrpclib.ServerProxy):
def __request(self, methodname, params):
ITERS = 10
for i in range(ITERS):
+ err = None
try:
return xmlrpclib.ServerProxy.__request(self, methodname, params)
except xmlrpclib.ProtocolError as e:
+ err = e
if e.errcode != 500:
raise
except socket.error as e:
+ err = e
pass
if i < ITERS-1:
if self.verbose_timeout:
- print >> sys.stderr, _('Server Error, retrying in %d seconds') % ((i+1)**2)
+ print(_('Server Error, retrying in %d seconds') % ((i+1)**2), file=sys.stderr)
time.sleep((i+1)**2)
else:
if self.verbose_timeout:
- print >> sys.stderr, _('Server Error, aborting')
- raise e
+ print(_('Server Error, aborting'), file=sys.stderr)
+ raise err
class AutobuildBuildScript(buildscript.BuildScript, TerminalBuildScript):
@@ -127,7 +133,7 @@ class AutobuildBuildScript(buildscript.BuildScript, TerminalBuildScript):
kws = {
'close_fds': True
}
- if isinstance(command, (str, unicode)):
+ if isinstance(command, string_types):
displayed_command = command
kws['shell'] = True
else:
@@ -135,7 +141,7 @@ class AutobuildBuildScript(buildscript.BuildScript, TerminalBuildScript):
self.phasefp.write('<span class="command">%s</span>\n' % escape(displayed_command))
if self.verbose:
- print ' $', displayed_command
+ print(' $', displayed_command)
kws['stdin'] = subprocess.PIPE
kws['stdout'] = subprocess.PIPE
@@ -145,7 +151,7 @@ class AutobuildBuildScript(buildscript.BuildScript, TerminalBuildScript):
if line[-1] == '\n':
line = line[:-1]
if self.verbose:
- print line
+ print(line)
if line.startswith('C '):
fp.write('<span class="conflict">%s</span>\n'
% escape(line))
@@ -158,9 +164,9 @@ class AutobuildBuildScript(buildscript.BuildScript, TerminalBuildScript):
line = line[:-1]
if self.verbose:
if error_output:
- print >> sys.stderr, line
+ print(line, file=sys.stderr)
else:
- print line
+ print(line)
if error_output:
fp.write('<span class="error">%s</span>\n'
% escape(line))
@@ -211,16 +217,16 @@ class AutobuildBuildScript(buildscript.BuildScript, TerminalBuildScript):
self.build_id = self.server.start_build(info)
except xmlrpclib.ProtocolError as e:
if e.errcode == 403:
- print >> sys.stderr, _('ERROR: Wrong credentials, please check username/password')
+ print(_('ERROR: Wrong credentials, please check username/password'), file=sys.stderr)
sys.exit(1)
raise
if self.verbose:
s = _('Starting Build #%s') % self.build_id
- print s
- print '=' * len(s)
- print ''
+ print(s)
+ print('=' * len(s))
+ print('')
def end_build(self, failures):
@@ -231,7 +237,7 @@ class AutobuildBuildScript(buildscript.BuildScript, TerminalBuildScript):
def start_module(self, module):
if self.verbose:
- print '\n%s' % t_bold + _('**** Starting module %s ****' % module) + t_reset
+ print('\n%s' % t_bold + _('**** Starting module %s ****' % module) + t_reset)
self.server.start_module(self.build_id, module)
self.current_module = module
self.modulefp = StringIO()
@@ -262,12 +268,12 @@ class AutobuildBuildScript(buildscript.BuildScript, TerminalBuildScript):
self._upload_logfile(module)
if isinstance(error, Exception):
- error = unicode(error)
+ error = text_type(error)
self.server.end_phase(self.build_id, module, phase, compress_data(log), error)
def handle_error(self, module, phase, nextphase, error, altphases):
'''handle error during build'''
- print 'FIXME: handle error! (failed build: %s: %s)' % (module, error)
+ print('FIXME: handle error! (failed build: %s: %s)' % (module, error))
return 'fail'
def _upload_ldtp_logfile (self, module):
diff --git a/jhbuild/frontends/buildscript.py b/jhbuild/frontends/buildscript.py
index 747b92b2..cc5be03d 100644
--- a/jhbuild/frontends/buildscript.py
+++ b/jhbuild/frontends/buildscript.py
@@ -26,6 +26,7 @@ import sys
from jhbuild.utils import trigger
from jhbuild.utils import cmds
from jhbuild.errors import FatalError, CommandError, SkipToPhase, SkipToEnd
+from jhbuild.utils.compat import string_types
class BuildScript:
def __init__(self, config, module_list=None, module_set=None):
@@ -90,7 +91,7 @@ class BuildScript:
def _prepare_execute(self, command):
if self.subprocess_nice_args:
- if isinstance(command, (str, unicode)):
+ if isinstance(command, string_types):
command = ' '.join(self.subprocess_nice_args) + ' ' + command
else:
command = self.subprocess_nice_args + command
@@ -270,7 +271,7 @@ class BuildScript:
try:
self.execute(trig.command())
except CommandError as err:
- if isinstance(trig.command(), (str, unicode)):
+ if isinstance(trig.command(), string_types):
displayed_command = trig.command()
else:
displayed_command = ' '.join(trig.command())
diff --git a/jhbuild/frontends/gtkui.py b/jhbuild/frontends/gtkui.py
index 9dbf11d2..3d26f673 100644
--- a/jhbuild/frontends/gtkui.py
+++ b/jhbuild/frontends/gtkui.py
@@ -42,6 +42,7 @@ import jhbuild.moduleset
from jhbuild.modtypes import MetaModule
from jhbuild.errors import CommandError
from jhbuild.utils import notify
+from jhbuild.utils.compat import string_types, cmp
from terminal import t_bold, t_reset
@@ -446,7 +447,7 @@ class AppWindow(gtk.Window, buildscript.BuildScript):
if not command:
raise CommandError(_('No command given'))
- if isinstance(command, (str, unicode)):
+ if isinstance(command, string_types):
short_command = command.split()[0]
else:
short_command = command[0]
@@ -454,7 +455,7 @@ class AppWindow(gtk.Window, buildscript.BuildScript):
if vte is None:
textbuffer = self.terminal.get_buffer()
- if isinstance(command, (str, unicode)):
+ if isinstance(command, string_types):
self.terminal.get_buffer().insert_with_tags_by_name(
textbuffer.get_end_iter(),
' $ ' + command + '\n', 'stdin')
@@ -465,7 +466,7 @@ class AppWindow(gtk.Window, buildscript.BuildScript):
kws = {
'close_fds': True,
- 'shell': isinstance(command, (str,unicode)),
+ 'shell': isinstance(command, string_types),
'stdin': subprocess.PIPE,
'stdout': subprocess.PIPE,
'stderr': subprocess.PIPE,
@@ -555,7 +556,7 @@ class AppWindow(gtk.Window, buildscript.BuildScript):
self.child_pid = None
else:
# use the vte widget
- if isinstance(command, (str, unicode)):
+ if isinstance(command, string_types):
self.terminal.feed(' $ ' + command + '\n\r')
command = [os.environ.get('SHELL', '/bin/sh'), '-c', command]
else:
diff --git a/jhbuild/frontends/terminal.py b/jhbuild/frontends/terminal.py
index 15a291f5..2c896dbd 100644
--- a/jhbuild/frontends/terminal.py
+++ b/jhbuild/frontends/terminal.py
@@ -18,6 +18,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+from __future__ import print_function
+
import sys
import os
import signal
@@ -30,6 +32,7 @@ from jhbuild.utils import cmds
from jhbuild.utils import trayicon
from jhbuild.utils import notify
from jhbuild.errors import CommandError, FatalError
+from jhbuild.utils.compat import input, string_types
term = os.environ.get('TERM', '')
is_xterm = term.find('xterm') >= 0 or term == 'rxvt'
@@ -180,7 +183,7 @@ class TerminalBuildScript(buildscript.BuildScript):
except OSError:
pass
- if isinstance(command, (str, unicode)):
+ if isinstance(command, string_types):
kws['shell'] = True
print_args['command'] = command
else:
@@ -197,7 +200,7 @@ class TerminalBuildScript(buildscript.BuildScript):
if not self.config.quiet_mode:
if self.config.print_command_pattern:
try:
- print self.config.print_command_pattern % print_args
+ print(self.config.print_command_pattern % print_args)
except TypeError as e:
raise FatalError('\'print_command_pattern\' %s' % e)
except KeyError as e:
@@ -249,13 +252,13 @@ class TerminalBuildScript(buildscript.BuildScript):
line = line[:-1]
if line.startswith('C '):
- print '%s%s%s' % (t_colour[12], line, t_reset)
+ print('%s%s%s' % (t_colour[12], line, t_reset))
elif line.startswith('M '):
- print '%s%s%s' % (t_colour[10], line, t_reset)
+ print('%s%s%s' % (t_colour[10], line, t_reset))
elif line.startswith('? '):
- print '%s%s%s' % (t_colour[8], line, t_reset)
+ print('%s%s%s' % (t_colour[8], line, t_reset))
else:
- print line
+ print(line)
cmds.pprint_output(p, format_line)
if conflicts:
@@ -282,7 +285,7 @@ class TerminalBuildScript(buildscript.BuildScript):
try:
if p.wait() != 0:
if self.config.quiet_mode:
- print ''.join(output)
+ print(''.join(output))
raise CommandError(_('########## Error running %s')
% print_args['command'], p.returncode)
except OSError:
@@ -305,8 +308,8 @@ class TerminalBuildScript(buildscript.BuildScript):
else:
self.message(_('the following modules were not built'))
for module in failures:
- print module,
- print
+ print(module, end=' ')
+ print('')
def handle_error(self, module, phase, nextphase, error, altphases):
'''handle error during build'''
@@ -353,7 +356,7 @@ class TerminalBuildScript(buildscript.BuildScript):
altphase_label = altphase
uprint(' [%d] %s' % (i, _('Go to phase "%s"') % altphase_label))
i += 1
- val = raw_input(uencode(_('choice: ')))
+ val = input(uencode(_('choice: ')))
val = udecode(val)
val = val.strip()
if val == '1':
@@ -400,7 +403,7 @@ class TerminalBuildScript(buildscript.BuildScript):
except AttributeError:
needs_confirmation = False
if needs_confirmation:
- val = raw_input(uencode(_('Type "yes" to confirm the action: ')))
+ val = input(uencode(_('Type "yes" to confirm the action: ')))
val = udecode(val)
val = val.strip()
diff --git a/jhbuild/frontends/tinderbox.py b/jhbuild/frontends/tinderbox.py
index 071d5356..67771cd7 100644
--- a/jhbuild/frontends/tinderbox.py
+++ b/jhbuild/frontends/tinderbox.py
@@ -29,6 +29,7 @@ from jhbuild.main import _encoding
from jhbuild.utils import cmds
from jhbuild.utils import sysid
from jhbuild.errors import CommandError, FatalError
+from jhbuild.utils.compat import string_types, text_type
import buildscript
import commands
@@ -135,8 +136,8 @@ buildlog_footer = '''
'''
def escape(string):
- if type(string) is not unicode:
- string = unicode(string, _encoding, 'replace')
+ if not isinstance(string, text_type):
+ string = text_type(string, _encoding, 'replace')
string = string.replace('&', '&').replace('<','<').replace(
'>','>').replace('\n','<br/>').replace(
'\t',' ')
@@ -202,7 +203,7 @@ class TinderboxBuildScript(buildscript.BuildScript):
print_args['cwd'] = os.getcwd()
self.modulefp.write('<pre>')
- if isinstance(command, (str, unicode)):
+ if isinstance(command, string_types):
kws['shell'] = True
print_args['command'] = command
else:
diff --git a/jhbuild/main.py b/jhbuild/main.py
index c266f99b..35777771 100644
--- a/jhbuild/main.py
+++ b/jhbuild/main.py
@@ -17,6 +17,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+from __future__ import print_function
+
import sys, os, errno
import optparse
import traceback
@@ -31,6 +33,7 @@ import jhbuild.commands
from jhbuild.errors import UsageError, FatalError
from jhbuild.utils.cmds import get_output
from jhbuild.moduleset import warn_local_modulesets
+from jhbuild.utils.compat import text_type
if sys.platform == 'darwin':
@@ -52,13 +55,13 @@ except (locale.Error, AssertionError):
_encoding = 'ascii'
def uencode(s):
- if type(s) is unicode:
+ if isinstance(s, text_type):
return s.encode(_encoding, 'replace')
else:
return s
def udecode(s):
- if type(s) is not unicode:
+ if not isinstance(s, text_type):
return s.decode(_encoding, 'replace')
else:
return s
@@ -66,9 +69,9 @@ def udecode(s):
def uprint(*args):
'''Print Unicode string encoded for the terminal'''
for s in args[:-1]:
- print uencode(s),
+ print(uencode(s), end=' ')
s = args[-1]
- print uencode(s)
+ print(uencode(s))
__builtin__.__dict__['uprint'] = uprint
__builtin__.__dict__['uencode'] = uencode
diff --git a/jhbuild/modtypes/autotools.py b/jhbuild/modtypes/autotools.py
index 92f14e57..a7121080 100644
--- a/jhbuild/modtypes/autotools.py
+++ b/jhbuild/modtypes/autotools.py
@@ -226,14 +226,14 @@ class AutogenModule(MakeModule, DownloadableModule):
srcdir = self.get_srcdir(buildscript)
try:
- if not (os.stat(os.path.join(srcdir, self.autogen_sh))[stat.ST_MODE] & 0111):
- os.chmod(os.path.join(srcdir, self.autogen_sh), 0755)
+ if not (os.stat(os.path.join(srcdir, self.autogen_sh))[stat.ST_MODE] & 0o111):
+ os.chmod(os.path.join(srcdir, self.autogen_sh), 0o755)
except:
pass
if self.autogen_sh == 'autoreconf':
buildscript.execute(['autoreconf', '-fi'], cwd=srcdir)
- os.chmod(os.path.join(srcdir, 'configure'), 0755)
+ os.chmod(os.path.join(srcdir, 'configure'), 0o755)
buildscript.execute(cmd, cwd = builddir, extra_env = self.extra_env)
do_configure.depends = [PHASE_CHECKOUT]
diff --git a/jhbuild/utils/Makefile.am b/jhbuild/utils/Makefile.am
index 0bc12e51..ffe0fd74 100644
--- a/jhbuild/utils/Makefile.am
+++ b/jhbuild/utils/Makefile.am
@@ -3,6 +3,7 @@ appdir = $(pythondir)/jhbuild/utils/
app_PYTHON = \
__init__.py \
cmds.py \
+ compat.py \
fileutils.py \
httpcache.py \
notify.py \
diff --git a/jhbuild/utils/cmds.py b/jhbuild/utils/cmds.py
index d8dba51a..131b24b9 100644
--- a/jhbuild/utils/cmds.py
+++ b/jhbuild/utils/cmds.py
@@ -24,6 +24,7 @@ import subprocess
import sys
from signal import SIGINT
from jhbuild.errors import CommandError
+from jhbuild.utils.compat import string_types
def get_output(cmd, cwd=None, extra_env=None, get_stderr = True):
'''Return the output (stdout and stderr) from the command.
@@ -40,7 +41,7 @@ def get_output(cmd, cwd=None, extra_env=None, get_stderr = True):
raise CommandError(_('Call to undefined command'))
kws = {}
- if isinstance(cmd, (str, unicode)):
+ if isinstance(cmd, string_types):
kws['shell'] = True
if cwd is not None:
kws['cwd'] = cwd
@@ -110,7 +111,7 @@ class Pipeline(subprocess.Popen):
c2cwrite = stdout
self.children.append(
- subprocess.Popen(cmd, shell=isinstance(cmd, (str, unicode)),
+ subprocess.Popen(cmd, shell=isinstance(cmd, string_types),
bufsize=bufsize, close_fds=True,
cwd=cwd, env=env,
stdin=stdin,
@@ -157,7 +158,7 @@ def spawn_child(command, use_pipe=False,
p = Pipeline(command, cwd=cwd, env=env,
stdin=stdin, stdout=stdout, stderr=stderr)
else:
- p = subprocess.Popen(command, shell=isinstance(command, (str,unicode)),
+ p = subprocess.Popen(command, shell=isinstance(command, string_types),
close_fds=True, cwd=cwd, env=env,
stdin=stdin, stdout=stdout, stderr=stderr)
return p
diff --git a/jhbuild/utils/compat.py b/jhbuild/utils/compat.py
new file mode 100644
index 00000000..8fd3c5df
--- /dev/null
+++ b/jhbuild/utils/compat.py
@@ -0,0 +1,55 @@
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+import sys
+
+
+PY2 = sys.version_info[0] == 2
+PY3 = not PY2
+
+if PY2:
+ import __builtin__ as builtins
+
+ cmp = builtins.cmp
+ text_type = builtins.unicode
+ string_types = (str, builtins.unicode)
+ file_type = builtins.file
+ input = builtins.raw_input
+ execfile = builtins.execfile
+elif PY3:
+ import builtins
+ from io import IOBase
+
+ def cmp(a, b):
+ return (a > b) - (a < b)
+
+ text_type = str
+ string_types = (str,)
+ file_type = IOBase
+ input = input
+
+ def execfile(filename, globals=None, locals=None):
+ if globals is None:
+ frame = sys._getframe(1)
+ globals = frame.f_globals
+ if locals is None:
+ locals = frame.f_locals
+ del frame
+ elif locals is None:
+ locals = globals
+
+ with open(filename, "rb") as f:
+ source = f.read()
+ code = compile(source, filename, "exec")
+ exec(code, globals, locals)
diff --git a/jhbuild/utils/packagedb.py b/jhbuild/utils/packagedb.py
index 54637633..6dfee356 100644
--- a/jhbuild/utils/packagedb.py
+++ b/jhbuild/utils/packagedb.py
@@ -60,7 +60,7 @@ class PackageEntry:
if not os.path.exists(os.path.join(self.dirname, 'manifests', self.package)):
return None
self._manifest = []
- for line in file(os.path.join(self.dirname, 'manifests', self.package)):
+ for line in open(os.path.join(self.dirname, 'manifests', self.package)):
self._manifest.append(line.strip())
return self._manifest
diff --git a/jhbuild/utils/subprocess_win32.py b/jhbuild/utils/subprocess_win32.py
index 852097a7..12888d01 100644
--- a/jhbuild/utils/subprocess_win32.py
+++ b/jhbuild/utils/subprocess_win32.py
@@ -21,6 +21,8 @@ import os
import sys
import subprocess as real_subprocess
+from .compat import file_type
+
PIPE = real_subprocess.PIPE
STDOUT = real_subprocess.STDOUT
@@ -131,7 +133,7 @@ class Popen(real_subprocess.Popen):
if self.__emulate_close_fds:
for f in self.stdin, self.stdout, self.stderr:
# This somehow tells us if we are dealing with a pipe.
- if isinstance(f, file) and f.name == '<fdopen>':
+ if isinstance(f, file_type) and f.name == '<fdopen>':
# Not that it actually matters.
f.close()
sys.stdout.flush()
diff --git a/jhbuild/utils/sxml.py b/jhbuild/utils/sxml.py
index 3a8da072..878c8aec 100644
--- a/jhbuild/utils/sxml.py
+++ b/jhbuild/utils/sxml.py
@@ -17,6 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+from .compat import string_types, text_type
"""
@@ -41,12 +42,12 @@ __all__ = ['sxml', 'sxml_to_string']
# from Django, originally. used to make sure xml is utf-8.
def smart_str(s, encoding='utf-8', errors='strict'):
# Returns a bytestring version of 's', encoded as specified in 'encoding'.
- if not isinstance(s, basestring):
+ if not isinstance(s, string_types):
try:
return str(s)
except UnicodeEncodeError:
- return unicode(s).encode(encoding, errors)
- elif isinstance(s, unicode):
+ return text_type(s).encode(encoding, errors)
+ elif isinstance(s, text_type):
return s.encode(encoding, errors)
elif s and encoding != 'utf-8':
return s.decode('utf-8', errors).encode(encoding, errors)
diff --git a/jhbuild/utils/systeminstall.py b/jhbuild/utils/systeminstall.py
index 8d81fde7..45c74c4e 100644
--- a/jhbuild/utils/systeminstall.py
+++ b/jhbuild/utils/systeminstall.py
@@ -17,6 +17,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+from __future__ import print_function
+
import os
import sys
import logging
@@ -549,5 +551,5 @@ _classes = [AptSystemInstall, PacmanSystemInstall, PKSystemInstall]
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
installer = SystemInstall.find_best()
- print "Using %r" % (installer, )
+ print("Using %r" % (installer, ))
installer.install(sys.argv[1:])
diff --git a/jhbuild/utils/unpack.py b/jhbuild/utils/unpack.py
index fac743a5..887eb8d8 100644
--- a/jhbuild/utils/unpack.py
+++ b/jhbuild/utils/unpack.py
@@ -50,9 +50,9 @@ def unpack_zip_file(localfile, target_directory):
def attr_to_file_perm(host, attr):
if host == 0:
if attr & 1:
- perm = 0444
+ perm = 0o444
else:
- perm = 0666
+ perm = 0o666
else:
perm = attr
perm &= 0x08FF0000
@@ -64,9 +64,9 @@ def unpack_zip_file(localfile, target_directory):
if host == 0:
# attr & 16 should be true (this is directory bit)
if attr & 1:
- perm = 0444
+ perm = 0o444
else:
- perm = 0666
+ perm = 0o666
else:
perm = attr
perm &= 0xFFFF0000
diff --git a/jhbuild/versioncontrol/bzr.py b/jhbuild/versioncontrol/bzr.py
index ea19919a..1d0f0859 100644
--- a/jhbuild/versioncontrol/bzr.py
+++ b/jhbuild/versioncontrol/bzr.py
@@ -115,7 +115,8 @@ class BzrBranch(Branch):
def get_revspec(self):
return self._revspec
- def set_revspec(self, (tag, revspec)):
+ def set_revspec(self, value):
+ tag, revspec = value
if revspec:
self._revspec = ['-r%s' % revspec]
elif tag:
diff --git a/jhbuild/versioncontrol/darcs.py b/jhbuild/versioncontrol/darcs.py
index bc2cf88f..c212808c 100644
--- a/jhbuild/versioncontrol/darcs.py
+++ b/jhbuild/versioncontrol/darcs.py
@@ -103,7 +103,7 @@ class DarcsBranch(Branch):
stat = os.stat(path)
except OSError:
continue
- os.chmod(path, stat.st_mode | 0111)
+ os.chmod(path, stat.st_mode | 0o111)
def checkout(self, buildscript):
if not inpath('darcs', os.environ['PATH'].split(os.pathsep)):
@@ -116,6 +116,6 @@ class DarcsBranch(Branch):
# this
if not os.path.exists(self.srcdir):
return None
- return hashlib.md5(file(os.path.join(self.srcdir, '_darcs', 'inventory')).read()).hexdigest()
+ return hashlib.md5(open(os.path.join(self.srcdir, '_darcs', 'inventory')).read()).hexdigest()
register_repo_type('darcs', DarcsRepository)
diff --git a/jhbuild/versioncontrol/git.py b/jhbuild/versioncontrol/git.py
index 24d8861c..ea05413d 100644
--- a/jhbuild/versioncontrol/git.py
+++ b/jhbuild/versioncontrol/git.py
@@ -614,7 +614,7 @@ class GitSvnBranch(GitBranch):
cmd = ['git', 'svn', 'show-ignore']
s = get_output(cmd, cwd = self.get_checkoutdir(copydir),
extra_env=get_git_extra_env())
- fd = file(os.path.join(
+ fd = open(os.path.join(
self.get_checkoutdir(copydir), '.git/info/exclude'), 'a')
fd.write(s)
fd.close()
diff --git a/jhbuild/versioncontrol/svn.py b/jhbuild/versioncontrol/svn.py
index a656f98c..d61d0090 100644
--- a/jhbuild/versioncontrol/svn.py
+++ b/jhbuild/versioncontrol/svn.py
@@ -17,6 +17,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+from __future__ import print_function
+
__all__ = []
__metaclass__ = type
@@ -72,7 +74,7 @@ def get_info(filename):
return ret
def get_subdirs(url):
- print _("Getting SVN subdirs: this operation might be long...")
+ print(_("Getting SVN subdirs: this operation might be long..."))
output = get_output(
['svn', 'ls', '-R', url], extra_env=get_svn_extra_env())
ret = []
diff --git a/jhbuild/versioncontrol/tarball.py b/jhbuild/versioncontrol/tarball.py
index 9e3720fb..516ca1d8 100644
--- a/jhbuild/versioncontrol/tarball.py
+++ b/jhbuild/versioncontrol/tarball.py
@@ -267,7 +267,7 @@ class TarballBranch(Branch):
patchfile = httpcache.load(patch, nonetwork=buildscript.config.nonetwork)
except urllib2.HTTPError as e:
raise BuildStateError(_('could not download patch (error: %s)') % e.code)
- except urllib2.URLError as e:
+ except urllib2.URLError:
raise BuildStateError(_('could not download patch'))
elif self.repository.moduleset_uri:
# get it relative to the moduleset uri, either in the same
@@ -277,7 +277,7 @@ class TarballBranch(Branch):
os.path.join(patch_prefix, patch))
try:
patchfile = httpcache.load(uri, nonetwork=buildscript.config.nonetwork)
- except Exception as e:
+ except Exception:
continue
if not os.path.isfile(patchfile):
continue
diff --git a/scripts/changecvsroot.py b/scripts/changecvsroot.py
index 0198c3b7..a2e262f5 100755
--- a/scripts/changecvsroot.py
+++ b/scripts/changecvsroot.py
@@ -21,15 +21,13 @@
import os
def changecvsroot(oldroot, newroot, *dirs):
- def handle((oldroot, newroot), dirname, fnames):
- if os.path.basename(dirname) == 'CVS' and 'Root' in fnames:
- r = open(os.path.join(dirname, 'Root'), 'r').read().strip()
+ for root, dirs, files in os.walk(dir):
+ if os.path.basename(root) == 'CVS' and 'Root' in files:
+ r = open(os.path.join(root, 'Root'), 'r').read().strip()
if r == oldroot:
- fp = open(os.path.join(dirname, 'Root'), 'w')
+ fp = open(os.path.join(root, 'Root'), 'w')
fp.write('%s\n' % newroot)
fp.close()
- for dir in dirs:
- os.path.walk(dir, handle, (oldroot, newroot))
if __name__ == '__main__':
import sys
diff --git a/scripts/hg-update.py b/scripts/hg-update.py
index f414495f..80cf8f6e 100755
--- a/scripts/hg-update.py
+++ b/scripts/hg-update.py
@@ -18,6 +18,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+from __future__ import print_function
+
import os
import sys
import re
@@ -51,11 +53,11 @@ def update():
# going to revert the update.
if index != -1:
out = out[:index]
- print out
+ print(out)
return hg.returncode == 0
def undo_update(parent):
- print 'Update failed, updating to parent revision'
+ print('Update failed, updating to parent revision')
env = dict(os.environ)
env['HGMERGE'] = 'false'
call(['hg', 'update', '--noninteractive', '-q', parent], env=env)
@@ -75,7 +77,7 @@ if __name__ == '__main__':
try:
ret = pull_and_update()
except OSError as e:
- print '%s: %s' % (sys.argv[0], e)
+ print('%s: %s' % (sys.argv[0], e))
if ret:
exit_code = 0
diff --git a/scripts/mk-tarball-moduleset.py b/scripts/mk-tarball-moduleset.py
index 99df7325..5bf60bd6 100755
--- a/scripts/mk-tarball-moduleset.py
+++ b/scripts/mk-tarball-moduleset.py
@@ -1,5 +1,7 @@
#!/usr/bin/python
+from __future__ import print_function
+
import sys
import os
import stat
@@ -114,8 +116,8 @@ def main(args):
exceptions = ConfigParser.ConfigParser()
for opt, arg in opts:
if opt in ('-h', '--help'):
- print usage
- print help
+ print(usage)
+ print(help)
sys.exit(0)
elif opt in ('-d', '--dependencies'):
dependencies = arg
diff --git a/tests/tests.py b/tests/tests.py
index d7332674..cdd9502c 100644
--- a/tests/tests.py
+++ b/tests/tests.py
@@ -19,6 +19,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+from __future__ import print_function
import os
import shutil
@@ -47,6 +48,7 @@ from jhbuild.errors import UsageError, CommandError
from jhbuild.modtypes import Package
from jhbuild.modtypes.autotools import AutogenModule
from jhbuild.modtypes.distutils import DistutilsModule
+from jhbuild.utils.compat import text_type
import jhbuild.config
import jhbuild.frontends.terminal
import jhbuild.moduleset
@@ -56,7 +58,7 @@ from jhbuild.main import _encoding
def uencode(s):
- if type(s) is unicode:
+ if isinstance(s, text_type):
return s.encode(_encoding, 'replace')
else:
return s
@@ -64,9 +66,9 @@ def uencode(s):
def uprint(*args):
'''Print Unicode string encoded for the terminal'''
for s in args[:-1]:
- print uencode(s),
+ print(uencode(s), end=' ')
s = args[-1]
- print uencode(s)
+ print(uencode(s))
__builtin__.__dict__['uprint'] = uprint
__builtin__.__dict__['uencode'] = uencode
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]