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


Python ZipFile.comment方法代码示例

本文整理汇总了Python中zipfile.ZipFile.comment方法的典型用法代码示例。如果您正苦于以下问题:Python ZipFile.comment方法的具体用法?Python ZipFile.comment怎么用?Python ZipFile.comment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在zipfile.ZipFile的用法示例。


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

示例1: _update_noversion

# 需要导入模块: from zipfile import ZipFile [as 别名]
# 或者: from zipfile.ZipFile import comment [as 别名]
    def _update_noversion(self, filepath):
        logging.debug('Updating from "no version"')

        oldzip = ZipFile(filepath, 'r')
        newzip = ZipFile(filepath + ".new", 'w')

        # Update keys.ini
        config = ConfigParser()

        fp = oldzip.open(KEYS_INI_FILENAME, 'r')
        config.read(StringIO(fp.read().decode('ascii')))

        for section, option, value in config:
            value = value.replace('pymontecarlo.result.base.result.', '')
            setattr(getattr(config, section), option, value)

        fp = StringIO()
        config.write(fp)
        newzip.writestr(KEYS_INI_FILENAME, fp.getvalue())

        # Add other files to new zip
        for zipinfo in oldzip.infolist():
            if zipinfo.filename == KEYS_INI_FILENAME:
                continue

            data = oldzip.read(zipinfo)
            newzip.writestr(zipinfo, data)

        # Add version
        newzip.comment = b'version=2'

        oldzip.close()
        newzip.close()

        # Remove old zip and replace with new one
        os.remove(filepath)
        os.rename(filepath + ".new", filepath)

        return self._update_version2(filepath)
开发者ID:pymontecarlo,项目名称:pymontecarlo,代码行数:41,代码来源:updater.py

示例2: _update_version1

# 需要导入模块: from zipfile import ZipFile [as 别名]
# 或者: from zipfile.ZipFile import comment [as 别名]
    def _update_version1(self, filepath):
        logging.debug('Updating from "version 1"')

        oldzip = ZipFile(filepath, 'r')
        newzip = ZipFile(filepath + ".new", 'w')

        # Update stats.cfg
        config = ConfigParser()
        config.read(oldzip.open('stats.cfg', 'r'))

        limit = config.stats.convergence_limit
        del config.stats.convergence_limit
        config.stats.convergor = '<CompositionConvergor(limit=%s)>' % limit

        fp = StringIO()
        config.write(fp)
        newzip.writestr('stats.cfg', fp.getvalue())

        # Add other files to new zip
        for zipinfo in oldzip.infolist():
            if zipinfo.filename == 'stats.cfg':
                continue

            data = oldzip.read(zipinfo)
            newzip.writestr(zipinfo, data)

        # Add version
        newzip.comment = 'version=%s' % VERSION

        oldzip.close()
        newzip.close()

        # Remove old zip and replace with new one
        os.remove(filepath)
        os.rename(filepath + ".new", filepath)

        return filepath
开发者ID:pymontecarlo,项目名称:pymontecarlo,代码行数:39,代码来源:updater.py

示例3: iCalendarZipArchiveData

# 需要导入模块: from zipfile import ZipFile [as 别名]
# 或者: from zipfile.ZipFile import comment [as 别名]
    def iCalendarZipArchiveData(self):
        calendarComponents = yield self.calendarComponents()

        fileHandle = StringIO()
        try:
            zipFile = ZipFile(fileHandle, "w", allowZip64=True)
            try:
                zipFile.comment = (
                    "Calendars for UID: {}".format(self._record.uid)
                )

                names = set()

                for name, component in calendarComponents:
                    if name in names:
                        i = 0
                        while True:
                            i += 1
                            nextName = "{} {:d}".format(name, i)
                            if nextName not in names:
                                name = nextName
                                break
                            assert i < len(calendarComponents)

                    text = component.getText().encode("utf-8")

                    zipFile.writestr(name.encode("utf-8"), text)

            finally:
                zipFile.close()

            data = fileHandle.getvalue()
        finally:
            fileHandle.close()

        returnValue(data)
开发者ID:nunb,项目名称:calendarserver,代码行数:38,代码来源:principals.py

示例4: _update_version2

# 需要导入模块: from zipfile import ZipFile [as 别名]
# 或者: from zipfile.ZipFile import comment [as 别名]
    def _update_version2(self, filepath):
        logging.debug('Updating from "version 2"')

        # Find options
        xmlfilepath = os.path.splitext(filepath)[0] + '.xml'
        if not os.path.exists(xmlfilepath):
            raise ValueError('Update requires an options file saved at %s' % xmlfilepath)
        with open(xmlfilepath, 'rb') as fp:
            source = fp.read()
        source = _update_options(source)
        options = Options.read(BytesIO(source))

        oldzip = ZipFile(filepath, 'r')
        newzip = ZipFile(filepath + ".new", 'w')

        # Add options file
        fp = BytesIO()
        options.write(fp)
        newzip.writestr(OPTIONS_FILENAME, fp.getvalue())

        # Add other files to new zip
        for zipinfo in oldzip.infolist():
            data = oldzip.read(zipinfo)
            newzip.writestr(zipinfo, data)

        # Add version
        newzip.comment = b'version=3'

        oldzip.close()
        newzip.close()

        # Remove old zip and replace with new one
        os.remove(filepath)
        os.rename(filepath + ".new", filepath)

        return self._update_version3(filepath)
开发者ID:pymontecarlo,项目名称:pymontecarlo,代码行数:38,代码来源:updater.py

示例5: save

# 需要导入模块: from zipfile import ZipFile [as 别名]
# 或者: from zipfile.ZipFile import comment [as 别名]
    def save(self, source):
        """
        Saves results in a results ZIP.
        
        :arg source: filepath or file-object
        """
        zipfile = ZipFile(source, 'w', compression=ZIP_DEFLATED)
        zipfile.comment = 'version=%s' % VERSION

        # Save compositions
        fp = StringIO()
        writer = csv.writer(fp)

        zs = self._compositions[0].keys()
        writer.writerow(['iteration'] + zs)

        for i, composition in enumerate(self._compositions):
            writer.writerow([i + 1] + [composition.get(z, 0.0) for z in zs])

        zipfile.writestr('compositions.csv', fp.getvalue())

        # Save stats
        config = ConfigParser()
        section = config.add_section('stats')

        section.elapsed_time_s = self.elapsed_time_s
        section.iterations = self.iterations
        section.max_iterations = self.max_iterations
        section.iterator = self.iterator
        section.convergor = self.convergor

        fp = StringIO()
        config.write(fp)
        zipfile.writestr('stats.cfg', fp.getvalue())

        zipfile.close()
开发者ID:pymontecarlo,项目名称:pymontecarlo,代码行数:38,代码来源:results.py


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