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 --- .gitlab-ci.yml | 4 +++- lorry | 24 ++++++++++++------------ lorry.gzip-importer | 2 +- lorry.zip-importer | 2 +- setup.py | 4 ++-- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2be9e7b..e682625 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,13 +2,15 @@ image: debian:stretch before_script: - apt-get update -y -- apt-get install -y -qq python-dev python-pip +- apt-get install -y -qq python3-dev python3-pip # Deps for running tests - apt-get install -y -qq cmdtest # Deps to run lorry tests - apt-get install -y -qq git bzr cvs mercurial subversion hg-fast-export git-svn git-cvs bzr-fastimport +- pip3 install pyyaml +- pip3 install https://gitlab.com/trovekube/cliapp/-/archive/cliapp-1.20180812.1/cliapp-cliapp-1.20180812.1.tar.gz # Configure git and bzr to run tests - git config --global user.email "jdoe@example.com" 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: diff --git a/lorry.gzip-importer b/lorry.gzip-importer index c1c7215..356a41a 100755 --- a/lorry.gzip-importer +++ b/lorry.gzip-importer @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # gzip archive frontend for git-fast-import diff --git a/lorry.zip-importer b/lorry.zip-importer index 5524834..9e40a04 100755 --- a/lorry.zip-importer +++ b/lorry.zip-importer @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 ## Note: Modified for Baserock lorry. diff --git a/setup.py b/setup.py index 498fccc..d84b466 100644 --- a/setup.py +++ b/setup.py @@ -31,10 +31,10 @@ class GenerateManpage(build): def run(self): build.run(self) - print 'building manpages' + print('building manpages') for x in ['lorry']: with open('%s.1' % x, 'w') as f: - subprocess.check_call(['python', x, + subprocess.check_call(['python3', x, '--generate-manpage=%s.1.in' % x, '--output=%s.1' % x], stdout=f) -- cgit v1.2.1