Skip to content

Commit

Permalink
Python 3 compatibility
Browse files Browse the repository at this point in the history
Change-Id: I2ed609aa494e906ad45a37b7f9ac540090b0c28b
  • Loading branch information
danc86 committed Jul 12, 2016
1 parent e4c57d4 commit 2e7b969
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 17 deletions.
2 changes: 1 addition & 1 deletion acceptance_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __call__(self, environ, start_response):
return [listing]
except OSError:
start_response('200 OK', [('Content-Length', str(os.path.getsize(localpath)))])
return wsgiref.util.FileWrapper(open(localpath, 'r'))
return wsgiref.util.FileWrapper(open(localpath, 'rb'))
else:
start_response('405 Method Not Allowed', [])
return []
Expand Down
5 changes: 3 additions & 2 deletions acceptance_tests/data_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
def run_rpmdeplint(args, **kwargs):
env = os.environ
env['PYTHONBUFFERED'] = '1'
env['PYTHONIOENCODING'] = 'UTF-8'

p = subprocess.Popen(args,
stdout=subprocess.PIPE,
Expand All @@ -21,10 +22,10 @@ def run_rpmdeplint(args, **kwargs):
**kwargs)

max_output = 10240
out = p.stdout.read(max_output)
out = p.stdout.read(max_output).decode('UTF-8')
if len(out) == max_output:
raise RuntimeError('Output size limit exceeded when invoking {}:\n{}'.format(args, out))
err = p.stderr.read(max_output)
err = p.stderr.read(max_output).decode('UTF-8')
if len(err) == max_output:
raise RuntimeError('Stderr size limit exceeded when invoking {}:\n{}'.format(args, out))
p.wait()
Expand Down
4 changes: 2 additions & 2 deletions acceptance_tests/test_check_conflicts.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ def test_conflict_is_ignored_for_rpm_level_conflicts(request, dir_server):
# https://fedoraproject.org/wiki/Packaging:Conflicts
p2 = rpmfluff.SimpleRpmBuild('mysql', '0.1', '1', ['i386'])
p2.add_installed_file(installPath='usr/bin/mysql',
sourceFile=rpmfluff.SourceFile('mysql', b'\177ELF-mysql'))
sourceFile=rpmfluff.SourceFile('mysql', b'\177ELF-mysql', encoding=None))
baserepo = rpmfluff.YumRepoBuild([p2])
baserepo.make('i386')
dir_server.basepath = baserepo.repoDir

p1 = rpmfluff.SimpleRpmBuild('mariadb', '0.1', '1', ['i386'])
p1.add_conflicts('mysql')
p1.add_installed_file(installPath='usr/bin/mysql',
sourceFile=rpmfluff.SourceFile('mysql', b'\177ELF-mariadb'))
sourceFile=rpmfluff.SourceFile('mysql', b'\177ELF-mariadb', encoding=None))
p1.make()

def cleanUp():
Expand Down
2 changes: 2 additions & 0 deletions rpmdeplint.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ BuildRequires: python-rpmfluff
BuildRequires: glibc-devel.i686
BuildRequires: libgcc.i686
%endif
BuildRequires: python-six
BuildRequires: rpm-python
BuildRequires: python-hawkey
BuildRequires: python-librepo
Requires: python-six
Requires: rpm-python
Requires: python-hawkey
Requires: python-librepo
Expand Down
24 changes: 14 additions & 10 deletions rpmdeplint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

from __future__ import absolute_import

from collections import defaultdict
from sets import Set
import binascii
import logging
import six
from six.moves import map
import hawkey
import rpm

Expand All @@ -18,10 +21,10 @@
class DependencySet(object):
def __init__(self):
self._packagedeps = defaultdict(lambda: dict(dependencies=[],problems=[]))
self._packages_with_problems = Set()
self._overall_problems = Set()
self._repodeps = defaultdict(lambda: Set())
self._repo_packages = defaultdict(lambda: Set())
self._packages_with_problems = set()
self._overall_problems = set()
self._repodeps = defaultdict(lambda: set())
self._repo_packages = defaultdict(lambda: set())
self._package_repo = {}

def add_package(self, pkg, reponame, dependencies, problems):
Expand All @@ -37,7 +40,7 @@ def add_package(self, pkg, reponame, dependencies, problems):

@property
def packages(self):
return self._packagedeps.keys()
return list(self._packagedeps.keys())

@property
def overall_problems(self):
Expand Down Expand Up @@ -99,7 +102,7 @@ def __enter__(self):

def __exit__(self, type, value, tb):
"""Clean up cache directory to prevent from growing unboundedly."""
for repo in self.repos_by_name.itervalues():
for repo in self.repos_by_name.values():
repo.cleanup_cache()

def find_packages_that_require(self, name):
Expand Down Expand Up @@ -130,7 +133,7 @@ def download_package(self, package):
return package.location
repo = self.repos_by_name[package.reponame]
checksum_type = hawkey.chksum_name(package.chksum[0])
checksum = binascii.hexlify(package.chksum[1])
checksum = binascii.hexlify(package.chksum[1]).decode('ascii')
return repo.download_package(package.location, checksum_type=checksum_type, checksum=checksum)

def try_to_install(self, *packages):
Expand All @@ -139,7 +142,8 @@ def try_to_install(self, *packages):
starting from an empty package set.
"""
g = hawkey.Goal(self._sack)
map(g.install, packages)
for package in packages:
g.install(package)
results = dict(installs = [], upgrades = [], erasures = [], problems = [])
install_succeeded = g.run()
if install_succeeded:
Expand Down Expand Up @@ -217,5 +221,5 @@ def find_conflicts(self):
logger.debug('Considering conflict on %s with %s', filename, conflicting)
if not self._file_conflict_is_permitted(package, conflicting, filename):
problems.append(u'{} provides {} which is also provided by {}'.format(
unicode(package), filename, unicode(conflicting)))
six.text_type(package), filename, six.text_type(conflicting)))
return problems
2 changes: 2 additions & 0 deletions rpmdeplint/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

from __future__ import absolute_import

import sys
import logging
import argparse
Expand Down
6 changes: 4 additions & 2 deletions rpmdeplint/repodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

from __future__ import absolute_import

import os
import logging
import tempfile
Expand All @@ -18,7 +20,7 @@
REPO_CACHE_NAME_PREFIX = 'rpmdeplint-'


class PackageDownloadError(StandardError):
class PackageDownloadError(Exception):
"""
Raised if a package is being downloaded for further analysis but the download fails.
"""
Expand Down Expand Up @@ -87,7 +89,7 @@ def cleanup_cache(self):

try:
shutil.rmtree(self._root_path)
except OSError, err:
except OSError as err:
logger.error(err)

@property
Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ class build(_build):
author_email='jorris@redhat.com',
classifiers=[
'License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
],
packages=['rpmdeplint', 'rpmdeplint.tests'],
install_requires=['six'],
tests_require=['pytest'],
data_files = [
('/usr/share/man/man1', glob('build/sphinx/man/*.1')),
Expand Down

0 comments on commit 2e7b969

Please sign in to comment.