Skip to content

Commit

Permalink
Add transparent compression support
Browse files Browse the repository at this point in the history
  • Loading branch information
pmrv committed Nov 10, 2022
1 parent 36d3d90 commit 9a00f53
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions pyiron_base/jobs/job/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,15 @@ def _job_list_files(job):
list of str: file names
"""
if os.path.isdir(self.working_directory):
return os.listdir(self.working_directory)
if _job_is_compressed(job):
with tarfile.open(_job_compressed_name, "r") as tar:
return [member.name for i in tar.getmembers() if member.isfile()]
else:
return os.listdir(self.working_directory)
return []


def _read_file(self, file_name):
def _job_read_file(self, file_name):
"""
Return list of lines of the given file.
Expand All @@ -342,8 +346,12 @@ def _read_file(self, file_name):
raise FileNotFoundError(file_name)

file_name = posixpath.join(self.working_directory, "{}".format(item))
with open(file_name) as f:
return f.readlines()
if _job_is_compressed(job):
with tarfile.open(_job_compressed_name(job)) as f:
return f.extractfile(item).readlines()
else:
with open(file_name) as f:
return f.readlines()


def _job_archive(job):
Expand Down

0 comments on commit 9a00f53

Please sign in to comment.