From f060919e92308b70c5bb28398d2e71ee849da677 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Tue, 26 Nov 2019 13:52:17 +0000 Subject: Migrate to Python 3 --- lorry | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'lorry') diff --git a/lorry b/lorry index b9f72ea..f949263 100755 --- a/lorry +++ b/lorry @@ -1,5 +1,5 @@ -#!/usr/bin/python -# Copyright (C) 2013-2016 Codethink Limited +#!/usr/bin/env python3 +# Copyright (C) 2013-2019 Codethink Limited # # 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 @@ -19,7 +19,7 @@ import cliapp import json import logging import os -import urllib2 +import urllib.request, urllib.parse import string import sys from datetime import datetime @@ -47,7 +47,7 @@ def quote_url(url): generated by lorry may no longer be found by morph. ''' - valid_chars = string.digits + string.letters + '%_' + valid_chars = string.digits + string.ascii_letters + '%_' transl = lambda x: x if x in valid_chars else '_' return ''.join([transl(x) for x in url]) @@ -118,7 +118,7 @@ class Lorry(cliapp.Application): self.progress('Getting: %s' % name) try: self.gitify(name, specs[name]) - except Exception,e: + except Exception as e: status += 1 sys.stderr.write( 'Error mirroring:\n%s' % traceback.format_exc()) @@ -352,7 +352,7 @@ class Lorry(cliapp.Application): branches['trunk'] = spec['url'] logging.debug('all branches: %s' % repr(branches)) - for branch, address in branches.iteritems(): + for branch, address in branches.items(): branchdir = os.path.join(bzrdir, branch) if not os.path.exists(branchdir): self.progress('.. doing initial bzr branch') @@ -368,7 +368,7 @@ class Lorry(cliapp.Application): exports = {} bzrmarks = os.path.join(gitdir, 'marks.bzr') - for branch, address in branches.iteritems(): + for branch, address in branches.items(): branchdir = os.path.join(bzrdir, branch) self.progress('.. fast-exporting branch %s from bzr' % branch) exports[branch] = os.path.join(dirname, 'fast-export' + branch) @@ -381,7 +381,7 @@ class Lorry(cliapp.Application): self.run_program(cmdline) gitmarks = os.path.join(gitdir, 'marks.git') - for branch, address in branches.iteritems(): + for branch, address in branches.items(): self.progress('.. fast-importing branch %s into git' % branch) with open(exports[branch], 'rb') as exportfile: cmdline = ['git', 'fast-import', '--export-marks=' + gitmarks] @@ -390,7 +390,7 @@ class Lorry(cliapp.Application): self.run_program(cmdline, stdin=exportfile, cwd=gitdir) - for branch, address in branches.iteritems(): + for branch, address in branches.items(): branchdir = os.path.join(bzrdir, branch) self.progress('.. removing temporary fast-export file ' + exports[branch]) @@ -494,15 +494,15 @@ class Lorry(cliapp.Application): assert archive_type in ['zip', 'gzip', 'tar'] url = spec['url'] - url_path = urllib2.urlparse.urlparse(url)[2] + url_path = urllib.parse.urlparse(url)[2] basename = os.path.basename(url_path) archive_dest = os.path.join(dirname, basename) self.progress('.. checking if we need to fetch %s' % basename) if file_missing_or_empty(archive_dest): self.progress('.. attempting to fetch.') try: - with open(archive_dest, 'w') as archive_file: - urlfile = urllib2.urlopen(spec['url']) + with open(archive_dest, 'wb') as archive_file: + urlfile = urllib.request.urlopen(spec['url']) archive_file.write(urlfile.read()) urlfile.close() except Exception as e: -- cgit v1.2.1