Skip to content

Commit

Permalink
use f-string
Browse files Browse the repository at this point in the history
  • Loading branch information
jbleyel committed Aug 27, 2023
1 parent b47b6b6 commit bb65cd2
Show file tree
Hide file tree
Showing 24 changed files with 216 additions and 232 deletions.
12 changes: 6 additions & 6 deletions plugin/controllers/AT.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def backupFiles(self):
return (True, ATFN)

except Exception as err:
print("[OpenWebif] Error: create autotimer backup '%s'" % str(err))
print(f"[OpenWebif] Error: create autotimer backup '{err}'")
return (False, "Error while preparing backup file.")


Expand All @@ -113,8 +113,8 @@ def restoreFiles(self):
if check_tar:
tar.extract("etc/enigma2/autotimer.xml", "/")
except Exception as err:
print("[OpenWebif] Error: extract autotimer.xml from backup '%s'" % str(err))
return (False, "Error, %s was not created with AutoTimerWebEditor..." % ATFN)
print(f"[OpenWebif] Error: extract autotimer.xml from backup '{err}'")
return (False, f"Error, {ATFN} was not created with AutoTimerWebEditor...")

if check_tar:
from Plugins.Extensions.AutoTimer.plugin import autotimer
Expand All @@ -124,15 +124,15 @@ def restoreFiles(self):
autotimer.configMtime = -1
autotimer.readXml()
except Exception as err:
print("[OpenWebif] Error: read autotimer.xml from backup '%s'" % str(err))
print(f"[OpenWebif] Error: read autotimer.xml from backup '{err}'")
remove(ATFN)
return (False, "Error in autotimer.xml ...")
remove(ATFN)
return (True, "AutoTimer-settings were restored successfully")
else:
return (False, "Error, %s was not created with AutoTimerWebEditor..." % ATFN)
return (False, f"Error, {ATFN} was not created with AutoTimerWebEditor...")
else:
return (False, "Error, %s does not exists, restore is not possible..." % ATFN)
return (False, f"Error, {ATFN} does not exists, restore is not possible...")


class ATController(ATBaseController):
Expand Down
2 changes: 1 addition & 1 deletion plugin/controllers/BQE.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def P_getservices(self, request):
calcpos = False

if sref == "":
sref = '%s FROM BOUQUET "bouquets.tv" ORDER BY bouquet' % (service_types_tv)
sref = f'{service_types_tv} FROM BOUQUET "bouquets.tv" ORDER BY bouquet'
calcpos = True
elif ' "bouquets.radio" ' in sref:
calcpos = True
Expand Down
60 changes: 30 additions & 30 deletions plugin/controllers/BouquetEditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def noBouquetName(self):
return (False, _("No bouquet name given!"))

def handleCommand(self, cmd):
print("[WebComponents.BouquetEditor] handleCommand with cmd = %s" % cmd)
print(f"[WebComponents.BouquetEditor] handleCommand with cmd = {cmd}")
if self.func is self.ADD_BOUQUET:
self.result = self.addToBouquet(cmd)
elif self.func is self.MOVE_BOUQUET:
Expand Down Expand Up @@ -100,7 +100,7 @@ def handleCommand(self, cmd):
self.result = (False, _("one two three four unknown command"))

def addToBouquet(self, param):
print("[WebComponents.BouquetEditor] addToBouquet with param = %s" % param)
print(f"[WebComponents.BouquetEditor] addToBouquet with param = {param}")
bname = param["name"]
if bname is None:
return self.noBouquetName()
Expand All @@ -117,10 +117,10 @@ def addBouquet(self, bname, mode, services):
name, filename = self.buildBouquetID(bname, prefix, mode)
if mode == MODE_TV:
bname += " (TV)"
sref = '1:7:1:0:0:0:0:0:0:0:FROM BOUQUET \"%s.%s.tv\" ORDER BY bouquet' % (prefix, name)
sref = f'1:7:1:0:0:0:0:0:0:0:FROM BOUQUET "{prefix}.{name}.tv" ORDER BY bouquet'
else:
bname += " (Radio)"
sref = '1:7:2:0:0:0:0:0:0:0:FROM BOUQUET \"%s.%s.radio\" ORDER BY bouquet' % (prefix, name)
sref = f'1:7:2:0:0:0:0:0:0:0:FROM BOUQUET "{prefix}.{name}.radio" ORDER BY bouquet'
new_bouquet_ref = eServiceReference(sref)
if not mutablebouquetlist.addService(new_bouquet_ref):
mutablebouquetlist.flushChanges()
Expand All @@ -131,7 +131,7 @@ def addBouquet(self, bname, mode, services):
if services is not None:
for service in services:
if mutablebouquet.addService(service):
print("add %s to new bouquet failed" % service.toString())
print(f"add {service.toString()} to new bouquet failed")
mutablebouquet.flushChanges()
self.setRoot(self.bouquet_rootstr)
return (True, _("Bouquet %s created.") % bname)
Expand All @@ -146,7 +146,7 @@ def addBouquet(self, bname, mode, services):
return (False, _("Multi-Bouquet is not enabled!"))

def addProviderToBouquetlist(self, param):
print("[WebComponents.BouquetEditor] addProviderToBouquet with param = %s" % param)
print(f"[WebComponents.BouquetEditor] addProviderToBouquet with param = {param}")
refstr = param["sProviderRef"]
if refstr is None:
return (False, _("No provider given!"))
Expand All @@ -161,7 +161,7 @@ def addProviderToBouquetlist(self, param):
return self.addBouquet(providername, mode, services and services.getContent('R', True))

def removeBouquet(self, param):
print("[WebComponents.BouquetEditor] removeBouquet with param = %s" % param)
print(f"[WebComponents.BouquetEditor] removeBouquet with param = {param}")
refstr = sref = param["sBouquetRef"]
if refstr is None:
return self.noBouquetName()
Expand Down Expand Up @@ -204,7 +204,7 @@ def removeBouquet(self, param):
return (False, _("Error: Bouquet %s could not deleted, OSError.") % filename)

def moveBouquet(self, param):
print("[WebComponents.BouquetEditor] moveBouquet with param = %s" % param)
print(f"[WebComponents.BouquetEditor] moveBouquet with param = {param}")
sbouquetref = param["sBouquetRef"]
if sbouquetref is None:
return self.noBouquetName()
Expand All @@ -228,7 +228,7 @@ def moveBouquet(self, param):
return (False, _("Bouquet %s can not be moved.") % self.getName(ref))

def removeService(self, param):
print("[WebComponents.BouquetEditor] removeService with param = %s" % param)
print(f"[WebComponents.BouquetEditor] removeService with param = {param}")
sbouquetref = param["sBouquetRef"]
if sbouquetref is None:
return self.noBouquet()
Expand All @@ -255,7 +255,7 @@ def removeService(self, param):
return (False, _("Service %s can not be removed.") % self.getName(ref))

def moveService(self, param):
print("[WebComponents.BouquetEditor] moveService with param = %s" % param)
print(f"[WebComponents.BouquetEditor] moveService with param = {param}")
sbouquetref = param["sBouquetRef"]
if sbouquetref is None:
return self.noBouquet()
Expand All @@ -277,7 +277,7 @@ def moveService(self, param):
return (False, _("Service can not be moved."))

def addServiceToBouquet(self, param):
print("[WebComponents.BouquetEditor] addService with param = %s" % param)
print(f"[WebComponents.BouquetEditor] addService with param = {param}")
sbouquetref = param["sBouquetRef"]
if sbouquetref is None:
return self.noBouquet()
Expand All @@ -304,15 +304,15 @@ def addServiceToBouquet(self, param):
prefix = "subbouquet"
name, filename = self.buildBouquetID(sname, prefix, mode)
if mode == MODE_TV:
sref = '1:7:1:0:0:0:0:0:0:0:FROM BOUQUET \"%s.%s.tv\" ORDER BY bouquet' % (prefix, name)
sref = f'1:7:1:0:0:0:0:0:0:0:FROM BOUQUET "{prefix}.{name}.tv" ORDER BY bouquet'
else:
sref = '1:7:2:0:0:0:0:0:0:0:FROM BOUQUET \"%s.%s.radio\" ORDER BY bouquet' % (prefix, name)
sref = f'1:7:2:0:0:0:0:0:0:0:FROM BOUQUET "{prefix}.{name}.radio" ORDER BY bouquet'
# create bouquet file
try:
with open(filename, "w") as fd:
fd.write("#NAME %s\n" % sname)
fd.write(f"#NAME {sname}\n")
except OSError as err:
print("Error %d: Unable to create file '%s'! (%s)" % (err.errno, filename, err.strerror))
print(f"Error {err.errno}: Unable to create file '{filename}'! ({err.strerror})")

bouquetref = eServiceReference(sbouquetref)
mutablebouquetlist = self.getMutableList(bouquetref)
Expand All @@ -333,7 +333,7 @@ def addServiceToBouquet(self, param):
return (False, _("This service can not be added."))

def addMarkerToBouquet(self, param):
print("[WebComponents.BouquetEditor] addMarkerToBouquet with param = %s" % param)
print(f"[WebComponents.BouquetEditor] addMarkerToBouquet with param = {param}")
sbouquetref = param["sBouquetRef"]
if sbouquetref is None:
return self.noBouquet()
Expand All @@ -348,9 +348,9 @@ def addMarkerToBouquet(self, param):
cnt = 0
while mutablebouquetlist:
if name is None:
service_str = '1:832:D:%d:0:0:0:0:0:0:' % cnt
service_str = f'1:832:D:{cnt}:0:0:0:0:0:0:'
else:
service_str = '1:64:%d:0:0:0:0:0:0:0::%s' % (cnt, name)
service_str = f'1:64:{cnt}:0:0:0:0:0:0:0::{name}'
ref = eServiceReference(service_str)
if not mutablebouquetlist.addService(ref, srefbefore):
mutablebouquetlist.flushChanges()
Expand Down Expand Up @@ -425,9 +425,9 @@ def addServiceToAlternative(self, param):
prefix = "alternatives"
name, filename = self.buildBouquetID(name, prefix, mode)
if mode == MODE_TV:
sref = '1:134:1:0:0:0:0:0:0:0:FROM BOUQUET \"%s.%s.tv\" ORDER BY bouquet' % (prefix, name)
sref = f'1:134:1:0:0:0:0:0:0:0:FROM BOUQUET "{prefix}.{name}.tv" ORDER BY bouquet'
else:
sref = '1:134:2:0:0:0:0:0:0:0:FROM BOUQUET \"%s.%s.radio\" ORDER BY bouquet' % (prefix, name)
sref = f'1:134:2:0:0:0:0:0:0:0:FROM BOUQUET "{prefix}.{name}.radio" ORDER BY bouquet'
new_ref = eServiceReference(sref)
if not mutablebouquetlist.addService(new_ref, cur_ref):
mutablebouquetlist.removeService(cur_ref)
Expand All @@ -437,7 +437,7 @@ def addServiceToAlternative(self, param):
if mutablealternatives:
mutablealternatives.setListName(name)
if mutablealternatives.addService(cur_ref):
print("add %s to new alternatives failed" % cur_ref.toString())
print(f"add {cur_ref.toString()} to new alternatives failed")
mutablealternatives.flushChanges()
self.setRoot(sbouquetref)
scurrentref = sref # currentRef is now an alternative (bouquet)
Expand All @@ -463,7 +463,7 @@ def addServiceToAlternative(self, param):
return returnvalue

def removeAlternativeServices(self, param):
print("[WebComponents.BouquetEditor] removeAlternativeServices with param = %s" % param)
print(f"[WebComponents.BouquetEditor] removeAlternativeServices with param = {param}")
sbouquetref = param["sBouquetRef"]
if sbouquetref is None:
return self.noBouquet()
Expand Down Expand Up @@ -546,7 +546,7 @@ def backupFiles(self, param):
if not filename:
filename = self.BACKUP_FILENAME
invalidcharacters = compile(r'[^A-Za-z0-9_. ]+|^\.|\.$|^ | $|^$')
tarfilename = "%s.tar" % invalidcharacters.sub('_', filename)
tarfilename = f"{invalidcharacters.sub('_', filename)}.tar"
backupfilename = pathjoin(self.BACKUP_PATH, tarfilename)
if exists(backupfilename):
remove(backupfilename)
Expand Down Expand Up @@ -578,7 +578,7 @@ def backupFiles(self, param):
# if not exists(arg):
# return (False, _("Error while preparing backup file, %s does not exists.") % arg)
except Exception as err:
print("[OpenWebif] Error: preparing backup file '%s'" % str(err))
print(f"[OpenWebif] Error: preparing backup file '{err}'")
return (False, _("Error while preparing backup file."))

remove(checkfile)
Expand Down Expand Up @@ -638,7 +638,7 @@ def restoreFiles(self, param):
else:
return (False, _("Error, %s was not created with WebBouquetEditor...") % backupfilename)
except Exception as err:
print("[OpenWebif] Error: extract files from backup '%s'" % str(err))
print(f"[OpenWebif] Error: extract files from backup '{err}'")
return (False, _("Error, extract files from backup '%s'") % backupfilename)
else:
return (False, _("Error, %s does not exists, restore is not possible...") % backupfilename)
Expand Down Expand Up @@ -678,15 +678,15 @@ def buildBouquetID(self, str, prefix, mode):
suffix = "tv"
else:
suffix = "radio"
filename = pathjoin(ETCENIGMA, "%s.%s.%s" % (prefix, name, suffix))
filename = pathjoin(ETCENIGMA, f"{prefix}.{name}.{suffix}")
if exists(filename):
i = 1
while True:
filename = pathjoin(ETCENIGMA, "%s.%s_%d.%s" % (prefix, name, i, suffix))
filename = pathjoin(ETCENIGMA, f"{prefix}.{name}_{i}.{suffix}")
if exists(filename):
i += 1
else:
name = "%s_%d" % (name, i)
name = f"{name}_{i}"
break
return name, filename

Expand Down Expand Up @@ -719,9 +719,9 @@ def importBouquet(self, param):
fullfilename = pathjoin(ETCENIGMA, filename)

if mode == MODE_TV:
sref = '1:7:1:0:0:0:0:0:0:0:FROM BOUQUET \"%s\" ORDER BY bouquet' % (filename)
sref = f'1:7:1:0:0:0:0:0:0:0:FROM BOUQUET "{filename}" ORDER BY bouquet'
else:
sref = '1:7:2:0:0:0:0:0:0:0:FROM BOUQUET \"%s\" ORDER BY bouquet' % (filename)
sref = f'1:7:2:0:0:0:0:0:0:0:FROM BOUQUET "{filename}" ORDER BY bouquet'

if not exists(fullfilename):
new_bouquet_ref = eServiceReference(str(sref))
Expand Down
6 changes: 3 additions & 3 deletions plugin/controllers/ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def P_about(self, request):
def P_boxinfo(self, request):
info = getInfo(self.session, need_fullinfo=True)
boxtype = info["boxtype"]
info["boximage"] = "%s_front.png" % boxtype
info["boximage"] = f"{boxtype}_front.png"
return info

# http://enigma2/ajax/epgpop?sstr=test&bouquetsonly=1
Expand Down Expand Up @@ -361,9 +361,9 @@ def P_webtv(self, request):
if session.GetAuth(request) is not None:
auth = ':'.join(session.GetAuth(request)) + "@"
else:
auth = '-sid:' + str(session.GetSID(request)) + "@"
auth = f"-sid:{session.GetSID(request)}@"
else:
auth = ''
auth = ""
transcoding = TRANSCODING
transcoder_port = 0
if transcoding:
Expand Down
8 changes: 4 additions & 4 deletions plugin/controllers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def _showImage(data):
@defer.inlineCallbacks
def _setContentDispositionAndSend(file_path):
filename = os.path.basename(file_path)
request.setHeader('content-disposition', 'filename="%s"' % filename)
request.setHeader('content-disposition', f'filename="{filename}"')
request.setHeader('content-type', "image/png")
f = open(file_path, "rb")
yield FileSender().beginFileTransfer(f, request)
Expand Down Expand Up @@ -223,7 +223,7 @@ def _setContentDispositionAndSend(file_path):
module = module.replace(".", "")
out = self.loadTemplate(module, self.path, data)
if out is None:
print("[OpenWebif] ERROR! Template not found for page '%s'" % request.uri)
print(f"[OpenWebif] ERROR! Template not found for page '{request.uri}'")
self.error404(request)
else:
if self.withMainTemplate:
Expand All @@ -238,7 +238,7 @@ def _setContentDispositionAndSend(file_path):
request.finish()

else:
print("[OpenWebif] page '%s' not found" % request.uri)
print(f"[OpenWebif] page '{request.uri}' not found")
self.error404(request)

# restore cached data
Expand Down Expand Up @@ -332,7 +332,7 @@ def prepareMainTemplate(self, request):
pass

if oscamwebif and port is not None:
url = "%s://%s:%s" % (proto, request.getRequestHostname(), port)
url = f"{proto}://{request.getRequestHostname()}:{port}"
if variant == "oscam":
extras.append({'key': url, 'description': _("OSCam Webinterface"), 'nw': '1'})
elif variant == "ncam":
Expand Down
10 changes: 5 additions & 5 deletions plugin/controllers/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from Tools.Directories import isPluginInstalled
from Plugins.Extensions.OpenWebif import __version__

OPENWEBIFVER = "OWIF %s" % __version__
OPENWEBIFVER = f"OWIF {__version__}"

PLUGIN_NAME = 'OpenWebif'
PLUGIN_DESCRIPTION = "OpenWebif Configuration"
Expand Down Expand Up @@ -108,7 +108,7 @@ def getPiconPath():
for folder in PICON_FOLDERS:
current = prefix + folder + '/'
if isdir(current):
print("Current Picon Path : %s" % current)
print(f"Current Picon Path : {current}")
return current
#: TODO discuss
# for item in os.listdir(current):
Expand Down Expand Up @@ -255,8 +255,8 @@ def showPicons():


def getCustomCSS(css):
cssfilename = "openwebif-%s.css" % css
csslinkpath = "%scss/%s" % (css + "/" if css == "modern" else "", cssfilename)
cssfilename = f"openwebif-{css}.css"
csslinkpath = f"{css + '/' if css == 'modern' else ''}css/{cssfilename}"
csssrcpath = pathjoin("/etc/enigma2", cssfilename)
try:
if isfile(csssrcpath):
Expand All @@ -267,7 +267,7 @@ def getCustomCSS(css):
symlink(csssrcpath, csspath)
return csslinkpath
except OSError as err:
print("[OpenWebif] Error getCustomCSS : %s" % str(err))
print(f"[OpenWebif] Error getCustomCSS : {err}")
return ""


Expand Down
Loading

0 comments on commit bb65cd2

Please sign in to comment.