Skip to content

Commit 3c4b02e

Browse files
committed
package.py - Implemented ZipFileStream.write_file
1 parent 7f9e731 commit 3c4b02e

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

examples/simple/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ module "lambda_function" {
7373
// }
7474
// }
7575

76-
source_path = "${path.module}/../fixtures/python3.8-app1"
76+
source_path = "${path.module}/../fixtures/python3.8-app1/"
7777
// source_path = [
7878
// "${path.module}/../fixtures/python3.8-app1-extra",
7979
// {

package.py

+15-9
Original file line numberDiff line numberDiff line change
@@ -313,14 +313,7 @@ def write_dirs(self, *base_dirs, prefix=None, timestamp=None):
313313
self._logger.info("adding content of directory '%s'", base_dir)
314314
for path in emit_dir_content(base_dir):
315315
arcname = os.path.relpath(path, base_dir)
316-
self._logger.info("adding '%s'", arcname)
317-
zinfo = self._make_zinfo_from_file(path, arcname)
318-
if timestamp is None:
319-
timestamp = self.timestamp
320-
date_time = self._timestamp_to_date_time(timestamp)
321-
if date_time:
322-
self._update_zinfo(zinfo, date_time=date_time)
323-
self._write_zinfo(zinfo, path)
316+
self._write_file(path, prefix, arcname, timestamp)
324317

325318
def write_files(self, files_stream, prefix=None, timestamp=None):
326319
"""
@@ -335,7 +328,20 @@ def write_file(self, file_path, prefix=None, name=None, timestamp=None):
335328
or a full qualified name in a zip archive
336329
"""
337330
self._ensure_open()
338-
raise NotImplementedError
331+
self._write_file(file_path, prefix, name, timestamp)
332+
333+
def _write_file(self, file_path, prefix=None, name=None, timestamp=None):
334+
arcname = name if name else os.path.basename(file_path)
335+
if prefix:
336+
arcname = os.path.join(prefix, arcname)
337+
self._logger.info("adding '%s'", arcname)
338+
zinfo = self._make_zinfo_from_file(file_path, arcname)
339+
if timestamp is None:
340+
timestamp = self.timestamp
341+
date_time = self._timestamp_to_date_time(timestamp)
342+
if date_time:
343+
self._update_zinfo(zinfo, date_time=date_time)
344+
self._write_zinfo(zinfo, file_path)
339345

340346
def write_file_obj(self, file_path, data, prefix=None, timestamp=None):
341347
"""

0 commit comments

Comments
 (0)