Skip to content

Commit

Permalink
initial attempt (not supported by mars client c++)
Browse files Browse the repository at this point in the history
  • Loading branch information
jameshawkes committed Apr 9, 2024
1 parent f75d63e commit 4576b59
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions polytope_server/common/datasource/mars.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# does it submit to any jurisdiction.
#

import copy
import logging
import os
import tempfile
Expand Down Expand Up @@ -113,17 +114,42 @@ def archive(self, request):

def retrieve(self, request):

r = yaml.safe_load(request.user_request) or {}

# Do a list first, to see how big the request will be
list_r = copy.deepcopy(r)
# list_r['output'] = 'cost'

# Make a temporary file for the request
with tempfile.NamedTemporaryFile(delete=False) as tmp:
self.request_file = tmp.name
logging.info("Writing list request to tempfile {}".format(self.request_file))
tmp.write(self.convert_to_mars_request("list", list_r).encode())

self.subprocess = Subprocess()
self.subprocess.run(
cmd=[self.command, self.request_file],
cwd=os.path.dirname(__file__),
env=self.make_env(request),
)
self.subprocess.finalize(request, "")
logging.info(self.subprocess.output)
os.unlink(self.request_file)





# Open a FIFO for MARS output
self.fifo = FIFO("MARS-FIFO-" + request.id)

# Parse the user request as YAML, and add the FIFO as target
r = yaml.safe_load(request.user_request) or {}
r["target"] = '"' + self.fifo.path + '"'

# Make a temporary file for the request
with tempfile.NamedTemporaryFile(delete=False) as tmp:
self.request_file = tmp.name
logging.info("Writing request to tempfile {}".format(self.request_file))
logging.info("Writing retrieve request to tempfile {}".format(self.request_file))
tmp.write(self.convert_to_mars_request("retrieve", r).encode())

# Call MARS
Expand Down

0 comments on commit 4576b59

Please sign in to comment.