Skip to content

Commit 374c200

Browse files
committed
Add some Python 3 compatibility fixes
- print is a function - Always use absolute imports - Use six.next to iterate maps Note some more fixes will still be needed for Python 3 support. Change-Id: I2862b87efad19839adf2756b7f319502331ec465
1 parent ddffd01 commit 374c200

File tree

21 files changed

+87
-69
lines changed

21 files changed

+87
-69
lines changed

rdopkg.spec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Requires: python-paramiko
1919
Requires: python-pymod2pkg >= 0.2.1
2020
Requires: python-requests
2121
Requires: python-setuptools
22+
Requires: python-six
2223
Requires: PyYAML
2324
Requires: git-core
2425
Requires: git-review

rdopkg/action.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
from __future__ import print_function
12
import inspect
23
import pkgutil
34

4-
import exception
5-
from utils import log
5+
from rdopkg import exception
6+
from rdopkg.utils import log
67

78

89
class Arg(object):
@@ -56,7 +57,7 @@ def actionsmod(self):
5657
if not self._actionsmod:
5758
astr = self.module.__name__ + '.actions'
5859
apath = astr.split('.')
59-
topmod = __import__(astr, globals(), locals(), [], -1)
60+
topmod = __import__(astr, globals(), locals(), [])
6061
mod = topmod
6162
for submod in apath[1:]:
6263
mod = getattr(mod, submod)

rdopkg/actionmods/cbsbuild.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
This module implement generic support of Koji through Koji ugly API.
33
For now, it's only used for CBS.
44
"""
5+
from __future__ import print_function
56
from distutils.spawn import find_executable
67
import os
78
import subprocess
@@ -67,9 +68,9 @@ def new_build(profile='cbs', scratch=True):
6768
kojiclient.uploadWrapper(srpm, serverdir, callback=_progress_callback)
6869
source = "%s/%s" % (serverdir, os.path.basename(srpm))
6970
task_id = kojiclient.build(source, build_target, {'scratch': scratch})
70-
print "Created task:", task_id
71+
print("Created task:", task_id)
7172

72-
print "Task info: {}/taskinfo?taskID={}".format(opts['weburl'], task_id)
73+
print("Task info: {}/taskinfo?taskID={}".format(opts['weburl'], task_id))
7374
kojiclient.logout()
7475
watch_tasks(kojiclient, [task_id])
7576

rdopkg/actionmods/copr.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- encoding: utf-8 -*-
22

3-
import ConfigParser
3+
from six.moves import configparser
44
import datetime
55
from functools import wraps
66
import json
@@ -85,7 +85,7 @@ def get_copr_conf_fn():
8585

8686

8787
def get_copr_user():
88-
config = ConfigParser.ConfigParser()
88+
config = configparser.ConfigParser()
8989
config_fn = get_copr_conf_fn()
9090
if not config.read(config_fn):
9191
raise exception.CoprError(
@@ -95,14 +95,14 @@ def get_copr_user():
9595
username = config.get('copr-cli', 'username', None)
9696
login = config.get('copr-cli', 'login', None)
9797
token = config.get('copr-cli', 'token', None)
98-
except ConfigParser.Error as err:
98+
except configparser.Error as err:
9999
raise exception.CoprError(
100100
'Bad configuration file %s: %s' % (config_fn, err))
101101
return {'username': username, 'token': token, 'login': login}
102102

103103

104104
def get_copr_url():
105-
config = ConfigParser.ConfigParser()
105+
config = configparser.ConfigParser()
106106
config.read(get_copr_conf_fn())
107107
copr_url = COPR_URL
108108
if (config.has_section('copr-cli') and

rdopkg/actionmods/kojibuild.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
Because fedpkg/pyrpkg sucks horribly, this entire file full of hacks is
33
needed to interface with it. Disgusting.
44
"""
5-
import ConfigParser
5+
from __future__ import print_function
6+
from six.moves import configparser
67
import logging
78
import sys
89
import os
@@ -51,7 +52,7 @@ def setup_fedpkg_logger():
5152

5253
def get_fedpkg_config():
5354
fedpkg_conf = '/etc/rpkg/fedpkg.conf'
54-
config = ConfigParser.SafeConfigParser()
55+
config = configparser.SafeConfigParser()
5556
config.read(fedpkg_conf)
5657
return config
5758

@@ -106,7 +107,7 @@ def new_build(watch=True):
106107
# TODO: might be good to push this return data back up
107108
# or check the status of the return
108109
r = cli._watch_koji_tasks(fcmd.kojisession, [task_id])
109-
except ConfigParser.NoSectionError:
110+
except configparser.NoSectionError:
110111
# <C-C> causes this for some reason
111112
print('')
112113
except Exception as ex:

rdopkg/actionmods/query.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
import re
23

34
from rdopkg.actionmods import rdoinfo

rdopkg/actionmods/rdoinfo.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
import collections
23
import imp
34
import re
@@ -190,12 +191,12 @@ def get_distrepos(self, release, dist=None):
190191
return distrepos
191192

192193
def print_releases(self):
193-
print "{t.bold}RDO releases & repos:{t.normal}".format(t=log.term)
194+
print("{t.bold}RDO releases & repos:{t.normal}".format(t=log.term))
194195
for rls in self.info['releases']:
195196
s = " {t.bold}{rls}{t.normal}".format(t=log.term, rls=rls['name'])
196197
if 'fedora' in rls:
197198
s += ' (Fedora %s)' % rls['fedora']
198-
print s
199+
print(s)
199200
for repo in rls['repos']:
200201
if 'special' in repo:
201202
print (" {t.bold}{name}{t.normal}: "
@@ -215,8 +216,8 @@ def print_releases(self):
215216
def print_pkg_summary(self):
216217
pkgs = self.info['packages']
217218
n = len(pkgs)
218-
print "{t.bold}{n} RDO packages defined:{t.normal}".format(
219-
t=log.term, n=n)
219+
print("{t.bold}{n} RDO packages defined:{t.normal}".format(
220+
t=log.term, n=n))
220221
confs = {}
221222
for pkg in pkgs:
222223
conf = pkg.get('conf')
@@ -243,7 +244,7 @@ def print_pkgs(self, filters=None):
243244
if filters:
244245
pkgs = filter_pkgs(pkgs, rexen=filters)
245246
if not pkgs:
246-
print "No packages match your filter."
247+
print("No packages match your filter.")
247248
return
248249
print("{t.bold}{n} packages found:{t.normal}".format(t=log.term,
249250
n=len(pkgs)))

rdopkg/actionmods/reqs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
from __future__ import print_function
12
import re
23
import pymod2pkg
34

4-
55
from rdopkg.actionmods import rdoinfo
66
from rdopkg.actionmods import query
77
from rdopkg import exception

rdopkg/actions/distgit/actions.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"""
22
This is the main rdopkg action module with actions for distgit management.
33
"""
4-
4+
from __future__ import print_function
55
import itertools
66
import os
77
import re
8+
import six
89
import sys
910

1011
from rdopkg.conf import cfg, cfg_files
@@ -19,7 +20,6 @@
1920
from rdopkg.utils import tidy_ssh_user
2021
from rdopkg import helpers
2122

22-
2323
FEDPKG = ['fedpkg']
2424

2525

@@ -112,13 +112,13 @@ def _putv(title, val):
112112
spec = specfile.Spec()
113113
vr = spec.get_vr()
114114
patches_apply_method = spec.patches_apply_method()
115-
print
115+
print('')
116116
_putv('Package: ', package)
117117
_putv('VR: ', vr)
118118
_putv('Version: ', version)
119119
_putv('Upstream: ', upstream_version)
120120
_putv('Tag style:', version_tag_style or 'X.Y.Z')
121-
print
121+
print('')
122122
_putv('Patches style: ', patches_style)
123123
_putv('Dist-git branch: ', branch)
124124
_putv('Local patches branch: ',
@@ -129,7 +129,7 @@ def _putv(title, val):
129129
'%s : %s' % (upstream_branch, upstream_str))
130130
if patches_style == 'review':
131131
_putv('Patches chain: ', gerrit_review_url)
132-
print
132+
print('')
133133
_putv('OS dist: ', osdist)
134134
_putv('Patches apply method: ', patches_apply_method)
135135

@@ -759,9 +759,9 @@ def _filter(check, stacker):
759759

760760
buckets = []
761761
stacker = _stacker(buckets)
762-
stacker.next()
762+
six.next(stacker)
763763
filter = _filter(take, stacker)
764-
filter.next()
764+
six.next(filter)
765765

766766
for patch in patches:
767767
filter.send(patch)
@@ -783,8 +783,9 @@ def update_patches(branch, local_patches_branch,
783783
action='update_patches',
784784
arg='version or new_version')
785785
tag = guess.version2tag(target_version, version_tag_style)
786+
786787
_ensure_branch(local_patches_branch)
787-
patches = git.get_commits(tag, local_patches_branch)
788+
patches = list(git.get_commits(tag, local_patches_branch))
788789
n_patches = len(patches)
789790
_ensure_branch(branch)
790791
spec = specfile.Spec()

rdopkg/actions/info/actions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
import sys
23

34
from rdopkg.actionmods import rdoinfo
@@ -25,7 +26,7 @@ def info(pkgs=None, local_info=None, apply_tag=None, force_fetch=False):
2526
inforepo.print_pkgs(filters)
2627
else:
2728
inforepo.print_summary()
28-
print
29+
print('')
2930
print("Supply regex filter(s) to list package details, e.g.:\n{t.cmd}"
3031
" rdopkg info nova\n"
3132
" rdopkg info conf:client maintainers:jruzicka\n"

0 commit comments

Comments
 (0)