本文整理汇总了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)
示例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
示例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)
示例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)
示例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()