convert some legacy percent format (manual)

ruff 'UP031'
This commit is contained in:
un-pogaz 2025-01-24 11:14:16 +01:00
parent 0560b429bf
commit 047ebcffe4
15 changed files with 29 additions and 29 deletions

View File

@ -50,7 +50,7 @@ class EPUBHelpBuilder(EpubBuilder):
fmt, width, height = identify(container.raw_data(imgname)) fmt, width, height = identify(container.raw_data(imgname))
if width == -1: if width == -1:
raise ValueError('Failed to read size of: {}'.format(imgname)) raise ValueError('Failed to read size of: {}'.format(imgname))
img.set('style', 'width: %dpx; height: %dpx' % (width, height)) img.set('style', 'width: {}px; height: {}px'.format(width, height))
def fix_opf(self, container): def fix_opf(self, container):
spine_names = {n for n, l in container.spine_names} spine_names = {n for n, l in container.spine_names}

View File

@ -21,7 +21,7 @@ from setup import SRC, Command, isbsd, isfreebsd, ishaiku, islinux, ismacos, isw
isunix = islinux or ismacos or isbsd or ishaiku isunix = islinux or ismacos or isbsd or ishaiku
py_lib = os.path.join(sys.prefix, 'libs', 'python%d%d.lib' % sys.version_info[:2]) py_lib = os.path.join(sys.prefix, 'libs', 'python{}{}.lib'.format(*sys.version_info[:2]))
class CompileCommand(NamedTuple): class CompileCommand(NamedTuple):
cmd: list[str] cmd: list[str]
@ -657,7 +657,7 @@ class Build(Command):
os.chdir(bdir) os.chdir(bdir)
try: try:
self.check_call(cmd + ['-S', os.path.dirname(sources[0])]) self.check_call(cmd + ['-S', os.path.dirname(sources[0])])
self.check_call([self.env.make] + ['-j%d'%(cpu_count or 1)]) self.check_call([self.env.make] + ['-j{}'.format(cpu_count or 1)])
finally: finally:
os.chdir(cwd) os.chdir(cwd)
os.rename(self.j(bdir, 'libheadless.so'), target) os.rename(self.j(bdir, 'libheadless.so'), target)
@ -734,7 +734,7 @@ sip-file = {os.path.basename(sipf)!r}
env = os.environ.copy() env = os.environ.copy()
if is_macos_universal_build: if is_macos_universal_build:
env['ARCHS'] = 'x86_64 arm64' env['ARCHS'] = 'x86_64 arm64'
self.check_call([self.env.make] + ([] if iswindows else ['-j%d'%(os.cpu_count() or 1)]), env=env) self.check_call([self.env.make] + ([] if iswindows else ['-j{}'.format(os.cpu_count() or 1)]), env=env)
e = 'pyd' if iswindows else 'so' e = 'pyd' if iswindows else 'so'
m = glob.glob(f'{ext.name}/{ext.name}.*{e}') m = glob.glob(f'{ext.name}/{ext.name}.*{e}')
if not m: if not m:

View File

@ -150,7 +150,7 @@ class Check(Command):
for i, f in enumerate(dirty_files): for i, f in enumerate(dirty_files):
self.info('\tChecking', f) self.info('\tChecking', f)
if self.file_has_errors(f): if self.file_has_errors(f):
self.info('%d files left to check' % (len(dirty_files) - i - 1)) self.info('{} files left to check'.format(len(dirty_files) - i - 1))
try: try:
edit_file(f) edit_file(f)
except FileNotFoundError: except FileNotFoundError:

View File

@ -56,16 +56,16 @@ class ReadFileWithProgressReporting: # {{{
eta = int((self._total - self.tell()) / bit_rate) + 1 eta = int((self._total - self.tell()) / bit_rate) + 1
eta_m, eta_s = eta / 60, eta % 60 eta_m, eta_s = eta / 60, eta % 60
sys.stdout.write( sys.stdout.write(
' %.1f%% %.1f/%.1fMB %.1f KB/sec %d minutes, %d seconds left' % ' {:.1f}% {:.1f}/{:.1f}MB {:.1f} KB/sec {} minutes, {} seconds left'
(frac * 100, mb_pos, mb_tot, kb_rate, eta_m, eta_s) .format(frac * 100, mb_pos, mb_tot, kb_rate, eta_m, eta_s)
) )
sys.stdout.write('\x1b[u') sys.stdout.write('\x1b[u')
if self.tell() >= self._total: if self.tell() >= self._total:
sys.stdout.write('\n') sys.stdout.write('\n')
t = int(time.time() - self.start_time) + 1 t = int(time.time() - self.start_time) + 1
print( print(
'Upload took %d minutes and %d seconds at %.1f KB/sec' % 'Upload took {} minutes and {} seconds at {:.1f} KB/sec'
(t / 60, t % 60, kb_rate) .format(t/60, t % 60, kb_rate)
) )
sys.stdout.flush() sys.stdout.flush()

View File

@ -388,7 +388,7 @@ class Bootstrap(Command):
st = time.time() st = time.time()
clone_cmd.insert(2, '--depth=1') clone_cmd.insert(2, '--depth=1')
subprocess.check_call(clone_cmd, cwd=self.d(self.SRC)) subprocess.check_call(clone_cmd, cwd=self.d(self.SRC))
print('Downloaded translations in %d seconds' % int(time.time() - st)) print('Downloaded translations in {} seconds'.format(int(time.time() - st)))
else: else:
if os.path.exists(tdir): if os.path.exists(tdir):
subprocess.check_call(['git', 'pull'], cwd=tdir) subprocess.check_call(['git', 'pull'], cwd=tdir)

View File

@ -20,7 +20,7 @@ def generate_data():
ans = [] ans = []
for x, limit in (('day', 8), ('mon', 13)): for x, limit in (('day', 8), ('mon', 13)):
for attr in ('ab' + x, x): for attr in ('ab' + x, x):
ans.append((attr, tuple(map(nl, (getattr(locale, '%s_%d' % (attr.upper(), i)) for i in range(1, limit)))))), ans.append((attr, tuple(map(nl, (getattr(locale, '{}_{}'.format(attr.upper(), i)) for i in range(1, limit)))))),
for x in ('d_t_fmt', 'd_fmt', 't_fmt', 't_fmt_ampm', 'radixchar', 'thousep', 'yesexpr', 'noexpr'): for x in ('d_t_fmt', 'd_fmt', 't_fmt', 't_fmt_ampm', 'radixchar', 'thousep', 'yesexpr', 'noexpr'):
ans.append((x, nl(getattr(locale, x.upper())))) ans.append((x, nl(getattr(locale, x.upper()))))
return ans return ans

View File

@ -476,7 +476,7 @@ def plugin_to_index(plugin, count):
block.append('<br>') block.append('<br>')
block.append('<li>{}</li>'.format(li)) block.append('<li>{}</li>'.format(li))
block = '<ul>{}</ul>'.format('\n'.join(block)) block = '<ul>{}</ul>'.format('\n'.join(block))
downloads = ('\xa0<span class="download-count">[%d total downloads]</span>' % count) if count else '' downloads = ('\xa0<span class="download-count">[{} total downloads]</span>'.format(count)) if count else ''
zipfile = '<div class="end"><a href={} title="Download plugin" download={}>Download plugin \u2193</a>{}</div>'.format( zipfile = '<div class="end"><a href={} title="Download plugin" download={}>Download plugin \u2193</a>{}</div>'.format(
quoteattr(plugin['file']), quoteattr(plugin['name'] + '.zip'), downloads) quoteattr(plugin['file']), quoteattr(plugin['name'] + '.zip'), downloads)
desc = plugin['description'] or '' desc = plugin['description'] or ''

View File

@ -203,7 +203,7 @@ class Manual(Command):
sys.executable, self.j(self.d(self.SRC), 'manual', 'build.py'), sys.executable, self.j(self.d(self.SRC), 'manual', 'build.py'),
language, self.j(tdir, language) language, self.j(tdir, language)
], '\n\n**************** Building translations for: {}'.format(language))) ], '\n\n**************** Building translations for: {}'.format(language)))
self.info('Building manual for %d languages' % len(jobs)) self.info('Building manual for {} languages'.format(len(jobs)))
subprocess.check_call(jobs[0].cmd) subprocess.check_call(jobs[0].cmd)
if not parallel_build(jobs[1:], self.info): if not parallel_build(jobs[1:], self.info):
raise SystemExit(1) raise SystemExit(1)
@ -222,8 +222,8 @@ class Manual(Command):
if x and not os.path.exists(x): if x and not os.path.exists(x):
os.symlink('.', x) os.symlink('.', x)
self.info( self.info(
'Built manual for %d languages in %s minutes' % 'Built manual for {} languages in {} minutes'
(len(jobs), int((time.time() - st) / 60.)) .format(len(jobs), int((time.time() - st) / 60.))
) )
finally: finally:
os.chdir(cwd) os.chdir(cwd)

View File

@ -93,7 +93,7 @@ class POT(Command): # {{{
ans = [] ans = []
for lineno, msg in msgs: for lineno, msg in msgs:
ans.append('#: %s:%d'%(path, lineno)) ans.append('#: {}:{}'.format(path, lineno))
slash = codepoint_to_chr(92) slash = codepoint_to_chr(92)
msg = msg.replace(slash, slash*2).replace('"', r'\"').replace('\n', msg = msg.replace(slash, slash*2).replace('"', r'\"').replace('\n',
r'\n').replace('\r', r'\r').replace('\t', r'\t') r'\n').replace('\r', r'\r').replace('\t', r'\t')

View File

@ -275,7 +275,7 @@ def cnv_points(attribute, arg, element):
return arg return arg
else: else:
try: try:
strarg = ' '.join(['%d,%d' % p for p in arg]) strarg = ' '.join(['{},{}'.format(*p) for p in arg])
except: except:
raise ValueError('Points must be string or [(0,0),(1,1)] - not {}'.format(arg)) raise ValueError('Points must be string or [(0,0),(1,1)] - not {}'.format(arg))
return strarg return strarg

View File

@ -131,7 +131,7 @@ class ParagraphProps:
def __unicode__(self): def __unicode__(self):
return '[bq=%s, h=%d, code=%s]' % (unicode_type(self.blockquote), return '[bq={}, h={}, code={}]'.format(unicode_type(self.blockquote),
self.headingLevel, self.headingLevel,
unicode_type(self.code)) unicode_type(self.code))
__str__ = __unicode__ __str__ = __unicode__

View File

@ -647,7 +647,7 @@ class ODF2XHTML(handler.ContentHandler):
''' Create a unique anchor id for a href name ''' ''' Create a unique anchor id for a href name '''
if name not in self.anchors: if name not in self.anchors:
# Changed by Kovid # Changed by Kovid
self.anchors[name] = 'anchor%d' % (len(self.anchors) + 1) self.anchors[name] = 'anchor{}'.format(len(self.anchors) + 1)
return self.anchors.get(name) return self.anchors.get(name)
def purgedata(self): def purgedata(self):
@ -940,13 +940,13 @@ dl.notes dd:last-of-type { page-break-after: avoid }
for key in range(1,self.currentnote+1): for key in range(1,self.currentnote+1):
note = self.notedict[key] note = self.notedict[key]
# for key,note in self.notedict.items(): # for key,note in self.notedict.items():
self.opentag('dt', {'id':'footnote-%d' % key}) self.opentag('dt', {'id':'footnote-{}'.format(key)})
# self.opentag('sup') # self.opentag('sup')
# self.writeout(escape(note['citation'])) # self.writeout(escape(note['citation']))
# self.closetag('sup', False) # self.closetag('sup', False)
self.writeout('[') self.writeout('[')
self.opentag('a', {'href': '#citation-%d' % key}) self.opentag('a', {'href': '#citation-{}'.format(key)})
self.writeout('%d' % key) self.writeout('{}'.format(key))
self.closetag('a') self.closetag('a')
self.writeout(']\xa0') self.writeout(']\xa0')
self.closetag('dt') self.closetag('dt')
@ -1335,7 +1335,7 @@ dl.notes dd:last-of-type { page-break-after: avoid }
# the list level must return to 1, even though the table or # the list level must return to 1, even though the table or
# textbox itself may be nested within another list. # textbox itself may be nested within another list.
name = self.tagstack.rfindattr((TEXTNS,'style-name')) name = self.tagstack.rfindattr((TEXTNS,'style-name'))
list_class = '%s_%d' % (name, level) list_class = '{}_{}'.format(name, level)
tag_name = self.listtypes.get(list_class,'ul') tag_name = self.listtypes.get(list_class,'ul')
number_class = tag_name + list_class number_class = tag_name + list_class
if list_id: if list_id:
@ -1372,7 +1372,7 @@ dl.notes dd:last-of-type { page-break-after: avoid }
# the list level must return to 1, even though the table or # the list level must return to 1, even though the table or
# textbox itself may be nested within another list. # textbox itself may be nested within another list.
name = self.tagstack.rfindattr((TEXTNS,'style-name')) name = self.tagstack.rfindattr((TEXTNS,'style-name'))
list_class = '%s_%d' % (name, level) list_class = '{}_{}'.format(name, level)
self.closetag(self.listtypes.get(list_class,'ul')) self.closetag(self.listtypes.get(list_class,'ul'))
self.purgedata() self.purgedata()

View File

@ -114,4 +114,4 @@ if __name__ == '__main__':
import sys import sys
result = odfmanifest(sys.argv[1]) result = odfmanifest(sys.argv[1])
for file in result.values(): for file in result.values():
print('%-40s %-40s' % (file['media-type'], file['full-path'])) print('{:<40} {:<40}'.format(file['media-type'], file['full-path']))

View File

@ -385,7 +385,7 @@ class OpenDocument:
''' '''
self.childobjects.append(document) self.childobjects.append(document)
if objectname is None: if objectname is None:
document.folder = '%s/Object %d' % (self.folder, len(self.childobjects)) document.folder = '{}/Object {}'.format(self.folder, len(self.childobjects))
else: else:
document.folder = objectname document.folder = objectname
return '.{}'.format(document.folder) return '.{}'.format(document.folder)
@ -407,7 +407,7 @@ class OpenDocument:
# Look in subobjects # Look in subobjects
subobjectnum = 1 subobjectnum = 1
for subobject in object.childobjects: for subobject in object.childobjects:
self._savePictures(subobject,'%sObject %d/' % (folder, subobjectnum)) self._savePictures(subobject,'{}Object {}/'.format(folder, subobjectnum))
subobjectnum += 1 subobjectnum += 1
def __replaceGenerator(self): def __replaceGenerator(self):
@ -524,7 +524,7 @@ class OpenDocument:
# Write subobjects # Write subobjects
subobjectnum = 1 subobjectnum = 1
for subobject in object.childobjects: for subobject in object.childobjects:
self._saveXmlObjects(subobject, '%sObject %d/' % (folder, subobjectnum)) self._saveXmlObjects(subobject, '{}Object {}/'.format(folder, subobjectnum))
subobjectnum += 1 subobjectnum += 1
# Document's DOM methods # Document's DOM methods