aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Fandrich <danf@mageia.org>2025-02-03 19:30:47 -0800
committerDan Fandrich <danf@mageia.org>2025-02-03 22:25:12 -0800
commitc488d9cdfb0aea78d4a0bde4778fe78eda1c46ea (patch)
tree034840bfc891f6873f4e2a0bcc86650291433f62
parent6d2c594260832373595effa4f63552a8068ae92c (diff)
downloadmgarepo-master.tar
mgarepo-master.tar.gz
mgarepo-master.tar.bz2
mgarepo-master.tar.xz
mgarepo-master.zip
Fix many errors found by pytypeHEADmaster
Some of these would always cause run-time exceptions, which makes me believe that because these haven't been reported before there's a lot of dead code in here. There are a few more pytype errors that don't have obvious fixes.
-rw-r--r--MgaRepo/ConfigParser.py14
-rw-r--r--MgaRepo/binrepo.py2
-rw-r--r--MgaRepo/cgi/xmlrpcserver.py16
-rw-r--r--MgaRepo/commands/submit.py9
-rw-r--r--MgaRepo/log.py6
-rw-r--r--MgaRepo/mirror.py3
-rw-r--r--MgaRepo/plugins/__init__.py2
-rw-r--r--MgaRepo/plugins/ldapusers.py15
-rw-r--r--MgaRepo/rpmutil.py1
-rw-r--r--MgaRepo/util.py16
10 files changed, 39 insertions, 45 deletions
diff --git a/MgaRepo/ConfigParser.py b/MgaRepo/ConfigParser.py
index 0d5624e..7fc32ac 100644
--- a/MgaRepo/ConfigParser.py
+++ b/MgaRepo/ConfigParser.py
@@ -167,7 +167,7 @@ class ConfigParser:
raise NoOptionError(option, section)
if raw:
return rawval
- return self.__interpolate(rawval, d)
+ return self.__interpolate(rawval, d, option, section)
def getall(self, section, option, raw=0, vars=None):
option = self.optionxform(option)
@@ -184,8 +184,8 @@ class ConfigParser:
return values
if vars:
d.update(vars)
- for i in len(values):
- values[i] = self.__interpolate(values[i], d)
+ for i in range(len(values)):
+ values[i] = self.__interpolate(values[i], d, option, section)
return values
def walk(self, section, option=None, raw=0, vars=None):
@@ -210,10 +210,10 @@ class ConfigParser:
for optname, value in options:
if not option or optname == option:
if not raw:
- value = self.__interpolate(value, d)
+ value = self.__interpolate(value, d, option, section)
yield (optname, value)
- def __interpolate(self, value, vars):
+ def __interpolate(self, value, vars, option, section):
rawval = value
depth = 0
while depth < 10:
@@ -233,10 +233,10 @@ class ConfigParser:
return conv(self.get(section, option))
def getint(self, section, option):
- return self.__get(section, string.atoi, option)
+ return self.__get(section, int, option)
def getfloat(self, section, option):
- return self.__get(section, string.atof, option)
+ return self.__get(section, float, option)
def getboolean(self, section, option):
states = {'1': 1, 'yes': 1, 'true': 1, 'on': 1,
diff --git a/MgaRepo/binrepo.py b/MgaRepo/binrepo.py
index a66df09..7c3aca1 100644
--- a/MgaRepo/binrepo.py
+++ b/MgaRepo/binrepo.py
@@ -146,7 +146,7 @@ def parse_sources(path):
try:
f = open(path, encoding="utf-8")
except IOError:
- return []
+ return {}
for rawline in f:
line = rawline.strip()
diff --git a/MgaRepo/cgi/xmlrpcserver.py b/MgaRepo/cgi/xmlrpcserver.py
index a1b2b73..60ebb85 100644
--- a/MgaRepo/cgi/xmlrpcserver.py
+++ b/MgaRepo/cgi/xmlrpcserver.py
@@ -91,21 +91,11 @@ def main():
meth = getattr(iface, method)
response = (meth(*parms),)
except CgiError as e:
- msg = str(e)
- try:
- msg = msg.decode("iso-8859-1")
- except UnicodeError:
- pass
- response = xmlrpc.client.Fault(1, msg)
+ response = xmlrpc.client.Fault(1, str(e))
except Exception as e:
- msg = str(e)
- try:
- msg = msg.decode("iso-8859-1")
- except UnicodeError:
- pass
- response = xmlrpc.client.Fault(1, msg)
+ response = xmlrpc.client.Fault(1, str(e))
sys.stdout.write("Content-type: text/xml\n\n")
- sys.stdout.write(xmlrpc.client.dumps(response, methodresponse=1))
+ sys.stdout.write(xmlrpc.client.dumps(response, methodresponse=True))
# vim:et:ts=4:sw=4
diff --git a/MgaRepo/commands/submit.py b/MgaRepo/commands/submit.py
index f0d66c5..ea56e60 100644
--- a/MgaRepo/commands/submit.py
+++ b/MgaRepo/commands/submit.py
@@ -168,12 +168,9 @@ def submit(urls, target, define=[], submithost=None, atonce=False, sid=None):
if submithost is None:
submithost = config.get("submit", "host")
if submithost is None:
- # extract the submit host from the svn host
- type, rest = urllib.parse.splittype(pkgdirurl)
- host, path = urllib.parse.splithost(rest)
- user, host = urllib.parse.splituser(host)
- submithost, port = urllib.parse.splitport(host)
- del type, user, port, path, rest
+ # extract the submit host from the first svn host
+ u = urllib.parse.urlparse(urls[0])
+ submithost = u.hostname
# runs a create-srpm in the server through ssh, which will make a
# copy of the rpm in the export directory
createsrpm = get_helper("create-srpm")
diff --git a/MgaRepo/log.py b/MgaRepo/log.py
index dca003f..e8b7e4d 100644
--- a/MgaRepo/log.py
+++ b/MgaRepo/log.py
@@ -41,7 +41,7 @@ def getrelease(pkgdirurl, rev=None, macros=[], exported=None, create=False):
if not create:
found = glob.glob(os.path.join(topdir, "SPECS", "*.spec"))
if not found:
- raise Error("no .spec file found inside %s" % specurl)
+ raise Error("no .spec file found inside %s/SPECS" % topdir)
specpath = found[0]
command = (("rpm -q --qf '%%{EPOCH}:%%{VERSION}-%%{RELEASE}\n' "
"--specfile %s %s --define '_topdir %s'") %
@@ -49,7 +49,7 @@ def getrelease(pkgdirurl, rev=None, macros=[], exported=None, create=False):
else:
found = glob.glob(os.path.join(topdir, "SRPMS", "*.src.rpm"))
if not found:
- raise Error("no .src.rpm file found inside %s" % srpmurl)
+ raise Error("no .src.rpm file found inside %s/SRPMS" % topdir)
srpmpath = found[0]
command = (("rpm -qp --qf '%%{EPOCH}:%%{VERSION}-%%{RELEASE}\n' "
" %s %s --define '_topdir %s'") %
@@ -92,7 +92,7 @@ class _Revision:
def __repr__(self):
lines = repr(self.lines)[:30] + "...]"
line = "<_Revision %d author=%r date=%r lines=%s>" % \
- (self.revision, self.author, self.date, lines)
+ (self.revision, self.author_email, self.date, lines)
return line
diff --git a/MgaRepo/mirror.py b/MgaRepo/mirror.py
index 205cc52..fad9133 100644
--- a/MgaRepo/mirror.py
+++ b/MgaRepo/mirror.py
@@ -25,10 +25,9 @@ def _joinurl(url, relpath):
parsed[3], parsed[4], parsed[5]))
return newurl
-
def strip_username(url):
parsed = list(urllib.parse.urlparse(url))
- _, parsed[1] = urllib.parse.splituser(parsed[1])
+ parsed[1] = parsed[1].rpartition('@')[-1]
newurl = urllib.parse.urlunparse(parsed)
return newurl
diff --git a/MgaRepo/plugins/__init__.py b/MgaRepo/plugins/__init__.py
index 82a4eaa..e734239 100644
--- a/MgaRepo/plugins/__init__.py
+++ b/MgaRepo/plugins/__init__.py
@@ -17,7 +17,7 @@ def load():
[entry])
def list():
- return list(loaded.keys())
+ return [*loaded.keys()]
def help(name):
from MgaRepo import Error
diff --git a/MgaRepo/plugins/ldapusers.py b/MgaRepo/plugins/ldapusers.py
index 0edc417..5822cf3 100644
--- a/MgaRepo/plugins/ldapusers.py
+++ b/MgaRepo/plugins/ldapusers.py
@@ -137,13 +137,12 @@ def make_handler():
"'yes' or 'no'" % raw)
try:
- from ldap3 import Server, Connection, ALL
+ import ldap3
#import ldap
except ImportError:
raise Error("LDAP support needs the ldap3 package "\
"to be installed")
- else:
- from ldap.utils.conv import escape_filter_chars
+ from ldap3.utils.conv import escape_filter_chars
def users_wrapper(section, option=None, default=None, walk=False):
global users_cache
@@ -158,23 +157,23 @@ def make_handler():
try:
#l = ldap.initialize(uri)
- l = Connection(uri, auto_bind=True, use_tls=starttls)
+ l = ldap3.Connection(uri, auto_bind=True, use_tls=starttls)
# if starttls:
# l.start_tls() #l.start_tls_s()
if binddn:
l.bind(binddn, bindpw)
- except ldap3.LDAPExceptionError as e:
+ except ldap3.core.exceptions.LDAPExceptionError as e:
raise LDAPError(e)
try:
data = {"username": escape_filter_chars(option)}
filter = interpolate("ldap-filterformat", filterformat, data)
attrs = used_attributes(format)
try:
- found = l.search(search_base='o='.basedn, search_filter=filter,
- attributes=attrs, search_scope=SUBTREE)
+ found = l.search(search_base='o='+basedn, search_filter=filter,
+ attributes=attrs, search_scope=ldap3.SUBTREE)
# found = l.search_s(basedn, ldap.SCOPE_SUBTREE, filter,
# attrlist=attrs)
- except ldap3.LDAPError as e:
+ except ldap3.core.exceptions.LDAPException as e:
raise LDAPError(e)
if found:
dn, entry = found[0]
diff --git a/MgaRepo/rpmutil.py b/MgaRepo/rpmutil.py
index a99c08a..1cbbd8a 100644
--- a/MgaRepo/rpmutil.py
+++ b/MgaRepo/rpmutil.py
@@ -707,6 +707,7 @@ def obsolete(pkgdirurl, branch=None, distro=None, backports=None, commit=False,
svn = SVN()
svn.mv(pkgdirurl, pkgdest, message=log)
if commit:
+ # TODO: what is path supposed to be?
svn.commit(path, log=log)
def switch(mirrorurl=None):
diff --git a/MgaRepo/util.py b/MgaRepo/util.py
index 519c199..8435ec2 100644
--- a/MgaRepo/util.py
+++ b/MgaRepo/util.py
@@ -23,11 +23,11 @@ def commands_getstatusoutput(cmd):
text = b''
pipe.stdin.close()
while True:
- text += os.read(of,8192)
+ text += os.read(of, 8192)
status = pipe.poll()
if status is not None or text == '':
break
- if text[-1:] == '\n': text = text[:-1]
+ if text[-1:] == b'\n': text = text[:-1]
return status, text.decode('utf8')
def execcmd(*cmd, **kwargs):
@@ -54,10 +54,14 @@ def execcmd(*cmd, **kwargs):
r,w,x = select.select((of,ef), (), ())
odata = None
if of in r:
+ # TODO: wait until all text is received before decoding to
+ # reduce the chance of decoding a partial UTF-8 codepoint
odata = (os.read(of, 8192)).decode('utf8')
sys.stdout.write(odata)
edata = None
if ef in r:
+ # TODO: wait until all text is received before decoding to
+ # reduce the chance of decoding a partial UTF-8 codepoint
edata = (os.read(ef, 8192)).decode('utf8')
err.write(edata)
sys.stderr.write(edata)
@@ -92,10 +96,14 @@ def get_output_exec(cmdstr):
r,w,x = select.select((of,ef), (), ())
odata = None
if of in r:
+ # TODO: wait until all text is received before decoding to
+ # reduce the chance of decoding a partial UTF-8 codepoint
odata = (os.read(of, 8192)).decode('utf8')
output.write(odata)
edata = None
if ef in r:
+ # TODO: wait until all text is received before decoding to
+ # reduce the chance of decoding a partial UTF-8 codepoint
edata = (os.read(ef, 8192)).decode('utf8')
err.write(edata)
status = p.poll()
@@ -135,12 +143,12 @@ def mapurl(url):
try:
expr_, replace = urlmap.split()[:2]
except ValueError:
- sys.stderr.buffer.write("invalid url-map: %s" % urlmap)
+ sys.stderr.buffer.write(("invalid url-map: %s" % urlmap).encode())
else:
try:
newurl = re.sub(expr_, replace, url)
except re.error as errmsg:
- sys.stderr.buffer.write("error in URL mapping regexp: %s" % errmsg)
+ sys.stderr.buffer.write(("error in URL mapping regexp: %s" % errmsg).encode())
return newurl