[projects/pld-ftp-admin] modules: ruff cleanup
arekm
arekm at pld-linux.org
Sat Oct 24 11:47:20 CEST 2026
commit 7f7eb3184d3d8d6902b5ac034ef399d9f8da9a68
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Tue Oct 20 15:59:19 2026 +0200
modules: ruff cleanup
modules/baseftptree.py | 16 ++----
modules/cmds.py | 45 +++++++--------
modules/common.py | 8 ++-
modules/config.py | 26 +++------
modules/cons.py | 15 ++---
modules/ftpio.py | 25 ++++-----
modules/ftptree.py | 149 ++++++++++++++++++++++---------------------------
modules/mailer.py | 20 +++----
modules/sign.py | 13 +++--
modules/wwwcmds.py | 6 +-
10 files changed, 144 insertions(+), 179 deletions(-)
---
diff --git a/modules/baseftptree.py b/modules/baseftptree.py
index 64f81a4..db58788 100644
--- a/modules/baseftptree.py
+++ b/modules/baseftptree.py
@@ -1,8 +1,9 @@
-# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
+# vi: ts=8 sts=4 sw=4 et
-import string, config
+import config
from common import fileexists
+
class Build:
def __init__(self):
self.requester=''
@@ -25,10 +26,8 @@ class BasePkg:
if content:
lines=content.splitlines()
else:
- f=open("%s/SRPMS/.metadata/%s.src.rpm.info" %
- (self.tree.basedir, self.nvr), 'r')
- lines=f.readlines()
- f.close()
+ with open(f"{self.tree.basedir}/SRPMS/.metadata/{self.nvr}.src.rpm.info") as f:
+ lines=f.readlines()
for entry in lines:
i=str.split(str.strip(entry), ':')
@@ -61,8 +60,5 @@ class BaseFtpTree:
return self.treename
def has_key(self, key):
- if fileexists(self.basedir+'/SRPMS/.metadata/'+key+'.src.rpm.info'):
- return True
- else:
- return False
+ return fileexists(self.basedir+'/SRPMS/.metadata/'+key+'.src.rpm.info')
diff --git a/modules/cmds.py b/modules/cmds.py
index dae454d..64163da 100644
--- a/modules/cmds.py
+++ b/modules/cmds.py
@@ -1,10 +1,10 @@
-# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
+# vi: ts=8 sts=4 sw=4 et
-import os
+import hashlib
import time
-import config
+
import common
-import hashlib
+import config
import ftptree
@@ -67,8 +67,8 @@ def cmd_show_locks(con):
res = []
for lockdata in locks.items():
tree, data = lockdata
- msg = "Tree: %s, Conn name: %s, Hard Lock: %s, Time: %s" % (
- tree, data['name'], data['hard'], time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(data['time'])))
+ when = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(data['time']))
+ msg = f"Tree: {tree}, Conn name: {data['name']}, Hard Lock: {data['hard']}, Time: {when}"
cmd_log(con, msg)
res.append(msg)
# con.sock.send(bytearray("BLOB:%d" % len(res), encoding='utf-8')))
@@ -78,7 +78,7 @@ def cmd_show_locks(con):
con.sock.send(bytearray("NLCK", encoding='utf-8'))
def cmd_log(con, msg):
- logfile.write('%s [%s] -- %s\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), con.name, msg))
+ logfile.write(f"{time.strftime('%Y-%m-%d %H:%M:%S')} [{con.name}] -- {msg}\n")
logfile.flush()
def cmd_name(con, name):
@@ -91,27 +91,23 @@ def load_creds():
if not common.fileexists(common.ftpadmdir+'/var/passwd'):
return
else:
- f=open(common.ftpadmdir+'/var/passwd', 'r')
- for line in f:
- x=line.strip().split(':')
- if len(x)>=2:
- users[x[0]]=x[1]
- f.close()
+ with open(common.ftpadmdir+'/var/passwd') as f:
+ for line in f:
+ x=line.strip().split(':')
+ if len(x)>=2:
+ users[x[0]]=x[1]
if not common.fileexists(common.ftpadmdir+'/var/cookies'):
return
else:
- f=open(common.ftpadmdir+'/var/cookies', 'r')
- for line in f:
- x=line.strip().split(':')
- if len(x)>=2:
- cookies[x[0]]=x[1]
- f.close()
+ with open(common.ftpadmdir+'/var/cookies') as f:
+ for line in f:
+ x=line.strip().split(':')
+ if len(x)>=2:
+ cookies[x[0]]=x[1]
def write_cookies():
- f=open(common.ftpadmdir+'/var/cookies', 'w')
- for key in cookies.keys():
- f.write('%s:%s\n' % (key, cookies[key]))
- f.close()
+ with open(common.ftpadmdir+'/var/cookies', 'w') as f:
+ f.writelines(f'{key}:{login}\n' for key, login in cookies.items())
def cmd_login_passwd(con, data):
tmp=data.split('\n')
@@ -190,7 +186,8 @@ cmdlist_noargs={'lout':cmd_logout, 'gett':cmd_gettree, 'slck':cmd_show_locks}
# Global stuff and initializations
locks={}
-logfile=open(common.ftpadmdir+'/var/log', 'a')
+# open for the daemon's lifetime
+logfile=open(common.ftpadmdir+'/var/log', 'a') # noqa: SIM115
load_creds()
reloadftptree()
salt=hashlib.md5(repr(time.time()).encode('utf-8')).hexdigest()
diff --git a/modules/common.py b/modules/common.py
index 2429749..5a3c9c7 100644
--- a/modules/common.py
+++ b/modules/common.py
@@ -1,8 +1,10 @@
-# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
+# vi: ts=8 sts=4 sw=4 et
-from __future__ import print_function
+import os
+import sys
+
+import config
-import os, sys, config
def fileexists(path):
if path[0] == '/':
diff --git a/modules/config.py b/modules/config.py
index 851e400..ed79f20 100644
--- a/modules/config.py
+++ b/modules/config.py
@@ -1,6 +1,6 @@
-# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
+# vi: ts=8 sts=4 sw=4 et
-import string, os
+import os
value = {}
@@ -9,9 +9,10 @@ if 'HOME' in os.environ:
else:
path = '../../' # cgi-bin interface
-f = open(path + '/.ftpadmrc', 'r')
+with open(path + '/.ftpadmrc') as f:
+ lines = f.readlines()
-for line in f.readlines():
+for line in lines:
if line[0] == '#' or str.find(line, '=') == -1:
continue
tuple = str.split(str.strip(line), '=', 1)
@@ -26,8 +27,6 @@ for line in f.readlines():
else:
value.pop(key, None)
-f.close()
-
default_to = value['ftp_dir'] + '/' + value['default_to'] + '/'
ftp_dir = value['ftp_dir'] + '/'
incoming_dir = value['ftp_dir'] + '/' + value['incoming_dir'] + '/'
@@ -36,15 +35,9 @@ ftp_archs = value['ftp_archs'].split(' ')
builderqueue = value['builderqueue']
-if 'sign_key' in value:
- sign_key = value['sign_key']
-else:
- sign_key = None
+sign_key = value.get('sign_key')
-if 'logs_list' in value:
- logs_list = value['logs_list']
-else:
- logs_list = None
+logs_list = value.get('logs_list')
if 'signed_trees' in value:
signed_trees = value['signed_trees'].split(' ')
@@ -76,7 +69,4 @@ if separate_noarch:
else:
all_ftp_archs = ftp_archs
-if 'ftp_dist' in value:
- ftp_dist = value['ftp_dist']
-else:
- ftp_dist = 'pld'
+ftp_dist = value.get('ftp_dist', 'pld')
diff --git a/modules/cons.py b/modules/cons.py
index 61f8680..1b58d96 100644
--- a/modules/cons.py
+++ b/modules/cons.py
@@ -1,12 +1,14 @@
-# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
+# vi: ts=8 sts=4 sw=4 et
-import socket
import os
import select
+import socket
import traceback
-from common import fileexists
-import ftpio
+
import cmds
+import ftpio
+from common import fileexists
+
class Connection:
def __init__(self, sock, authorized):
@@ -38,7 +40,7 @@ class Connection:
cmds.parse(self)
except cmds.BailOut:
self.destroy()
- except Exception:
+ except Exception: # noqa: BLE001
# every tool locks through this daemon; a bad client or a failed command must not stop it
cmds.cmd_log(self, 'command failed: ' + traceback.format_exc())
self.destroy()
@@ -53,8 +55,7 @@ def readables():
lst=cons[:]
lst.append(privlistener)
lst.append(publistener)
- inlst,outlst,errlst = select.select(lst, [], [], 0.1)
- return inlst
+ return select.select(lst, [], [], 0.1)[0]
def createlistener(path):
if fileexists(path):
diff --git a/modules/ftpio.py b/modules/ftpio.py
index 148c7da..3d3eac1 100644
--- a/modules/ftpio.py
+++ b/modules/ftpio.py
@@ -1,9 +1,10 @@
-# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
+# vi: ts=8 sts=4 sw=4 et
import os
-import sys
import socket
+import sys
import time
+
import config
pubsock=config.value['pubsock']
@@ -19,12 +20,12 @@ def connect(name=None):
sock=socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.connect(socketname)
if not name:
- name = "pid_%d_name_%s" % (os.getpid(), sys.argv[0])
- sock.send(bytearray('name %s\0' % name, encoding='utf-8'))
+ name = f"pid_{os.getpid()}_name_{sys.argv[0]}"
+ sock.send(bytearray(f'name {name}\0', encoding='utf-8'))
def login_passwd(login, passwd):
'Return cookie if ok'
- sock.send(bytearray('linp %s\n%s\0' % (login, passwd), encoding='utf-8'))
+ sock.send(bytearray(f'linp {login}\n{passwd}\0', encoding='utf-8'))
retval=sock.recv(256).decode("utf-8")
if retval=='FAIL':
return ''
@@ -33,7 +34,7 @@ def login_passwd(login, passwd):
def login_cookie(cookie):
'Return login if ok'
- sock.send(bytearray('linc %s\0' % cookie, encoding='utf-8'))
+ sock.send(bytearray(f'linc {cookie}\0', encoding='utf-8'))
retval=sock.recv(256).decode('utf-8')
if retval=='FAIL':
return ''
@@ -46,9 +47,9 @@ def logout():
def lock(path, hard=False):
def dolock():
if hard:
- sock.send(bytearray('lckh %s\0' % path, encoding='utf-8'))
+ sock.send(bytearray(f'lckh {path}\0', encoding='utf-8'))
else:
- sock.send(bytearray('lcks %s\0' % path, encoding='utf-8'))
+ sock.send(bytearray(f'lcks {path}\0', encoding='utf-8'))
return sock.recv(20).decode("utf-8")
for i in range(3):
retcode=dolock()
@@ -61,14 +62,12 @@ def lock(path, hard=False):
return False
def unlock(path):
- sock.send(bytearray('ulck %s\0' % path, encoding='utf-8'))
+ sock.send(bytearray(f'ulck {path}\0', encoding='utf-8'))
ret = sock.recv(20).decode("utf-8")
- if ret == "OK":
- return True
- return False
+ return ret == "OK"
def log(msg):
- sock.send(bytearray('log1 %s\0' % msg, encoding='utf-8'))
+ sock.send(bytearray(f'log1 {msg}\0', encoding='utf-8'))
def locks_dump():
sock.send(bytearray('slck\0', encoding='utf-8'))
diff --git a/modules/ftptree.py b/modules/ftptree.py
index 5dd27b4..2421860 100644
--- a/modules/ftptree.py
+++ b/modules/ftptree.py
@@ -1,15 +1,13 @@
-# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
-
-from __future__ import print_function
+# vi: ts=8 sts=4 sw=4 et
import os
-import config
-import string
-import urllib.request
import re
+import urllib.request
+
+import config
import rpm
+from baseftptree import BaseFtpTree, BasePkg
from common import fileexists, noarchcachedir
-from baseftptree import BasePkg, BaseFtpTree
from sign import is_signed
errnum = 0
@@ -23,8 +21,8 @@ class SomeError(Exception):
return "An Error occured!"
def bailoutonerror():
- if not errnum == 0:
- print("%d error(s) encountered... aborting" % errnum)
+ if errnum != 0:
+ print(f"{errnum} error(s) encountered... aborting")
raise SomeError()
def pinfo(msg):
@@ -41,12 +39,12 @@ def pwarning(msg):
def rm(file, test = False):
if test:
if not os.path.exists(file):
- pinfo("TEST os.remove(%s): file doesn't exists" % file)
+ pinfo(f"TEST os.remove({file}): file doesn't exists")
else:
try:
os.remove(file)
except OSError as e:
- pinfo("os.remove(%s): %s" % (file, e))
+ pinfo(f"os.remove({file}): {e}")
#raise
def mv(src, dst, test = False):
@@ -54,14 +52,14 @@ def mv(src, dst, test = False):
fdst = dst + '/' + src.split('/')[-1]
if test:
if not os.path.exists(fsrc):
- pinfo("TEST os.rename(%s, %s): source doesn't exists" % (fsrc, fdst))
+ pinfo(f"TEST os.rename({fsrc}, {fdst}): source doesn't exists")
if not os.path.exists(dst):
- pinfo("TEST destination doesn't exist: %s" % dst)
+ pinfo(f"TEST destination doesn't exist: {dst}")
else:
try:
os.rename(fsrc, fdst)
except OSError as e:
- pinfo("os.rename(%s, %s): %s" % (fsrc, fdst, e))
+ pinfo(f"os.rename({fsrc}, {fdst}): {e}")
raise
class Pkg(BasePkg):
@@ -134,12 +132,12 @@ class Pkg(BasePkg):
def error(self, msg):
self.errors.append(msg)
if not quietmode:
- perror('%s %s' % (self.nvr, msg))
+ perror(f'{self.nvr} {msg}')
def warning(self, msg):
self.warnings.append(msg)
if not quietmode:
- pwarning('%s %s' % (self.nvr, msg))
+ pwarning(f'{self.nvr} {msg}')
def load(self, content=None):
BasePkg.load(self, content)
@@ -147,30 +145,27 @@ class Pkg(BasePkg):
self.mark4moving()
def writeinfo(self):
- f = open(self.tree.basedir+'/SRPMS/.metadata/'+self.nvr+'.src.rpm.info', 'w')
- for bid in self.build.keys():
- f.write("info:build:%s:requester:%s\ninfo:build:%s:requester_email:%s\n" % (bid, self.build[bid].requester, bid, self.build[bid].requester_email))
- for key in self.info.keys():
- f.write("info:%s:%s\n" % (key, ':'.join(self.info[key])))
- for arch in self.files.keys():
- for rpm in self.files[arch]:
- f.write("file:%s:%s\n" % (arch, rpm))
+ with open(self.tree.basedir+'/SRPMS/.metadata/'+self.nvr+'.src.rpm.info', 'w') as f:
+ f.writelines(f"info:build:{bid}:requester:{build.requester}\ninfo:build:{bid}:requester_email:{build.requester_email}\n" for bid, build in self.build.items())
+ f.writelines(f"info:{key}:{':'.join(values)}\n" for key, values in self.info.items())
+ for arch, rpmfiles in self.files.items():
+ f.writelines(f"file:{arch}:{rpmfile}\n" for rpmfile in rpmfiles)
def remove(self, test = False):
"""
Remove package from ftp
"""
- for arch in self.files.keys():
- for rpm in self.files[arch]:
- if self.is_debuginfo(rpm):
- rm(self.tree.basedir + '/' + arch + '/debuginfo/' + rpm, test)
+ for arch in self.files:
+ for rpmfile in self.files[arch]:
+ if self.is_debuginfo(rpmfile):
+ rm(self.tree.basedir + '/' + arch + '/debuginfo/' + rpmfile, test)
else:
- rm(self.tree.basedir + '/' + arch + '/RPMS/' + rpm, test)
+ rm(self.tree.basedir + '/' + arch + '/RPMS/' + rpmfile, test)
if arch == 'noarch':
- if fileexists(noarchcachedir + rpm + '.filelist'):
- rm(noarchcachedir + rpm + '.filelist', test)
- if fileexists(noarchcachedir + rpm + '.reqlist'):
- rm(noarchcachedir + rpm + '.reqlist', test)
+ if fileexists(noarchcachedir + rpmfile + '.filelist'):
+ rm(noarchcachedir + rpmfile + '.filelist', test)
+ if fileexists(noarchcachedir + rpmfile + '.reqlist'):
+ rm(noarchcachedir + rpmfile + '.reqlist', test)
rm(self.tree.basedir + '/SRPMS/.metadata/' + self.nvr + '.src.rpm.info', test)
def rpmfiles(self, debugfiles = True, sourcefiles = True):
@@ -229,38 +224,38 @@ class Pkg(BasePkg):
def move(self, dsttree, test = False):
if dsttree.has_key(self.nvr):
movedany = False
- for arch in self.files.keys():
- if arch in dsttree[self.nvr].files.keys():
+ for arch in self.files:
+ if arch in dsttree[self.nvr].files:
msg = ""
if test:
msg = "TEST "
- pinfo("%sArch %s for %s is already present in dest tree; removing from srctree" % (msg, arch, self.nvr))
- for rpm in self.files[arch]:
- if self.is_debuginfo(rpm):
- rm(self.tree.basedir + '/' + arch + '/debuginfo/' + rpm, test)
+ pinfo(f"{msg}Arch {arch} for {self.nvr} is already present in dest tree; removing from srctree")
+ for rpmfile in self.files[arch]:
+ if self.is_debuginfo(rpmfile):
+ rm(self.tree.basedir + '/' + arch + '/debuginfo/' + rpmfile, test)
else:
- rm(self.tree.basedir + '/' + arch + '/RPMS/' + rpm, test)
+ rm(self.tree.basedir + '/' + arch + '/RPMS/' + rpmfile, test)
else:
movedany = True
dsttree[self.nvr].files[arch] = self.files[arch]
- for rpm in self.files[arch]:
- if self.is_debuginfo(rpm):
- mv(self.tree.basedir + '/' + arch + '/debuginfo/' + rpm, dsttree.basedir + '/' + arch + '/debuginfo/', test)
+ for rpmfile in self.files[arch]:
+ if self.is_debuginfo(rpmfile):
+ mv(self.tree.basedir + '/' + arch + '/debuginfo/' + rpmfile, dsttree.basedir + '/' + arch + '/debuginfo/', test)
else:
- mv(self.tree.basedir + '/' + arch + '/RPMS/' + rpm, dsttree.basedir + '/' + arch + '/RPMS/', test)
+ mv(self.tree.basedir + '/' + arch + '/RPMS/' + rpmfile, dsttree.basedir + '/' + arch + '/RPMS/', test)
if not test and movedany:
- for bid in self.build.keys():
+ for bid in self.build:
dsttree[self.nvr].build[bid] = self.build[bid]
dsttree[self.nvr].writeinfo()
rm(self.tree.basedir + '/SRPMS/.metadata/' + self.nvr + '.src.rpm.info', test)
else:
# move files
- for arch in self.files.keys():
- for rpm in self.files[arch]:
- if self.is_debuginfo(rpm):
- mv(self.tree.basedir + '/' + arch + '/debuginfo/' + rpm, dsttree.basedir + '/' + arch + '/debuginfo/', test)
+ for arch in self.files:
+ for rpmfile in self.files[arch]:
+ if self.is_debuginfo(rpmfile):
+ mv(self.tree.basedir + '/' + arch + '/debuginfo/' + rpmfile, dsttree.basedir + '/' + arch + '/debuginfo/', test)
else:
- mv(self.tree.basedir + '/' + arch + '/RPMS/' + rpm, dsttree.basedir + '/' + arch + '/RPMS/', test)
+ mv(self.tree.basedir + '/' + arch + '/RPMS/' + rpmfile, dsttree.basedir + '/' + arch + '/RPMS/', test)
# move metadata
mv(self.tree.basedir + '/SRPMS/.metadata/' + self.nvr + '.src.rpm.info', dsttree.basedir + '/SRPMS/.metadata/', test)
@@ -290,10 +285,7 @@ class FtpTree(BaseFtpTree):
raise KeyError(key)
def has_key(self, key):
- if key in self.pkgnames:
- return True
- else:
- return False
+ return key in self.pkgnames
def keys(self):
return self.pkgnames
@@ -374,12 +366,9 @@ class FtpTree(BaseFtpTree):
def __loadpkgnames(self):
def checkfiletype(name):
- if name[-13:]=='.src.rpm.info':
- return True
- else:
- return False
+ return name[-13:]=='.src.rpm.info'
pkglist = list(filter(checkfiletype, os.listdir(self.basedir+'/SRPMS/.metadata')))
- self.pkgnames = list(map((lambda x: x[:-13]), pkglist))
+ self.pkgnames = [x[:-13] for x in pkglist]
def __mark4something(self, wannabepkgs, markfunction):
def chopoffextension(pkg):
@@ -392,11 +381,11 @@ class FtpTree(BaseFtpTree):
for wannabepkg in wannabepkgs:
pkgname = chopoffextension(wannabepkg)
if pkgname in self.pkgnames:
- if not pkgname in self.loadedpkgs.keys():
+ if not pkgname in self.loadedpkgs:
self.loadedpkgs[pkgname]=Pkg(pkgname, self)
markfunction(self.loadedpkgs[pkgname])
else:
- perror('%s not found in source tree' % pkgname)
+ perror(f'{pkgname} not found in source tree')
bailoutonerror()
def __checkbuild(self, marked):
@@ -413,7 +402,7 @@ class FtpTree(BaseFtpTree):
requests = {}
reid = re.compile(r'^.*id=(.*) pri.*$')
- regb = re.compile(r'^group:.*$|builders:.*$', re.M)
+ regb = re.compile(r'^group:.*$|builders:.*$', re.MULTILINE)
for i in re.findall(regb, f.read().decode('utf-8')):
if i[0] == 'g':
id = reid.sub(r'\1', i)
@@ -423,9 +412,9 @@ class FtpTree(BaseFtpTree):
f.close()
for pkg in marked:
- for bid in pkg.build.keys():
- if bid in requests and not requests[bid].find('?') == -1:
- pkg.error("(buildid %s) building not finished" % bid)
+ for bid in pkg.build:
+ if bid in requests and '?' in requests[bid]:
+ pkg.error(f"(buildid {bid}) building not finished")
def __checkarchs(self, dsttree, marked):
"""
@@ -444,15 +433,15 @@ class FtpTree(BaseFtpTree):
for somepkg in otherpkgnames:
curarchs.extend(Pkg(somepkg, dsttree).files.keys())
for arch in curarchs:
- if arch not in pkg.files.keys():
+ if arch not in pkg.files:
missingarchs.append(arch)
if missingarchs:
- pkg.error('moving would remove archs: %s' % self.__arch_stringify(missingarchs))
+ pkg.error(f'moving would remove archs: {self.__arch_stringify(missingarchs)}')
else:
# warn if a package isn't built for all archs
# ftp_archs + SRPMS
ftp_archs_num = len(config.ftp_archs) + 1
- if (config.separate_noarch and 'noarch' in pkg.files.keys()):
+ if (config.separate_noarch and 'noarch' in pkg.files):
# ftp_archs + SRPMS + noarch subpackages
ftp_archs_num += 1
# plain simple noarch package
@@ -462,9 +451,9 @@ class FtpTree(BaseFtpTree):
if len(pkg.files.keys()) != ftp_archs_num:
missingarchs = []
for arch in config.ftp_archs:
- if arch not in pkg.files.keys():
+ if arch not in pkg.files:
missingarchs.append(arch)
- pkg.warning('not built for archs: %s' % self.__arch_stringify(missingarchs))
+ pkg.warning(f'not built for archs: {self.__arch_stringify(missingarchs)}')
def __checkduplicates(self, marked):
"""
@@ -475,7 +464,7 @@ class FtpTree(BaseFtpTree):
for i in olderpkgnames:
markednames = [str(x) for x in marked]
if i in markednames:
- pkg.error('duplicate package: %s' % i)
+ pkg.error(f'duplicate package: {i}')
def __rmolderfromsrc(self, test = False):
for pkg in self.marked4moving:
@@ -497,10 +486,7 @@ class FtpTree(BaseFtpTree):
escapedpkgname = pkg.name.replace('.', r'\.').replace('+', r'\+')
ziewre = re.compile(escapedpkgname + '-[^-]*-[^-]*$')
def filter_other_pkgs(x):
- if ziewre.match(x) and not x == pkg.nvr:
- return True
- else:
- return False
+ return ziewre.match(x) is not None and x != pkg.nvr
return list(filter(filter_other_pkgs, tree.pkgnames))
def __find_older_pkgs(self, pkg):
@@ -508,10 +494,7 @@ class FtpTree(BaseFtpTree):
c = x.split('-')
rc = rpm.labelCompare(('0', pkg.version, pkg.release),
('0', c[-2], c[-1]))
- if rc == 1: # pkg > x
- return True
- else:
- return False
+ return rc == 1 # pkg > x
return list(filter(filter_older_pkgs, self.__find_other_pkgs(pkg, self)))
def __checksigns(self, tree, pkgs, test = False):
@@ -532,9 +515,9 @@ class FtpTree(BaseFtpTree):
if unsigned != 0:
if test == True:
if not quietmode:
- pkg.warning('%d files not signed' % unsigned)
+ pkg.warning(f'{unsigned} files not signed')
else:
- pkg.error('%d files not signed' % unsigned)
+ pkg.error(f'{unsigned} files not signed')
def __checkforobsoletes(self, tree, pkgs, test = False):
"""
@@ -560,7 +543,7 @@ class FtpTree(BaseFtpTree):
for item in setlist:
p = findbyname(item)
if p:
- pkg.warning('obsoletes %s (via %s) in dest tree, perhaps you want rmpkg' % (p,pn))
+ pkg.warning(f'obsoletes {p} (via {pn}) in dest tree, perhaps you want rmpkg')
def __checkforrelease(self, tree, pkgs, test = False):
"""
@@ -572,4 +555,4 @@ class FtpTree(BaseFtpTree):
for pkg in pkgs:
if not pkg.is_release():
- pkg.warning('non-integer release: %s' % pkg.release)
+ pkg.warning(f'non-integer release: {pkg.release}')
diff --git a/modules/mailer.py b/modules/mailer.py
index 825446f..df8b6a4 100644
--- a/modules/mailer.py
+++ b/modules/mailer.py
@@ -1,20 +1,17 @@
-# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
+# vi: ts=8 sts=4 sw=4 et
-import time
+import io
import os
-import sys
-if sys.version_info[0] == 2:
- import StringIO
-else:
- import io as StringIO
+import time
import config
+
cval=config.value
class Message:
def __init__(self):
self.headers = {}
- self.body = StringIO.StringIO()
+ self.body = io.StringIO()
self.__set_std_headers()
def set_header(self, n, v):
@@ -29,7 +26,7 @@ class Message:
self.set_header("Subject", subject)
def write_line(self, l):
- self.body.write("%s\n" % l)
+ self.body.write(f"{l}\n")
def write(self, s):
self.body.write(s)
@@ -42,14 +39,13 @@ class Message:
def __set_std_headers(self):
self.headers["Date"] = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())
- self.headers["Message-ID"] = "<pld-builder.%f.%d@%s>" \
- % (time.time(), os.getpid(), os.uname()[1])
+ self.headers["Message-ID"] = f"<pld-builder.{time.time():f}.{os.getpid()}@{os.uname()[1]}>"
self.headers["From"] = cval['from_field']
self.headers["X-PLD-Builder"] = cval['xpldbuilder']
def __write_to(self, f):
for k, v in self.headers.items():
- f.write("%s: %s\n" % (k, v))
+ f.write(f"{k}: {v}\n")
f.write("\n")
self.body.seek(0)
self.__sendfile(self.body, f)
diff --git a/modules/sign.py b/modules/sign.py
index de7712a..66520f1 100644
--- a/modules/sign.py
+++ b/modules/sign.py
@@ -1,12 +1,13 @@
-#!/usr/bin/env python3
-# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
+# vi: ts=8 sts=4 sw=4 et
import os
import sys
-import rpm
+
import pexpect
+import rpm
from config import sign_key
+
def getSigInfo(hdr):
"""checks signature from an hdr hand back signature information and/or
an error code"""
@@ -59,7 +60,7 @@ def signpkgs(files, password, force=False):
child.logfile_read = sys.stderr
# TODO: we need a smarter way to figuring out if rpm already stored password in gpg-agent
try:
- child.expect(u'Enter passphrase:', timeout=30)
+ child.expect('Enter passphrase:', timeout=30)
child.sendline(password)
except (pexpect.exceptions.TIMEOUT, pexpect.exceptions.EOF):
print('WARN: rpm did not ask for password', file=sys.stderr)
@@ -68,5 +69,5 @@ def signpkgs(files, password, force=False):
rc = child.exitstatus
if rc != 0:
raise OSError('package signing failed')
- for rpm in files:
- os.chmod(rpm, 0o644)
+ for rpmfile in files:
+ os.chmod(rpmfile, 0o644)
diff --git a/modules/wwwcmds.py b/modules/wwwcmds.py
index d15b136..004797f 100644
--- a/modules/wwwcmds.py
+++ b/modules/wwwcmds.py
@@ -1,11 +1,11 @@
-# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
+# vi: ts=8 sts=4 sw=4 et
import ftpio
def handlecmds(options, page):
def chkbox(pkgname, value):
- retval='<input type="checkbox" name="%s"' % pkgname
+ retval=f'<input type="checkbox" name="{pkgname}"'
if value:
retval=retval+' checked="yes"'
retval=retval+'>'
@@ -17,7 +17,7 @@ def handlecmds(options, page):
page.addcontent('<form action="index.py" method="post"><table border="1">')
page.addcontent('<tr><td>Mv</td><td>Rm</td><td>Package</td></tr>')
for pkg in ftpio.gettree():
- page.addcontent('<tr><td>%s</td><td>%s</td><td>%s</td></tr>' % (chkbox('mv:' + pkg[0], pkg[1]), chkbox('rm:' + pkg[0], pkg[2]), pkg[0]))
+ page.addcontent(f'<tr><td>{chkbox(f"mv:{pkg[0]}", pkg[1])}</td><td>{chkbox(f"rm:{pkg[0]}", pkg[2])}</td><td>{pkg[0]}</td></tr>')
page.addcontent('<tr><td> </td><td> </td><td><input type="submit" value="Commit"></td></tr>')
page.addcontent('</table></form>')
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/projects/pld-ftp-admin.git/commitdiff/e14cb7d4d74f8bdd9368d9645ecaf49593cf6335
More information about the pld-cvs-commit
mailing list