1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2026-04-11 07:33:35 +02:00

Removed prints and extract function from init module

This commit is contained in:
2020-07-13 21:38:06 +02:00
parent 025878dfe5
commit 4216fef20e
20 changed files with 97 additions and 336 deletions

View File

@@ -2,7 +2,7 @@ import os
from collections import defaultdict
from threading import Thread
from ebook_converter import walk, prints
from ebook_converter import walk
from ebook_converter.constants_old import isosx
from ebook_converter.constants_old import plugins, DEBUG
from ebook_converter.constants_old import filesystem_encoding
@@ -67,7 +67,7 @@ def fc_list():
try:
ans.append(d.decode(filesystem_encoding))
except ValueError:
prints('Ignoring undecodeable font path: %r' % d)
print(f'Ignoring undecodeable font path: {d}')
continue
end(str_list)
if len(ans) < 3:
@@ -309,7 +309,7 @@ class FontScanner(Thread):
files = tuple(walk(folder))
except EnvironmentError as e:
if DEBUG:
prints('Failed to walk font folder:', folder, str(e))
print(f'Failed to walk font folder: {folder}, {e}')
continue
for candidate in files:
if (candidate.rpartition('.')[-1].lower() not in
@@ -332,8 +332,8 @@ class FontScanner(Thread):
self.read_font_metadata(candidate, fileid)
except Exception as e:
if DEBUG:
prints('Failed to read metadata from font file:',
candidate, str(e))
print(f'Failed to read metadata from font file '
f'{candidate}: {e}')
continue
if frozenset(cached_fonts) != frozenset(self.cached_fonts):
@@ -369,18 +369,18 @@ class FontScanner(Thread):
def dump_fonts(self):
self.join()
for family in self.font_families:
prints(family)
print(family)
for font in self.fonts_for_family(family):
prints('\t%s: %s' % (font['full_name'], font['path']))
prints(end='\t')
print('\t%s: %s' % (font['full_name'], font['path']))
print(end='\t')
for key in ('font-stretch', 'font-weight', 'font-style'):
prints('%s: %s' % (key, font[key]), end=' ')
prints()
prints('\tSub-family:', font['wws_subfamily_name'] or
font['preferred_subfamily_name'] or
font['subfamily_name'])
prints()
prints()
print('%s: %s' % (key, font[key]))
print()
print('\tSub-family: %s' % (font['wws_subfamily_name'] or
font['preferred_subfamily_name']
or font['subfamily_name']))
print()
print()
font_scanner = FontScanner()

View File

@@ -204,15 +204,13 @@ def option_parser():
def print_stats(old_stats, new_stats):
from ebook_converter import prints
prints('========= Table comparison (original vs. subset) =========')
prints('Table', ' ', '%10s'%'Size', ' ', 'Percent', ' ', '%10s'%'New Size',
' New Percent')
prints('='*80)
print('========= Table comparison (original vs. subset) =========')
print('Table Size Percent New Size New Percent')
print('='*80)
old_total = sum(old_stats.values())
new_total = sum(new_stats.values())
tables = sorted(old_stats, key=lambda x:old_stats[x],
reverse=True)
tables = sorted(old_stats, key=lambda x: old_stats[x],
reverse=True)
for table in tables:
osz = old_stats[table]
op = osz/old_total * 100
@@ -220,15 +218,14 @@ def print_stats(old_stats, new_stats):
np = nsz/new_total * 100
suffix = ' | same size'
if nsz != osz:
suffix = ' | reduced to %.1f %%'%(nsz/osz * 100)
prints('%4s'%table, ' ', '%10s'%osz, ' ', '%5.1f %%'%op, ' ',
'%10s'%nsz, ' ', '%5.1f %%'%np, suffix)
prints('='*80)
suffix = ' | reduced to %.1f %%' % (nsz/osz * 100)
print('%4s %10s %5.1f %% %10s %5.1f %% %s' %
(table, osz, op, nsz, np, suffix))
print('='*80)
def main(args):
import sys, time
from ebook_converter import prints
parser = option_parser()
opts, args = parser.parse_args(args)
if len(args) < 4 or len(args) > 4:
@@ -243,7 +240,7 @@ def main(args):
def not_single(c):
if len(c) > 1:
prints(c, 'is not a single character', file=sys.stderr)
print(f'{c}is not a single character')
raise SystemExit(1)
def conv_code(c):
@@ -255,7 +252,7 @@ def main(args):
if '-' in c:
parts = [x.strip() for x in c.split('-')]
if len(parts) != 2:
prints('Invalid range:', c, file=sys.stderr)
print(f'Invalid range: {c}')
raise SystemExit(1)
if opts.codes:
parts = tuple(map(conv_code, parts))
@@ -272,13 +269,14 @@ def main(args):
reduced = (len(sf)/len(orig)) * 100
def sz(x):
return '%gKB'%(len(x)/1024.)
return '%gKB' % (len(x)/1024.)
print_stats(old_stats, new_stats)
prints('Original size:', sz(orig), 'Subset size:', sz(sf), 'Reduced to: %g%%'%(reduced))
prints('Subsetting took %g seconds'%taken)
print('Original size:', sz(orig), 'Subset size:', sz(sf),
'Reduced to: %g%%' % (reduced))
print('Subsetting took %g seconds' % taken)
with open(off, 'wb') as f:
f.write(sf)
prints('Subset font written to:', off)
print('Subset font written to:', off)
if __name__ == '__main__':