Commit a10e3713 authored by Carles Garcia Cabot's avatar Carles Garcia Cabot Committed by Mihai Patrascoiu
Browse files

Add parsing of params in bulk file

parent 05e4498a
...@@ -172,8 +172,9 @@ class JobSubmitter(Base): ...@@ -172,8 +172,9 @@ class JobSubmitter(Base):
def _build_transfers(self): def _build_transfers(self):
if self.options.bulk_file: if self.options.bulk_file:
filecontent = open(self.options.bulk_file).read() with open(self.options.bulk_file, 'r') as file:
bulk = json.loads(filecontent) filecontent = file.read()
bulk = json.loads(filecontent)
if "files" in bulk: if "files" in bulk:
return bulk["files"] return bulk["files"]
elif "Files" in bulk: elif "Files" in bulk:
...@@ -184,6 +185,15 @@ class JobSubmitter(Base): ...@@ -184,6 +185,15 @@ class JobSubmitter(Base):
else: else:
return [{"sources": [self.source], "destinations": [self.destination]}] return [{"sources": [self.source], "destinations": [self.destination]}]
def _build_params(self):
with open(self.options.bulk_file, 'r') as file:
filecontent = file.read()
bulk = json.loads(filecontent)
params = None
if 'params' in bulk:
params = bulk['params']
return params
def _do_submit(self, context): def _do_submit(self, context):
#Backwards compatibility: compare_checksum parameter #Backwards compatibility: compare_checksum parameter
if self.options.compare_checksum: if self.options.compare_checksum:
...@@ -213,7 +223,8 @@ class JobSubmitter(Base): ...@@ -213,7 +223,8 @@ class JobSubmitter(Base):
submitter = Submitter(context) submitter = Submitter(context)
job_id = submitter.submit( job_id = submitter.submit(
self._build_transfers(), transfers=self._build_transfers(),
params=self._build_params(),
checksum=self.checksum, checksum=self.checksum,
bring_online=self.options.bring_online, bring_online=self.options.bring_online,
archive_timeout=self.options.archive_timeout, archive_timeout=self.options.archive_timeout,
......
...@@ -27,10 +27,12 @@ class Submitter(object): ...@@ -27,10 +27,12 @@ class Submitter(object):
self.context = context self.context = context
@staticmethod @staticmethod
def build_submission(transfers=None, delete=None, staging=None, **kwargs): def build_submission(transfers=None, delete=None, staging=None, params=None, **kwargs):
job = dict() job = dict()
if params:
job['params'] = dict() job['params'] = params
else:
job['params'] = dict()
job['params'].update(kwargs) job['params'].update(kwargs)
if delete: if delete:
...@@ -55,8 +57,11 @@ class Submitter(object): ...@@ -55,8 +57,11 @@ class Submitter(object):
return json.dumps(job, indent=2) return json.dumps(job, indent=2)
def submit(self, transfers=None, delete=None, **kwargs): def submit(self, transfers=None, delete=None, params=None, **kwargs):
job = Submitter.build_submission(transfers, delete, **kwargs) job = Submitter.build_submission(transfers=transfers,
delete=delete,
params=params,
**kwargs)
r = json.loads(self.context.post_json('/jobs', job)) r = json.loads(self.context.post_json('/jobs', job))
return r['job_id'] return r['job_id']
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment