Skip to content

Commit

Permalink
Fix: Script generation for pyflow resource
Browse files Browse the repository at this point in the history
  • Loading branch information
tbkr committed Jun 4, 2024
1 parent 7ab51b7 commit c35578a
Showing 1 changed file with 11 additions and 30 deletions.
41 changes: 11 additions & 30 deletions pyflow/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,30 +80,8 @@ def get_resource(self, filename):

return []

def install_file_stub(self, target):
"""
Installs any data associated with the resource object that is going to be deployed from the **ecFlow** server.
Parameters:
target(Deployment): The target deployment where the resource data should be installed.
"""

"""
n.b. If a resource does not need to save data at deployment time, it should not do so (e.g. WebResource)
"""
# Install path is for the suite, so we don't need to include the suite name
assert self.fullname.count("/") > 1
subpath = self.fullname[self.fullname.find("/", 1) + 1 :]

self._server_filename = os.path.join(
target.files_install_path(), subpath, self.name
)

super().install_file_stub(target)

self.save_data(target, self._server_filename)

def build_script(self):
def generate_script(self):
"""
Returns the installer script for the data resource.
Expand All @@ -128,7 +106,7 @@ def build_script(self):
for h in self._hosts:
lines += h.copy_file_to(self._server_filename, self.location()).split("\n")

return lines
return lines, []

def location(self):
"""
Expand All @@ -141,6 +119,7 @@ def location(self):
return os.path.join(self._resource_directory, self.name)



class DataResource(Resource):
"""
Provides a data resource to be deployed at suite generation time.
Expand Down Expand Up @@ -206,9 +185,8 @@ class FileResource(Resource):
"""

def __init__(self, name, hosts, source_file):
self._source = source_file

super().__init__(name, hosts)
self._server_filename = source_file

def md5(self):
"""
Expand All @@ -219,19 +197,22 @@ def md5(self):
"""

m = hashlib.md5()
m.update(self.data())
m.update(self._data)
return m.hexdigest()

def data(self):
def get_resource(self, filename):
"""
Returns the resource data from the provided file.
Returns:
The resource data.
"""

with open(self._source, "rb") as f:
return f.read()
with open(filename, "rb") as f:
return [
'mkdir -p $(dirname "{}")'.format(filename),
f.read()
]

def save_data(self, target, filename):
"""
Expand Down

0 comments on commit c35578a

Please sign in to comment.