def generate_ebook_convert_help(preamble, app): from calibre.ebooks.conversion.cli import create_option_parser, manual_index_strings from calibre.customize.ui import input_format_plugins, output_format_plugins from calibre.utils.logging import default_log preamble = re.sub(r'http.*\.html', ':ref:`conversion`', preamble) raw = preamble + '\n\n' + manual_index_strings() % 'ebook-convert myfile.input_format myfile.output_format -h' parser, plumber = create_option_parser(['ebook-convert', 'dummyi.mobi', 'dummyo.epub', '-h'], default_log) groups = [(None, None, parser.option_list)] for grp in parser.option_groups: if grp.title not in {'INPUT OPTIONS', 'OUTPUT OPTIONS'}: groups.append((titlecase(app, grp.title), grp.description, grp.option_list)) options = '\n'.join(render_options('ebook-convert', groups, False)) raw += '\n\n.. contents::\n :local:' raw += '\n\n' + options for pl in sorted(input_format_plugins(), key=lambda x: x.name): parser, plumber = create_option_parser(['ebook-convert', 'dummyi.'+sorted(pl.file_types)[0], 'dummyo.epub', '-h'], default_log) groups = [(pl.name+ ' Options', '', g.option_list) for g in parser.option_groups if g.title == "INPUT OPTIONS"] prog = 'ebook-convert-'+(pl.name.lower().replace(' ', '-')) raw += '\n\n' + '\n'.join(render_options(prog, groups, False, True)) for pl in sorted(output_format_plugins(), key=lambda x: x.name): parser, plumber = create_option_parser(['ebook-convert', 'd.epub', 'dummyi.'+pl.file_type, '-h'], default_log) groups = [(pl.name+ ' Options', '', g.option_list) for g in parser.option_groups if g.title == "OUTPUT OPTIONS"] prog = 'ebook-convert-'+(pl.name.lower().replace(' ', '-')) raw += '\n\n' + '\n'.join(render_options(prog, groups, False, True)) update_cli_doc('ebook-convert', raw, app)
def generate_ebook_convert_help(preamble, app): from calibre.ebooks.conversion.cli import create_option_parser, manual_index_strings from calibre.customize.ui import input_format_plugins, output_format_plugins from calibre.utils.logging import default_log preamble = re.sub(r'http.*\.html', ':ref:`conversion`', preamble) raw = preamble + '\n\n' + manual_index_strings() % 'ebook-convert myfile.input_format myfile.output_format -h' parser, plumber = create_option_parser(['ebook-convert', 'dummyi.mobi', 'dummyo.epub', '-h'], default_log) groups = [(None, None, parser.option_list)] for grp in parser.option_groups: if grp.title not in {'INPUT OPTIONS', 'OUTPUT OPTIONS'}: groups.append((grp.title.title(), grp.description, grp.option_list)) options = '\n'.join(render_options('ebook-convert', groups, False)) raw += '\n\n.. contents::\n :local:' raw += '\n\n' + options for pl in sorted(input_format_plugins(), key=lambda x:x.name): parser, plumber = create_option_parser(['ebook-convert', 'dummyi.'+list(pl.file_types)[0], 'dummyo.epub', '-h'], default_log) groups = [(pl.name+ ' Options', '', g.option_list) for g in parser.option_groups if g.title == "INPUT OPTIONS"] prog = 'ebook-convert-'+(pl.name.lower().replace(' ', '-')) raw += '\n\n' + '\n'.join(render_options(prog, groups, False, True)) for pl in sorted(output_format_plugins(), key=lambda x: x.name): parser, plumber = create_option_parser(['ebook-convert', 'd.epub', 'dummyi.'+pl.file_type, '-h'], default_log) groups = [(pl.name+ ' Options', '', g.option_list) for g in parser.option_groups if g.title == "OUTPUT OPTIONS"] prog = 'ebook-convert-'+(pl.name.lower().replace(' ', '-')) raw += '\n\n' + '\n'.join(render_options(prog, groups, False, True)) update_cli_doc('ebook-convert', raw, app)
def complete(self, wc): if wc == 2: self.complete_input() elif wc == 3: self.complete_output() else: q = list(self.words[1:3]) q = [ os.path.splitext(x)[0 if x.startswith('.') else 1].partition( '.')[-1].lower() for x in q ] if not q[1]: q[1] = 'oeb' q = tuple(q) if q in self.cache: ans = [x for x in self.cache[q] if x.startswith(self.prefix)] else: from calibre.ebooks.conversion.cli import create_option_parser from calibre.utils.logging import Log log = Log() log.outputs = [] ans = [] if not self.prefix or self.prefix.startswith('-'): try: parser, _ = create_option_parser(self.words[:3], log) ans += list(get_opts_from_parser(parser, self.prefix)) except: pass if self.previous.startswith('-'): ans += list(files_and_dirs(self.prefix, None)) send(ans)
def complete(self, wc): if wc == 2: self.complete_input() elif wc == 3: self.complete_output() else: q = list(self.words[1:3]) q = [os.path.splitext(x)[0 if x.startswith('.') else 1].partition('.')[-1].lower() for x in q] if not q[1]: q[1] = 'oeb' q = tuple(q) if q in self.cache: ans = [x for x in self.cache[q] if x.startswith(self.prefix)] else: from calibre.ebooks.conversion.cli import create_option_parser from calibre.utils.logging import Log log = Log() log.outputs = [] ans = [] if not self.prefix or self.prefix.startswith('-'): try: parser, _ = create_option_parser(self.words[:3], log) ans += list(get_opts_from_parser(parser, self.prefix)) except: pass if self.previous.startswith('-'): ans += list(files_and_dirs(self.prefix, None)) send(ans)
def generate_ebook_convert_help(preamble, info): from calibre.ebooks.conversion.cli import create_option_parser from calibre.customize.ui import input_format_plugins, output_format_plugins from calibre.utils.logging import default_log preamble = re.sub(r'http.*\.html', ':ref:`conversion`', preamble) raw = preamble + textwrap.dedent(''' The options and default values for the options change depending on both the input and output formats, so you should always check with:: ebook-convert myfile.input_format myfile.output_format -h Below are the options that are common to all conversion, followed by the options specific to every input and output format ''') parser, plumber = create_option_parser( ['ebook-convert', 'dummyi.mobi', 'dummyo.epub', '-h'], default_log) groups = [(None, None, parser.option_list)] for grp in parser.option_groups: if grp.title not in {'INPUT OPTIONS', 'OUTPUT OPTIONS'}: groups.append( (grp.title.title(), grp.description, grp.option_list)) options = '\n'.join(render_options('ebook-convert', groups, False)) raw += '\n\n.. contents::\n :local:' raw += '\n\n' + options for pl in sorted(input_format_plugins(), key=lambda x: x.name): parser, plumber = create_option_parser([ 'ebook-convert', 'dummyi.' + list(pl.file_types)[0], 'dummyo.epub', '-h' ], default_log) groups = [(pl.name + ' Options', '', g.option_list) for g in parser.option_groups if g.title == "INPUT OPTIONS"] prog = 'ebook-convert-' + (pl.name.lower().replace(' ', '-')) raw += '\n\n' + '\n'.join(render_options(prog, groups, False, True)) for pl in sorted(output_format_plugins(), key=lambda x: x.name): parser, plumber = create_option_parser( ['ebook-convert', 'd.epub', 'dummyi.' + pl.file_type, '-h'], default_log) groups = [(pl.name + ' Options', '', g.option_list) for g in parser.option_groups if g.title == "OUTPUT OPTIONS"] prog = 'ebook-convert-' + (pl.name.lower().replace(' ', '-')) raw += '\n\n' + '\n'.join(render_options(prog, groups, False, True)) update_cli_doc(os.path.join('cli', 'ebook-convert.rst'), raw, info)
def run(self, opts): from calibre.utils.serialize import msgpack_dumps scripts = {} for x in ['console']: for name in basenames[x]: if name in ('calibre-complete', 'calibre_postinstall'): continue scripts[name] = x dest = self.j(self.RESOURCES, 'scripts.calibre_msgpack') if self.newer(dest, self.j(self.SRC, 'calibre', 'linux.py')): self.info('\tCreating ' + self.b(dest)) with open(dest, 'wb') as f: f.write(msgpack_dumps(scripts)) recipe_icon_dir = self.a( self.j(self.RESOURCES, '..', 'recipes', 'icons')) dest = os.path.splitext(dest)[0] + '.zip' files = glob.glob(self.j(recipe_icon_dir, '*.png')) if self.newer(dest, files): self.info('\tCreating builtin_recipes.zip') with zipfile.ZipFile(dest, 'w', zipfile.ZIP_STORED) as zf: for n in sorted(files, key=self.b): with open(n, 'rb') as f: zf.writestr(self.b(n), f.read()) dest = self.j(self.RESOURCES, 'ebook-convert-complete.calibre_msgpack') files = [] for x in os.walk(self.j(self.SRC, 'calibre')): for f in x[-1]: if f.endswith('.py'): files.append(self.j(x[0], f)) if self.newer(dest, files): self.info('\tCreating ' + self.b(dest)) complete = {} from calibre.ebooks.conversion.plumber import supported_input_formats complete['input_fmts'] = set(supported_input_formats()) from calibre.customize.ui import available_output_formats complete['output'] = set(available_output_formats()) from calibre.ebooks.conversion.cli import create_option_parser from calibre.utils.logging import Log log = Log() # log.outputs = [] for inf in supported_input_formats(): if inf in ('zip', 'rar', 'oebzip'): continue for ouf in available_output_formats(): of = ouf if ouf == 'oeb' else 'dummy.' + ouf p = create_option_parser(('ec', 'dummy1.' + inf, of, '-h'), log)[0] complete[(inf, ouf)] = [ x + ' ' for x in get_opts_from_parser(p) ] with open(dest, 'wb') as f: f.write(msgpack_dumps(only_unicode_recursive(complete)))
def generate_ebook_convert_help(preamble, info): from calibre.ebooks.conversion.cli import create_option_parser from calibre.customize.ui import input_format_plugins, output_format_plugins from calibre.utils.logging import default_log preamble = re.sub(r'http.*\.html', ':ref:`conversion`', preamble) raw = preamble + textwrap.dedent(''' The options and default values for the options change depending on both the input and output formats, so you should always check with:: ebook-convert myfile.input_format myfile.output_format -h Below are the options that are common to all conversion, followed by the options specific to every input and output format ''') parser, plumber = create_option_parser(['ebook-convert', 'dummyi.mobi', 'dummyo.epub', '-h'], default_log) groups = [(None, None, parser.option_list)] for grp in parser.option_groups: if grp.title not in {'INPUT OPTIONS', 'OUTPUT OPTIONS'}: groups.append((grp.title.title(), grp.description, grp.option_list)) options = '\n'.join(render_options('ebook-convert', groups, False)) raw += '\n\n.. contents::\n :local:' raw += '\n\n' + options for pl in sorted(input_format_plugins(), key=lambda x:x.name): parser, plumber = create_option_parser(['ebook-convert', 'dummyi.'+list(pl.file_types)[0], 'dummyo.epub', '-h'], default_log) groups = [(pl.name+ ' Options', '', g.option_list) for g in parser.option_groups if g.title == "INPUT OPTIONS"] prog = 'ebook-convert-'+(pl.name.lower().replace(' ', '-')) raw += '\n\n' + '\n'.join(render_options(prog, groups, False, True)) for pl in sorted(output_format_plugins(), key=lambda x: x.name): parser, plumber = create_option_parser(['ebook-convert', 'd.epub', 'dummyi.'+pl.file_type, '-h'], default_log) groups = [(pl.name+ ' Options', '', g.option_list) for g in parser.option_groups if g.title == "OUTPUT OPTIONS"] prog = 'ebook-convert-'+(pl.name.lower().replace(' ', '-')) raw += '\n\n' + '\n'.join(render_options(prog, groups, False, True)) update_cli_doc(os.path.join('cli', 'ebook-convert.rst'), raw, info)
def run(self, opts): scripts = {} for x in ('console', 'gui'): for name in basenames[x]: if name in ('calibre-complete', 'calibre_postinstall'): continue scripts[name] = x dest = self.j(self.RESOURCES, 'scripts.pickle') if self.newer(dest, self.j(self.SRC, 'calibre', 'linux.py')): self.info('\tCreating scripts.pickle') f = open(dest, 'wb') cPickle.dump(scripts, f, -1) from calibre.web.feeds.recipes.collection import \ serialize_builtin_recipes, iterate_over_builtin_recipe_files files = [x[1] for x in iterate_over_builtin_recipe_files()] dest = self.j(self.RESOURCES, 'builtin_recipes.xml') if self.newer(dest, files): self.info('\tCreating builtin_recipes.xml') xml = serialize_builtin_recipes() with open(dest, 'wb') as f: f.write(xml) recipe_icon_dir = self.a(self.j(self.RESOURCES, '..', 'recipes', 'icons')) dest = os.path.splitext(dest)[0] + '.zip' files += glob.glob(self.j(recipe_icon_dir, '*.png')) if self.newer(dest, files): self.info('\tCreating builtin_recipes.zip') with zipfile.ZipFile(dest, 'w', zipfile.ZIP_STORED) as zf: for n in sorted(files, key=self.b): with open(n, 'rb') as f: zf.writestr(os.path.basename(n), f.read()) dest = self.j(self.RESOURCES, 'ebook-convert-complete.pickle') files = [] for x in os.walk(self.j(self.SRC, 'calibre')): for f in x[-1]: if f.endswith('.py'): files.append(self.j(x[0], f)) if self.newer(dest, files): self.info('\tCreating ebook-convert-complete.pickle') complete = {} from calibre.ebooks.conversion.plumber import supported_input_formats complete['input_fmts'] = set(supported_input_formats()) from calibre.web.feeds.recipes.collection import get_builtin_recipe_titles complete['input_recipes'] = [t+'.recipe ' for t in get_builtin_recipe_titles()] from calibre.customize.ui import available_output_formats complete['output'] = set(available_output_formats()) from calibre.ebooks.conversion.cli import create_option_parser from calibre.utils.logging import Log log = Log() # log.outputs = [] for inf in supported_input_formats(): if inf in ('zip', 'rar', 'oebzip'): continue for ouf in available_output_formats(): of = ouf if ouf == 'oeb' else 'dummy.'+ouf p = create_option_parser(('ec', 'dummy1.'+inf, of, '-h'), log)[0] complete[(inf, ouf)] = [x+' 'for x in get_opts_from_parser(p)] cPickle.dump(complete, open(dest, 'wb'), -1) self.info('\tCreating template-functions.json') dest = self.j(self.RESOURCES, 'template-functions.json') function_dict = {} import inspect from calibre.utils.formatter_functions import formatter_functions for obj in formatter_functions().get_builtins().values(): eval_func = inspect.getmembers(obj, lambda x: inspect.ismethod(x) and x.__name__ == 'evaluate') try: lines = [l[4:] for l in inspect.getsourcelines(eval_func[0][1])[0]] except: continue lines = ''.join(lines) function_dict[obj.name] = lines import json json.dump(function_dict, open(dest, 'wb'), indent=4)
def run(self, opts): from calibre.utils.serialize import msgpack_dumps scripts = {} for x in ('console', 'gui'): for name in basenames[x]: if name in ('calibre-complete', 'calibre_postinstall'): continue scripts[name] = x dest = self.j(self.RESOURCES, 'scripts.calibre_msgpack') if self.newer(dest, self.j(self.SRC, 'calibre', 'linux.py')): self.info('\tCreating ' + self.b(dest)) with open(dest, 'wb') as f: f.write(msgpack_dumps(scripts)) from calibre.web.feeds.recipes.collection import \ serialize_builtin_recipes, iterate_over_builtin_recipe_files files = [x[1] for x in iterate_over_builtin_recipe_files()] dest = self.j(self.RESOURCES, 'builtin_recipes.xml') if self.newer(dest, files): self.info('\tCreating builtin_recipes.xml') xml = serialize_builtin_recipes() with open(dest, 'wb') as f: f.write(xml) recipe_icon_dir = self.a( self.j(self.RESOURCES, '..', 'recipes', 'icons')) dest = os.path.splitext(dest)[0] + '.zip' files += glob.glob(self.j(recipe_icon_dir, '*.png')) if self.newer(dest, files): self.info('\tCreating builtin_recipes.zip') with zipfile.ZipFile(dest, 'w', zipfile.ZIP_STORED) as zf: for n in sorted(files, key=self.b): with open(n, 'rb') as f: zf.writestr(self.b(n), f.read()) dest = self.j(self.RESOURCES, 'ebook-convert-complete.calibre_msgpack') files = [] for x in os.walk(self.j(self.SRC, 'calibre')): for f in x[-1]: if f.endswith('.py'): files.append(self.j(x[0], f)) if self.newer(dest, files): self.info('\tCreating ' + self.b(dest)) complete = {} from calibre.ebooks.conversion.plumber import supported_input_formats complete['input_fmts'] = set(supported_input_formats()) from calibre.web.feeds.recipes.collection import get_builtin_recipe_titles complete['input_recipes'] = [ t + '.recipe ' for t in get_builtin_recipe_titles() ] from calibre.customize.ui import available_output_formats complete['output'] = set(available_output_formats()) from calibre.ebooks.conversion.cli import create_option_parser from calibre.utils.logging import Log log = Log() # log.outputs = [] for inf in supported_input_formats(): if inf in ('zip', 'rar', 'oebzip'): continue for ouf in available_output_formats(): of = ouf if ouf == 'oeb' else 'dummy.' + ouf p = create_option_parser(('ec', 'dummy1.' + inf, of, '-h'), log)[0] complete[(inf, ouf)] = [ x + ' ' for x in get_opts_from_parser(p) ] with open(dest, 'wb') as f: f.write(msgpack_dumps(only_unicode_recursive(complete))) self.info('\tCreating template-functions.json') dest = self.j(self.RESOURCES, 'template-functions.json') function_dict = {} import inspect from calibre.utils.formatter_functions import formatter_functions for obj in formatter_functions().get_builtins().values(): eval_func = inspect.getmembers( obj, lambda x: inspect.ismethod(x) and x.__name__ == 'evaluate') try: lines = [ l[4:] for l in inspect.getsourcelines(eval_func[0][1])[0] ] except: continue lines = ''.join(lines) function_dict[obj.name] = lines dump_json(function_dict, dest) self.info('\tCreating editor-functions.json') dest = self.j(self.RESOURCES, 'editor-functions.json') function_dict = {} from calibre.gui2.tweak_book.function_replace import builtin_functions for func in builtin_functions(): try: src = ''.join(inspect.getsourcelines(func)[0][1:]) except Exception: continue src = src.replace('def ' + func.__name__, 'def replace') 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 dump_json(function_dict, dest) self.info('\tCreating user-manual-translation-stats.json') d = {} for lc, stats in iteritems( json.load( open( self.j(self.d(self.SRC), 'manual', 'locale', 'completed.json')))): total = sum(itervalues(stats)) d[lc] = stats['translated'] / float(total) dump_json(d, self.j(self.RESOURCES, 'user-manual-translation-stats.json')) src = self.j(self.SRC, '..', 'Changelog.txt') dest = self.j(self.RESOURCES, 'changelog.json') if self.newer(dest, [src]): self.info('\tCreating changelog.json') from setup.changelog import parse with open(src, encoding='utf-8') as f: dump_json(parse(f.read(), parse_dates=False), dest)
def get_parser(input_fmt='epub', output_fmt=None): of = ('dummy2.' + output_fmt) if output_fmt else 'dummy' return create_option_parser( ('ec', 'dummy1.' + input_fmt, of, '-h'), log)[0]
def get_parser(input_fmt='epub', output_fmt=None): of = ('dummy2.'+output_fmt) if output_fmt else 'dummy' return create_option_parser(('ec', 'dummy1.'+input_fmt, of, '-h'), log)[0]
def run(self, opts): scripts = {} for x in ('console', 'gui'): for name in basenames[x]: if name in ('calibre-complete', 'calibre_postinstall'): continue scripts[name] = x dest = self.j(self.RESOURCES, 'scripts.pickle') if self.newer(dest, self.j(self.SRC, 'calibre', 'linux.py')): self.info('\tCreating scripts.pickle') f = open(dest, 'wb') cPickle.dump(scripts, f, -1) from calibre.web.feeds.recipes.collection import \ serialize_builtin_recipes, iterate_over_builtin_recipe_files files = [x[1] for x in iterate_over_builtin_recipe_files()] dest = self.j(self.RESOURCES, 'builtin_recipes.xml') if self.newer(dest, files): self.info('\tCreating builtin_recipes.xml') xml = serialize_builtin_recipes() with open(dest, 'wb') as f: f.write(xml) recipe_icon_dir = self.a( self.j(self.RESOURCES, '..', 'recipes', 'icons')) dest = os.path.splitext(dest)[0] + '.zip' files += glob.glob(self.j(recipe_icon_dir, '*.png')) if self.newer(dest, files): self.info('\tCreating builtin_recipes.zip') with zipfile.ZipFile(dest, 'w', zipfile.ZIP_STORED) as zf: for n in sorted(files, key=self.b): with open(n, 'rb') as f: zf.writestr(os.path.basename(n), f.read()) dest = self.j(self.RESOURCES, 'ebook-convert-complete.pickle') files = [] for x in os.walk(self.j(self.SRC, 'calibre')): for f in x[-1]: if f.endswith('.py'): files.append(self.j(x[0], f)) if self.newer(dest, files): self.info('\tCreating ebook-convert-complete.pickle') complete = {} from calibre.ebooks.conversion.plumber import supported_input_formats complete['input_fmts'] = set(supported_input_formats()) from calibre.web.feeds.recipes.collection import get_builtin_recipe_titles complete['input_recipes'] = [ t + '.recipe ' for t in get_builtin_recipe_titles() ] from calibre.customize.ui import available_output_formats complete['output'] = set(available_output_formats()) from calibre.ebooks.conversion.cli import create_option_parser from calibre.utils.logging import Log log = Log() #log.outputs = [] for inf in supported_input_formats(): if inf in ('zip', 'rar', 'oebzip'): continue for ouf in available_output_formats(): of = ouf if ouf == 'oeb' else 'dummy.' + ouf p = create_option_parser(('ec', 'dummy1.' + inf, of, '-h'), log)[0] complete[(inf, ouf)] = [ x + ' ' for x in get_opts_from_parser(p) ] cPickle.dump(complete, open(dest, 'wb'), -1) self.info('\tCreating template-functions.json') dest = self.j(self.RESOURCES, 'template-functions.json') function_dict = {} import inspect from calibre.utils.formatter_functions import formatter_functions for obj in formatter_functions().get_builtins().values(): eval_func = inspect.getmembers( obj, lambda x: inspect.ismethod(x) and x.__name__ == 'evaluate') try: lines = [ l[4:] for l in inspect.getsourcelines(eval_func[0][1])[0] ] except: continue lines = ''.join(lines) function_dict[obj.name] = lines import json json.dump(function_dict, open(dest, 'wb'), indent=4)
def get_parser(input_fmt="epub", output_fmt=None): of = ("dummy2." + output_fmt) if output_fmt else "dummy" return create_option_parser(("ec", "dummy1." + input_fmt, of, "-h"), log)[0]
def run(self, opts): from calibre.utils.serialize import msgpack_dumps scripts = {} for x in ('console', 'gui'): for name in basenames[x]: if name in ('calibre-complete', 'calibre_postinstall'): continue scripts[name] = x dest = self.j(self.RESOURCES, 'scripts.calibre_msgpack') if self.newer(dest, self.j(self.SRC, 'calibre', 'linux.py')): self.info('\tCreating ' + os.path.basename(dest)) with open(dest, 'wb') as f: f.write(msgpack_dumps(scripts)) from calibre.web.feeds.recipes.collection import \ serialize_builtin_recipes, iterate_over_builtin_recipe_files files = [x[1] for x in iterate_over_builtin_recipe_files()] dest = self.j(self.RESOURCES, 'builtin_recipes.xml') if self.newer(dest, files): self.info('\tCreating builtin_recipes.xml') xml = serialize_builtin_recipes() with open(dest, 'wb') as f: f.write(xml) recipe_icon_dir = self.a(self.j(self.RESOURCES, '..', 'recipes', 'icons')) dest = os.path.splitext(dest)[0] + '.zip' files += glob.glob(self.j(recipe_icon_dir, '*.png')) if self.newer(dest, files): self.info('\tCreating builtin_recipes.zip') with zipfile.ZipFile(dest, 'w', zipfile.ZIP_STORED) as zf: for n in sorted(files, key=self.b): with open(n, 'rb') as f: zf.writestr(os.path.basename(n), f.read()) dest = self.j(self.RESOURCES, 'ebook-convert-complete.calibre_msgpack') files = [] for x in os.walk(self.j(self.SRC, 'calibre')): for f in x[-1]: if f.endswith('.py'): files.append(self.j(x[0], f)) if self.newer(dest, files): self.info('\tCreating ebook-convert-complete.pickle') complete = {} from calibre.ebooks.conversion.plumber import supported_input_formats complete['input_fmts'] = set(supported_input_formats()) from calibre.web.feeds.recipes.collection import get_builtin_recipe_titles complete['input_recipes'] = [t+'.recipe ' for t in get_builtin_recipe_titles()] from calibre.customize.ui import available_output_formats complete['output'] = set(available_output_formats()) from calibre.ebooks.conversion.cli import create_option_parser from calibre.utils.logging import Log log = Log() # log.outputs = [] for inf in supported_input_formats(): if inf in ('zip', 'rar', 'oebzip'): continue for ouf in available_output_formats(): of = ouf if ouf == 'oeb' else 'dummy.'+ouf p = create_option_parser(('ec', 'dummy1.'+inf, of, '-h'), log)[0] complete[(inf, ouf)] = [x+' 'for x in get_opts_from_parser(p)] with open(dest, 'wb') as f: f.write(msgpack_dumps(complete)) self.info('\tCreating template-functions.json') dest = self.j(self.RESOURCES, 'template-functions.json') function_dict = {} import inspect from calibre.utils.formatter_functions import formatter_functions for obj in formatter_functions().get_builtins().values(): eval_func = inspect.getmembers(obj, lambda x: inspect.ismethod(x) and x.__name__ == 'evaluate') try: lines = [l[4:] for l in inspect.getsourcelines(eval_func[0][1])[0]] except: continue lines = ''.join(lines) function_dict[obj.name] = lines import json json.dump(function_dict, open(dest, 'wb'), indent=4) self.info('\tCreating editor-functions.json') dest = self.j(self.RESOURCES, 'editor-functions.json') function_dict = {} from calibre.gui2.tweak_book.function_replace import builtin_functions for func in builtin_functions(): try: src = ''.join(inspect.getsourcelines(func)[0][1:]) except Exception: continue src = src.replace('def ' + func.func_name, 'def replace') imports = ['from %s import %s' % (x.__module__, x.__name__) for x in func.imports] if imports: src = '\n'.join(imports) + '\n\n' + src function_dict[func.name] = src json.dump(function_dict, open(dest, 'wb'), indent=4) self.info('\tCreating user-manual-translation-stats.json') d = {} for lc, stats in iteritems(json.load(open(self.j(self.d(self.SRC), 'manual', 'locale', 'completed.json')))): total = sum(itervalues(stats)) d[lc] = stats['translated'] / float(total) json.dump(d, open(self.j(self.RESOURCES, 'user-manual-translation-stats.json'), 'wb'), indent=4)
def run(self, opts): scripts = {} for x in ("console", "gui"): for name in basenames[x]: if name in ("calibre-complete", "calibre_postinstall"): continue scripts[name] = x dest = self.j(self.RESOURCES, "scripts.pickle") if self.newer(dest, self.j(self.SRC, "calibre", "linux.py")): self.info("\tCreating scripts.pickle") f = open(dest, "wb") cPickle.dump(scripts, f, -1) from calibre.web.feeds.recipes.collection import serialize_builtin_recipes, iterate_over_builtin_recipe_files files = [x[1] for x in iterate_over_builtin_recipe_files()] dest = self.j(self.RESOURCES, "builtin_recipes.xml") if self.newer(dest, files): self.info("\tCreating builtin_recipes.xml") xml = serialize_builtin_recipes() with open(dest, "wb") as f: f.write(xml) recipe_icon_dir = self.a(self.j(self.RESOURCES, "..", "recipes", "icons")) dest = os.path.splitext(dest)[0] + ".zip" files += glob.glob(self.j(recipe_icon_dir, "*.png")) if self.newer(dest, files): self.info("\tCreating builtin_recipes.zip") with zipfile.ZipFile(dest, "w", zipfile.ZIP_STORED) as zf: for n in sorted(files, key=self.b): with open(n, "rb") as f: zf.writestr(os.path.basename(n), f.read()) dest = self.j(self.RESOURCES, "ebook-convert-complete.pickle") files = [] for x in os.walk(self.j(self.SRC, "calibre")): for f in x[-1]: if f.endswith(".py"): files.append(self.j(x[0], f)) if self.newer(dest, files): self.info("\tCreating ebook-convert-complete.pickle") complete = {} from calibre.ebooks.conversion.plumber import supported_input_formats complete["input_fmts"] = set(supported_input_formats()) from calibre.web.feeds.recipes.collection import get_builtin_recipe_titles complete["input_recipes"] = [t + ".recipe " for t in get_builtin_recipe_titles()] from calibre.customize.ui import available_output_formats complete["output"] = set(available_output_formats()) from calibre.ebooks.conversion.cli import create_option_parser from calibre.utils.logging import Log log = Log() # log.outputs = [] for inf in supported_input_formats(): if inf in ("zip", "rar", "oebzip"): continue for ouf in available_output_formats(): of = ouf if ouf == "oeb" else "dummy." + ouf p = create_option_parser(("ec", "dummy1." + inf, of, "-h"), log)[0] complete[(inf, ouf)] = [x + " " for x in get_opts_from_parser(p)] cPickle.dump(complete, open(dest, "wb"), -1) self.info("\tCreating template-functions.json") dest = self.j(self.RESOURCES, "template-functions.json") function_dict = {} import inspect from calibre.utils.formatter_functions import formatter_functions for obj in formatter_functions().get_builtins().values(): eval_func = inspect.getmembers(obj, lambda x: inspect.ismethod(x) and x.__name__ == "evaluate") try: lines = [l[4:] for l in inspect.getsourcelines(eval_func[0][1])[0]] except: continue lines = "".join(lines) function_dict[obj.name] = lines import json json.dump(function_dict, open(dest, "wb"), indent=4)