本文整理汇总了Python中tvb.core.entities.file.files_helper.FilesHelper.zip_folder方法的典型用法代码示例。如果您正苦于以下问题:Python FilesHelper.zip_folder方法的具体用法?Python FilesHelper.zip_folder怎么用?Python FilesHelper.zip_folder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tvb.core.entities.file.files_helper.FilesHelper
的用法示例。
在下文中一共展示了FilesHelper.zip_folder方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: introduce_unmapped_node
# 需要导入模块: from tvb.core.entities.file.files_helper import FilesHelper [as 别名]
# 或者: from tvb.core.entities.file.files_helper.FilesHelper import zip_folder [as 别名]
def introduce_unmapped_node(out_pth, conn_zip_pth):
"""
Creates a connectivity with one extra node in the first position.
This node represents the unmapped regions.
:param out_pth: destination path
:param conn_zip_pth: connectivity zip path.
"""
fh = FilesHelper()
tmp_pth = os.path.splitext(out_pth)[0]
fh.check_created(tmp_pth)
files = fh.unpack_zip(conn_zip_pth, tmp_pth)
for file_name in files:
file_name_low = file_name.lower()
if "centres" in file_name_low:
with open(file_name) as f:
lines = f.readlines()
with open(file_name, "w") as f:
f.write("None 0.000000 0.000000 0.000000\n")
f.writelines(lines)
elif "weight" in file_name_low or "tract" in file_name_low:
with open(file_name) as f:
lines = f.readlines()
nr_regions = len(lines)
with open(file_name, "w") as f:
f.write(" 0.0000000e+00" * (nr_regions + 1) + "\n")
for line in lines:
f.write(" 0.0000000e+00" + line)
else:
raise Exception("this transformation does not support the file " + file_name)
fh.zip_folder(out_pth, tmp_pth)
fh.remove_folder(tmp_pth)
示例2: export_project
# 需要导入模块: from tvb.core.entities.file.files_helper import FilesHelper [as 别名]
# 或者: from tvb.core.entities.file.files_helper.FilesHelper import zip_folder [as 别名]
def export_project(self, project):
"""
Given a project root and the TVB storage_path, create a ZIP
ready for export.
:param project: project object which identifies project to be exported
"""
if project is None:
raise ExportException("Please provide project to be exported")
files_helper = FilesHelper()
project_folder = files_helper.get_project_folder(project)
bursts_dict = {}
datatype_burst_mapping = {}
bursts_count = dao.get_bursts_for_project(project.id, count=True)
for start_idx in range(0, bursts_count, BURST_PAGE_SIZE):
bursts = dao.get_bursts_for_project(project.id, page_start=start_idx, page_end=start_idx + BURST_PAGE_SIZE)
for burst in bursts:
self._build_burst_export_dict(burst, bursts_dict)
datatypes_count = dao.get_datatypes_for_project(project.id, count=True)
for start_idx in range(0, datatypes_count, DATAYPES_PAGE_SIZE):
datatypes = dao.get_datatypes_for_project(project.id, page_start=start_idx,
page_end=start_idx + DATAYPES_PAGE_SIZE)
for datatype in datatypes:
datatype_burst_mapping[datatype.gid] = datatype.fk_parent_burst
# Compute path and name of the zip file
now = datetime.now()
date_str = now.strftime("%Y-%m-%d_%H-%M")
zip_file_name = "%s_%s.%s" % (date_str, project.name, self.ZIP_FILE_EXTENSION)
export_folder = self._build_data_export_folder(project)
result_path = os.path.join(export_folder, zip_file_name)
bursts_file_name = os.path.join(project_folder, BURST_INFO_FILE)
burst_info = {BURSTS_DICT_KEY: bursts_dict,
DT_BURST_MAP: datatype_burst_mapping}
with open(bursts_file_name, 'w') as bursts_file:
bursts_file.write(json.dumps(burst_info))
# pack project content into a ZIP file
result_zip = files_helper.zip_folder(result_path, project_folder)
# remove these files, since we only want them in export archive
os.remove(bursts_file_name)
return result_zip