示例#1
0
    def create(self, static_site_id):
        config = Config.getInstance()
        self._fileHandler = ZIPFileHandler()

        # create the home page html
        self._create_home()

        # Create main and static folders
        self._mainPath = self._normalize_path(u'OfflineWebsite-{}'.format(
            self._conf.getTitle().decode('utf-8')))
        self._fileHandler.addDir(self._mainPath)
        self._staticPath = os.path.join(self._mainPath, "static")
        self._fileHandler.addDir(self._staticPath)
        # Add i18n js
        self._addFolderFromSrc(
            os.path.join(self._staticPath, 'js', 'indico', 'i18n'),
            os.path.join(config.getHtdocsDir(), 'js', 'indico', 'i18n'))
        # Add system icons (not referenced in HTML/CSS)
        for icon in Config.getInstance().getSystemIcons().itervalues():
            self._addFileFromSrc(
                os.path.join(self._staticPath, 'images', icon),
                os.path.join(config.getHtdocsDir(), 'images', icon))
        # IE compat files (in conditional comments so BS doesn't see them)
        for path in ie_compatibility.urls():
            self._addFileFromSrc(
                os.path.join(self._staticPath, path.lstrip('/')),
                os.path.join(config.getHtdocsDir(), path.lstrip('/')))
        # Mathjax plugins can't be discovered by parsing the HTML
        self._addFolderFromSrc(
            os.path.join(self._staticPath, 'js', 'lib', 'mathjax'),
            os.path.join(config.getHtdocsDir(), 'js', 'lib', 'mathjax'))

        # Getting all materials, static files (css, images, js and vars.js.tpl)
        self._getAllMaterial()
        self._html = self._get_static_files(self._html)

        # Specific changes
        self._create_other_pages()

        # Retrieve files that were not available in the file system (e.e. js/css from plugins)
        self._get_failed_paths()
        self._failed_paths = set()

        # Retrieve files referenced in CSS files
        self._get_css_refs()

        # A custom event CSS might reference an uploaded image so we need to check for failed paths again
        self._get_failed_paths()

        # Create overview.html file (main page for the event)
        conferenceDisplayPath = os.path.join(self._mainPath, 'overview.html')
        self._fileHandler.addNewFile(conferenceDisplayPath, self._html)

        # Creating index.html file
        self._fileHandler.addNewFile(
            'index.html', '<meta http-equiv="Refresh" content="0; url=%s">' %
            conferenceDisplayPath)

        self._fileHandler.close()
        return self._save_file(self._fileHandler.getPath(), static_site_id)
示例#2
0
 def _process( self ):
     p = ReviewingPacker(self._conf)
     path = p.pack(ZIPFileHandler())
     filename = "accepted-papers.zip"
     cfg = Config.getInstance()
     mimetype = cfg.getFileTypeMimeType( "ZIP" )
     self._req.content_type = """%s"""%(mimetype)
     self._req.headers_out["Content-Disposition"] = """inline; filename="%s\""""%filename
     self._req.sendfile(path)
示例#3
0
    def create(self):
        config = Config.getInstance()
        self._fileHandler = ZIPFileHandler()

        # create the home page html
        self._create_home()

        # Create main and static folders
        self._mainPath = "OfflineWebsite-%s" % self._normalize_path(self._conf.getTitle())
        self._fileHandler.addDir(self._mainPath)
        self._staticPath = os.path.join(self._mainPath, "static")
        self._fileHandler.addDir(self._staticPath)
        # Add i18n js
        self._addFolderFromSrc(
            os.path.join(self._staticPath, "js", "indico", "i18n"),
            os.path.join(config.getHtdocsDir(), "js", "indico", "i18n"),
        )
        # Add system icons (not referenced in HTML/CSS)
        for icon in Config.getInstance().getSystemIcons().itervalues():
            self._addFileFromSrc(
                os.path.join(self._staticPath, "images", icon), os.path.join(config.getHtdocsDir(), "images", icon)
            )
        # IE compat files (in conditional comments so BS doesn't see them)
        for path in ie_compatibility.urls():
            self._addFileFromSrc(
                os.path.join(self._staticPath, path.lstrip("/")), os.path.join(config.getHtdocsDir(), path.lstrip("/"))
            )

        # Getting all materials, static files (css, images, js and vars.js.tpl)
        self._getAllMaterial()
        self._html = self._get_static_files(self._html)

        # Specific changes
        self._create_other_pages()

        # Retrieve files that were not available in the file system (e.e. js/css from plugins)
        self._get_failed_paths()
        self._failed_paths = set()

        # Retrieve files referenced in CSS files
        self._get_css_refs()

        # A custom event CSS might reference an uploaded image so we need to check for failed paths again
        self._get_failed_paths()

        # Creating ConferenceDisplay.html file
        conferenceDisplayPath = os.path.join(self._mainPath, urlHandlers.UHConferenceDisplay.getStaticURL())
        self._fileHandler.addNewFile(conferenceDisplayPath, self._html)

        # Creating index.html file
        self._fileHandler.addNewFile(
            "index.html", '<meta http-equiv="Refresh" content="0; url=%s">' % conferenceDisplayPath
        )

        self._fileHandler.close()
        self._outputFile = self._generateZipFile(self._fileHandler.getPath())
        return self._outputFile
示例#4
0
    def create(self, static_site_id):
        config = Config.getInstance()
        self._fileHandler = ZIPFileHandler()

        # create the home page html
        self._create_home()

        # Create main and static folders
        self._mainPath = self._normalize_path(u"OfflineWebsite-{}".format(self._conf.getTitle().decode("utf-8")))
        self._fileHandler.addDir(self._mainPath)
        self._staticPath = os.path.join(self._mainPath, "static")
        self._fileHandler.addDir(self._staticPath)
        # Add i18n js
        self._addFolderFromSrc(
            os.path.join(self._staticPath, "js", "indico", "i18n"),
            os.path.join(config.getHtdocsDir(), "js", "indico", "i18n"),
        )
        # Add system icons (not referenced in HTML/CSS)
        for icon in Config.getInstance().getSystemIcons().itervalues():
            self._addFileFromSrc(
                os.path.join(self._staticPath, "images", icon), os.path.join(config.getHtdocsDir(), "images", icon)
            )
        # Mathjax plugins can't be discovered by parsing the HTML
        self._addFolderFromSrc(
            os.path.join(self._staticPath, "js", "lib", "mathjax"),
            os.path.join(config.getHtdocsDir(), "js", "lib", "mathjax"),
        )

        # Getting all materials, static files (css, images, js and vars.js.tpl)
        self._getAllMaterial()
        self._html = self._get_static_files(self._html)

        # Specific changes
        self._create_other_pages()

        # Retrieve files that were not available in the file system (e.e. js/css from plugins)
        self._get_failed_paths()
        self._failed_paths = set()

        # Retrieve files referenced in CSS files
        self._get_css_refs()

        # A custom event CSS might reference an uploaded image so we need to check for failed paths again
        self._get_failed_paths()

        # Create overview.html file (main page for the event)
        conferenceDisplayPath = os.path.join(self._mainPath, "overview.html")
        self._fileHandler.addNewFile(conferenceDisplayPath, self._html)

        # Creating index.html file
        self._fileHandler.addNewFile(
            "index.html", '<meta http-equiv="Refresh" content="0; url=%s">' % conferenceDisplayPath
        )

        self._fileHandler.close()
        return self._save_file(self._fileHandler.getPath(), static_site_id)
示例#5
0
 def pack( self ):
     from MaKaC.common.contribPacker import ZIPFileHandler,RegistrantPacker
     p=RegistrantPacker(self._conf)
     path=p.pack(self._list, ZIPFileHandler())
     filename = "registrants.zip"
     cfg = Config.getInstance()
     mimetype = cfg.getFileTypeMimeType( "ZIP" )
     self._rh._req.set_content_length(os.path.getsize(path))
     self._rh._req.content_type = """%s"""%(mimetype)
     self._rh._req.headers_out["Content-Disposition"] = """inline; filename="%s\""""%filename
     self._rh._req.sendfile(path)
    def create(self, static_site_id):
        config = Config.getInstance()
        self._fileHandler = ZIPFileHandler()

        # create the home page html
        self._create_home()

        # Create main and static folders
        self._mainPath = self._normalize_path(u'OfflineWebsite-{}'.format(self._conf.getTitle().decode('utf-8')))
        self._fileHandler.addDir(self._mainPath)
        self._staticPath = os.path.join(self._mainPath, "static")
        self._fileHandler.addDir(self._staticPath)
        # Add i18n js
        self._addFolderFromSrc(os.path.join(self._staticPath, 'js', 'indico', 'i18n'),
                               os.path.join(config.getHtdocsDir(), 'js', 'indico', 'i18n'))
        # Add system icons (not referenced in HTML/CSS)
        for icon in Config.getInstance().getSystemIcons().itervalues():
            self._addFileFromSrc(os.path.join(self._staticPath, 'images', icon),
                                 os.path.join(config.getHtdocsDir(), 'images', icon))
        # IE compat files (in conditional comments so BS doesn't see them)
        for path in ie_compatibility.urls():
            self._addFileFromSrc(os.path.join(self._staticPath, path.lstrip('/')),
                                 os.path.join(config.getHtdocsDir(), path.lstrip('/')))

        # Getting all materials, static files (css, images, js and vars.js.tpl)
        self._getAllMaterial()
        self._html = self._get_static_files(self._html)

        # Specific changes
        self._create_other_pages()

        # Retrieve files that were not available in the file system (e.e. js/css from plugins)
        self._get_failed_paths()
        self._failed_paths = set()

        # Retrieve files referenced in CSS files
        self._get_css_refs()

        # A custom event CSS might reference an uploaded image so we need to check for failed paths again
        self._get_failed_paths()

        # Create overview.html file (main page for the event)
        conferenceDisplayPath = os.path.join(self._mainPath, 'overview.html')
        self._fileHandler.addNewFile(conferenceDisplayPath, self._html)

        # Creating index.html file
        self._fileHandler.addNewFile('index.html',
                                     '<meta http-equiv="Refresh" content="0; url=%s">' % conferenceDisplayPath)

        self._fileHandler.close()
        return self._save_file(self._fileHandler.getPath(), static_site_id)
 def _process(self):
     if not self._cancel:
         if self._materialTypes != []:
             p = ConferencePacker(self._conf, self._aw)
             path = p.pack(self._materialTypes, self._days,
                           self._mainResource, self._fromDate,
                           ZIPFileHandler(), self._sessionList)
             if not p.getItems():
                 raise NoReportError(
                     _("The selected package does not contain any items."))
             return send_file('full-material.zip',
                              path,
                              'ZIP',
                              inline=False)
         else:
             raise NoReportError(
                 _("You have to select at least one material type"))
     else:
         self._redirect(urlHandlers.UHConferenceDisplay.getURL(self._conf))
示例#8
0
    def run(self, fileHandler=None):
        publicFileURL = ""
        try:
            if fileHandler is None:
                self._fileHandler = ZIPFileHandler()
            else:
                self._fileHandler = fileHandler
            dvdPath = "Meeting-%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.WPXSLMeetingStaticDisplay(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:
                        paraux = self.getRootDirPars(mat, par)
                        fname = os.path.join(
                            dvdPath, urlHandlers.UHMStaticMaterialDisplay.getRelativeURL(mat, escape=False)
                        )
                        p = conferences.WPMMaterialStaticDisplay(self._rh, mat, paraux)
                        html = p.display()
                        self._fileHandler.addNewFile(fname, html)
                    for res in mat.getResourceList():
                        if isinstance(res, conference.LocalFile):
                            fname = os.path.join(dvdPath, urlHandlers.UHMStaticResourceDisplay.getRelativeURL(res))
                            self._fileHandler.addNewFile(fname, res.readBin())

            # Material pages for the contributions in the meeting
            for contrib in self._conf.getContributionList():
                if contrib.isScheduled():
                    for mat in contrib.getAllMaterialList():
                        if len(mat.getResourceList()) != 1:
                            fname = os.path.join(
                                dvdPath, urlHandlers.UHMStaticMaterialDisplay.getRelativeURL(mat, escape=False)
                            )
                            paraux = self.getRootDirPars(mat, par)
                            p = conferences.WPMMaterialStaticDisplay(self._rh, mat, paraux)
                            try:
                                html = p.display()
                            except Exception, e:
                                continue
                            self._fileHandler.addNewFile(fname, html)
                        for res in mat.getResourceList():
                            if isinstance(res, conference.LocalFile):
                                fname = os.path.join(
                                    dvdPath, urlHandlers.UHMStaticResourceDisplay.getRelativeURL(res, escape=False)
                                )
                                try:
                                    self._fileHandler.addNewFile(fname, res.readBin())
                                except Exception, e:
                                    continue
                    for subcont in contrib.getSubContributionList():
                        for mat in subcont.getAllMaterialList():
                            if len(mat.getResourceList()) != 1:
                                paraux = self.getRootDirPars(mat, par)
                                fname = os.path.join(
                                    dvdPath, urlHandlers.UHMStaticMaterialDisplay.getRelativeURL(mat, escape=False)
                                )
                                p = conferences.WPMMaterialStaticDisplay(self._rh, mat, paraux)
                                try:
                                    html = p.display()
                                except Exception, e:
                                    continue
                                self._fileHandler.addNewFile(fname, html)
                            for res in mat.getResourceList():
                                if isinstance(res, conference.LocalFile):
                                    fname = os.path.join(
                                        dvdPath, urlHandlers.UHMStaticResourceDisplay.getRelativeURL(res, escape=False)
                                    )
                                    try:
                                        self._fileHandler.addNewFile(fname, res.readBin())
                                    except Exception, e:
                                        continue
示例#9
0
    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)
class OfflineEventCreator(object):

    def __init__(self, rh, conf, event_type=""):
        self._rh = rh
        self._conf = conf
        self.event = conf.as_event
        self._html = ""
        self._fileHandler = None
        self._mainPath = ""
        self._staticPath = ""
        self._eventType = event_type
        self._failed_paths = set()
        self._css_files = set()
        self._downloaded_files = {}

    def create(self, static_site_id):
        config = Config.getInstance()
        self._fileHandler = ZIPFileHandler()

        # create the home page html
        self._create_home()

        # Create main and static folders
        self._mainPath = self._normalize_path(u'OfflineWebsite-{}'.format(self._conf.getTitle().decode('utf-8')))
        self._fileHandler.addDir(self._mainPath)
        self._staticPath = os.path.join(self._mainPath, "static")
        self._fileHandler.addDir(self._staticPath)
        # Add i18n js
        self._addFolderFromSrc(os.path.join(self._staticPath, 'js', 'indico', 'i18n'),
                               os.path.join(config.getHtdocsDir(), 'js', 'indico', 'i18n'))
        # Add system icons (not referenced in HTML/CSS)
        for icon in Config.getInstance().getSystemIcons().itervalues():
            self._addFileFromSrc(os.path.join(self._staticPath, 'images', icon),
                                 os.path.join(config.getHtdocsDir(), 'images', icon))
        # IE compat files (in conditional comments so BS doesn't see them)
        for path in ie_compatibility.urls():
            self._addFileFromSrc(os.path.join(self._staticPath, path.lstrip('/')),
                                 os.path.join(config.getHtdocsDir(), path.lstrip('/')))

        # Getting all materials, static files (css, images, js and vars.js.tpl)
        self._getAllMaterial()
        self._html = self._get_static_files(self._html)

        # Specific changes
        self._create_other_pages()

        # Retrieve files that were not available in the file system (e.e. js/css from plugins)
        self._get_failed_paths()
        self._failed_paths = set()

        # Retrieve files referenced in CSS files
        self._get_css_refs()

        # A custom event CSS might reference an uploaded image so we need to check for failed paths again
        self._get_failed_paths()

        # Create overview.html file (main page for the event)
        conferenceDisplayPath = os.path.join(self._mainPath, 'overview.html')
        self._fileHandler.addNewFile(conferenceDisplayPath, self._html)

        # Creating index.html file
        self._fileHandler.addNewFile('index.html',
                                     '<meta http-equiv="Refresh" content="0; url=%s">' % conferenceDisplayPath)

        self._fileHandler.close()
        return self._save_file(self._fileHandler.getPath(), static_site_id)

    def _get_static_files(self, html):
        config = Config.getInstance()
        soup = BeautifulSoup(html)
        images = set(_fix_url_path(x['src']) for x in soup.select('img[src]'))
        scripts = set(_fix_url_path(x['src']) for x in soup.select('script[src]'))
        styles = set(_fix_url_path(x['href']) for x in soup.select('link[rel="stylesheet"]'))
        for path in itertools.chain(images, scripts, styles):
            src_path = re.sub(r'#.*$', '', os.path.join(config.getHtdocsDir(), path))
            dst_path = os.path.join(self._staticPath, path)
            if path in styles:
                self._css_files.add(path)
            if not os.path.isfile(src_path):
                self._failed_paths.add(path)
            elif path not in styles:
                self._addFileFromSrc(dst_path, src_path)
        for image in soup.select('img[src]'):
            image['src'] = os.path.join('static', _fix_url_path(image['src']))
        for script in soup.select('script[src]'):
            script['src'] = os.path.join('static', _fix_url_path(script['src']))
        for style in soup.select('link[rel="stylesheet"]'):
            style['href'] = os.path.join('static', _fix_url_path(style['href']))
        return str(soup)

    def _get_failed_paths(self):
        """Downloads files that were not available in the fielystem via HTTP.
        This is the only clean way to deal with static files from plugins since otherwise
        we would have to emulate RHHtdocs.
        """
        cfg = Config.getInstance()
        # If we have the embedded webserver prefer its base url since the iptables hack does
        # not work for connections from the same machine
        base_url = cfg.getBaseURL()
        for path in self._failed_paths:
            dst_path = os.path.join(self._staticPath, path)
            if not self._fileHandler.hasFile(dst_path):
                response = requests.get(os.path.join(base_url, path), verify=False)
                self._downloaded_files[dst_path] = response.content
                self._fileHandler.addNewFile(dst_path, response.content)

    def _get_css_refs(self):
        """Adds files referenced in stylesheets and rewrite the URLs inside those stylesheets"""
        config = Config.getInstance()
        for path in self._css_files:
            src_path = os.path.join(config.getHtdocsDir(), path)
            dst_path = os.path.join(self._staticPath, path)
            if dst_path in self._downloaded_files and not os.path.exists(src_path):
                css = self._downloaded_files[dst_path]
            else:
                with open(src_path, 'rb') as f:
                    css = f.read()
            # Extract all paths inside url()
            urls = set(m.group('url') for m in RE_CSS_URL.finditer(css) if m.group('url')[0] != '#')
            for url in urls:
                orig_url = url
                url = _remove_qs(url)  # get rid of cache busters
                if url[0] == '/':
                    # make it relative and resolve '..' elements
                    url = os.path.normpath(url[1:])
                    # anything else is straightforward: the url is now relative to the htdocs folder
                    ref_src_path = os.path.join(config.getHtdocsDir(), url)
                    ref_dst_path = os.path.join(self._staticPath, url)
                    # the new url is relative to the css location
                    static_url = os.path.relpath(url, os.path.dirname(path))
                else:
                    # make the relative path absolute (note: it's most likely NOT relative to htdocs!)
                    css_abs_path = os.path.join(config.getHtdocsDir(), path)
                    # now we can combine the relative url with that path to get the proper paths of the resource
                    ref_src_path = os.path.normpath(os.path.join(os.path.dirname(css_abs_path), url))
                    ref_dst_path = os.path.normpath(os.path.join(self._staticPath, os.path.dirname(path), url))
                    static_url = os.path.relpath(ref_src_path, os.path.dirname(css_abs_path))
                if not os.path.isfile(ref_src_path):
                    htdocs_relative_path = os.path.relpath(ref_src_path, config.getHtdocsDir())
                    htdocs_relative_path = re.sub(r'#.*$', '', htdocs_relative_path)
                    self._failed_paths.add(htdocs_relative_path)
                else:
                    self._addFileFromSrc(ref_dst_path, ref_src_path)
                css = css.replace(orig_url, static_url)
            self._fileHandler.addNewFile(dst_path, css)

    def _create_home(self):
        # get default/selected view
        styleMgr = HelperMaKaCInfo.getMaKaCInfoInstance().getStyleManager()
        view = self._rh._target.getDefaultStyle()
        # if no default view was attributed, then get the configuration default
        if view == "" or not styleMgr.existsStyle(view) or view in styleMgr.getXSLStyles():
            view = styleMgr.getDefaultStyleForEventType(self._eventType)
        p = WPTPLStaticConferenceDisplay(self._rh, self._rh._target, view, self._eventType, self._rh._reqParams)
        self._html = p.display(**self._rh._getRequestParams())

    def _create_other_pages(self):
        pass

    def _normalize_path(self, path):
        return secure_filename(remove_tags(path))

    def _getAllMaterial(self):
        self._addMaterialFrom(self._conf, "events/conference")
        for contrib in self._conf.getContributionList():
            self._addMaterialFrom(contrib, "agenda/%s-contribution" % contrib.getId())
            if contrib.getSubContributionList():
                for sc in contrib.getSubContributionList():
                    self._addMaterialFrom(sc, "agenda/%s-subcontribution" % sc.getId())
        for session in self._conf.getSessionList():
            self._addMaterialFrom(session, "agenda/%s-session" % session.getId())

    def _addMaterialFrom(self, target, categoryPath):
        for folder in AttachmentFolder.get_for_linked_object(target, preload_event=True):
            for attachment in folder.attachments:
                if attachment.type == AttachmentType.file:
                    dst_path = posixpath.join(self._mainPath, "files", categoryPath,
                                              "{}-{}".format(attachment.id, attachment.file.filename))
                    with attachment.file.get_local_path() as file_path:
                        self._addFileFromSrc(dst_path, file_path)

    def _addFileFromSrc(self, dstPath, srcPath):
        if not os.path.isfile(dstPath) and os.path.isfile(srcPath):
            if not self._fileHandler.hasFile(dstPath):
                newFile = open(srcPath, "rb")
                self._fileHandler.addNewFile(dstPath, newFile.read())
                newFile.close()

    def _addFolderFromSrc(self, dstPath, srcPath):
        for root, subfolders, files in os.walk(srcPath):
            for filename in files:
                src_filepath = os.path.join(root, filename)
                dst_dirpath = os.path.join(dstPath, root.strip(srcPath))
                dst_filepath = os.path.join(dst_dirpath, filename)
                self._fileHandler.addDir(dst_dirpath)
                if not self._fileHandler.hasFile(dst_filepath):
                    self._fileHandler.add(dst_filepath, src_filepath)

    def _save_file(self, srcPath, static_site_id):
        volume = HelperMaKaCInfo.getMaKaCInfoInstance().getArchivingVolume()
        path = os.path.join(Config.getInstance().getOfflineStore(), volume, 'offline', self._conf.getId())
        file_path = os.path.join(path, '{}.zip'.format(static_site_id))
        try:
            os.makedirs(path)
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise
        shutil.copyfile(srcPath, file_path)
        return file_path
示例#11
0
class OfflineEventCreator(object):
    def __init__(self, rh, conf, event_type=""):
        self._rh = rh
        self._conf = conf
        self._html = ""
        self._outputFile = ""
        self._fileHandler = None
        self._mainPath = ""
        self._staticPath = ""
        self._eventType = event_type
        self._failed_paths = set()
        self._css_files = set()
        self._downloaded_files = {}

    def create(self):
        config = Config.getInstance()
        self._fileHandler = ZIPFileHandler()

        # create the home page html
        self._create_home()

        # Create main and static folders
        self._mainPath = self._normalize_path(u'OfflineWebsite-{}'.format(
            self._conf.getTitle().decode('utf-8')))
        self._fileHandler.addDir(self._mainPath)
        self._staticPath = os.path.join(self._mainPath, "static")
        self._fileHandler.addDir(self._staticPath)
        # Add i18n js
        self._addFolderFromSrc(
            os.path.join(self._staticPath, 'js', 'indico', 'i18n'),
            os.path.join(config.getHtdocsDir(), 'js', 'indico', 'i18n'))
        # Add system icons (not referenced in HTML/CSS)
        for icon in Config.getInstance().getSystemIcons().itervalues():
            self._addFileFromSrc(
                os.path.join(self._staticPath, 'images', icon),
                os.path.join(config.getHtdocsDir(), 'images', icon))
        # IE compat files (in conditional comments so BS doesn't see them)
        for path in ie_compatibility.urls():
            self._addFileFromSrc(
                os.path.join(self._staticPath, path.lstrip('/')),
                os.path.join(config.getHtdocsDir(), path.lstrip('/')))

        # Getting all materials, static files (css, images, js and vars.js.tpl)
        self._getAllMaterial()
        self._html = self._get_static_files(self._html)

        # Specific changes
        self._create_other_pages()

        # Retrieve files that were not available in the file system (e.e. js/css from plugins)
        self._get_failed_paths()
        self._failed_paths = set()

        # Retrieve files referenced in CSS files
        self._get_css_refs()

        # A custom event CSS might reference an uploaded image so we need to check for failed paths again
        self._get_failed_paths()

        # Creating ConferenceDisplay.html file
        conferenceDisplayPath = os.path.join(
            self._mainPath, urlHandlers.UHConferenceDisplay.getStaticURL())
        self._fileHandler.addNewFile(conferenceDisplayPath, self._html)

        # Creating index.html file
        self._fileHandler.addNewFile(
            'index.html', '<meta http-equiv="Refresh" content="0; url=%s">' %
            conferenceDisplayPath)

        self._fileHandler.close()
        self._outputFile = self._generateZipFile(self._fileHandler.getPath())
        return self._outputFile

    def _get_static_files(self, html):
        config = Config.getInstance()
        soup = BeautifulSoup(html)
        scripts = set(
            _fix_url_path(x['src']) for x in soup.select('script[src]'))
        styles = set(
            _fix_url_path(x['href'])
            for x in soup.select('link[rel="stylesheet"]'))
        for path in itertools.chain(scripts, styles):
            src_path = os.path.join(config.getHtdocsDir(), path)
            dst_path = os.path.join(self._staticPath, path)
            if path in styles:
                self._css_files.add(path)
            if not os.path.isfile(src_path):
                self._failed_paths.add(path)
            elif path not in styles:
                self._addFileFromSrc(dst_path, src_path)
        for script in soup.select('script[src]'):
            script['src'] = os.path.join('static',
                                         _fix_url_path(script['src']))
        for style in soup.select('link[rel="stylesheet"]'):
            style['href'] = os.path.join('static',
                                         _fix_url_path(style['href']))
        return str(soup)

    def _get_failed_paths(self):
        """Downloads files that were not available in the fielystem via HTTP.
        This is the only clean way to deal with static files from plugins since otherwise
        we would have to emulate RHHtdocs.
        """
        cfg = Config.getInstance()
        # If we have the embedded webserver prefer its base url since the iptables hack does
        # not work for connections from the same machine
        base_url = cfg.getEmbeddedWebserverBaseURL() or cfg.getBaseURL()
        for path in self._failed_paths:
            dst_path = os.path.join(self._staticPath, path)
            if not self._fileHandler.hasFile(dst_path):
                response = requests.get(os.path.join(base_url, path),
                                        verify=False)
                self._downloaded_files[dst_path] = response.content
                self._fileHandler.addNewFile(dst_path, response.content)

    def _get_css_refs(self):
        """Adds files referenced in stylesheets and rewrite the URLs inside those stylesheets"""
        config = Config.getInstance()
        for path in self._css_files:
            src_path = os.path.join(config.getHtdocsDir(), path)
            dst_path = os.path.join(self._staticPath, path)
            if dst_path in self._downloaded_files and not os.path.exists(
                    src_path):
                css = self._downloaded_files[dst_path]
            else:
                with open(src_path, 'rb') as f:
                    css = f.read()
            # Extract all paths inside url()
            urls = set(
                m.group('url') for m in RE_CSS_URL.finditer(css)
                if m.group('url')[0] != '#')
            for url in urls:
                orig_url = url
                url = _remove_qs(url)  # get rid of cache busters
                if url[0] == '/':
                    # make it relative and resolve '..' elements
                    url = os.path.normpath(url[1:])
                    # anything else is straightforward: the url is now relative to the htdocs folder
                    ref_src_path = os.path.join(config.getHtdocsDir(), url)
                    ref_dst_path = os.path.join(self._staticPath, url)
                    # the new url is relative to the css location
                    static_url = os.path.relpath(url, os.path.dirname(path))
                else:
                    # make the relative path absolute (note: it's most likely NOT relative to htdocs!)
                    css_abs_path = os.path.join(config.getHtdocsDir(), path)
                    # now we can combine the relative url with that path to get the proper paths of the resource
                    ref_src_path = os.path.normpath(
                        os.path.join(os.path.dirname(css_abs_path), url))
                    ref_dst_path = os.path.normpath(
                        os.path.join(self._staticPath, os.path.dirname(path),
                                     url))
                    static_url = os.path.relpath(ref_src_path,
                                                 os.path.dirname(css_abs_path))
                if not os.path.isfile(ref_src_path):
                    htdocs_relative_path = os.path.relpath(
                        ref_src_path, config.getHtdocsDir())
                    self._failed_paths.add(htdocs_relative_path)
                else:
                    self._addFileFromSrc(ref_dst_path, ref_src_path)
                css = css.replace(orig_url, static_url)
            self._fileHandler.addNewFile(dst_path, css)

    def _create_home(self):
        # get default/selected view
        styleMgr = info.HelperMaKaCInfo.getMaKaCInfoInstance().getStyleManager(
        )
        view = displayMgr.ConfDisplayMgrRegistery().getDisplayMgr(
            self._rh._target).getDefaultStyle()
        # if no default view was attributed, then get the configuration default
        if view == "" or not styleMgr.existsStyle(
                view) or view in styleMgr.getXSLStyles():
            view = styleMgr.getDefaultStyleForEventType(self._eventType)
        p = WPTPLStaticConferenceDisplay(self._rh, self._rh._target, view,
                                         self._eventType, self._rh._reqParams)
        self._html = p.display(**self._rh._getRequestParams())

    def _create_other_pages(self):
        pass

    def _normalize_path(self, path):
        return secure_filename(remove_tags(path))

    def _getAllMaterial(self):
        self._addMaterialFrom(self._conf, "events/conference")
        for contrib in self._conf.getContributionList():
            self._addMaterialFrom(contrib,
                                  "agenda/%s-contribution" % contrib.getId())
            if contrib.getSubContributionList():
                for sc in contrib.getSubContributionList():
                    self._addMaterialFrom(
                        sc, "agenda/%s-subcontribution" % sc.getId())
        for session in self._conf.getSessionList():
            self._addMaterialFrom(session,
                                  "agenda/%s-session" % session.getId())

    def _addMaterialFrom(self, target, categoryPath):
        if target.getAllMaterialList():
            for mat in target.getAllMaterialList():
                for res in mat.getResourceList():
                    if isinstance(res, conference.LocalFile):
                        dstPath = os.path.join(
                            self._mainPath, "files", categoryPath, mat.getId(),
                            res.getId() + "-" + res.getName())
                        self._addFileFromSrc(dstPath, res.getFilePath())

    def _addFileFromSrc(self, dstPath, srcPath):
        if not os.path.isfile(dstPath) and os.path.isfile(srcPath):
            if not self._fileHandler.hasFile(dstPath):
                newFile = open(srcPath, "rb")
                self._fileHandler.addNewFile(dstPath, newFile.read())
                newFile.close()

    def _addFolderFromSrc(self, dstPath, srcPath):
        for root, subfolders, files in os.walk(srcPath):
            for filename in files:
                src_filepath = os.path.join(root, filename)
                dst_dirpath = os.path.join(dstPath, root.strip(srcPath))
                dst_filepath = os.path.join(dst_dirpath, filename)
                self._fileHandler.addDir(dst_dirpath)
                if not self._fileHandler.hasFile(dst_filepath):
                    self._fileHandler.add(dst_filepath, src_filepath)

    def _generateZipFile(self, srcPath):
        repo = OfflineRepository.getRepositoryFromDB()
        filename = os.path.basename(srcPath) + ".zip"
        fd = LocalFile()
        fd.setFilePath(srcPath)
        fd.setFileName(filename)
        repo.storeFile(fd, self._conf.getId())
        return fd
示例#12
0
 def _process(self):
     p = ReviewingPacker(self._conf)
     path = p.pack(ZIPFileHandler())
     if not os.path.getsize(path):
         raise NoReportError(_('There are no accepted papers.'))
     return send_file('accepted-papers.zip', path, 'ZIP', inline=False)
示例#13
0
class OfflineEventCreator(object):
    def __init__(self, rh, conf, event_type=""):
        self._rh = rh
        self._conf = conf
        self._html = ""
        self._outputFile = ""
        self._fileHandler = None
        self._mainPath = ""
        self._staticPath = ""
        self._eventType = event_type
        self._failed_paths = set()
        self._css_files = set()
        self._downloaded_files = {}

    def create(self):
        config = Config.getInstance()
        self._fileHandler = ZIPFileHandler()

        # create the home page html
        self._create_home()

        # Create main and static folders
        self._mainPath = "OfflineWebsite-%s" % self._normalize_path(self._conf.getTitle())
        self._fileHandler.addDir(self._mainPath)
        self._staticPath = os.path.join(self._mainPath, "static")
        self._fileHandler.addDir(self._staticPath)
        # Add i18n js
        self._addFolderFromSrc(
            os.path.join(self._staticPath, "js", "indico", "i18n"),
            os.path.join(config.getHtdocsDir(), "js", "indico", "i18n"),
        )
        # Add system icons (not referenced in HTML/CSS)
        for icon in Config.getInstance().getSystemIcons().itervalues():
            self._addFileFromSrc(
                os.path.join(self._staticPath, "images", icon), os.path.join(config.getHtdocsDir(), "images", icon)
            )
        # IE compat files (in conditional comments so BS doesn't see them)
        for path in ie_compatibility.urls():
            self._addFileFromSrc(
                os.path.join(self._staticPath, path.lstrip("/")), os.path.join(config.getHtdocsDir(), path.lstrip("/"))
            )

        # Getting all materials, static files (css, images, js and vars.js.tpl)
        self._getAllMaterial()
        self._html = self._get_static_files(self._html)

        # Specific changes
        self._create_other_pages()

        # Retrieve files that were not available in the file system (e.e. js/css from plugins)
        self._get_failed_paths()
        self._failed_paths = set()

        # Retrieve files referenced in CSS files
        self._get_css_refs()

        # A custom event CSS might reference an uploaded image so we need to check for failed paths again
        self._get_failed_paths()

        # Creating ConferenceDisplay.html file
        conferenceDisplayPath = os.path.join(self._mainPath, urlHandlers.UHConferenceDisplay.getStaticURL())
        self._fileHandler.addNewFile(conferenceDisplayPath, self._html)

        # Creating index.html file
        self._fileHandler.addNewFile(
            "index.html", '<meta http-equiv="Refresh" content="0; url=%s">' % conferenceDisplayPath
        )

        self._fileHandler.close()
        self._outputFile = self._generateZipFile(self._fileHandler.getPath())
        return self._outputFile

    def _get_static_files(self, html):
        config = Config.getInstance()
        soup = BeautifulSoup(html)
        scripts = set(_fix_url_path(x["src"]) for x in soup.select("script[src]"))
        styles = set(_fix_url_path(x["href"]) for x in soup.select('link[rel="stylesheet"]'))
        for path in itertools.chain(scripts, styles):
            src_path = os.path.join(config.getHtdocsDir(), path)
            dst_path = os.path.join(self._staticPath, path)
            if path in styles:
                self._css_files.add(path)
            if not os.path.isfile(src_path):
                self._failed_paths.add(path)
            elif path not in styles:
                self._addFileFromSrc(dst_path, src_path)
        for script in soup.select("script[src]"):
            script["src"] = os.path.join("static", _fix_url_path(script["src"]))
        for style in soup.select('link[rel="stylesheet"]'):
            style["href"] = os.path.join("static", _fix_url_path(style["href"]))
        return str(soup)

    def _get_failed_paths(self):
        """Downloads files that were not available in the fielystem via HTTP.
        This is the only clean way to deal with static files from plugins since otherwise
        we would have to emulate RHHtdocs.
        """
        cfg = Config.getInstance()
        # If we have the embedded webserver prefer its base url since the iptables hack does
        # not work for connections from the same machine
        base_url = cfg.getEmbeddedWebserverBaseURL() or cfg.getBaseURL()
        for path in self._failed_paths:
            dst_path = os.path.join(self._staticPath, path)
            if not self._fileHandler.hasFile(dst_path):
                response = requests.get(os.path.join(base_url, path), verify=False)
                self._downloaded_files[dst_path] = response.content
                self._fileHandler.addNewFile(dst_path, response.content)

    def _get_css_refs(self):
        """Adds files referenced in stylesheets and rewrite the URLs inside those stylesheets"""
        config = Config.getInstance()
        for path in self._css_files:
            src_path = os.path.join(config.getHtdocsDir(), path)
            dst_path = os.path.join(self._staticPath, path)
            if dst_path in self._downloaded_files and not os.path.exists(src_path):
                css = self._downloaded_files[dst_path]
            else:
                with open(src_path, "rb") as f:
                    css = f.read()
            # Extract all paths inside url()
            urls = set(m.group("url") for m in RE_CSS_URL.finditer(css) if m.group("url")[0] != "#")
            for url in urls:
                orig_url = url
                url = _remove_qs(url)  # get rid of cache busters
                if url[0] == "/":
                    # make it relative and resolve '..' elements
                    url = os.path.normpath(url[1:])
                    # anything else is straightforward: the url is now relative to the htdocs folder
                    ref_src_path = os.path.join(config.getHtdocsDir(), url)
                    ref_dst_path = os.path.join(self._staticPath, url)
                    # the new url is relative to the css location
                    static_url = os.path.relpath(url, os.path.dirname(path))
                else:
                    # make the relative path absolute (note: it's most likely NOT relative to htdocs!)
                    css_abs_path = os.path.join(config.getHtdocsDir(), path)
                    # now we can combine the relative url with that path to get the proper paths of the resource
                    ref_src_path = os.path.normpath(os.path.join(os.path.dirname(css_abs_path), url))
                    ref_dst_path = os.path.normpath(os.path.join(self._staticPath, os.path.dirname(path), url))
                    static_url = os.path.relpath(ref_src_path, os.path.dirname(css_abs_path))
                if not os.path.isfile(ref_src_path):
                    htdocs_relative_path = os.path.relpath(ref_src_path, config.getHtdocsDir())
                    self._failed_paths.add(htdocs_relative_path)
                else:
                    self._addFileFromSrc(ref_dst_path, ref_src_path)
                css = css.replace(orig_url, static_url)
            self._fileHandler.addNewFile(dst_path, css)

    def _create_home(self):
        # get default/selected view
        styleMgr = info.HelperMaKaCInfo.getMaKaCInfoInstance().getStyleManager()
        view = displayMgr.ConfDisplayMgrRegistery().getDisplayMgr(self._rh._target).getDefaultStyle()
        # if no default view was attributed, then get the configuration default
        if view == "" or not styleMgr.existsStyle(view) or view in styleMgr.getXSLStyles():
            view = styleMgr.getDefaultStyleForEventType(self._eventType)
        p = WPTPLStaticConferenceDisplay(self._rh, self._rh._target, view, self._eventType, self._rh._reqParams)
        self._html = p.display(**self._rh._getRequestParams())

    def _create_other_pages(self):
        pass

    def _normalize_path(self, path):
        return path.translate(string.maketrans(' /:()*?<>|"', "___________"))

    def _getAllMaterial(self):
        self._addMaterialFrom(self._conf, "events/conference")
        for contrib in self._conf.getContributionList():
            self._addMaterialFrom(contrib, "agenda/%s-contribution" % contrib.getId())
            if contrib.getSubContributionList():
                for sc in contrib.getSubContributionList():
                    self._addMaterialFrom(sc, "agenda/%s-subcontribution" % sc.getId())
        for session in self._conf.getSessionList():
            self._addMaterialFrom(session, "agenda/%s-session" % session.getId())

    def _addMaterialFrom(self, target, categoryPath):
        if target.getAllMaterialList():
            for mat in target.getAllMaterialList():
                for res in mat.getResourceList():
                    if isinstance(res, conference.LocalFile):
                        dstPath = os.path.join(
                            self._mainPath, "files", categoryPath, mat.getId(), res.getId() + "-" + res.getName()
                        )
                        self._addFileFromSrc(dstPath, res.getFilePath())

    def _addFileFromSrc(self, dstPath, srcPath):
        if not os.path.isfile(dstPath) and os.path.isfile(srcPath):
            if not self._fileHandler.hasFile(dstPath):
                newFile = open(srcPath, "rb")
                self._fileHandler.addNewFile(dstPath, newFile.read())
                newFile.close()

    def _addFolderFromSrc(self, dstPath, srcPath):
        for root, subfolders, files in os.walk(srcPath):
            for filename in files:
                src_filepath = os.path.join(root, filename)
                dst_dirpath = os.path.join(dstPath, root.strip(srcPath))
                dst_filepath = os.path.join(dst_dirpath, filename)
                self._fileHandler.addDir(dst_dirpath)
                if not self._fileHandler.hasFile(dst_filepath):
                    self._fileHandler.add(dst_filepath, src_filepath)

    def _generateZipFile(self, srcPath):
        repo = OfflineRepository.getRepositoryFromDB()
        filename = os.path.basename(srcPath) + ".zip"
        fd = LocalFile()
        fd.setFilePath(srcPath)
        fd.setFileName(filename)
        repo.storeFile(fd, self._conf.getId())
        return fd
示例#14
0
    def run(self, fileHandler=None):
        publicFileURL = ""
        try:
            if fileHandler is None:
                self._fileHandler = ZIPFileHandler()
            else:
                self._fileHandler = fileHandler
            dvdPath = "Meeting-%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.WPXSLMeetingStaticDisplay(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:
                        paraux = self.getRootDirPars(mat, par)
                        fname = os.path.join(
                            dvdPath,
                            urlHandlers.UHMStaticMaterialDisplay.
                            getRelativeURL(mat, escape=False))
                        p = conferences.WPMMaterialStaticDisplay(
                            self._rh, mat, paraux)
                        html = p.display()
                        self._fileHandler.addNewFile(fname, html)
                    for res in mat.getResourceList():
                        if isinstance(res, conference.LocalFile):
                            fname = os.path.join(
                                dvdPath,
                                urlHandlers.UHMStaticResourceDisplay.
                                getRelativeURL(res))
                            self._fileHandler.addNewFile(fname, res.readBin())

            # Material pages for the contributions in the meeting
            for contrib in self._conf.getContributionList():
                if contrib.isScheduled():
                    for mat in contrib.getAllMaterialList():
                        if len(mat.getResourceList()) != 1:
                            fname = os.path.join(
                                dvdPath,
                                urlHandlers.UHMStaticMaterialDisplay.
                                getRelativeURL(mat, escape=False))
                            paraux = self.getRootDirPars(mat, par)
                            p = conferences.WPMMaterialStaticDisplay(
                                self._rh, mat, paraux)
                            try:
                                html = p.display()
                            except Exception, e:
                                continue
                            self._fileHandler.addNewFile(fname, html)
                        for res in mat.getResourceList():
                            if isinstance(res, conference.LocalFile):
                                fname = os.path.join(
                                    dvdPath,
                                    urlHandlers.UHMStaticResourceDisplay.
                                    getRelativeURL(res, escape=False))
                                try:
                                    self._fileHandler.addNewFile(
                                        fname, res.readBin())
                                except Exception, e:
                                    continue
                    for subcont in contrib.getSubContributionList():
                        for mat in subcont.getAllMaterialList():
                            if len(mat.getResourceList()) != 1:
                                paraux = self.getRootDirPars(mat, par)
                                fname = os.path.join(
                                    dvdPath,
                                    urlHandlers.UHMStaticMaterialDisplay.
                                    getRelativeURL(mat, escape=False))
                                p = conferences.WPMMaterialStaticDisplay(
                                    self._rh, mat, paraux)
                                try:
                                    html = p.display()
                                except Exception, e:
                                    continue
                                self._fileHandler.addNewFile(fname, html)
                            for res in mat.getResourceList():
                                if isinstance(res, conference.LocalFile):
                                    fname = os.path.join(
                                        dvdPath,
                                        urlHandlers.UHMStaticResourceDisplay.
                                        getRelativeURL(res, escape=False))
                                    try:
                                        self._fileHandler.addNewFile(
                                            fname, res.readBin())
                                    except Exception, e:
                                        continue
示例#15
0
    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)
示例#16
0
 def pack(self):
     from MaKaC.common.contribPacker import ZIPFileHandler, RegistrantPacker
     p = RegistrantPacker(self._conf)
     path = p.pack(self._list, ZIPFileHandler())
     return send_file('registrants.zip', path, 'ZIP', inline=False)
示例#17
0
class OfflineEventCreator(object):
    def __init__(self, rh, conf, event_type=""):
        self._rh = rh
        self._conf = conf
        self._display_tz = timezoneUtils.DisplayTZ(self._rh._aw,
                                                   self._conf).getDisplayTZ()
        self.event = conf.as_event
        self._html = ""
        self._fileHandler = None
        self._mainPath = ""
        self._staticPath = ""
        self._eventType = event_type
        self._failed_paths = set()
        self._css_files = set()
        self._downloaded_files = {}

    def create(self, static_site_id):
        config = Config.getInstance()
        self._fileHandler = ZIPFileHandler()

        # create the home page html
        self._create_home()

        # Create main and static folders
        self._mainPath = self._normalize_path(u'OfflineWebsite-{}'.format(
            self._conf.getTitle().decode('utf-8')))
        self._fileHandler.addDir(self._mainPath)
        self._staticPath = os.path.join(self._mainPath, "static")
        self._fileHandler.addDir(self._staticPath)
        # Add i18n js
        self._addFolderFromSrc(
            os.path.join(self._staticPath, 'js', 'indico', 'i18n'),
            os.path.join(config.getHtdocsDir(), 'js', 'indico', 'i18n'))
        # Add system icons (not referenced in HTML/CSS)
        for icon in Config.getInstance().getSystemIcons().itervalues():
            self._addFileFromSrc(
                os.path.join(self._staticPath, 'images', icon),
                os.path.join(config.getHtdocsDir(), 'images', icon))
        # IE compat files (in conditional comments so BS doesn't see them)
        for path in ie_compatibility.urls():
            self._addFileFromSrc(
                os.path.join(self._staticPath, path.lstrip('/')),
                os.path.join(config.getHtdocsDir(), path.lstrip('/')))
        # Mathjax plugins can't be discovered by parsing the HTML
        self._addFolderFromSrc(
            os.path.join(self._staticPath, 'js', 'lib', 'mathjax'),
            os.path.join(config.getHtdocsDir(), 'js', 'lib', 'mathjax'))

        # Getting all materials, static files (css, images, js and vars.js.tpl)
        self._getAllMaterial()
        self._html = self._get_static_files(self._html)

        # Specific changes
        self._create_other_pages()

        # Retrieve files that were not available in the file system (e.e. js/css from plugins)
        self._get_failed_paths()
        self._failed_paths = set()

        # Retrieve files referenced in CSS files
        self._get_css_refs()

        # A custom event CSS might reference an uploaded image so we need to check for failed paths again
        self._get_failed_paths()

        # Create overview.html file (main page for the event)
        conferenceDisplayPath = os.path.join(self._mainPath, 'overview.html')
        self._fileHandler.addNewFile(conferenceDisplayPath, self._html)

        # Creating index.html file
        self._fileHandler.addNewFile(
            'index.html', '<meta http-equiv="Refresh" content="0; url=%s">' %
            conferenceDisplayPath)

        self._fileHandler.close()
        return self._save_file(self._fileHandler.getPath(), static_site_id)

    def _get_static_files(self, html):
        config = Config.getInstance()
        soup = BeautifulSoup(html)
        images = set(_fix_url_path(x['src']) for x in soup.select('img[src]'))
        scripts = set(
            _fix_url_path(x['src']) for x in soup.select('script[src]'))
        styles = set(
            _fix_url_path(x['href'])
            for x in soup.select('link[rel="stylesheet"]'))
        for path in itertools.chain(images, scripts, styles):
            src_path = re.sub(r'#.*$', '',
                              os.path.join(config.getHtdocsDir(), path))
            dst_path = os.path.join(self._staticPath, path)
            if path in styles:
                self._css_files.add(path)
            if not os.path.isfile(src_path):
                self._failed_paths.add(path)
            elif path not in styles:
                self._addFileFromSrc(dst_path, src_path)
        for image in soup.select('img[src]'):
            image['src'] = os.path.join('static', _fix_url_path(image['src']))
        for script in soup.select('script[src]'):
            script['src'] = os.path.join('static',
                                         _fix_url_path(script['src']))
        for style in soup.select('link[rel="stylesheet"]'):
            style['href'] = os.path.join('static',
                                         _fix_url_path(style['href']))
        return str(soup)

    def _get_failed_paths(self):
        """Downloads files that were not available in the fielystem via HTTP.
        This is the only clean way to deal with static files from plugins since otherwise
        we would have to emulate RHHtdocs.
        """
        cfg = Config.getInstance()
        # If we have the embedded webserver prefer its base url since the iptables hack does
        # not work for connections from the same machine
        base_url = cfg.getBaseURL()
        for path in self._failed_paths:
            dst_path = os.path.join(self._staticPath, path)
            if not self._fileHandler.hasFile(dst_path):
                response = requests.get(os.path.join(base_url, path),
                                        verify=False)
                self._downloaded_files[dst_path] = response.content
                self._fileHandler.addNewFile(dst_path, response.content)

    def _get_css_refs(self):
        """Adds files referenced in stylesheets and rewrite the URLs inside those stylesheets"""
        config = Config.getInstance()
        for path in self._css_files:
            src_path = os.path.join(config.getHtdocsDir(), path)
            dst_path = os.path.join(self._staticPath, path)
            if dst_path in self._downloaded_files and not os.path.exists(
                    src_path):
                css = self._downloaded_files[dst_path]
            else:
                with open(src_path, 'rb') as f:
                    css = f.read()
            # Extract all paths inside url()
            urls = set(
                m.group('url') for m in RE_CSS_URL.finditer(css)
                if m.group('url')[0] != '#')
            for url in urls:
                orig_url = url
                url = _remove_qs(url)  # get rid of cache busters
                if url[0] == '/':
                    # make it relative and resolve '..' elements
                    url = os.path.normpath(url[1:])
                    # anything else is straightforward: the url is now relative to the htdocs folder
                    ref_src_path = os.path.join(config.getHtdocsDir(), url)
                    ref_dst_path = os.path.join(self._staticPath, url)
                    # the new url is relative to the css location
                    static_url = os.path.relpath(url, os.path.dirname(path))
                else:
                    # make the relative path absolute (note: it's most likely NOT relative to htdocs!)
                    css_abs_path = os.path.join(config.getHtdocsDir(), path)
                    # now we can combine the relative url with that path to get the proper paths of the resource
                    ref_src_path = os.path.normpath(
                        os.path.join(os.path.dirname(css_abs_path), url))
                    ref_dst_path = os.path.normpath(
                        os.path.join(self._staticPath, os.path.dirname(path),
                                     url))
                    static_url = os.path.relpath(ref_src_path,
                                                 os.path.dirname(css_abs_path))
                if not os.path.isfile(ref_src_path):
                    htdocs_relative_path = os.path.relpath(
                        ref_src_path, config.getHtdocsDir())
                    htdocs_relative_path = re.sub(r'#.*$', '',
                                                  htdocs_relative_path)
                    self._failed_paths.add(htdocs_relative_path)
                else:
                    self._addFileFromSrc(ref_dst_path, ref_src_path)
                css = css.replace(orig_url, static_url)
            self._fileHandler.addNewFile(dst_path, css)

    def _create_home(self):
        # get default/selected view
        view = self._rh._target.as_event.theme
        # if no default view was attributed, then get the configuration default
        if not view or view not in theme_settings.themes or theme_settings.themes[
                view].get('is_xml'):
            view = theme_settings.defaults[self._eventType]
        p = WPTPLStaticConferenceDisplay(self._rh, self._rh._target, view,
                                         self._eventType, self._rh._reqParams)
        self._html = p.display(**self._rh._getRequestParams())

    def _create_other_pages(self):
        pass

    def _normalize_path(self, path):
        return secure_filename(remove_tags(path))

    def _getAllMaterial(self):
        self._addMaterialFrom(self.event, "events/conference")
        for contrib in self.event.contributions:
            self._addMaterialFrom(contrib,
                                  "agenda/%s-contribution" % contrib.id)
            for sc in contrib.subcontributions:
                self._addMaterialFrom(sc, "agenda/%s-subcontribution" % sc.id)
        for session in self.event.sessions:
            self._addMaterialFrom(session, "agenda/%s-session" % session.id)

    def _addMaterialFrom(self, target, categoryPath):
        for folder in AttachmentFolder.get_for_linked_object(
                target, preload_event=True):
            for attachment in folder.attachments:
                if attachment.type == AttachmentType.file:
                    dst_path = posixpath.join(
                        self._mainPath, "files", categoryPath,
                        "{}-{}".format(attachment.id,
                                       attachment.file.filename))
                    with attachment.file.get_local_path() as file_path:
                        self._addFileFromSrc(dst_path, file_path)

    def _addFileFromSrc(self, dstPath, srcPath):
        if not os.path.isfile(dstPath) and os.path.isfile(srcPath):
            if not self._fileHandler.hasFile(dstPath):
                newFile = open(srcPath, "rb")
                self._fileHandler.addNewFile(dstPath, newFile.read())
                newFile.close()

    def _addFolderFromSrc(self, dstPath, srcPath):
        for root, subfolders, files in os.walk(srcPath):
            for filename in files:
                src_filepath = os.path.join(root, filename)
                if root.startswith(srcPath):
                    dst_dirpath = os.path.join(dstPath,
                                               root[len(srcPath):].strip('/'))
                else:
                    dst_dirpath = dstPath
                dst_filepath = os.path.join(dst_dirpath, filename)
                self._fileHandler.addDir(dst_dirpath)
                if not self._fileHandler.hasFile(dst_filepath):
                    self._fileHandler.add(dst_filepath, src_filepath)

    def _save_file(self, srcPath, static_site_id):
        volume = HelperMaKaCInfo.getMaKaCInfoInstance().getArchivingVolume()
        path = os.path.join(Config.getInstance().getOfflineStore(), volume,
                            'offline', self._conf.getId())
        file_path = os.path.join(path, '{}.zip'.format(static_site_id))
        try:
            os.makedirs(path)
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise
        shutil.copyfile(srcPath, file_path)
        return file_path