Skip to content

Commit

Permalink
updated testing script and creator to not add duplicate entries
Browse files Browse the repository at this point in the history
  • Loading branch information
gkiar committed Apr 27, 2018
1 parent bdd7984 commit 83d565f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
39 changes: 24 additions & 15 deletions tools/python/boutiques/creator.py
Expand Up @@ -99,6 +99,7 @@ def __init__(self, parser=None, **kwargs):
"tool-version": "v0.1.0"
}

self.count = 0
if parser is None:
return self.descriptor
else:
Expand All @@ -108,6 +109,10 @@ def __init__(self, parser=None, **kwargs):

self.parseParser(**kwargs)

def counter(self):
self.count += 1
return self.count

def parseParser(self, **kwargs):
self.descriptor["command-line"] = kwargs.get("execname")
for act in self.parser._actions:
Expand All @@ -126,46 +131,50 @@ def parseAction(self, action, **kwargs):
print("(interpreting _SubParsersAction)")
# print("subbyyyyy")
subparser = self.parseAction(action, addParser=True)
bigdelta = {}
inpts = {}
for act in action.choices:
delta = {}
inpts[act] = {}
for subact in action.choices[act]._actions:
# input relies on sub action selection
delta.update(self.parseAction(subact, subparser=act))
inpts[act].update(self.parseAction(subact, subparser=act))
# act enables all the subacts in delta
# "value-disables": {
# "mychoice1.log": [],
# "mychoice2.log": []
# },
bigdelta.update(delta)
# Set "value-disables" based on overlap
self.descriptor["inputs"] += [subparser]
# acts in bigdelta are mutually exclusive
return bigdelta
return subparser.update(inpts)
else:
actdict = vars(action)
if action.dest == "==SUPPRESS==":
import random
import string
def id_generator(size=3, chars=string.digits):
return ''.join(random.choice(chars) for _ in range(size))
adest = "subparser{0}".format(id_generator())

adest = "subparser-{0}".format(self.counter())
else:
adest = action.dest

self.descriptor["command-line"] += " [{0}]".format(adest.upper())
print(action)
newinput = {
"id": adest,
"name": adest,
"description": action.help,
"optional": not action.required,
"type": action.type or "String",
"value-key": "[{0}]".format(adest.upper())
"value-key": "{0}".format(adest.upper())
}
if action.default:
newinput["default-value"] = action.default
if action.choices:
newinput["value-choices"] = action.choices
if len(action.option_strings):
newinput["command-line-flag"] = action.option_strings[0]
if type(action) is argparse._StoreTrueAction:
newinput["type"] = "Flag"

self.descriptor["inputs"] += [newinput]
if any(newinput["id"] == it["id"]
for it in self.descriptor["inputs"]):
print("duplicate; rename or ignore, ID won't be added twice")
else:
self.descriptor["command-line"] += " {0}".format(adest.upper())
self.descriptor["inputs"] += [newinput]
return newinput

4 changes: 3 additions & 1 deletion tools/python/creatordev.py
Expand Up @@ -10,10 +10,12 @@
# dest="choicer")

sb1 = subparser.add_parser("option1", help="the first value")
sb1.add_argument("suboption1", help="the first sub option option")
sb1.add_argument("suboption2", help="the first sub option option")

sb1 = subparser.add_parser("option2", help="the second value")
sb1.add_argument("suboption2", help="the second sub option option")
sb1.add_argument("--suboptionflag1", "-s", help="the second sub option flag")
sb1.add_argument("--suboptionflag2", "-d", action="store_true",
help="the second sub option flag")

creatorObj = bc.CreateDescriptor(parser, execname='/path/to/myscript.py')

0 comments on commit 83d565f

Please sign in to comment.