From 9ee7dec20293204440aeb63a38ba88b3b223ecf6 Mon Sep 17 00:00:00 2001 From: Place Jean-Marie Date: Sun, 26 Sep 2021 23:27:54 +0200 Subject: [PATCH] deal with binary files (zip) --- app/pe/pe_tools.py | 5 +++-- app/scodoc/gen_tables.py | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/pe/pe_tools.py b/app/pe/pe_tools.py index ae00f4ac..4df97cfc 100644 --- a/app/pe/pe_tools.py +++ b/app/pe/pe_tools.py @@ -164,11 +164,12 @@ def list_directory_filenames(path): return R -def add_local_file_to_zip(zipfile, ziproot, pathname, path_in_zip): +def add_local_file_to_zip(zipfile, ziproot, pathname, path_in_zip, mode='r'): """Read pathname server file and add content to zip under path_in_zip""" rooted_path_in_zip = os.path.join(ziproot, path_in_zip) - data = open(pathname).read() breakpoint() + with open(rooted_path_in_zip, mode=mode) as f: + data = f.read() zipfile.writestr(rooted_path_in_zip, data) diff --git a/app/scodoc/gen_tables.py b/app/scodoc/gen_tables.py index b49ab5da..f6ac6c34 100644 --- a/app/scodoc/gen_tables.py +++ b/app/scodoc/gen_tables.py @@ -471,7 +471,10 @@ class GenTable(object): def excel(self, wb=None): """Simple Excel representation of the table""" - ses = sco_excel.ScoExcelSheet(sheet_name=self.xls_sheet_name, wb=wb) + if wb is None: + ses = sco_excel.ScoExcelSheet(sheet_name=self.xls_sheet_name, wb=wb) + else: + ses = wb.create_sheet(sheet_name=self.xls_sheet_name) ses.rows += self.xls_before_table style_bold = sco_excel.excel_make_style(bold=True) style_base = sco_excel.excel_make_style() @@ -486,8 +489,6 @@ class GenTable(object): ses.append_single_cell_row(self.origin, style_base) if wb is None: return ses.generate() - else: - ses.generate() def text(self): "raw text representation of the table"