def __call__(self, options, timeout=10, dry_run=False, **kwargs): args = [WK_COMMAND] args.extend(options) out = _output() args.append(out) cleanup = set(kwargs.get('cleanup') or []) cleanup.add(out) job = PdfJob(args, out, timeout, cleanup) if dry_run: return job safe = kwargs.get('safe', True) job.run(safe=safe) return job
def concat(self, pdfs, default=None, timeout=10, dry_run=False, **kwargs): """ Concat more PDF to one """ if not pdfs: return default out = _output() cleanup = set(kwargs.get('cleanup') or []) cleanup.add(out) job = PdfMergeJob('', out, timeout, cleanup, dependencies=pdfs) if dry_run: return job safe = kwargs.get('safe', True) job.run(safe=safe) return job
def concat(self, pdfs, default=None, timeout=10, dry_run=False, **kwargs): """ Concat more PDF to one """ if not CAN_JOIN_PDFS: return default if not pdfs: return default out = _output() cmd = ['pdftk', '%(dependencies)s', 'output', out] cleanup = set(kwargs.get('cleanup') or []) cleanup.add(out) job = PdfJob(cmd, out, timeout, cleanup, dependencies=pdfs) if dry_run: return job safe = kwargs.get('safe', True) job.run(safe=safe) return job
class AsyncExportView(ExportView): """ Download ePub asynchronously """ template = ViewPageTemplateFile('../zpt/download.pt') def __init__(self, context, request): super(AsyncExportView, self).__init__(context, request) self._title = '' self._message = _( u"* The email is only used for the purpose of sending the ePub. " u"We do not store it for any other use.") self._email = '' self._link = '' @property def message(self): """ Message """ return self._message @property def title(self): """ Title """ if self._title: return self._title title = self.context.title_or_id() if isinstance(title, str): title = title.decode('utf-8') return _( u"Enter your email address where to send '${title}' ePub when ready", mapping={'title': title}) @property def email(self): """ User email """ return self._email def _redirect(self, msg='', title=''): """ Redirect """ self.request.set('disable_border', 1) self.request.set('disable_plone.leftcolumn', 1) self.request.set('disable_plone.rightcolumn', 1) if msg: self._message = msg if title: self._title = title return self.template() def link(self): """ Download link """ if not self._link: storage = IStorage(self.context).of('epub') self._link = storage.absolute_url() return self._link def period(self): """ Wait period """ ptype = getattr(self.context, 'portal_type', '') if ptype.lower() in ('collection', 'topic', 'folder', 'atfolder'): return _(u"minutes") return _(u"seconds") def finish(self, email=''): """ Finish download """ if email: self._email = email self._title = _( u"An email will be sent to you when the ePub is ready") self._message = _( u"If you don't have access to your email address " u"check <a href='${link}'>this link</a> in a few ${period}.", mapping={ u"link": u"%s?direct=1" % self.link(), u"period": self.period() }) return self._redirect() def download(self, email='', **kwargs): """ Download """ # Fallback ePub provided if self.fallback: self._link = self.fallback storage = IStorage(self.context).of('epub') filepath = storage.filepath() fileurl = self.link() url = self.context.absolute_url() title = self.context.title_or_id() portal = getSite() from_name = portal.getProperty('email_from_name') from_email = portal.getProperty('email_from_address') if self.fallback or async .file_exists(filepath): wrapper = async .ContextWrapper(self.context)( fileurl=fileurl, filepath=filepath, email=email, url=url, from_name=from_name, from_email=from_email, title=title, etype='epub') event.notify(AsyncEPUBExportSuccess(wrapper)) return self.finish(email=email) # Async generate PDF out = _output(suffix='.epub') cmd = url body = 'epub.body' cover = 'epub.cover' job = EpubJob(cmd=cmd, title=self.context.Title(), body=body, cover=cover, cookies=self.request.cookies, output=out, timeout=60, cleanup=[out]) worker = queryUtility(IAsyncService) worker.queueJob(async .run_async_job, self.context, job, success_event=AsyncEPUBExportSuccess, fail_event=AsyncEPUBExportFail, email=email, filepath=filepath, fileurl=fileurl, url=url, from_name=from_name, from_email=from_email, title=title, etype='epub') return self.finish(email=email)