コード例 #1
0
 def check_for_completions(self):
     from calibre.utils.filenames import retry_on_fail
     for job in tuple(self.jobs):
         started_path = job['path'] + '.started'
         result_path = job['path'] + '.result'
         if job['started'] and os.path.exists(result_path):
             self.jobs.remove(job)
             with open(result_path) as f:
                 ret = int(f.read().strip())
             retry_on_fail(os.remove, result_path)
             if ret == 0:
                 db = self.gui.current_db
                 if db.new_api.library_id != job['library_id']:
                     error_dialog(self.gui, _('Library changed'), _(
                         'Cannot save changes made to {0} by the ToC editor as'
                         ' the calibre library has changed.').format(job['title']), show=True)
                 else:
                     db.new_api.add_format(job['book_id'], job['fmt'], job['path'], run_hooks=False)
             os.remove(job['path'])
         else:
             if monotonic() - job['start_time'] > 120:
                 self.jobs.remove(job)
                 continue
             if os.path.exists(started_path):
                 job['started'] = True
                 retry_on_fail(os.remove, started_path)
     if self.jobs:
         QTimer.singleShot(100, self.check_for_completions)
コード例 #2
0
ファイル: simple.py プロジェクト: buoyantair/calibre
 def fetch_url(self, url_or_qurl, source='', timeout=60):
     w = self.worker_for_source(source)
     if isinstance(url_or_qurl, str):
         url_or_qurl = QUrl(url_or_qurl)
     w.stdin.write(b'FETCH:')
     w.stdin.write(
         json.dumps({
             'url': bytes(url_or_qurl.toEncoded()).decode('utf-8'),
             'timeout': timeout
         }).encode('utf-8'))
     w.stdin.write(b'\n')
     w.stdin.flush()
     output = json.loads(w.stdout.readline())
     if not output['ok']:
         raise ValueError(output['err'])
     with open(output['html_file'], 'rb') as f:
         html = f.read().decode('utf-8')
     retry_on_fail(os.remove, output['html_file'])
     return html