Drop pre-2.6 compat function koji.util._relpath

Fixes: https://pagure.io/koji/issue/818
This commit is contained in:
Tomas Kopecek 2018-02-26 15:59:07 +01:00 committed by Mike McLean
parent 22a7998f3a
commit 2eff45f763
6 changed files with 24 additions and 55 deletions

View file

@ -725,7 +725,7 @@ class BuildRoot(object):
raise ValueError(
'path %r is not within the BuildRoot at %r' % (path, root)
)
return os.path.join('/', koji.util.relpath(path, root))
return os.path.join('/', os.path.relpath(path, root))
def resultdir(self):
return "%s/%s/result" % (self.options.mockdir, self.name)

View file

@ -2343,7 +2343,7 @@ def repo_init(tag, with_src=False, with_debuginfo=False, event=None):
archdir = os.path.join(repodir, repoarch)
koji.ensuredir(archdir)
# Make a symlink to our topdir
top_relpath = koji.util.relpath(koji.pathinfo.topdir, archdir)
top_relpath = os.path.relpath(koji.pathinfo.topdir, archdir)
top_link = os.path.join(archdir, 'toplink')
os.symlink(top_relpath, top_link)
pkglist[repoarch] = open(os.path.join(archdir, 'pkglist'), 'w')
@ -2402,7 +2402,7 @@ def repo_init(tag, with_src=False, with_debuginfo=False, event=None):
if not dest_parent in created_dirs:
koji.ensuredir(dest_parent)
created_dirs.add(dest_parent)
relpath = koji.util.relpath(srcdir, dest_parent)
relpath = os.path.relpath(srcdir, dest_parent)
try:
os.symlink(relpath, destlink)
except:
@ -3554,14 +3554,14 @@ def get_build_logs(build):
"""Return a list of log files for the given build"""
buildinfo = get_build(build, strict=True)
logdir = koji.pathinfo.build_logs(buildinfo)
logreldir = koji.util.relpath(logdir, koji.pathinfo.topdir)
logreldir = os.path.relpath(logdir, koji.pathinfo.topdir)
if not os.path.exists(logdir):
return []
if not os.path.isdir(logdir):
raise koji.GenericError("Not a directory: %s" % logdir)
logs = []
for dirpath, dirs, files in os.walk(logdir):
subdir = koji.util.relpath(dirpath, logdir)
subdir = os.path.relpath(dirpath, logdir)
for fn in files:
filepath = os.path.join(dirpath, fn)
if os.path.islink(filepath):
@ -4792,7 +4792,7 @@ def _set_build_volume(binfo, volinfo, strict=True):
basedir = koji.pathinfo.build(base_binfo)
if os.path.islink(basedir):
os.unlink(basedir)
relpath = koji.util.relpath(newdir, os.path.dirname(basedir))
relpath = os.path.relpath(newdir, os.path.dirname(basedir))
os.symlink(relpath, basedir)
koji.plugin.run_callbacks('postBuildStateChange', attribute='volume_id', old=old_binfo['volume_id'], new=volinfo['id'], info=binfo)

View file

@ -46,7 +46,6 @@ import six.moves.http_client
import imp
import logging
import logging.handlers
from koji.util import md5_constructor
SSL_Error = None
try:
from OpenSSL.SSL import Error as SSL_Error
@ -75,11 +74,11 @@ import struct
import tempfile
import time
import traceback
from . import util
import warnings
import xml.sax
import xml.sax.handler
import six.moves.urllib
from . import util
from koji.xmlrpcplus import getparser, loads, dumps, Fault, xmlrpc_client
@ -1412,8 +1411,7 @@ def genMockConfig(name, arch, managed=False, repoid=None, tag_name=None, **opts)
"""
mockdir = opts.get('mockdir', '/var/lib/mock')
if 'url' in opts:
from warnings import warn
warn('The url option for genMockConfig is deprecated', DeprecationWarning)
util.deprecated('The url option for genMockConfig is deprecated')
urls = [opts['url']]
else:
if not (repoid and tag_name):
@ -2418,23 +2416,14 @@ class ClientSession(object):
if _key == 'data' and len(_val) > 1024:
_val = _val[:1024] + '...'
print("%s: %r" % (_key, _val))
catcher = None
if hasattr(warnings, 'catch_warnings'):
# TODO: convert to a with statement when we drop 2.4.3 support
catcher = warnings.catch_warnings()
catcher.__enter__()
try:
if catcher:
warnings.simplefilter("ignore")
with warnings.catch_warnings():
warnings.simplefilter("ignore")
r = self.rsession.post(handler, **callopts)
r.raise_for_status()
try:
ret = self._read_xmlrpc_response(r)
finally:
r.close()
finally:
if catcher:
catcher.__exit__()
return ret
def _read_xmlrpc_response(self, response):
@ -2675,7 +2664,7 @@ class ClientSession(object):
fo = open(localfile, "r") #specify bufsize?
totalsize = os.path.getsize(localfile)
ofs = 0
md5sum = md5_constructor()
md5sum = util.md5_constructor()
debug = self.opts.get('debug', False)
if callback:
callback(0, totalsize, 0, 0, 0)
@ -2692,7 +2681,7 @@ class ClientSession(object):
sz = ofs
else:
offset = ofs
digest = md5_constructor(contents).hexdigest()
digest = util.md5_constructor(contents).hexdigest()
sz = size
del contents
tries = 0

View file

@ -37,6 +37,7 @@ import six.moves.configparser
from zlib import adler32
from six.moves import range
import six
import warnings
# imported from kojiweb and kojihub
try:
@ -49,6 +50,12 @@ except ImportError: # pragma: no cover
from sha import new as sha1_constructor
def deprecated(message):
"""Print deprecation warning"""
with warnings.catch_warnings():
warnings.simplefilter('always', DeprecationWarning)
warnings.warn(message, DeprecationWarning)
def _changelogDate(cldate):
return time.strftime('%a %b %d %Y', time.strptime(koji.formatTime(cldate), '%Y-%m-%d %H:%M:%S'))
@ -442,27 +449,11 @@ def safer_move(src, dst):
shutil.move(src, dst)
def _relpath(path, start=getattr(os.path, 'curdir', '.')):
"""Backport of os.path.relpath for python<2.6"""
def relpath(*args, **kwargs):
deprecated("koji.util.relpath() is deprecated and will be removed in a "
"future version. See: https://pagure.io/koji/issue/834")
return os.path.relpath(*args, **kwargs)
sep = getattr(os.path, 'sep', '/')
pardir = getattr(os.path, 'pardir', '..')
if not path:
raise ValueError("no path specified")
start_list = [x for x in os.path.abspath(start).split(sep) if x]
path_list = [x for x in os.path.abspath(path).split(sep) if x]
i = -1
for i in range(min(len(start_list), len(path_list))):
if start_list[i] != path_list[i]:
break
else:
i += 1
rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
if not rel_list:
return getattr(os.path, 'curdir', '.')
return os.path.join(*rel_list)
relpath = getattr(os.path, 'relpath', _relpath)
def eventFromOpts(session, opts):
"""Determine event id from standard cli options

View file

@ -126,7 +126,7 @@ class TestCompleteMavenBuild(unittest.TestCase):
# make sure we wrote the files we expect
files = []
for dirpath, dirnames, filenames in os.walk(self.tempdir + '/packages'):
relpath = koji.util.relpath(dirpath, self.tempdir)
relpath = os.path.relpath(dirpath, self.tempdir)
files.extend([os.path.join(relpath, fn) for fn in filenames])
self.assertEqual(set(files), set(self.expected_files))
# check callbacks

View file

@ -843,17 +843,6 @@ class MavenUtilTestCase(unittest.TestCase):
self.assertEqual('[value hidden]', str(hv2))
self.assertEqual('HiddenValue()', repr(hv2))
def test_relpath(self):
"""Test _relpath function"""
self.assertRaises(ValueError, koji.util._relpath, None)
self.assertRaises(ValueError, koji.util._relpath, "")
# _relpath is a backport of os.path.relpath
# their behaviors and outputs should be the same.
for p in ["/", ".", "..", "/bin", "\0", "\n", "\t/tmp"]:
for s in [os.curdir, '/tmp']:
self.assertEqual(os.path.relpath(p, s), koji.util._relpath(p, s))
def test_eventFromOpts(self):
"""Test eventFromOpts function"""
timestamp = datetime.now().strftime('%s')