def _process(self): boaConfig = self._conf.getBOAConfig() pdfFilename = "%s - Book of abstracts.pdf" % cleanHTMLHeaderFilename( self._target.getTitle()) cacheFile = self._getCacheFileName() if os.path.isfile(cacheFile): mtime = pytz.utc.localize( datetime.utcfromtimestamp(os.path.getmtime(cacheFile))) else: mtime = None if boaConfig.isCacheEnabled( ) and not self._noCache and mtime and mtime > boaConfig.lastChanged: return send_file(pdfFilename, cacheFile, 'PDF') else: tz = timezoneUtils.DisplayTZ(self._aw, self._target).getDisplayTZ() pdf = AbstractBook(self._target, self.getAW(), tz=tz) fname = pdf.generate() with open(fname, 'rb') as f: data = f.read() with open(cacheFile, 'wb') as f: f.write(data) return send_file(pdfFilename, cacheFile, 'PDF')
def create_boa(event): """Create the book of abstracts if necessary :return: The path to the PDF file """ path = boa_settings.get(event, 'cache_path') if path and os.path.exists(path): return path pdf = AbstractBook(event) tmp_path = pdf.generate() path = os.path.join(Config.getInstance().getXMLCacheDir(), 'boa-{}.pdf'.format(event.id)) shutil.move(tmp_path, path) boa_settings.set(event, 'cache_path', path) return path
def create_boa(event): """Create the book of abstracts if necessary :return: The path to the PDF file """ path = boa_settings.get(event, 'cache_path') if path and os.path.exists(path): return path pdf = AbstractBook(event) tmp_path = pdf.generate() filename = 'boa-{}.pdf'.format(event.id) full_path = os.path.join(Config.getInstance().getXMLCacheDir(), filename) shutil.move(tmp_path, full_path) boa_settings.set(event, 'cache_path', filename) return full_path
def _process(self): boaConfig = self._conf.getBOAConfig() pdfFilename = "%s - Book of abstracts.pdf" % cleanHTMLHeaderFilename(self._target.getTitle()) cacheFile = self._getCacheFileName() if os.path.isfile(cacheFile): mtime = pytz.utc.localize(datetime.utcfromtimestamp(os.path.getmtime(cacheFile))) else: mtime = None if boaConfig.isCacheEnabled() and not self._noCache and mtime and mtime > boaConfig.lastChanged: return send_file(pdfFilename, cacheFile, 'PDF') else: tz = timezoneUtils.DisplayTZ(self._aw,self._target).getDisplayTZ() pdf = AbstractBook(self._target,self.getAW(), tz=tz) data = pdf.getPDFBin() with open(cacheFile, 'wb') as f: f.write(data) return send_file(pdfFilename, cacheFile, 'PDF')
def run(self, fileHandler=None): publicFileURL = "" try: # print "[DVD] Creating offline site . . .", if fileHandler is None: self._fileHandler = ZIPFileHandler() else: self._fileHandler = fileHandler # Folder with the DVD dvdPath = "Conference-%s" % self._normalisePath(self._conf.getTitle()) self._fileHandler.addDir(dvdPath) # Folder with the images imagesPath = os.path.join(dvdPath, "images") self._fileHandler.addDir(imagesPath) # Get all the images imagesPaths = self._getImagesList() self._getAllImages(imagesPath) # print ".", # CSS Style fname = os.path.join(dvdPath, "css", Config.getInstance().getCssStylesheetName()) cssFile = open( os.path.join(Config.getInstance().getHtdocsDir(), "css", Config.getInstance().getCssStylesheetName()), "rb", ) self._fileHandler.addNewFile(fname, cssFile.read()) cssFile.close() commonCSSFile = open(os.path.join(Config.getInstance().getHtdocsDir(), "css", "common.css")) self._fileHandler.addNewFile(os.path.join(dvdPath, "css", "common.css"), commonCSSFile.read()) commonCSSFile.close() # Index web page for a conference + material/resources fname = os.path.join(dvdPath, urlHandlers.UHStaticConferenceDisplay.getRelativeURL()) par = imagesPaths p = conferences.WPConferenceStaticDisplay(self._rh, self._conf, par) html = p.display() self._fileHandler.addNewFile(fname, html) materialList = self._conf.getAllMaterialList() if materialList is not None: for mat in materialList: if len(mat.getResourceList()) > 1 or len(mat.getResourceList()) == 0: fname = os.path.join( dvdPath, urlHandlers.UHStaticMaterialDisplay.getRelativeURL(mat, escape=False) ) p = conferences.WPMaterialStaticDisplay(self._rh, mat, par) html = p.display() self._fileHandler.addNewFile(fname, html) for res in mat.getResourceList(): if isinstance(res, conference.LocalFile): fname = os.path.join( dvdPath, urlHandlers.UHStaticResourceDisplay.getRelativeURL(res, escape=False) ) self._fileHandler.addNewFile(fname, res.readBin()) # print ".", # Scientific programme page fname = os.path.join(dvdPath, urlHandlers.UHStaticConferenceProgram.getRelativeURL()) par = imagesPaths p = conferences.WPConferenceStaticProgram(self._rh, self._conf, par) html = p.display() self._fileHandler.addNewFile(fname, html) # print ".", # AbstractBook fname = os.path.join(dvdPath, urlHandlers.UHStaticConfAbstractBook.getRelativeURL()) from MaKaC.PDFinterface.conference import AbstractBook pdf = AbstractBook(self._conf, self._rh.getAW(), "") data = pdf.getPDFBin() self._fileHandler.addNewFile(fname, data) # print ".", # Author index page fname = os.path.join(dvdPath, urlHandlers.UHStaticConfAuthorIndex.getRelativeURL()) par = imagesPaths p = conferences.WPStaticAuthorIndex(self._rh, self._conf, par) html = p.display() self._fileHandler.addNewFile(fname, html) # print ".", # Get every contribution order by track and by scheduled trackDict = {} for track in self._conf.getTrackList(): trackDict[track.getId()] = [] for session in self._conf.getSessionList(): for slotEntry in session.getSchedule().getEntries(): slot = slotEntry.getOwner() for contribEntry in slot.getSchedule().getEntries(): contrib = contribEntry.getOwner() if isinstance(contribEntry, schedule.LinkedTimeSchEntry): track = contrib.getTrack() if track is not None: trackDict[track.getId()].append(contrib) # print ".", # Contribution list page fname = os.path.join(dvdPath, urlHandlers.UHStaticContributionList.getRelativeURL()) par = imagesPaths p = conferences.WPStaticContributionList(self._rh, self._conf, par, trackDict) html = p.display() self._fileHandler.addNewFile(fname, html) # print ".", # ----- Create tracks folders, materials and contributions pages par = self._getSubdir(imagesPaths) for track in self._conf.getTrackList(): trackDir = os.path.join(dvdPath, track.getTitle().replace(" ", "_")) # Track folder self._fileHandler.addDir(trackDir) # Track contribution list fname = os.path.join(dvdPath, urlHandlers.UHStaticTrackContribList.getRelativeURL(track, escape=False)) p = conferences.WPTrackStaticContribList(self._rh, track, imagesPaths, trackDict) html = p.display() self._fileHandler.addNewFile(fname, html) # Contribs for contrib in track.getContributionList(): fname = os.path.join( dvdPath, urlHandlers.UHStaticContributionDisplay.getRelativeURL(contrib, escape=False) ) p = conferences.WPContributionStaticDisplay(self._rh, contrib, par) html = p.display() self._fileHandler.addNewFile(fname, html) materialList = contrib.getAllMaterialList() if materialList is not None: for mat in materialList: if len(mat.getResourceList()) > 1 or len(mat.getResourceList()) == 0: fname = os.path.join( trackDir, urlHandlers.UHStaticMaterialDisplay.getRelativeURL(mat, escape=False) ) p = conferences.WPMaterialStaticDisplay(self._rh, mat, par) html = p.display() self._fileHandler.addNewFile(fname, html) for res in mat.getResourceList(): if isinstance(res, conference.LocalFile): fname = os.path.join( trackDir, urlHandlers.UHStaticResourceDisplay.getRelativeURL(res) ) self._fileHandler.addNewFile(fname, res.readBin()) # print ".", # ------ Other contributions not within a track ------- otherContribsDir = os.path.join(dvdPath, "other_contributions") # Other Contribs folder self._fileHandler.addDir(otherContribsDir) for contrib in self._conf.getContributionList(): if contrib.getTrack() is None: fname = os.path.join( dvdPath, urlHandlers.UHStaticContributionDisplay.getRelativeURL(contrib, escape=False) ) p = conferences.WPContributionStaticDisplay(self._rh, contrib, par) html = p.display() self._fileHandler.addNewFile(fname, html) materialList = contrib.getAllMaterialList() if materialList is not None: for mat in materialList: if len(mat.getResourceList()) > 1 or len(mat.getResourceList()) == 0: fname = os.path.join( otherContribsDir, urlHandlers.UHStaticMaterialDisplay.getRelativeURL(mat, escape=False), ) p = conferences.WPMaterialStaticDisplay(self._rh, mat, par) html = p.display() self._fileHandler.addNewFile(fname, html) for res in mat.getResourceList(): if isinstance(res, conference.LocalFile): fname = os.path.join( otherContribsDir, urlHandlers.UHStaticResourceDisplay.getRelativeURL(res) ) self._fileHandler.addNewFile(fname, res.readBin()) # print ".", # Timetable fname = os.path.join(dvdPath, urlHandlers.UHStaticConferenceTimeTable.getRelativeURL()) par = imagesPaths p = conferences.WPConferenceStaticTimeTable(self._rh, self._conf, par) html = p.display() self._fileHandler.addNewFile(fname, html) # print ".", # Session in Timetable sessionsDir = os.path.join(dvdPath, "sessions") par = self._getSubdir(imagesPaths) for session in self._conf.getSessionList(): fname = os.path.join(dvdPath, urlHandlers.UHStaticSessionDisplay.getRelativeURL(session)) p = conferences.WPSessionStaticDisplay(self._rh, session, par) html = p.display() self._fileHandler.addNewFile(fname, html) materialList = session.getAllMaterialList() if materialList is not None: for mat in materialList: if len(mat.getResourceList()) > 1 or len(mat.getResourceList()) == 0: fname = os.path.join( sessionsDir, urlHandlers.UHStaticMaterialDisplay.getRelativeURL(mat, escape=False) ) p = conferences.WPMaterialStaticDisplay(self._rh, mat, par) html = p.display() self._fileHandler.addNewFile(fname, html) for res in mat.getResourceList(): if isinstance(res, conference.LocalFile): fname = os.path.join( sessionsDir, urlHandlers.UHStaticResourceDisplay.getRelativeURL(res) ) self._fileHandler.addNewFile(fname, res.readBin()) self._fileHandler.close() # print "[DONE]\nmaking public the DVD...", self._outputFileName = self._publicFile(self._fileHandler.getPath()) # print "[DONE]" publicFileURL = "%s/%s" % (Config.getInstance().getPublicURL(), self._outputFileName) # print "sending email...", self._sendEmail(publicFileURL) # print "[DONE]" except Exception, e: # print "[ERROR]" self._sendErrorEmail(e)
def run(self, fileHandler=None): publicFileURL = "" try: #print "[DVD] Creating offline site . . .", if fileHandler is None: self._fileHandler = ZIPFileHandler() else: self._fileHandler = fileHandler # Folder with the DVD dvdPath = "Conference-%s" % self._normalisePath( self._conf.getTitle()) self._fileHandler.addDir(dvdPath) # Folder with the images imagesPath = os.path.join(dvdPath, "images") self._fileHandler.addDir(imagesPath) # Get all the images imagesPaths = self._getImagesList() self._getAllImages(imagesPath) #print ".", # CSS Style fname = os.path.join(dvdPath, "css", Config.getInstance().getCssStylesheetName()) cssFile = open( os.path.join(Config.getInstance().getHtdocsDir(), "css", Config.getInstance().getCssStylesheetName()), "rb") self._fileHandler.addNewFile(fname, cssFile.read()) cssFile.close() commonCSSFile = open( os.path.join(Config.getInstance().getHtdocsDir(), "css", "common.css")) self._fileHandler.addNewFile( os.path.join(dvdPath, "css", "common.css"), commonCSSFile.read()) commonCSSFile.close() # Index web page for a conference + material/resources fname = os.path.join( dvdPath, urlHandlers.UHStaticConferenceDisplay.getRelativeURL()) par = imagesPaths p = conferences.WPConferenceStaticDisplay(self._rh, self._conf, par) html = p.display() self._fileHandler.addNewFile(fname, html) materialList = self._conf.getAllMaterialList() if materialList is not None: for mat in materialList: if len(mat.getResourceList()) > 1 or len( mat.getResourceList()) == 0: fname = os.path.join( dvdPath, urlHandlers.UHStaticMaterialDisplay.getRelativeURL( mat, escape=False)) p = conferences.WPMaterialStaticDisplay( self._rh, mat, par) html = p.display() self._fileHandler.addNewFile(fname, html) for res in mat.getResourceList(): if isinstance(res, conference.LocalFile): fname = os.path.join( dvdPath, urlHandlers.UHStaticResourceDisplay. getRelativeURL(res, escape=False)) self._fileHandler.addNewFile(fname, res.readBin()) #print ".", # Scientific programme page fname = os.path.join( dvdPath, urlHandlers.UHStaticConferenceProgram.getRelativeURL()) par = imagesPaths p = conferences.WPConferenceStaticProgram(self._rh, self._conf, par) html = p.display() self._fileHandler.addNewFile(fname, html) #print ".", # AbstractBook fname = os.path.join( dvdPath, urlHandlers.UHStaticConfAbstractBook.getRelativeURL()) from MaKaC.PDFinterface.conference import AbstractBook pdf = AbstractBook(self._conf, self._rh.getAW(), "") data = pdf.getPDFBin() self._fileHandler.addNewFile(fname, data) #print ".", # Author index page fname = os.path.join( dvdPath, urlHandlers.UHStaticConfAuthorIndex.getRelativeURL()) par = imagesPaths p = conferences.WPStaticAuthorIndex(self._rh, self._conf, par) html = p.display() self._fileHandler.addNewFile(fname, html) #print ".", # Get every contribution order by track and by scheduled trackDict = {} for track in self._conf.getTrackList(): trackDict[track.getId()] = [] for session in self._conf.getSessionList(): for slotEntry in session.getSchedule().getEntries(): slot = slotEntry.getOwner() for contribEntry in slot.getSchedule().getEntries(): contrib = contribEntry.getOwner() if isinstance(contribEntry, schedule.LinkedTimeSchEntry): track = contrib.getTrack() if track is not None: trackDict[track.getId()].append(contrib) #print ".", # Contribution list page fname = os.path.join( dvdPath, urlHandlers.UHStaticContributionList.getRelativeURL()) par = imagesPaths p = conferences.WPStaticContributionList(self._rh, self._conf, par, trackDict) html = p.display() self._fileHandler.addNewFile(fname, html) #print ".", # ----- Create tracks folders, materials and contributions pages par = self._getSubdir(imagesPaths) for track in self._conf.getTrackList(): trackDir = os.path.join(dvdPath, track.getTitle().replace(" ", "_")) # Track folder self._fileHandler.addDir(trackDir) # Track contribution list fname = os.path.join( dvdPath, urlHandlers.UHStaticTrackContribList.getRelativeURL( track, escape=False)) p = conferences.WPTrackStaticContribList( self._rh, track, imagesPaths, trackDict) html = p.display() self._fileHandler.addNewFile(fname, html) # Contribs for contrib in track.getContributionList(): fname = os.path.join( dvdPath, urlHandlers.UHStaticContributionDisplay.getRelativeURL( contrib, escape=False)) p = conferences.WPContributionStaticDisplay( self._rh, contrib, par) html = p.display() self._fileHandler.addNewFile(fname, html) materialList = contrib.getAllMaterialList() if materialList is not None: for mat in materialList: if len(mat.getResourceList()) > 1 or len( mat.getResourceList()) == 0: fname = os.path.join( trackDir, urlHandlers.UHStaticMaterialDisplay. getRelativeURL(mat, escape=False)) p = conferences.WPMaterialStaticDisplay( self._rh, mat, par) html = p.display() self._fileHandler.addNewFile(fname, html) for res in mat.getResourceList(): if isinstance(res, conference.LocalFile): fname = os.path.join( trackDir, urlHandlers.UHStaticResourceDisplay. getRelativeURL(res)) self._fileHandler.addNewFile( fname, res.readBin()) #print ".", # ------ Other contributions not within a track ------- otherContribsDir = os.path.join(dvdPath, "other_contributions") # Other Contribs folder self._fileHandler.addDir(otherContribsDir) for contrib in self._conf.getContributionList(): if contrib.getTrack() is None: fname = os.path.join( dvdPath, urlHandlers.UHStaticContributionDisplay.getRelativeURL( contrib, escape=False)) p = conferences.WPContributionStaticDisplay( self._rh, contrib, par) html = p.display() self._fileHandler.addNewFile(fname, html) materialList = contrib.getAllMaterialList() if materialList is not None: for mat in materialList: if len(mat.getResourceList()) > 1 or len( mat.getResourceList()) == 0: fname = os.path.join( otherContribsDir, urlHandlers.UHStaticMaterialDisplay. getRelativeURL(mat, escape=False)) p = conferences.WPMaterialStaticDisplay( self._rh, mat, par) html = p.display() self._fileHandler.addNewFile(fname, html) for res in mat.getResourceList(): if isinstance(res, conference.LocalFile): fname = os.path.join( otherContribsDir, urlHandlers.UHStaticResourceDisplay. getRelativeURL(res)) self._fileHandler.addNewFile( fname, res.readBin()) #print ".", # Timetable fname = os.path.join( dvdPath, urlHandlers.UHStaticConferenceTimeTable.getRelativeURL()) par = imagesPaths p = conferences.WPConferenceStaticTimeTable( self._rh, self._conf, par) html = p.display() self._fileHandler.addNewFile(fname, html) #print ".", # Session in Timetable sessionsDir = os.path.join(dvdPath, "sessions") par = self._getSubdir(imagesPaths) for session in self._conf.getSessionList(): fname = os.path.join( dvdPath, urlHandlers.UHStaticSessionDisplay.getRelativeURL(session)) p = conferences.WPSessionStaticDisplay(self._rh, session, par) html = p.display() self._fileHandler.addNewFile(fname, html) materialList = session.getAllMaterialList() if materialList is not None: for mat in materialList: if len(mat.getResourceList()) > 1 or len( mat.getResourceList()) == 0: fname = os.path.join( sessionsDir, urlHandlers.UHStaticMaterialDisplay. getRelativeURL(mat, escape=False)) p = conferences.WPMaterialStaticDisplay( self._rh, mat, par) html = p.display() self._fileHandler.addNewFile(fname, html) for res in mat.getResourceList(): if isinstance(res, conference.LocalFile): fname = os.path.join( sessionsDir, urlHandlers.UHStaticResourceDisplay. getRelativeURL(res)) self._fileHandler.addNewFile( fname, res.readBin()) self._fileHandler.close() #print "[DONE]\nmaking public the DVD...", self._outputFileName = self._publicFile( self._fileHandler.getPath()) #print "[DONE]" publicFileURL = "%s/%s" % (Config.getInstance().getPublicURL(), self._outputFileName) #print "sending email...", self._sendEmail(publicFileURL) #print "[DONE]" except Exception, e: #print "[ERROR]" self._sendErrorEmail(e)