also upgrade code in setup folder

This commit is contained in:
Kovid Goyal 2022-01-08 12:15:18 +05:30
parent f47f50d359
commit 24c460faec
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
33 changed files with 96 additions and 132 deletions

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
__license__ = 'GPL v3' __license__ = 'GPL v3'
@ -92,7 +91,7 @@ def build_cache_dir():
_cache_dir_built = True _cache_dir_built = True
try: try:
os.mkdir(ans) os.mkdir(ans)
except EnvironmentError as err: except OSError as err:
if err.errno != errno.EEXIST: if err.errno != errno.EEXIST:
raise raise
return ans return ans
@ -100,7 +99,7 @@ def build_cache_dir():
def require_git_master(branch='master'): def require_git_master(branch='master'):
if subprocess.check_output(['git', 'symbolic-ref', '--short', 'HEAD']).decode('utf-8').strip() != branch: if subprocess.check_output(['git', 'symbolic-ref', '--short', 'HEAD']).decode('utf-8').strip() != branch:
raise SystemExit('You must be in the {} git branch'.format(branch)) raise SystemExit(f'You must be in the {branch} git branch')
def require_clean_git(): def require_clean_git():
@ -225,7 +224,7 @@ class Command:
st = time.time() st = time.time()
self.running(cmd) self.running(cmd)
cmd.run(opts) cmd.run(opts)
self.info('* %s took %.1f seconds' % (command_names[cmd], time.time() - st)) self.info(f'* {command_names[cmd]} took {time.time() - st:.1f} seconds')
if os.environ.get('CI'): if os.environ.get('CI'):
self.info('::endgroup::') self.info('::endgroup::')

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net> # License: GPLv3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
__license__ = 'GPL v3' __license__ = 'GPL v3'
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>' __copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
@ -28,7 +27,7 @@ def init_symbol_name(name):
def absolutize(paths): def absolutize(paths):
return list(set([x if os.path.isabs(x) else os.path.join(SRC, x.replace('/', os.sep)) for x in paths])) return list({x if os.path.isabs(x) else os.path.join(SRC, x.replace('/', os.sep)) for x in paths})
class Extension: class Extension:

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
__license__ = 'GPL v3' __license__ = 'GPL v3'

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net> # License: GPL v3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
from datetime import date from datetime import date

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
__license__ = 'GPL v3' __license__ = 'GPL v3'
@ -16,7 +15,7 @@ class Message:
self.filename, self.lineno, self.msg = filename, lineno, msg self.filename, self.lineno, self.msg = filename, lineno, msg
def __str__(self): def __str__(self):
return '%s:%s: %s' % (self.filename, self.lineno, self.msg) return f'{self.filename}:{self.lineno}: {self.msg}'
def checkable_python_files(SRC): def checkable_python_files(SRC):
@ -95,7 +94,7 @@ class Check(Command):
try: try:
with open(self.cache_file, 'rb') as f: with open(self.cache_file, 'rb') as f:
cache = json.load(f) cache = json.load(f)
except EnvironmentError as err: except OSError as err:
if err.errno != errno.ENOENT: if err.errno != errno.ENOENT:
raise raise
dirty_files = tuple(f for f in self.get_files() if not self.is_cache_valid(f, cache)) dirty_files = tuple(f for f in self.get_files() if not self.is_cache_valid(f, cache))
@ -118,7 +117,7 @@ class Check(Command):
def clean(self): def clean(self):
try: try:
os.remove(self.cache_file) os.remove(self.cache_file)
except EnvironmentError as err: except OSError as err:
if err.errno != errno.ENOENT: if err.errno != errno.ENOENT:
raise raise
@ -129,6 +128,10 @@ class UpgradeSourceCode(Command):
def run(self, opts): def run(self, opts):
files = [] files = []
for f in os.listdir(os.path.dirname(os.path.abspath(__file__))):
q = os.path.join('setup', f)
if f.endswith('.py') and f not in ('linux-installer.py',) and not os.path.isdir(q):
files.append(q)
for path in checkable_python_files(self.SRC): for path in checkable_python_files(self.SRC):
q = path.replace(os.sep, '/') q = path.replace(os.sep, '/')
if '/metadata/sources/' in q or '/store/stores/' in q: if '/metadata/sources/' in q or '/store/stores/' in q:

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
__license__ = 'GPL v3' __license__ = 'GPL v3'

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net> # License: GPL v3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
import os import os

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=utf-8
__license__ = 'GPL v3' __license__ = 'GPL v3'

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=utf-8
__license__ = 'GPL v3' __license__ = 'GPL v3'
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>' __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=utf-8
__license__ = 'GPL v3' __license__ = 'GPL v3'
__copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>' __copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2008, Kovid Goyal <kovid at kovidgoyal.net> # License: GPLv3 Copyright: 2008, Kovid Goyal <kovid at kovidgoyal.net>
@ -55,7 +54,7 @@ class Bug:
print('Working on bug:', summary) print('Working on bug:', summary)
if int(bug) > 100000 and action != 'See': if int(bug) > 100000 and action != 'See':
self.close_bug(bug, action) self.close_bug(bug, action)
return match.group() + ' [%s](%s)' % (summary, LAUNCHPAD_BUG % bug) return match.group() + f' [{summary}]({LAUNCHPAD_BUG % bug})'
return match.group() + ' (%s)' % summary return match.group() + ' (%s)' % summary
return match.group() return match.group()
@ -66,7 +65,7 @@ class Bug:
'calibre is usually released every alternate Friday.' 'calibre is usually released every alternate Friday.'
) )
action += 'ed' action += 'ed'
msg = '%s in branch %s. %s' % (action, 'master', suffix) msg = '{} in branch {}. {}'.format(action, 'master', suffix)
msg = msg.replace('Fixesed', 'Fixed') msg = msg.replace('Fixesed', 'Fixed')
msg += '\n\n status fixreleased' msg += '\n\n status fixreleased'

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2019, Eli Schwartz <eschwartz@archlinux.org> # License: GPLv3 Copyright: 2019, Eli Schwartz <eschwartz@archlinux.org>

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
__license__ = 'GPL v3' __license__ = 'GPL v3'

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
__license__ = 'GPL v3' __license__ = 'GPL v3'
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>' __copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
@ -150,7 +149,7 @@ class GitHub(Base): # {{{
existing_assets = self.existing_assets(release['id']) existing_assets = self.existing_assets(release['id'])
for path, desc in self.files.items(): for path, desc in self.files.items():
self.info('') self.info('')
url = self.API + 'repos/%s/%s/releases/assets/{}' % ( url = self.API + 'repos/{}/{}/releases/assets/{{}}'.format(
self.username, self.reponame self.username, self.reponame
) )
fname = os.path.basename(path) fname = os.path.basename(path)
@ -206,7 +205,7 @@ class GitHub(Base): # {{{
def do_upload(self, url, path, desc, fname): def do_upload(self, url, path, desc, fname):
mime_type = mimetypes.guess_type(fname)[0] or 'application/octet-stream' mime_type = mimetypes.guess_type(fname)[0] or 'application/octet-stream'
self.info('Uploading to GitHub: %s (%s)' % (fname, mime_type)) self.info(f'Uploading to GitHub: {fname} ({mime_type})')
with ReadFileWithProgressReporting(path) as f: with ReadFileWithProgressReporting(path) as f:
return self.requests.post( return self.requests.post(
url, url,
@ -229,7 +228,7 @@ class GitHub(Base): # {{{
return error_code == 'already_exists' return error_code == 'already_exists'
def existing_assets(self, release_id): def existing_assets(self, release_id):
url = self.API + 'repos/%s/%s/releases/%s/assets' % ( url = self.API + 'repos/{}/{}/releases/{}/assets'.format(
self.username, self.reponame, release_id self.username, self.reponame, release_id
) )
r = self.requests.get(url) r = self.requests.get(url)
@ -238,7 +237,7 @@ class GitHub(Base): # {{{
return {asset['name']: asset['id'] for asset in r.json()} return {asset['name']: asset['id'] for asset in r.json()}
def releases(self): def releases(self):
url = self.API + 'repos/%s/%s/releases' % (self.username, self.reponame) url = self.API + f'repos/{self.username}/{self.reponame}/releases'
r = self.requests.get(url) r = self.requests.get(url)
if r.status_code != 200: if r.status_code != 200:
self.fail(r, 'Failed to list releases') self.fail(r, 'Failed to list releases')
@ -250,7 +249,7 @@ class GitHub(Base): # {{{
# Check for existing release # Check for existing release
if release['tag_name'] == self.current_tag_name: if release['tag_name'] == self.current_tag_name:
return release return release
url = self.API + 'repos/%s/%s/releases' % (self.username, self.reponame) url = self.API + f'repos/{self.username}/{self.reponame}/releases'
r = self.requests.post( r = self.requests.post(
url, url,
data=json.dumps({ data=json.dumps({
@ -275,7 +274,7 @@ def generate_index(): # {{{
releases = set() releases = set()
for x in os.listdir('.'): for x in os.listdir('.'):
if os.path.isdir(x) and '.' in x: if os.path.isdir(x) and '.' in x:
releases.add(tuple((int(y) for y in x.split('.')))) releases.add(tuple(int(y) for y in x.split('.')))
rmap = OrderedDict() rmap = OrderedDict()
for rnum in sorted(releases, reverse=True): for rnum in sorted(releases, reverse=True):
series = rnum[:2] if rnum[0] == 0 else rnum[:1] series = rnum[:2] if rnum[0] == 0 else rnum[:1]
@ -301,10 +300,10 @@ def generate_index(): # {{{
body.append( body.append(
'<li><a href="{0}.html" title="Releases in the {0}.x series">{0}.x</a>\xa0\xa0\xa0<span style="font-size:smaller">[{1} releases]</span></li>' '<li><a href="{0}.html" title="Releases in the {0}.x series">{0}.x</a>\xa0\xa0\xa0<span style="font-size:smaller">[{1} releases]</span></li>'
.format( # noqa .format( # noqa
'.'.join(map(type(''), series)), len(rmap[series]) '.'.join(map(str, series)), len(rmap[series])
) )
) )
body = '<ul>{0}</ul>'.format(' '.join(body)) body = '<ul>{}</ul>'.format(' '.join(body))
index = template.format( index = template.format(
title='Previous calibre releases', title='Previous calibre releases',
style=style, style=style,
@ -315,13 +314,13 @@ def generate_index(): # {{{
f.write(index.encode('utf-8')) f.write(index.encode('utf-8'))
for series, releases in rmap.items(): for series, releases in rmap.items():
sname = '.'.join(map(type(''), series)) sname = '.'.join(map(str, series))
body = [ body = [
'<li><a href="{0}/" title="Release {0}">{0}</a></li>'.format( '<li><a href="{0}/" title="Release {0}">{0}</a></li>'.format(
'.'.join(map(type(''), r)) '.'.join(map(str, r))
) for r in releases ) for r in releases
] ]
body = '<ul class="release-list">{0}</ul>'.format(' '.join(body)) body = '<ul class="release-list">{}</ul>'.format(' '.join(body))
index = template.format( index = template.format(
title='Previous calibre releases (%s.x)' % sname, title='Previous calibre releases (%s.x)' % sname,
style=style, style=style,
@ -332,7 +331,7 @@ def generate_index(): # {{{
f.write(index.encode('utf-8')) f.write(index.encode('utf-8'))
for r in releases: for r in releases:
rname = '.'.join(map(type(''), r)) rname = '.'.join(map(str, r))
os.chdir(rname) os.chdir(rname)
try: try:
body = [] body = []
@ -346,7 +345,7 @@ def generate_index(): # {{{
) for x in windows ) for x in windows
] ]
body.append( body.append(
'<dt>Windows</dt><dd><ul>{0}</ul></dd>'.format( '<dt>Windows</dt><dd><ul>{}</ul></dd>'.format(
' '.join(windows) ' '.join(windows)
) )
) )
@ -373,7 +372,7 @@ def generate_index(): # {{{
) for x in linux ) for x in linux
] ]
body.append( body.append(
'<dt>Linux</dt><dd><ul>{0}</ul></dd>'.format( '<dt>Linux</dt><dd><ul>{}</ul></dd>'.format(
' '.join(linux) ' '.join(linux)
) )
) )
@ -384,7 +383,7 @@ def generate_index(): # {{{
.format(source[0], 'Source code (all platforms)') .format(source[0], 'Source code (all platforms)')
) )
body = '<dl>{0}</dl>'.format(''.join(body)) body = '<dl>{}</dl>'.format(''.join(body))
index = template.format( index = template.format(
title='calibre release (%s)' % rname, title='calibre release (%s)' % rname,
style=style, style=style,

View File

@ -1,7 +1,5 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai
# License: GPLv3 Copyright: 2019, Kovid Goyal <kovid at kovidgoyal.net> # License: GPLv3 Copyright: 2019, Kovid Goyal <kovid at kovidgoyal.net>
from __future__ import absolute_import, division, print_function, unicode_literals
import glob import glob
import hashlib import hashlib
@ -100,7 +98,7 @@ class Hyphenation(ReVendor):
for dic in dics: for dic in dics:
with open(os.path.join(output_dir, dic), 'rb') as f: with open(os.path.join(output_dir, dic), 'rb') as f:
m.update(f.read()) m.update(f.read())
hsh = type('')(m.hexdigest()) hsh = str(m.hexdigest())
buf = BytesIO() buf = BytesIO()
with tarfile.TarFile(fileobj=buf, mode='w') as tf: with tarfile.TarFile(fileobj=buf, mode='w') as tf:
for dic in dics: for dic in dics:

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
# License: GPLv3 Copyright: 2009, Kovid Goyal <kovid at kovidgoyal.net> # License: GPLv3 Copyright: 2009, Kovid Goyal <kovid at kovidgoyal.net>
@ -163,7 +162,7 @@ class Develop(Command):
try: try:
if not os.path.exists(libdir): if not os.path.exists(libdir):
os.makedirs(libdir) os.makedirs(libdir)
except EnvironmentError: except OSError:
self.warn('Cannot install calibre environment module to: '+libdir) self.warn('Cannot install calibre environment module to: '+libdir)
else: else:
path = os.path.join(libdir, 'init_calibre.py') path = os.path.join(libdir, 'init_calibre.py')
@ -367,7 +366,7 @@ class Bootstrap(Command):
def pre_sub_commands(self, opts): def pre_sub_commands(self, opts):
tdir = self.j(self.d(self.SRC), 'translations') tdir = self.j(self.d(self.SRC), 'translations')
clone_cmd = [ clone_cmd = [
'git', 'clone', 'https://github.com/{}.git'.format(self.TRANSLATIONS_REPO), 'translations'] 'git', 'clone', f'https://github.com/{self.TRANSLATIONS_REPO}.git', 'translations']
if opts.ephemeral: if opts.ephemeral:
if os.path.exists(tdir): if os.path.exists(tdir):
shutil.rmtree(tdir) shutil.rmtree(tdir)

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net> # License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
@ -86,7 +85,7 @@ def build_single(which='windows', bitness='64', shutdown=True, sign_installers=T
dest = os.path.join(base, 'dist', x) dest = os.path.join(base, 'dist', x)
try: try:
os.remove(dest) os.remove(dest)
except EnvironmentError: except OSError:
pass pass
os.link(src, dest) os.link(src, dest)
if shutdown: if shutdown:
@ -248,9 +247,9 @@ class ExtDev(Command):
try: try:
path = path.format(ext) path = path.format(ext)
src = os.path.join(ext_dir, os.path.basename(path)) src = os.path.join(ext_dir, os.path.basename(path))
subprocess.check_call(['ssh', '-S', control_path, host, 'chmod', '+w', '"{}"'.format(path)]) subprocess.check_call(['ssh', '-S', control_path, host, 'chmod', '+w', f'"{path}"'])
with open(src, 'rb') as f: with open(src, 'rb') as f:
p = subprocess.Popen(['ssh', '-S', control_path, host, 'cat - > "{}"'.format(path)], stdin=subprocess.PIPE) p = subprocess.Popen(['ssh', '-S', control_path, host, f'cat - > "{path}"'], stdin=subprocess.PIPE)
p.communicate(f.read()) p.communicate(f.read())
if p.wait() != 0: if p.wait() != 0:
raise SystemExit(1) raise SystemExit(1)

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# vim:fileencoding=utf-8
__license__ = 'GPL v3' __license__ = 'GPL v3'

View File

@ -1,7 +1,5 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai
# License: GPLv3 Copyright: 2019, Kovid Goyal <kovid at kovidgoyal.net> # License: GPLv3 Copyright: 2019, Kovid Goyal <kovid at kovidgoyal.net>
from __future__ import absolute_import, division, print_function, unicode_literals
import glob import glob
import os import os

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai
__license__ = 'GPL v3' __license__ = 'GPL v3'

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=utf-8
__license__ = 'GPL v3' __license__ = 'GPL v3'

View File

@ -1,7 +1,5 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2013, Kovid Goyal <kovid at kovidgoyal.net> # License: GPLv3 Copyright: 2013, Kovid Goyal <kovid at kovidgoyal.net>
from __future__ import absolute_import, division, print_function, unicode_literals
# Imports {{{ # Imports {{{
@ -128,7 +126,7 @@ def parse_index(raw=None): # {{{
thread_id = url_to_plugin_id(url, deprecated) thread_id = url_to_plugin_id(url, deprecated)
if thread_id in seen: if thread_id in seen:
raise ValueError('thread_id for %s and %s is the same: %s' % (seen[thread_id], name, thread_id)) raise ValueError(f'thread_id for {seen[thread_id]} and {name} is the same: {thread_id}')
seen[thread_id] = name seen[thread_id] = name
entry = IndexEntry(name, url, donate, history, uninstall, deprecated, thread_id) entry = IndexEntry(name, url, donate, history, uninstall, deprecated, thread_id)
yield entry yield entry
@ -147,7 +145,7 @@ def load_plugins_index():
try: try:
with open(PLUGINS, 'rb') as f: with open(PLUGINS, 'rb') as f:
raw = f.read() raw = f.read()
except IOError as err: except OSError as err:
if err.errno == errno.ENOENT: if err.errno == errno.ENOENT:
return {} return {}
raise raise
@ -173,13 +171,13 @@ def convert_node(fields, x, names={}, import_data=None):
return dict(zip(keys, values)) return dict(zip(keys, values))
elif name == 'Call': elif name == 'Call':
if len(x.args) != 1 and len(x.keywords) != 0: if len(x.args) != 1 and len(x.keywords) != 0:
raise TypeError('Unsupported function call for fields: %s' % (fields,)) raise TypeError(f'Unsupported function call for fields: {fields}')
return tuple(map(conv, x.args))[0] return tuple(map(conv, x.args))[0]
elif name == 'Name': elif name == 'Name':
if x.id not in names: if x.id not in names:
if import_data is not None and x.id in import_data[0]: if import_data is not None and x.id in import_data[0]:
return get_import_data(x.id, import_data[0][x.id], *import_data[1:]) return get_import_data(x.id, import_data[0][x.id], *import_data[1:])
raise ValueError('Could not find name %s for fields: %s' % (x.id, fields)) raise ValueError(f'Could not find name {x.id} for fields: {fields}')
return names[x.id] return names[x.id]
elif name == 'BinOp': elif name == 'BinOp':
if x.right.__class__.__name__ == 'Str': if x.right.__class__.__name__ == 'Str':
@ -188,7 +186,7 @@ def convert_node(fields, x, names={}, import_data=None):
return x.right.value return x.right.value
elif name == 'Attribute': elif name == 'Attribute':
return conv(getattr(conv(x.value), x.attr)) return conv(getattr(conv(x.value), x.attr))
raise TypeError('Unknown datatype %s for fields: %s' % (x, fields)) raise TypeError(f'Unknown datatype {x} for fields: {fields}')
Alias = namedtuple('Alias', 'name asname') Alias = namedtuple('Alias', 'name asname')
@ -221,7 +219,7 @@ def get_import_data(name, mod, zf, names):
return convert_node({x}, node.value) return convert_node({x}, node.value)
if is_module_import: if is_module_import:
return module return module
raise ValueError('Failed to find name: %r in module: %r' % (name, mod)) raise ValueError(f'Failed to find name: {name!r} in module: {mod!r}')
else: else:
raise ValueError('Failed to find module: %r' % mod) raise ValueError('Failed to find module: %r' % mod)
@ -457,7 +455,7 @@ def fetch_plugins(old_index):
def plugin_to_index(plugin, count): def plugin_to_index(plugin, count):
title = '<h3><img src="plugin-icon.png"><a href=%s title="Plugin forum thread">%s</a></h3>' % ( # noqa title = '<h3><img src="plugin-icon.png"><a href={} title="Plugin forum thread">{}</a></h3>'.format( # noqa
quoteattr(plugin['thread_url']), escape(plugin['name'])) quoteattr(plugin['thread_url']), escape(plugin['name']))
released = datetime(*tuple(map(int, re.split(r'\D', plugin['last_modified'])))[:6]).strftime('%e %b, %Y').lstrip() released = datetime(*tuple(map(int, re.split(r'\D', plugin['last_modified'])))[:6]).strftime('%e %b, %Y').lstrip()
details = [ details = [
@ -478,12 +476,12 @@ def plugin_to_index(plugin, count):
block.append('<li>%s</li>' % li) block.append('<li>%s</li>' % li)
block = '<ul>%s</ul>' % ('\n'.join(block)) block = '<ul>%s</ul>' % ('\n'.join(block))
downloads = ('\xa0<span class="download-count">[%d total downloads]</span>' % count) if count else '' downloads = ('\xa0<span class="download-count">[%d total downloads]</span>' % count) if count else ''
zipfile = '<div class="end"><a href=%s title="Download plugin" download=%s>Download plugin \u2193</a>%s</div>' % ( 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 ''
if desc: if desc:
desc = '<p>%s</p>' % desc desc = '<p>%s</p>' % desc
return '%s\n%s\n%s\n%s\n\n' % (title, desc, block, zipfile) return f'{title}\n{desc}\n{block}\n{zipfile}\n\n'
def create_index(index, raw_stats): def create_index(index, raw_stats):
@ -526,14 +524,14 @@ h1 { text-align: center }
try: try:
with open('index.html', 'rb') as f: with open('index.html', 'rb') as f:
oraw = f.read() oraw = f.read()
except EnvironmentError: except OSError:
oraw = None oraw = None
if raw != oraw: if raw != oraw:
atomic_write(raw, 'index.html') atomic_write(raw, 'index.html')
def plugin_stats(x): def plugin_stats(x):
name, count = x name, count = x
return '<tr><td>%s</td><td>%s</td></tr>\n' % (escape(name), count) return f'<tr><td>{escape(name)}</td><td>{count}</td></tr>\n'
pstats = list(map(plugin_stats, sorted(stats.items(), reverse=True, key=lambda x:x[1]))) pstats = list(map(plugin_stats, sorted(stats.items(), reverse=True, key=lambda x:x[1])))
stats = '''\ stats = '''\
@ -560,7 +558,7 @@ h1 { text-align: center }
try: try:
with open('stats.html', 'rb') as f: with open('stats.html', 'rb') as f:
oraw = f.read() oraw = f.read()
except EnvironmentError: except OSError:
oraw = None oraw = None
if raw != oraw: if raw != oraw:
atomic_write(raw, 'stats.html') atomic_write(raw, 'stats.html')
@ -574,7 +572,7 @@ def singleinstance():
s = _singleinstance = socket.socket(socket.AF_UNIX) s = _singleinstance = socket.socket(socket.AF_UNIX)
try: try:
s.bind(b'\0calibre-plugins-mirror-singleinstance') s.bind(b'\0calibre-plugins-mirror-singleinstance')
except socket.error as err: except OSError as err:
if getattr(err, 'errno', None) == errno.EADDRINUSE: if getattr(err, 'errno', None) == errno.EADDRINUSE:
return False return False
raise raise
@ -590,7 +588,7 @@ def update_stats():
try: try:
with open('stats.json', 'rb') as f: with open('stats.json', 'rb') as f:
stats = json.load(f) stats = json.load(f)
except EnvironmentError as err: except OSError as err:
if err.errno != errno.ENOENT: if err.errno != errno.ENOENT:
raise raise
if os.geteuid() != 0: if os.geteuid() != 0:
@ -688,7 +686,7 @@ def test_parse(): # {{{
new_entries = tuple(parse_index(raw)) new_entries = tuple(parse_index(raw))
for i, entry in enumerate(old_entries): for i, entry in enumerate(old_entries):
if entry != new_entries[i]: if entry != new_entries[i]:
print('The new entry: %s != %s' % (new_entries[i], entry)) print(f'The new entry: {new_entries[i]} != {entry}')
raise SystemExit(1) raise SystemExit(1)
pool = ThreadPool(processes=20) pool = ThreadPool(processes=20)
urls = [e.url for e in new_entries] urls = [e.url for e in new_entries]
@ -705,7 +703,7 @@ def test_parse(): # {{{
break break
new_url, aname = parse_plugin_zip_url(raw) new_url, aname = parse_plugin_zip_url(raw)
if new_url != full_url: if new_url != full_url:
print('new url (%s): %s != %s for plugin at: %s' % (aname, new_url, full_url, url)) print(f'new url ({aname}): {new_url} != {full_url} for plugin at: {url}')
raise SystemExit(1) raise SystemExit(1)
# }}} # }}}

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
__license__ = 'GPL v3' __license__ = 'GPL v3'
@ -225,7 +224,7 @@ class Manual(Command):
orig = self.j(self.d(base), r) orig = self.j(self.d(base), r)
try: try:
sz = os.stat(orig).st_size sz = os.stat(orig).st_size
except EnvironmentError: except OSError:
continue continue
if sz == os.stat(f).st_size and filecmp._do_cmp(f, orig): if sz == os.stat(f).st_size and filecmp._do_cmp(f, orig):
os.remove(f) os.remove(f)
@ -260,7 +259,7 @@ class ManPages(Command):
os.environ['ALL_USER_MANUAL_LANGUAGES'] = ' '.join(languages) os.environ['ALL_USER_MANUAL_LANGUAGES'] = ' '.join(languages)
try: try:
os.makedirs(dest) os.makedirs(dest)
except EnvironmentError: except OSError:
pass pass
jobs = [] jobs = []
for l in languages: for l in languages:
@ -268,7 +267,7 @@ class ManPages(Command):
[sys.executable, self.j(base, 'build.py'), '--man-pages', l, dest], [sys.executable, self.j(base, 'build.py'), '--man-pages', l, dest],
'\n\n**************** Building translations for: %s' % l) '\n\n**************** Building translations for: %s' % l)
) )
self.info('\tCreating man pages in {} for {} languages...'.format(dest, len(jobs))) self.info(f'\tCreating man pages in {dest} for {len(jobs)} languages...')
subprocess.check_call(jobs[0].cmd) subprocess.check_call(jobs[0].cmd)
if not parallel_build(jobs[1:], self.info, verbose=False): if not parallel_build(jobs[1:], self.info, verbose=False):
raise SystemExit(1) raise SystemExit(1)
@ -307,4 +306,4 @@ class TagRelease(Command):
subprocess.check_call( subprocess.check_call(
'git tag -s v{0} -m "version-{0}"'.format(__version__).split() 'git tag -s v{0} -m "version-{0}"'.format(__version__).split()
) )
subprocess.check_call('git push origin v{0}'.format(__version__).split()) subprocess.check_call(f'git push origin v{__version__}'.split())

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
__license__ = 'GPL v3' __license__ = 'GPL v3'
@ -16,17 +15,13 @@ from polyglot.builtins import codepoint_to_chr, itervalues, iteritems, only_unic
def get_opts_from_parser(parser): def get_opts_from_parser(parser):
def do_opt(opt): def do_opt(opt):
for x in opt._long_opts: yield from opt._long_opts
yield x yield from opt._short_opts
for x in opt._short_opts:
yield x
for o in parser.option_list: for o in parser.option_list:
for x in do_opt(o): yield from do_opt(o)
yield x
for g in parser.option_groups: for g in parser.option_groups:
for o in g.option_list: for o in g.option_list:
for x in do_opt(o): yield from do_opt(o)
yield x
class Kakasi(Command): # {{{ class Kakasi(Command): # {{{
@ -145,7 +140,7 @@ class CACerts(Command): # {{{
try: try:
with open(self.CA_PATH, 'rb') as f: with open(self.CA_PATH, 'rb') as f:
raw = f.read() raw = f.read()
except EnvironmentError as err: except OSError as err:
if err.errno != errno.ENOENT: if err.errno != errno.ENOENT:
raise raise
raw = b'' raw = b''
@ -298,7 +293,7 @@ class Resources(Command): # {{{
except Exception: except Exception:
continue continue
src = src.replace('def ' + func.__name__, 'def replace') src = src.replace('def ' + func.__name__, 'def replace')
imports = ['from %s import %s' % (x.__module__, x.__name__) for x in func.imports] imports = [f'from {x.__module__} import {x.__name__}' for x in func.imports]
if imports: if imports:
src = '\n'.join(imports) + '\n\n' + src src = '\n'.join(imports) + '\n\n' + src
function_dict[func.name] = src function_dict[func.name] = src

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2019, Eli Schwartz <eschwartz@archlinux.org> # License: GPL v3 Copyright: 2019, Eli Schwartz <eschwartz@archlinux.org>
import os import os

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net> # License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net> # License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
__license__ = 'GPL v3' __license__ = 'GPL v3'
@ -108,7 +107,7 @@ class POT(Command): # {{{
for x in sorted(entries, key=lambda x:name_getter(x).lower()): for x in sorted(entries, key=lambda x:name_getter(x).lower()):
name = name_getter(x) name = name_getter(x)
if name: if name:
ans.append(u'msgid "{}"'.format(name)) ans.append(f'msgid "{name}"')
ans.append('msgstr ""') ans.append('msgstr ""')
ans.append('') ans.append('')
pot = self.pot_header() + '\n\n' + '\n'.join(ans) pot = self.pot_header() + '\n\n' + '\n'.join(ans)
@ -278,7 +277,7 @@ class Translations(POT): # {{{
self.cache_dir_created = True self.cache_dir_created = True
try: try:
os.mkdir(ans) os.mkdir(ans)
except EnvironmentError as err: except OSError as err:
if err.errno != errno.EEXIST: if err.errno != errno.EEXIST:
raise raise
return ans return ans
@ -293,7 +292,7 @@ class Translations(POT): # {{{
with open(self.j(self.cache_dir, cname), 'rb') as f: with open(self.j(self.cache_dir, cname), 'rb') as f:
data = f.read() data = f.read()
return data[:20], data[20:] return data[:20], data[20:]
except EnvironmentError as err: except OSError as err:
if err.errno != errno.ENOENT: if err.errno != errno.ENOENT:
raise raise
return None, None return None, None
@ -387,7 +386,7 @@ class Translations(POT): # {{{
self.bad.add(msgstr) self.bad.add(msgstr)
return match.group() return match.group()
self.seen.add(self.msgid) self.seen.add(self.msgid)
return 'msgstr "{}"'.format(self.msgid) return f'msgstr "{self.msgid}"'
self.seen.add(msgstr) self.seen.add(msgstr)
return match.group() return match.group()
@ -405,7 +404,7 @@ class Translations(POT): # {{{
if msgstr: if msgstr:
if msgstr and msgstr in self.bad: if msgstr and msgstr in self.bad:
self.bad.discard(msgstr) self.bad.discard(msgstr)
return 'msgstr "{}"'.format(self.msgid) return f'msgstr "{self.msgid}"'
return match.group() return match.group()
for (po_path, mo_path) in files: for (po_path, mo_path) in files:
@ -475,7 +474,7 @@ class Translations(POT): # {{{
base = self.d(dest) base = self.d(dest)
try: try:
os.mkdir(base) os.mkdir(base)
except EnvironmentError as err: except OSError as err:
if err.errno != errno.EEXIST: if err.errno != errno.EEXIST:
raise raise
from calibre.utils.serialize import msgpack_dumps from calibre.utils.serialize import msgpack_dumps
@ -506,12 +505,12 @@ class Translations(POT): # {{{
po_data = data.decode('utf-8') po_data = data.decode('utf-8')
data = json.loads(msgfmt(po_data)) data = json.loads(msgfmt(po_data))
translated_entries = {k:v for k, v in iteritems(data['entries']) if v and sum(map(len, v))} translated_entries = {k:v for k, v in iteritems(data['entries']) if v and sum(map(len, v))}
data[u'entries'] = translated_entries data['entries'] = translated_entries
data[u'hash'] = h.hexdigest() data['hash'] = h.hexdigest()
cdata = b'{}' cdata = b'{}'
if translated_entries: if translated_entries:
raw = json.dumps(data, ensure_ascii=False, sort_keys=True) raw = json.dumps(data, ensure_ascii=False, sort_keys=True)
if isinstance(raw, type(u'')): if isinstance(raw, str):
raw = raw.encode('utf-8') raw = raw.encode('utf-8')
cdata = raw cdata = raw
self.write_cache(cdata, current_hash, src) self.write_cache(cdata, current_hash, src)
@ -539,7 +538,7 @@ class Translations(POT): # {{{
cm = langnames_to_langcodes([omsgid, msgid]) cm = langnames_to_langcodes([omsgid, msgid])
if cm[msgid] and cm[omsgid] and cm[msgid] != cm[omsgid]: if cm[msgid] and cm[omsgid] and cm[msgid] != cm[omsgid]:
has_errors = True has_errors = True
self.iso639_errors.append('In file %s the name %s is used as translation for both %s and %s' % ( self.iso639_errors.append('In file {} the name {} is used as translation for both {} and {}'.format(
os.path.basename(path), msgstr, msgid, rmap[msgstr])) os.path.basename(path), msgstr, msgid, rmap[msgstr]))
# raise SystemExit(1) # raise SystemExit(1)
rmap[msgstr] = msgid rmap[msgstr] = msgid
@ -730,8 +729,8 @@ class GetTranslations(Translations): # {{{
if changed: if changed:
f.save() f.save()
for slug, languages in iteritems(changes): for slug, languages in iteritems(changes):
print('Pushing fixes for languages: %s in %s' % (', '.join(languages), slug)) print('Pushing fixes for languages: {} in {}'.format(', '.join(languages), slug))
self.tx('push -r calibre.%s -t -l %s' % (slug, ','.join(languages))) self.tx('push -r calibre.{} -t -l {}'.format(slug, ','.join(languages)))
def check_for_errors(self): def check_for_errors(self):
self.info('Checking for errors in .po files...') self.info('Checking for errors in .po files...')
@ -750,8 +749,8 @@ class GetTranslations(Translations): # {{{
languages.add(os.path.basename(parts[-1]).partition('.')[0]) languages.add(os.path.basename(parts[-1]).partition('.')[0])
if languages: if languages:
pot = 'main' if group == 'calibre' else group.replace('-', '_') pot = 'main' if group == 'calibre' else group.replace('-', '_')
print('Pushing fixes for %s.pot languages: %s' % (pot, ', '.join(languages))) print('Pushing fixes for {}.pot languages: {}'.format(pot, ', '.join(languages)))
self.tx('push -r calibre.{} -t -l '.format(pot) + ','.join(languages)) self.tx(f'push -r calibre.{pot} -t -l ' + ','.join(languages))
def check_group(self, group): def check_group(self, group):
files = glob.glob(os.path.join(self.TRANSLATIONS, group, '*.po')) files = glob.glob(os.path.join(self.TRANSLATIONS, group, '*.po'))
@ -769,11 +768,11 @@ class GetTranslations(Translations): # {{{
def check_for_control_chars(f): def check_for_control_chars(f):
with open(f, 'rb') as f: with open(f, 'rb') as f:
raw = f.read().decode('utf-8') raw = f.read().decode('utf-8')
pat = re.compile(type(u'')(r'[\0-\x08\x0b\x0c\x0e-\x1f\x7f\x80-\x9f]')) pat = re.compile(r'[\0-\x08\x0b\x0c\x0e-\x1f\x7f\x80-\x9f]')
errs = [] errs = []
for i, line in enumerate(raw.splitlines()): for i, line in enumerate(raw.splitlines()):
if pat.search(line) is not None: if pat.search(line) is not None:
errs.append('There are ASCII control codes on line number: {}'.format(i + 1)) errs.append(f'There are ASCII control codes on line number: {i + 1}')
return '\n'.join(errs) return '\n'.join(errs)
for f in files: for f in files:
@ -848,7 +847,7 @@ class ISO639(Command): # {{{
m3to2 = {} m3to2 = {}
nm = {} nm = {}
codes2, codes3 = set(), set() codes2, codes3 = set(), set()
unicode_type = type(u'') unicode_type = str
for x in entries: for x in entries:
two = x.get('alpha_2') two = x.get('alpha_2')
if two: if two:
@ -874,9 +873,9 @@ class ISO639(Command): # {{{
base_name = name.lower() base_name = name.lower()
nm[base_name] = threeb nm[base_name] = threeb
x = {u'by_2':by_2, u'by_3':by_3, u'codes2':codes2, x = {'by_2':by_2, 'by_3':by_3, 'codes2':codes2,
u'codes3':codes3, u'2to3':m2to3, 'codes3':codes3, '2to3':m2to3,
u'3to2':m3to2, u'name_map':nm} '3to2':m3to2, 'name_map':nm}
from calibre.utils.serialize import msgpack_dumps from calibre.utils.serialize import msgpack_dumps
with open(dest, 'wb') as f: with open(dest, 'wb') as f:
f.write(msgpack_dumps(x)) f.write(msgpack_dumps(x))
@ -911,7 +910,7 @@ class ISO3166(ISO639): # {{{
codes = set() codes = set()
three_map = {} three_map = {}
name_map = {} name_map = {}
unicode_type = type(u'') unicode_type = str
for x in db['3166-1']: for x in db['3166-1']:
two = x.get('alpha_2') two = x.get('alpha_2')
if two: if two:
@ -923,7 +922,7 @@ class ISO3166(ISO639): # {{{
three = x.get('alpha_3') three = x.get('alpha_3')
if three: if three:
three_map[unicode_type(three)] = two three_map[unicode_type(three)] = two
x = {u'names':name_map, u'codes':frozenset(codes), u'three_map':three_map} x = {'names':name_map, 'codes':frozenset(codes), 'three_map':three_map}
from calibre.utils.serialize import msgpack_dumps from calibre.utils.serialize import msgpack_dumps
with open(dest, 'wb') as f: with open(dest, 'wb') as f:
f.write(msgpack_dumps(x)) f.write(msgpack_dumps(x))

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net> # License: GPLv3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>
@ -119,7 +118,7 @@ def main():
tball = 'macos-64' if ismacos else 'linux-64' tball = 'macos-64' if ismacos else 'linux-64'
download_and_decompress( download_and_decompress(
'https://download.calibre-ebook.com/ci/calibre3/{}.tar.xz'.format(tball), SW f'https://download.calibre-ebook.com/ci/calibre3/{tball}.tar.xz', SW
) )
if not ismacos: if not ismacos:
install_linux_deps() install_linux_deps()
@ -152,7 +151,7 @@ username = api
run_python('setup.py test') run_python('setup.py test')
run_python('setup.py test_rs') run_python('setup.py test_rs')
else: else:
raise SystemExit('Unknown action: {}'.format(action)) raise SystemExit(f'Unknown action: {action}')
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
__license__ = 'GPL v3' __license__ = 'GPL v3'
@ -34,9 +33,9 @@ def installers(include_source=True):
installers.append(installer_name('txz', is64bit=True)) installers.append(installer_name('txz', is64bit=True))
installers.append(installer_name('msi', is64bit=True)) installers.append(installer_name('msi', is64bit=True))
if include_source: if include_source:
installers.insert(0, 'dist/%s-%s.tar.xz' % (__appname__, __version__)) installers.insert(0, f'dist/{__appname__}-{__version__}.tar.xz')
installers.append( installers.append(
'dist/%s-portable-installer-%s.exe' % (__appname__, __version__) f'dist/{__appname__}-portable-installer-{__version__}.exe'
) )
return installers return installers
@ -126,7 +125,7 @@ def get_fosshub_data():
def send_data(loc): def send_data(loc):
subprocess.check_call([ subprocess.check_call([
'rsync', '--inplace', '--delete', '-r', '-zz', '-h', '--info=progress2', '-e', 'rsync', '--inplace', '--delete', '-r', '-zz', '-h', '--info=progress2', '-e',
'ssh -x', loc + '/', '%s@%s:%s' % (STAGING_USER, STAGING_HOST, STAGING_DIR) 'ssh -x', loc + '/', f'{STAGING_USER}@{STAGING_HOST}:{STAGING_DIR}'
]) ])
@ -160,7 +159,7 @@ def calibre_cmdline(ver):
def run_remote_upload(args): def run_remote_upload(args):
print('Running remotely:', ' '.join(args)) print('Running remotely:', ' '.join(args))
subprocess.check_call([ subprocess.check_call([
'ssh', '-x', '%s@%s' % (STAGING_USER, STAGING_HOST), 'cd', STAGING_DIR, '&&', 'ssh', '-x', f'{STAGING_USER}@{STAGING_HOST}', 'cd', STAGING_DIR, '&&',
'python', 'hosting.py' 'python', 'hosting.py'
] + args) ] + args)
@ -185,7 +184,7 @@ def upload_to_fosshub():
if ans.get('error'): if ans.get('error'):
raise SystemExit(ans['error']) raise SystemExit(ans['error'])
if res.getcode() != 200: if res.getcode() != 200:
raise SystemExit('Request to {} failed with response code: {}'.format(path, res.getcode())) raise SystemExit(f'Request to {path} failed with response code: {res.getcode()}')
# from pprint import pprint # from pprint import pprint
# pprint(ans) # pprint(ans)
return ans['status'] if 'status' in ans else ans['data'] return ans['status'] if 'status' in ans else ans['data']
@ -204,7 +203,7 @@ def upload_to_fosshub():
entries = [] entries = []
for fname in files: for fname in files:
desc = installer_description(fname) desc = installer_description(fname)
url = 'https://download.calibre-ebook.com/%s/%s' % ( url = 'https://download.calibre-ebook.com/{}/{}'.format(
__version__, os.path.basename(fname) __version__, os.path.basename(fname)
) )
entries.append({ entries.append({
@ -221,7 +220,7 @@ def upload_to_fosshub():
data = json.dumps(jq) data = json.dumps(jq)
# print(data) # print(data)
data = data.encode('utf-8') data = data.encode('utf-8')
if not request('projects/{}/releases/'.format(project_id), data=data): if not request(f'projects/{project_id}/releases/', data=data):
raise SystemExit('Failed to queue publish job with fosshub') raise SystemExit('Failed to queue publish job with fosshub')
@ -263,7 +262,7 @@ class UploadInstallers(Command): # {{{
def record_sizes(self, sizes): def record_sizes(self, sizes):
print('\nRecording dist sizes') print('\nRecording dist sizes')
args = [ args = [
'%s:%s:%s' % (__version__, fname, size) f'{__version__}:{fname}:{size}'
for fname, size in iteritems(sizes) for fname, size in iteritems(sizes)
] ]
check_call(['ssh', 'code', '/usr/local/bin/dist_sizes'] + args) check_call(['ssh', 'code', '/usr/local/bin/dist_sizes'] + args)
@ -285,7 +284,7 @@ class UploadInstallers(Command): # {{{
with open(os.path.join(tdir, 'fmap'), 'wb') as fo: with open(os.path.join(tdir, 'fmap'), 'wb') as fo:
for f, desc in iteritems(files): for f, desc in iteritems(files):
fo.write(('%s: %s\n' % (f, desc)).encode('utf-8')) fo.write((f'{f}: {desc}\n').encode())
while True: while True:
try: try:
@ -345,7 +344,7 @@ class UploadUserManual(Command): # {{{
for y in os.listdir(x): for y in os.listdir(x):
zf.write(os.path.join(x, y)) zf.write(os.path.join(x, y))
bname = self.b(path) + '_plugin.zip' bname = self.b(path) + '_plugin.zip'
dest = '%s/%s' % (DOWNLOADS, bname) dest = f'{DOWNLOADS}/{bname}'
subprocess.check_call(['scp', f.name, 'main:' + dest]) subprocess.check_call(['scp', f.name, 'main:' + dest])
def run(self, opts): def run(self, opts):
@ -387,7 +386,7 @@ class UploadDemo(Command): # {{{
shell=True shell=True
) )
check_call('scp /tmp/html-demo.zip main:%s/' % (DOWNLOADS, ), shell=True) check_call(f'scp /tmp/html-demo.zip main:{DOWNLOADS}/', shell=True)
# }}} # }}}

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net> # License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
import ctypes.wintypes import ctypes.wintypes
@ -129,7 +128,7 @@ def query_process(cmd, is64bit):
def query_vcvarsall(is64bit=True): def query_vcvarsall(is64bit=True):
plat = 'amd64' if is64bit else 'amd64_x86' plat = 'amd64' if is64bit else 'amd64_x86'
vcvarsall = find_vcvarsall() vcvarsall = find_vcvarsall()
env = query_process('"%s" %s & set' % (vcvarsall, plat), is64bit) env = query_process(f'"{vcvarsall}" {plat} & set', is64bit)
def g(k): def g(k):
try: try:

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net> # License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>