Skip to content

Commit

Permalink
Added a new function for copying files into the final location in pyC…
Browse files Browse the repository at this point in the history
…OMPSs
  • Loading branch information
markmcdowall committed Aug 1, 2018
1 parent 6f0be94 commit 7557cdf
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions mg_common/tool/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,41 @@ class common(object): # pylint: disable=too-few-public-methods, invalid-name
Common functions that can be used generically across tools and pipelines
"""

@staticmethod
def to_output_file(input_file, output_file, empty=True):
"""
When handling the output of files within the @task function copying the
results into the correct output files should be done by reading from and
writing to rather than renaming.
In cases where there are a known set of output files, if the input file
is missing then a blank file should be created and handled by the run()
function of the tool. If an empty file should not be created then the
empty parameter should be set to False.
Parameters
----------
input_file : str
Location of the input file
output_file : str
Location of the output file
empty : bool
In cases where the input_file is missing an empty output_file is
created. Should be set to False if no file shold be created.
"""
logger.info(input_file + ' - ' + str(os.path.isfile(input_file)))
if os.path.isfile(input_file) is True and os.path.getsize(input_file) > 0:
with open(output_file, "wb") as f_out:
with open(input_file, "rb") as f_in:
f_out.write(f_in.read())
return True

if empty:
with open(output_file, "w") as f_out:
f_out.write("")

return True

@staticmethod
def zip_file(location):
"""
Expand Down

0 comments on commit 7557cdf

Please sign in to comment.