当前位置: 首页>>代码示例>>Python>>正文


Python contribPacker.ZIPFileHandler类代码示例

本文整理汇总了Python中MaKaC.common.contribPacker.ZIPFileHandler的典型用法代码示例。如果您正苦于以下问题:Python ZIPFileHandler类的具体用法?Python ZIPFileHandler怎么用?Python ZIPFileHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ZIPFileHandler类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create

    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
开发者ID:jbenito3,项目名称:indico,代码行数:57,代码来源:offlineWebsiteCreator.py

示例2: create

    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)
开发者ID:OmeGak,项目名称:indico,代码行数:56,代码来源:offlineWebsiteCreator.py

示例3: create

    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)
开发者ID:MichelCordeiro,项目名称:indico,代码行数:51,代码来源:offlineWebsiteCreator.py

示例4: run

    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
开发者ID:bubbas,项目名称:indico,代码行数:100,代码来源:dvdCreation.py

示例5: OfflineEventCreator

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:
#.........这里部分代码省略.........
开发者ID:MichelCordeiro,项目名称:indico,代码行数:101,代码来源:offlineWebsiteCreator.py

示例6: OfflineEventCreator

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
#.........这里部分代码省略.........
开发者ID:jbenito3,项目名称:indico,代码行数:101,代码来源:offlineWebsiteCreator.py


注:本文中的MaKaC.common.contribPacker.ZIPFileHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。