Exemple #1
0
def save_book(ids, dpath, plugboards, template_functions, path, recs,
              notification=lambda x,y:x):
    from calibre.library.save_to_disk import config, save_serialized_to_disk
    from calibre.customize.ui import apply_null_metadata
    from calibre.utils.formatter_functions import load_user_template_functions
    load_user_template_functions('', template_functions)
    opts = config().parse()
    for name in recs:
        setattr(opts, name, recs[name])

    results = []

    def callback(id, title, failed, tb):
        results.append((id, title, not failed, tb))
        notification((id, title, not failed, tb))
        return True

    data_ = json.loads(open(dpath, 'rb').read().decode('utf-8'))
    data = {}
    for k, v in data_.iteritems():
        data[int(k)] = v

    with apply_null_metadata:
        save_serialized_to_disk(ids, data, plugboards, path, opts, callback)

    return results
Exemple #2
0
    def __init__(self, book_ids, db, opts, root, parent=None, spare_server=None):
        QObject.__init__(self, parent)
        if parent is not None:
            setattr(parent, 'no_gc_%s' % id(self), self)
        self.db = db.new_api
        self.plugboards = self.db.pref('plugboards', {})
        self.template_functions = self.db.pref('user_template_functions', [])
        load_user_template_functions('', self.template_functions)
        self.collected_data = {}
        self.metadata_data = {}
        self.errors = defaultdict(list)
        self._book_id_data = {}
        self.all_book_ids = frozenset(book_ids)
        self.pd = ProgressDialog(_('Saving %d books...') % len(self.all_book_ids), _('Collecting metadata...'), min=0, max=0, parent=parent, icon='save.png')
        self.do_one_signal.connect(self.tick, type=Qt.QueuedConnection)
        self.do_one = self.do_one_collect
        self.ids_to_collect = iter(self.all_book_ids)
        self.plugboard_cache = {}
        self.tdir = PersistentTemporaryDirectory('_save_to_disk')
        self.server = spare_server

        self.pd.show()
        self.root, self.opts, self.path_length = sanitize_args(root, opts)
        self.do_one_signal.emit()
        if DEBUG:
            self.start_time = time.time()
Exemple #3
0
 def commit(self):
     # formatter_functions().reset_to_builtins()
     pref_value = []
     for name, cls in self.funcs.iteritems():
         if name not in self.builtins:
             pref_value.append((cls.name, cls.doc, cls.arg_count, cls.program_text))
     self.db.new_api.set_pref('user_template_functions', pref_value)
     load_user_template_functions(self.db.library_id, pref_value)
     return False
Exemple #4
0
def export(opts, dbctx, book_id, dest, dbproxy, length, first):
    mi, plugboards, formats, library_id, template_funcs = dbctx.run(
        'export', 'setup', book_id, opts.formats
    )
    if dbctx.is_remote and first:
        load_user_template_functions(library_id, template_funcs)
    return do_save_book_to_disk(
        dbproxy, book_id, mi, plugboards, formats, dest, opts, length
    )
Exemple #5
0
 def commit(self):
     # formatter_functions().reset_to_builtins()
     pref_value = []
     for f in self.funcs:
         func = self.funcs[f]
         pref_value.append((func.name, func.doc, func.arg_count, func.program_text))
     self.db.prefs.set('user_template_functions', pref_value)
     formatter_functions().unregister_functions(self.db.library_id)
     load_user_template_functions(self.db.library_id, pref_value)
     return False
Exemple #6
0
 def commit(self):
     pref_value = []
     for name, cls in iteritems(self.funcs):
         if name not in self.builtins:
             pref_value.append(cls.to_pref())
     for v in self.st_funcs.values():
         pref_value.append(v.to_pref())
     self.db.new_api.set_pref('user_template_functions', pref_value)
     funcs = compile_user_template_functions(pref_value)
     self.db.new_api.set_user_template_functions(funcs)
     self.gui.library_view.model().refresh()
     load_user_template_functions(self.db.library_id, [], funcs)
     return False
 def commit(self):
     # formatter_functions().reset_to_builtins()
     pref_value = []
     for name, cls in self.funcs.iteritems():
         if name not in self.builtins:
             pref_value.append(
                 (cls.name, cls.doc, cls.arg_count, cls.program_text))
     self.db.new_api.set_pref('user_template_functions', pref_value)
     funcs = compile_user_template_functions(pref_value)
     self.db.new_api.set_user_template_functions(funcs)
     self.gui.library_view.model().refresh()
     load_user_template_functions(self.db.library_id, [], funcs)
     return False
Exemple #8
0
    def __init__(self, book_ids, db, opts, root, parent=None, pool=None):
        QObject.__init__(self, parent)
        self.db = db.new_api
        self.plugboards = self.db.pref('plugboards', {})
        self.template_functions = self.db.pref('user_template_functions', [])
        load_user_template_functions('', self.template_functions)
        self.collected_data = {}
        self.errors = defaultdict(list)
        self._book_id_data = {}
        self.all_book_ids = frozenset(book_ids)
        self.pd = ProgressDialog(_('Saving %d books...') % len(self.all_book_ids), _('Collecting metadata...'), min=0, max=0, parent=parent, icon='save.png')
        self.do_one_signal.connect(self.tick, type=Qt.QueuedConnection)
        self.do_one = self.do_one_collect
        self.ids_to_collect = iter(self.all_book_ids)
        self.tdir = PersistentTemporaryDirectory('_save_to_disk')
        self.pool = pool

        self.pd.show()
        self.root, self.opts, self.path_length = sanitize_args(root, opts)
        self.do_one_signal.emit()
        if DEBUG:
            self.start_time = time.time()