mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Collect stats on how many plugins have been ported to Qt 5
This commit is contained in:
parent
aa4a24f2f0
commit
9289d6a4eb
@ -229,7 +229,18 @@ def parse_metadata(raw, namelist, zf):
|
|||||||
|
|
||||||
raise ValueError('Could not find plugin class')
|
raise ValueError('Could not find plugin class')
|
||||||
|
|
||||||
def get_plugin_info(raw):
|
def check_qt5_compatibility(zf, names):
|
||||||
|
uses_qt = False
|
||||||
|
for name in names:
|
||||||
|
if name.endswith('.py'):
|
||||||
|
raw = zf.read(name)
|
||||||
|
has_qt4 = b'PyQt4' in raw
|
||||||
|
uses_qt = uses_qt or has_qt4
|
||||||
|
if uses_qt and has_qt4 and b'PyQt5' not in raw:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
def get_plugin_info(raw, check_for_qt5=False):
|
||||||
metadata = None
|
metadata = None
|
||||||
with zipfile.ZipFile(io.BytesIO(raw)) as zf:
|
with zipfile.ZipFile(io.BytesIO(raw)) as zf:
|
||||||
names = {x.decode('utf-8') if isinstance(x, bytes) else x : x for x in zf.namelist()}
|
names = {x.decode('utf-8') if isinstance(x, bytes) else x : x for x in zf.namelist()}
|
||||||
@ -248,6 +259,8 @@ def get_plugin_info(raw):
|
|||||||
raw = zf.open(metadata).read()
|
raw = zf.open(metadata).read()
|
||||||
ans = parse_metadata(raw, names, zf)
|
ans = parse_metadata(raw, names, zf)
|
||||||
if isinstance(ans, dict):
|
if isinstance(ans, dict):
|
||||||
|
if check_for_qt5:
|
||||||
|
ans['qt5'] = check_qt5_compatibility(zf, names)
|
||||||
return ans
|
return ans
|
||||||
# The plugin is importing its base class from somewhere else, le sigh
|
# The plugin is importing its base class from somewhere else, le sigh
|
||||||
for mod, _ in ans:
|
for mod, _ in ans:
|
||||||
@ -259,6 +272,8 @@ def get_plugin_info(raw):
|
|||||||
raw = zf.open(names[mod]).read()
|
raw = zf.open(names[mod]).read()
|
||||||
ans = parse_metadata(raw, names, zf)
|
ans = parse_metadata(raw, names, zf)
|
||||||
if isinstance(ans, dict):
|
if isinstance(ans, dict):
|
||||||
|
if check_for_qt5:
|
||||||
|
ans['qt5'] = check_qt5_compatibility(zf, names)
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
raise ValueError('Failed to find plugin class')
|
raise ValueError('Failed to find plugin class')
|
||||||
@ -498,6 +513,43 @@ def update_stats():
|
|||||||
json.dump(stats, f, indent=2)
|
json.dump(stats, f, indent=2)
|
||||||
return stats
|
return stats
|
||||||
|
|
||||||
|
def check_for_qt5_incompatibility():
|
||||||
|
ok_plugins, bad_plugins = [], []
|
||||||
|
for name in os.listdir('.'):
|
||||||
|
if name.endswith('.zip') and not name.endswith('-deprecated.zip'):
|
||||||
|
with open(name, 'rb') as f:
|
||||||
|
info = get_plugin_info(f.read(), check_for_qt5=True)
|
||||||
|
if info['qt5']:
|
||||||
|
ok_plugins.append(info)
|
||||||
|
else:
|
||||||
|
bad_plugins.append(info)
|
||||||
|
plugs = ['<li>%s</li>' % x['name'] for x in bad_plugins]
|
||||||
|
stats = '''
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head><meta charset="utf-8"><title>Stats for porting of calibre plugins to Qt 5</title>
|
||||||
|
<link rel="icon" type="image/x-icon" href="http://calibre-ebook.com/favicon.ico" />
|
||||||
|
<style type="text/css">
|
||||||
|
body { background-color: #eee; }
|
||||||
|
h1 img, h3 img { vertical-align: middle; margin-right: 0.5em; }
|
||||||
|
h1 { text-align: center }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1><img src="http://manual.calibre-ebook.com/_static/logo.png">Stats for porting of calibre plugins to Qt 5</h1>
|
||||||
|
<p>Number of Qt 5 compatible plugins: %s<br>Number of Qt 5 incompatible plugins: %s<br>Percentage of plugins ported: %.0f%%</p>
|
||||||
|
<h2>Plugins still to be ported</h2>
|
||||||
|
<ul>
|
||||||
|
%s
|
||||||
|
</ul>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
''' % (len(ok_plugins), len(bad_plugins), len(ok_plugins)/(len(ok_plugins) + len(bad_plugins)) * 100,
|
||||||
|
'\n'.join(sorted(plugs, key=lambda x:x.lower())))
|
||||||
|
with open('porting.html', 'wb') as f:
|
||||||
|
f.write(stats.encode('utf-8'))
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
os.chdir(WORKDIR)
|
os.chdir(WORKDIR)
|
||||||
@ -519,6 +571,7 @@ def main():
|
|||||||
plugins_index = load_plugins_index()
|
plugins_index = load_plugins_index()
|
||||||
plugins_index = fetch_plugins(plugins_index)
|
plugins_index = fetch_plugins(plugins_index)
|
||||||
create_index(plugins_index, stats)
|
create_index(plugins_index, stats)
|
||||||
|
check_for_qt5_incompatibility()
|
||||||
except:
|
except:
|
||||||
import traceback
|
import traceback
|
||||||
log('Failed to run at:', datetime.utcnow().isoformat())
|
log('Failed to run at:', datetime.utcnow().isoformat())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user