Fixed actions in subparsers
This commit is contained in:
parent
c0d0e11591
commit
b589dd70f3
6 changed files with 42 additions and 14 deletions
|
@ -90,7 +90,7 @@ class ActionContainer():
|
||||||
internal_dict = {}
|
internal_dict = {}
|
||||||
internal_dict['uuid'] = str(self.uuid)
|
internal_dict['uuid'] = str(self.uuid)
|
||||||
internal_dict['actions'] = [action.as_dict() for action in self.actions]
|
internal_dict['actions'] = [action.as_dict() for action in self.actions]
|
||||||
internal_dict['groups'] = [[action.as_dict() for action in group] for group in self.groups]
|
internal_dict['groups'] = [group.as_dict() for group in self.groups]
|
||||||
return internal_dict
|
return internal_dict
|
||||||
|
|
||||||
class StoreAction(Action):
|
class StoreAction(Action):
|
||||||
|
@ -110,4 +110,4 @@ class MutuallyExclusiveGroup(ActionContainer):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "Group Object: ( Actions: {}, Groups: {} )".format(self.actions, self.mutex_groups)
|
return "Group Object: ( Actions: {}, Groups: {} )".format(self.actions, self.groups)
|
||||||
|
|
|
@ -112,6 +112,7 @@ def start_module(name, is_module):
|
||||||
views.app.output.stop()
|
views.app.output.stop()
|
||||||
|
|
||||||
ioerr.write("Process stopped ({})\n".format(views.app.module_process.exitcode))
|
ioerr.write("Process stopped ({})\n".format(views.app.module_process.exitcode))
|
||||||
|
views.app.output.queue.put(("sig", "stop"))
|
||||||
views.app.restart.wait()
|
views.app.restart.wait()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,3 +11,4 @@ if __name__ == "__main__":
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
print("Subparser %s was selected" % args.command)
|
print("Subparser %s was selected" % args.command)
|
||||||
|
print(args)
|
||||||
|
|
|
@ -7,6 +7,15 @@
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.checkbox {
|
||||||
|
height:100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type=checkbox] {
|
||||||
|
width: 2em;
|
||||||
|
height: 2em;
|
||||||
|
-moz-appearance: none;
|
||||||
|
}
|
||||||
|
|
||||||
#output {
|
#output {
|
||||||
flex:1;
|
flex:1;
|
||||||
|
|
|
@ -21,6 +21,9 @@ function createSubparserAction(action) {
|
||||||
|
|
||||||
var content_div = $("<div/>", { id: choice['uuid'] })
|
var content_div = $("<div/>", { id: choice['uuid'] })
|
||||||
.addClass("tabs-panel").appendTo(tab_content);
|
.addClass("tabs-panel").appendTo(tab_content);
|
||||||
|
choice['groups'].forEach(function(group) {
|
||||||
|
content_div.append(createGroup(group));
|
||||||
|
});
|
||||||
choice['actions'].forEach(function(action) {
|
choice['actions'].forEach(function(action) {
|
||||||
content_div.append(createAction(action));
|
content_div.append(createAction(action));
|
||||||
});
|
});
|
||||||
|
@ -31,13 +34,14 @@ function createSubparserAction(action) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function createCheckboxAction(action) {
|
function createCheckboxAction(action) {
|
||||||
var switch_div = $("<div/>").addClass("switch");
|
//var switch_div = $("<div/>").addClass("switch");
|
||||||
|
var switch_div = $("<div/>").addClass("checkbox");
|
||||||
var input = $("<input/>", {
|
var input = $("<input/>", {
|
||||||
id: action["uuid"],
|
id: action["uuid"],
|
||||||
type: 'checkbox',
|
type: 'checkbox',
|
||||||
name: action['uuid']
|
name: action['uuid']
|
||||||
}).addClass('switch-input').data("name", action['dest']).appendTo(switch_div);
|
}).data("name", action['dest']).appendTo(switch_div);
|
||||||
var paddle = $("<label/>", {for: action["uuid"]}).addClass("switch-paddle")
|
var paddle = $("<label/>", {for: action["uuid"]}).addClass("css-label")
|
||||||
.appendTo(switch_div);
|
.appendTo(switch_div);
|
||||||
if(action['checked'] === true) {
|
if(action['checked'] === true) {
|
||||||
input.attr('checked', true);
|
input.attr('checked', true);
|
||||||
|
|
|
@ -12,21 +12,35 @@ from flask import Flask, render_template, request, Response, \
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.mutex_groups=[]
|
app.mutex_groups=[]
|
||||||
|
|
||||||
def parse_argument(name, json, action):
|
def parse_argument(name, json, action, namespace):
|
||||||
|
print(name)
|
||||||
try:
|
try:
|
||||||
argument = json[name]
|
argument = json[name]
|
||||||
if type(argument) == list:
|
if type(argument) == list:
|
||||||
if len(argument) == 1:
|
if len(argument) == 1:
|
||||||
return action.type_function(argument[0])
|
setattr(namespace, action.name, action.type_function(argument[0]))
|
||||||
else:
|
else:
|
||||||
return [action.type_function(elem) for elem in argument]
|
setattr(namespace, action.name, [action.type_function(elem) for elem in argument])
|
||||||
else:
|
else:
|
||||||
return action.type_function(argument)
|
setattr(namespace, action.name, action.type_function(argument))
|
||||||
except (KeyError, ValueError):
|
except (KeyError, ValueError):
|
||||||
if name.endswith("[]"):
|
if name.endswith("[]"):
|
||||||
return action.on_none
|
setattr(namespace, action.name, action.on_none)
|
||||||
else:
|
else:
|
||||||
return parse_argument(name + "[]", json, action)
|
parse_argument(name + "[]", json, action, namespace)
|
||||||
|
|
||||||
|
try:
|
||||||
|
for name, choice in action.choices.items():
|
||||||
|
print(choice)
|
||||||
|
actions = choice.actions
|
||||||
|
for group in choice.groups:
|
||||||
|
action.extend(group.actions)
|
||||||
|
for action in actions:
|
||||||
|
parse_argument(action.name, json, action, namespace)
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/arguments", methods=['POST'])
|
@app.route("/arguments", methods=['POST'])
|
||||||
|
@ -34,13 +48,13 @@ def fill_namespace():
|
||||||
json = dict(request.form)
|
json = dict(request.form)
|
||||||
namespace = argparse.Namespace()
|
namespace = argparse.Namespace()
|
||||||
all_actions = app.actions
|
all_actions = app.actions
|
||||||
|
print(all_actions)
|
||||||
|
|
||||||
for group in app.mutex_groups:
|
for group in app.mutex_groups:
|
||||||
all_actions.extend(group.actions)
|
all_actions.extend(group.actions)
|
||||||
|
|
||||||
for action in all_actions:
|
for action in all_actions:
|
||||||
value = parse_argument(action.name, json, action)
|
parse_argument(action.name, json, action, namespace)
|
||||||
setattr(namespace, action.name, value)
|
|
||||||
|
|
||||||
app.namespaceQueue.put(namespace)
|
app.namespaceQueue.put(namespace)
|
||||||
app.output.queue.put(("sig", "start"))
|
app.output.queue.put(("sig", "start"))
|
||||||
|
@ -57,7 +71,6 @@ def get_arguments():
|
||||||
def stop():
|
def stop():
|
||||||
os.kill(app.module_process.pid, signal.SIGCONT)
|
os.kill(app.module_process.pid, signal.SIGCONT)
|
||||||
app.module_process.terminate()
|
app.module_process.terminate()
|
||||||
app.output.queue.put(("sig", "stop"))
|
|
||||||
return "OK"
|
return "OK"
|
||||||
|
|
||||||
@app.route("/resume")
|
@app.route("/resume")
|
||||||
|
|
Loading…
Add table
Reference in a new issue