Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nexus: fix job option usage at user level #5255

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 12 additions & 23 deletions nexus/lib/machines.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,30 +110,19 @@ def add(self,**kwargs):


def read(self,options):
nopts = 0
intext = False
nstart = -2
nend = -2
n = 0
for c in options:
if c=='-' and nstart!=n-1 and not intext:
prevdash=True
if nopts>0:
opt = options[nstart:n].strip()
name = opt.replace('-','').replace('=',' ').split()[0]
self[name]=opt
if isinstance(options,(dict,obj)):
self.add(**options)
elif isinstance(options,list):
for o in options:
if not isinstance(o,str):
self.error('each option must be a string')
#end if
nopts+=1
nstart = n
elif c=='"' or c=="'":
intext=not intext
#end if
n+=1
#end for
if nopts>0:
opt = options[nstart:n].strip()
name = opt.replace('-','').replace('=',' ').split()[0]
self[name]=opt
self[str(len(self))] = o
#end for
elif isinstance(options,str):
self[str(len(self))] = options
else:
self.error('invalid type provided to Options')
#end if
#end def read

Expand Down
14 changes: 3 additions & 11 deletions nexus/tests/unit/test_machines.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,16 @@ def test_options():

# read
opts = '-a -b 1 -c=2 --dname="0 1 2" --evar -fval -gval other --hval'
ref = obj(
a = '-a',
b = '-b 1',
c = '-c=2',
dname = '--dname="0 1 2"',
evar = '--evar',
fval = '-fval',
gval = '-gval other',
hval = '--hval',
)
ref = obj()
ref['0'] = opts
o = Options()
o.read(opts)
assert(object_eq(o.to_obj(),ref))

# write
opts_write = o.write()
o2 = Options()
o2.read(opts_write)
o2.read(opts_write.strip())
assert(object_eq(o2.to_obj(),ref))
#end def test_options

Expand Down
Loading