mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
also upgrade code in setup folder
This commit is contained in:
parent
f47f50d359
commit
24c460faec
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
@ -92,7 +91,7 @@ def build_cache_dir():
|
||||
_cache_dir_built = True
|
||||
try:
|
||||
os.mkdir(ans)
|
||||
except EnvironmentError as err:
|
||||
except OSError as err:
|
||||
if err.errno != errno.EEXIST:
|
||||
raise
|
||||
return ans
|
||||
@ -100,7 +99,7 @@ def build_cache_dir():
|
||||
|
||||
def require_git_master(branch='master'):
|
||||
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():
|
||||
@ -225,7 +224,7 @@ class Command:
|
||||
st = time.time()
|
||||
self.running(cmd)
|
||||
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'):
|
||||
self.info('::endgroup::')
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPLv3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
@ -28,7 +27,7 @@ def init_symbol_name(name):
|
||||
|
||||
|
||||
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:
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPL v3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
from datetime import date
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
@ -16,7 +15,7 @@ class Message:
|
||||
self.filename, self.lineno, self.msg = filename, lineno, msg
|
||||
|
||||
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):
|
||||
@ -95,7 +94,7 @@ class Check(Command):
|
||||
try:
|
||||
with open(self.cache_file, 'rb') as f:
|
||||
cache = json.load(f)
|
||||
except EnvironmentError as err:
|
||||
except OSError as err:
|
||||
if err.errno != errno.ENOENT:
|
||||
raise
|
||||
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):
|
||||
try:
|
||||
os.remove(self.cache_file)
|
||||
except EnvironmentError as err:
|
||||
except OSError as err:
|
||||
if err.errno != errno.ENOENT:
|
||||
raise
|
||||
|
||||
@ -129,6 +128,10 @@ class UpgradeSourceCode(Command):
|
||||
|
||||
def run(self, opts):
|
||||
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):
|
||||
q = path.replace(os.sep, '/')
|
||||
if '/metadata/sources/' in q or '/store/stores/' in q:
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPL v3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
import os
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=utf-8
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=utf-8
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=utf-8
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPLv3 Copyright: 2008, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
|
||||
@ -55,7 +54,7 @@ class Bug:
|
||||
print('Working on bug:', summary)
|
||||
if int(bug) > 100000 and action != 'See':
|
||||
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()
|
||||
|
||||
@ -66,7 +65,7 @@ class Bug:
|
||||
'calibre is usually released every alternate Friday.'
|
||||
)
|
||||
action += 'ed'
|
||||
msg = '%s in branch %s. %s' % (action, 'master', suffix)
|
||||
msg = '{} in branch {}. {}'.format(action, 'master', suffix)
|
||||
msg = msg.replace('Fixesed', 'Fixed')
|
||||
msg += '\n\n status fixreleased'
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPLv3 Copyright: 2019, Eli Schwartz <eschwartz@archlinux.org>
|
||||
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
@ -150,7 +149,7 @@ class GitHub(Base): # {{{
|
||||
existing_assets = self.existing_assets(release['id'])
|
||||
for path, desc in self.files.items():
|
||||
self.info('')
|
||||
url = self.API + 'repos/%s/%s/releases/assets/{}' % (
|
||||
url = self.API + 'repos/{}/{}/releases/assets/{{}}'.format(
|
||||
self.username, self.reponame
|
||||
)
|
||||
fname = os.path.basename(path)
|
||||
@ -206,7 +205,7 @@ class GitHub(Base): # {{{
|
||||
|
||||
def do_upload(self, url, path, desc, fname):
|
||||
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:
|
||||
return self.requests.post(
|
||||
url,
|
||||
@ -229,7 +228,7 @@ class GitHub(Base): # {{{
|
||||
return error_code == 'already_exists'
|
||||
|
||||
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
|
||||
)
|
||||
r = self.requests.get(url)
|
||||
@ -238,7 +237,7 @@ class GitHub(Base): # {{{
|
||||
return {asset['name']: asset['id'] for asset in r.json()}
|
||||
|
||||
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)
|
||||
if r.status_code != 200:
|
||||
self.fail(r, 'Failed to list releases')
|
||||
@ -250,7 +249,7 @@ class GitHub(Base): # {{{
|
||||
# Check for existing release
|
||||
if release['tag_name'] == self.current_tag_name:
|
||||
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(
|
||||
url,
|
||||
data=json.dumps({
|
||||
@ -275,7 +274,7 @@ def generate_index(): # {{{
|
||||
releases = set()
|
||||
for x in os.listdir('.'):
|
||||
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()
|
||||
for rnum in sorted(releases, reverse=True):
|
||||
series = rnum[:2] if rnum[0] == 0 else rnum[:1]
|
||||
@ -301,10 +300,10 @@ def generate_index(): # {{{
|
||||
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>'
|
||||
.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(
|
||||
title='Previous calibre releases',
|
||||
style=style,
|
||||
@ -315,13 +314,13 @@ def generate_index(): # {{{
|
||||
f.write(index.encode('utf-8'))
|
||||
|
||||
for series, releases in rmap.items():
|
||||
sname = '.'.join(map(type(''), series))
|
||||
sname = '.'.join(map(str, series))
|
||||
body = [
|
||||
'<li><a href="{0}/" title="Release {0}">{0}</a></li>'.format(
|
||||
'.'.join(map(type(''), r))
|
||||
'.'.join(map(str, r))
|
||||
) 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(
|
||||
title='Previous calibre releases (%s.x)' % sname,
|
||||
style=style,
|
||||
@ -332,7 +331,7 @@ def generate_index(): # {{{
|
||||
f.write(index.encode('utf-8'))
|
||||
|
||||
for r in releases:
|
||||
rname = '.'.join(map(type(''), r))
|
||||
rname = '.'.join(map(str, r))
|
||||
os.chdir(rname)
|
||||
try:
|
||||
body = []
|
||||
@ -346,7 +345,7 @@ def generate_index(): # {{{
|
||||
) for x in windows
|
||||
]
|
||||
body.append(
|
||||
'<dt>Windows</dt><dd><ul>{0}</ul></dd>'.format(
|
||||
'<dt>Windows</dt><dd><ul>{}</ul></dd>'.format(
|
||||
' '.join(windows)
|
||||
)
|
||||
)
|
||||
@ -373,7 +372,7 @@ def generate_index(): # {{{
|
||||
) for x in linux
|
||||
]
|
||||
body.append(
|
||||
'<dt>Linux</dt><dd><ul>{0}</ul></dd>'.format(
|
||||
'<dt>Linux</dt><dd><ul>{}</ul></dd>'.format(
|
||||
' '.join(linux)
|
||||
)
|
||||
)
|
||||
@ -384,7 +383,7 @@ def generate_index(): # {{{
|
||||
.format(source[0], 'Source code (all platforms)')
|
||||
)
|
||||
|
||||
body = '<dl>{0}</dl>'.format(''.join(body))
|
||||
body = '<dl>{}</dl>'.format(''.join(body))
|
||||
index = template.format(
|
||||
title='calibre release (%s)' % rname,
|
||||
style=style,
|
||||
|
@ -1,7 +1,5 @@
|
||||
#!/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>
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
|
||||
import glob
|
||||
import hashlib
|
||||
@ -100,7 +98,7 @@ class Hyphenation(ReVendor):
|
||||
for dic in dics:
|
||||
with open(os.path.join(output_dir, dic), 'rb') as f:
|
||||
m.update(f.read())
|
||||
hsh = type('')(m.hexdigest())
|
||||
hsh = str(m.hexdigest())
|
||||
buf = BytesIO()
|
||||
with tarfile.TarFile(fileobj=buf, mode='w') as tf:
|
||||
for dic in dics:
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/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>
|
||||
|
||||
|
||||
@ -163,7 +162,7 @@ class Develop(Command):
|
||||
try:
|
||||
if not os.path.exists(libdir):
|
||||
os.makedirs(libdir)
|
||||
except EnvironmentError:
|
||||
except OSError:
|
||||
self.warn('Cannot install calibre environment module to: '+libdir)
|
||||
else:
|
||||
path = os.path.join(libdir, 'init_calibre.py')
|
||||
@ -367,7 +366,7 @@ class Bootstrap(Command):
|
||||
def pre_sub_commands(self, opts):
|
||||
tdir = self.j(self.d(self.SRC), 'translations')
|
||||
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 os.path.exists(tdir):
|
||||
shutil.rmtree(tdir)
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=utf-8
|
||||
# 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)
|
||||
try:
|
||||
os.remove(dest)
|
||||
except EnvironmentError:
|
||||
except OSError:
|
||||
pass
|
||||
os.link(src, dest)
|
||||
if shutdown:
|
||||
@ -248,9 +247,9 @@ class ExtDev(Command):
|
||||
try:
|
||||
path = path.format(ext)
|
||||
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:
|
||||
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())
|
||||
if p.wait() != 0:
|
||||
raise SystemExit(1)
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python3
|
||||
# vim:fileencoding=utf-8
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
@ -1,7 +1,5 @@
|
||||
#!/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>
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
|
||||
import glob
|
||||
import os
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=utf-8
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
@ -1,7 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPLv3 Copyright: 2013, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
|
||||
|
||||
# Imports {{{
|
||||
@ -128,7 +126,7 @@ def parse_index(raw=None): # {{{
|
||||
|
||||
thread_id = url_to_plugin_id(url, deprecated)
|
||||
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
|
||||
entry = IndexEntry(name, url, donate, history, uninstall, deprecated, thread_id)
|
||||
yield entry
|
||||
@ -147,7 +145,7 @@ def load_plugins_index():
|
||||
try:
|
||||
with open(PLUGINS, 'rb') as f:
|
||||
raw = f.read()
|
||||
except IOError as err:
|
||||
except OSError as err:
|
||||
if err.errno == errno.ENOENT:
|
||||
return {}
|
||||
raise
|
||||
@ -173,13 +171,13 @@ def convert_node(fields, x, names={}, import_data=None):
|
||||
return dict(zip(keys, values))
|
||||
elif name == 'Call':
|
||||
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]
|
||||
elif name == 'Name':
|
||||
if x.id not in names:
|
||||
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:])
|
||||
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]
|
||||
elif name == 'BinOp':
|
||||
if x.right.__class__.__name__ == 'Str':
|
||||
@ -188,7 +186,7 @@ def convert_node(fields, x, names={}, import_data=None):
|
||||
return x.right.value
|
||||
elif name == 'Attribute':
|
||||
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')
|
||||
@ -221,7 +219,7 @@ def get_import_data(name, mod, zf, names):
|
||||
return convert_node({x}, node.value)
|
||||
if is_module_import:
|
||||
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:
|
||||
raise ValueError('Failed to find module: %r' % mod)
|
||||
|
||||
@ -457,7 +455,7 @@ def fetch_plugins(old_index):
|
||||
|
||||
|
||||
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']))
|
||||
released = datetime(*tuple(map(int, re.split(r'\D', plugin['last_modified'])))[:6]).strftime('%e %b, %Y').lstrip()
|
||||
details = [
|
||||
@ -478,12 +476,12 @@ def plugin_to_index(plugin, count):
|
||||
block.append('<li>%s</li>' % li)
|
||||
block = '<ul>%s</ul>' % ('\n'.join(block))
|
||||
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)
|
||||
desc = plugin['description'] or ''
|
||||
if 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):
|
||||
@ -526,14 +524,14 @@ h1 { text-align: center }
|
||||
try:
|
||||
with open('index.html', 'rb') as f:
|
||||
oraw = f.read()
|
||||
except EnvironmentError:
|
||||
except OSError:
|
||||
oraw = None
|
||||
if raw != oraw:
|
||||
atomic_write(raw, 'index.html')
|
||||
|
||||
def plugin_stats(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])))
|
||||
stats = '''\
|
||||
@ -560,7 +558,7 @@ h1 { text-align: center }
|
||||
try:
|
||||
with open('stats.html', 'rb') as f:
|
||||
oraw = f.read()
|
||||
except EnvironmentError:
|
||||
except OSError:
|
||||
oraw = None
|
||||
if raw != oraw:
|
||||
atomic_write(raw, 'stats.html')
|
||||
@ -574,7 +572,7 @@ def singleinstance():
|
||||
s = _singleinstance = socket.socket(socket.AF_UNIX)
|
||||
try:
|
||||
s.bind(b'\0calibre-plugins-mirror-singleinstance')
|
||||
except socket.error as err:
|
||||
except OSError as err:
|
||||
if getattr(err, 'errno', None) == errno.EADDRINUSE:
|
||||
return False
|
||||
raise
|
||||
@ -590,7 +588,7 @@ def update_stats():
|
||||
try:
|
||||
with open('stats.json', 'rb') as f:
|
||||
stats = json.load(f)
|
||||
except EnvironmentError as err:
|
||||
except OSError as err:
|
||||
if err.errno != errno.ENOENT:
|
||||
raise
|
||||
if os.geteuid() != 0:
|
||||
@ -688,7 +686,7 @@ def test_parse(): # {{{
|
||||
new_entries = tuple(parse_index(raw))
|
||||
for i, entry in enumerate(old_entries):
|
||||
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)
|
||||
pool = ThreadPool(processes=20)
|
||||
urls = [e.url for e in new_entries]
|
||||
@ -705,7 +703,7 @@ def test_parse(): # {{{
|
||||
break
|
||||
new_url, aname = parse_plugin_zip_url(raw)
|
||||
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)
|
||||
|
||||
# }}}
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
@ -225,7 +224,7 @@ class Manual(Command):
|
||||
orig = self.j(self.d(base), r)
|
||||
try:
|
||||
sz = os.stat(orig).st_size
|
||||
except EnvironmentError:
|
||||
except OSError:
|
||||
continue
|
||||
if sz == os.stat(f).st_size and filecmp._do_cmp(f, orig):
|
||||
os.remove(f)
|
||||
@ -260,7 +259,7 @@ class ManPages(Command):
|
||||
os.environ['ALL_USER_MANUAL_LANGUAGES'] = ' '.join(languages)
|
||||
try:
|
||||
os.makedirs(dest)
|
||||
except EnvironmentError:
|
||||
except OSError:
|
||||
pass
|
||||
jobs = []
|
||||
for l in languages:
|
||||
@ -268,7 +267,7 @@ class ManPages(Command):
|
||||
[sys.executable, self.j(base, 'build.py'), '--man-pages', l, dest],
|
||||
'\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)
|
||||
if not parallel_build(jobs[1:], self.info, verbose=False):
|
||||
raise SystemExit(1)
|
||||
@ -307,4 +306,4 @@ class TagRelease(Command):
|
||||
subprocess.check_call(
|
||||
'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())
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||
|
||||
|
||||
__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 do_opt(opt):
|
||||
for x in opt._long_opts:
|
||||
yield x
|
||||
for x in opt._short_opts:
|
||||
yield x
|
||||
yield from opt._long_opts
|
||||
yield from opt._short_opts
|
||||
for o in parser.option_list:
|
||||
for x in do_opt(o):
|
||||
yield x
|
||||
yield from do_opt(o)
|
||||
for g in parser.option_groups:
|
||||
for o in g.option_list:
|
||||
for x in do_opt(o):
|
||||
yield x
|
||||
yield from do_opt(o)
|
||||
|
||||
|
||||
class Kakasi(Command): # {{{
|
||||
@ -145,7 +140,7 @@ class CACerts(Command): # {{{
|
||||
try:
|
||||
with open(self.CA_PATH, 'rb') as f:
|
||||
raw = f.read()
|
||||
except EnvironmentError as err:
|
||||
except OSError as err:
|
||||
if err.errno != errno.ENOENT:
|
||||
raise
|
||||
raw = b''
|
||||
@ -298,7 +293,7 @@ class Resources(Command): # {{{
|
||||
except Exception:
|
||||
continue
|
||||
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:
|
||||
src = '\n'.join(imports) + '\n\n' + src
|
||||
function_dict[func.name] = src
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPL v3 Copyright: 2019, Eli Schwartz <eschwartz@archlinux.org>
|
||||
|
||||
import os
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
@ -108,7 +107,7 @@ class POT(Command): # {{{
|
||||
for x in sorted(entries, key=lambda x:name_getter(x).lower()):
|
||||
name = name_getter(x)
|
||||
if name:
|
||||
ans.append(u'msgid "{}"'.format(name))
|
||||
ans.append(f'msgid "{name}"')
|
||||
ans.append('msgstr ""')
|
||||
ans.append('')
|
||||
pot = self.pot_header() + '\n\n' + '\n'.join(ans)
|
||||
@ -278,7 +277,7 @@ class Translations(POT): # {{{
|
||||
self.cache_dir_created = True
|
||||
try:
|
||||
os.mkdir(ans)
|
||||
except EnvironmentError as err:
|
||||
except OSError as err:
|
||||
if err.errno != errno.EEXIST:
|
||||
raise
|
||||
return ans
|
||||
@ -293,7 +292,7 @@ class Translations(POT): # {{{
|
||||
with open(self.j(self.cache_dir, cname), 'rb') as f:
|
||||
data = f.read()
|
||||
return data[:20], data[20:]
|
||||
except EnvironmentError as err:
|
||||
except OSError as err:
|
||||
if err.errno != errno.ENOENT:
|
||||
raise
|
||||
return None, None
|
||||
@ -387,7 +386,7 @@ class Translations(POT): # {{{
|
||||
self.bad.add(msgstr)
|
||||
return match.group()
|
||||
self.seen.add(self.msgid)
|
||||
return 'msgstr "{}"'.format(self.msgid)
|
||||
return f'msgstr "{self.msgid}"'
|
||||
self.seen.add(msgstr)
|
||||
return match.group()
|
||||
|
||||
@ -405,7 +404,7 @@ class Translations(POT): # {{{
|
||||
if msgstr:
|
||||
if msgstr and msgstr in self.bad:
|
||||
self.bad.discard(msgstr)
|
||||
return 'msgstr "{}"'.format(self.msgid)
|
||||
return f'msgstr "{self.msgid}"'
|
||||
return match.group()
|
||||
|
||||
for (po_path, mo_path) in files:
|
||||
@ -475,7 +474,7 @@ class Translations(POT): # {{{
|
||||
base = self.d(dest)
|
||||
try:
|
||||
os.mkdir(base)
|
||||
except EnvironmentError as err:
|
||||
except OSError as err:
|
||||
if err.errno != errno.EEXIST:
|
||||
raise
|
||||
from calibre.utils.serialize import msgpack_dumps
|
||||
@ -506,12 +505,12 @@ class Translations(POT): # {{{
|
||||
po_data = data.decode('utf-8')
|
||||
data = json.loads(msgfmt(po_data))
|
||||
translated_entries = {k:v for k, v in iteritems(data['entries']) if v and sum(map(len, v))}
|
||||
data[u'entries'] = translated_entries
|
||||
data[u'hash'] = h.hexdigest()
|
||||
data['entries'] = translated_entries
|
||||
data['hash'] = h.hexdigest()
|
||||
cdata = b'{}'
|
||||
if translated_entries:
|
||||
raw = json.dumps(data, ensure_ascii=False, sort_keys=True)
|
||||
if isinstance(raw, type(u'')):
|
||||
if isinstance(raw, str):
|
||||
raw = raw.encode('utf-8')
|
||||
cdata = raw
|
||||
self.write_cache(cdata, current_hash, src)
|
||||
@ -539,7 +538,7 @@ class Translations(POT): # {{{
|
||||
cm = langnames_to_langcodes([omsgid, msgid])
|
||||
if cm[msgid] and cm[omsgid] and cm[msgid] != cm[omsgid]:
|
||||
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]))
|
||||
# raise SystemExit(1)
|
||||
rmap[msgstr] = msgid
|
||||
@ -730,8 +729,8 @@ class GetTranslations(Translations): # {{{
|
||||
if changed:
|
||||
f.save()
|
||||
for slug, languages in iteritems(changes):
|
||||
print('Pushing fixes for languages: %s in %s' % (', '.join(languages), slug))
|
||||
self.tx('push -r calibre.%s -t -l %s' % (slug, ','.join(languages)))
|
||||
print('Pushing fixes for languages: {} in {}'.format(', '.join(languages), slug))
|
||||
self.tx('push -r calibre.{} -t -l {}'.format(slug, ','.join(languages)))
|
||||
|
||||
def check_for_errors(self):
|
||||
self.info('Checking for errors in .po files...')
|
||||
@ -750,8 +749,8 @@ class GetTranslations(Translations): # {{{
|
||||
languages.add(os.path.basename(parts[-1]).partition('.')[0])
|
||||
if languages:
|
||||
pot = 'main' if group == 'calibre' else group.replace('-', '_')
|
||||
print('Pushing fixes for %s.pot languages: %s' % (pot, ', '.join(languages)))
|
||||
self.tx('push -r calibre.{} -t -l '.format(pot) + ','.join(languages))
|
||||
print('Pushing fixes for {}.pot languages: {}'.format(pot, ', '.join(languages)))
|
||||
self.tx(f'push -r calibre.{pot} -t -l ' + ','.join(languages))
|
||||
|
||||
def check_group(self, group):
|
||||
files = glob.glob(os.path.join(self.TRANSLATIONS, group, '*.po'))
|
||||
@ -769,11 +768,11 @@ class GetTranslations(Translations): # {{{
|
||||
def check_for_control_chars(f):
|
||||
with open(f, 'rb') as f:
|
||||
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 = []
|
||||
for i, line in enumerate(raw.splitlines()):
|
||||
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)
|
||||
|
||||
for f in files:
|
||||
@ -848,7 +847,7 @@ class ISO639(Command): # {{{
|
||||
m3to2 = {}
|
||||
nm = {}
|
||||
codes2, codes3 = set(), set()
|
||||
unicode_type = type(u'')
|
||||
unicode_type = str
|
||||
for x in entries:
|
||||
two = x.get('alpha_2')
|
||||
if two:
|
||||
@ -874,9 +873,9 @@ class ISO639(Command): # {{{
|
||||
base_name = name.lower()
|
||||
nm[base_name] = threeb
|
||||
|
||||
x = {u'by_2':by_2, u'by_3':by_3, u'codes2':codes2,
|
||||
u'codes3':codes3, u'2to3':m2to3,
|
||||
u'3to2':m3to2, u'name_map':nm}
|
||||
x = {'by_2':by_2, 'by_3':by_3, 'codes2':codes2,
|
||||
'codes3':codes3, '2to3':m2to3,
|
||||
'3to2':m3to2, 'name_map':nm}
|
||||
from calibre.utils.serialize import msgpack_dumps
|
||||
with open(dest, 'wb') as f:
|
||||
f.write(msgpack_dumps(x))
|
||||
@ -911,7 +910,7 @@ class ISO3166(ISO639): # {{{
|
||||
codes = set()
|
||||
three_map = {}
|
||||
name_map = {}
|
||||
unicode_type = type(u'')
|
||||
unicode_type = str
|
||||
for x in db['3166-1']:
|
||||
two = x.get('alpha_2')
|
||||
if two:
|
||||
@ -923,7 +922,7 @@ class ISO3166(ISO639): # {{{
|
||||
three = x.get('alpha_3')
|
||||
if three:
|
||||
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
|
||||
with open(dest, 'wb') as f:
|
||||
f.write(msgpack_dumps(x))
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPLv3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
|
||||
@ -119,7 +118,7 @@ def main():
|
||||
|
||||
tball = 'macos-64' if ismacos else 'linux-64'
|
||||
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:
|
||||
install_linux_deps()
|
||||
@ -152,7 +151,7 @@ username = api
|
||||
run_python('setup.py test')
|
||||
run_python('setup.py test_rs')
|
||||
else:
|
||||
raise SystemExit('Unknown action: {}'.format(action))
|
||||
raise SystemExit(f'Unknown action: {action}')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
@ -34,9 +33,9 @@ def installers(include_source=True):
|
||||
installers.append(installer_name('txz', is64bit=True))
|
||||
installers.append(installer_name('msi', is64bit=True))
|
||||
if include_source:
|
||||
installers.insert(0, 'dist/%s-%s.tar.xz' % (__appname__, __version__))
|
||||
installers.insert(0, f'dist/{__appname__}-{__version__}.tar.xz')
|
||||
installers.append(
|
||||
'dist/%s-portable-installer-%s.exe' % (__appname__, __version__)
|
||||
f'dist/{__appname__}-portable-installer-{__version__}.exe'
|
||||
)
|
||||
return installers
|
||||
|
||||
@ -126,7 +125,7 @@ def get_fosshub_data():
|
||||
def send_data(loc):
|
||||
subprocess.check_call([
|
||||
'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):
|
||||
print('Running remotely:', ' '.join(args))
|
||||
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'
|
||||
] + args)
|
||||
|
||||
@ -185,7 +184,7 @@ def upload_to_fosshub():
|
||||
if ans.get('error'):
|
||||
raise SystemExit(ans['error'])
|
||||
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
|
||||
# pprint(ans)
|
||||
return ans['status'] if 'status' in ans else ans['data']
|
||||
@ -204,7 +203,7 @@ def upload_to_fosshub():
|
||||
entries = []
|
||||
for fname in files:
|
||||
desc = installer_description(fname)
|
||||
url = 'https://download.calibre-ebook.com/%s/%s' % (
|
||||
url = 'https://download.calibre-ebook.com/{}/{}'.format(
|
||||
__version__, os.path.basename(fname)
|
||||
)
|
||||
entries.append({
|
||||
@ -221,7 +220,7 @@ def upload_to_fosshub():
|
||||
data = json.dumps(jq)
|
||||
# print(data)
|
||||
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')
|
||||
|
||||
|
||||
@ -263,7 +262,7 @@ class UploadInstallers(Command): # {{{
|
||||
def record_sizes(self, sizes):
|
||||
print('\nRecording dist sizes')
|
||||
args = [
|
||||
'%s:%s:%s' % (__version__, fname, size)
|
||||
f'{__version__}:{fname}:{size}'
|
||||
for fname, size in iteritems(sizes)
|
||||
]
|
||||
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:
|
||||
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:
|
||||
try:
|
||||
@ -345,7 +344,7 @@ class UploadUserManual(Command): # {{{
|
||||
for y in os.listdir(x):
|
||||
zf.write(os.path.join(x, y))
|
||||
bname = self.b(path) + '_plugin.zip'
|
||||
dest = '%s/%s' % (DOWNLOADS, bname)
|
||||
dest = f'{DOWNLOADS}/{bname}'
|
||||
subprocess.check_call(['scp', f.name, 'main:' + dest])
|
||||
|
||||
def run(self, opts):
|
||||
@ -387,7 +386,7 @@ class UploadDemo(Command): # {{{
|
||||
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)
|
||||
|
||||
|
||||
# }}}
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
import ctypes.wintypes
|
||||
@ -129,7 +128,7 @@ def query_process(cmd, is64bit):
|
||||
def query_vcvarsall(is64bit=True):
|
||||
plat = 'amd64' if is64bit else 'amd64_x86'
|
||||
vcvarsall = find_vcvarsall()
|
||||
env = query_process('"%s" %s & set' % (vcvarsall, plat), is64bit)
|
||||
env = query_process(f'"{vcvarsall}" {plat} & set', is64bit)
|
||||
|
||||
def g(k):
|
||||
try:
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user