mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Connection bug fix
This commit is contained in:
parent
4f5961f413
commit
d6efde407e
1 changed files with 56 additions and 21 deletions
67
parse_args
67
parse_args
|
@ -469,7 +469,7 @@ def parse_dict(action_map):
|
|||
else:
|
||||
parsers[category + '_' + action].add_argument(arg_name, **arg_params)
|
||||
|
||||
return { 'category' : sys.argv[1], 'action' : sys.argv[2], 'args' : parsers['general'].parse_args() }
|
||||
return parsers['general'].parse_args()
|
||||
|
||||
def display_error(error):
|
||||
"""
|
||||
|
@ -483,19 +483,18 @@ def display_error(error):
|
|||
else:
|
||||
print(json.dumps({ 'error' : error.message }))
|
||||
|
||||
def main():
|
||||
def connect_services(action_map):
|
||||
"""
|
||||
Main instructions
|
||||
Connect to different services needed by the action
|
||||
|
||||
Parse the action_dict and execute the action-specific function,
|
||||
then print json or pretty result if executed in a tty :)
|
||||
Keyword arguments:
|
||||
action_map -- Map of actions
|
||||
|
||||
Returns:
|
||||
int -- 0 or error code
|
||||
Dict|int -- openned connections or error code
|
||||
|
||||
"""
|
||||
parsed = parse_dict(action_map)
|
||||
action_dict = action_map[parsed['category']]['actions'][parsed['action']]
|
||||
action_dict = action_map[argv[1]]['actions'][argv[2]]
|
||||
connections = {}
|
||||
required_connections = []
|
||||
|
||||
|
@ -512,12 +511,51 @@ def main():
|
|||
except YunoHostError, error:
|
||||
display_error(error)
|
||||
return error.code
|
||||
else:
|
||||
return connections
|
||||
|
||||
def disconnect_services(connections):
|
||||
"""
|
||||
Disconnect openned connections
|
||||
|
||||
Keyword arguments:
|
||||
connections -- Dictionnary of openned connections
|
||||
|
||||
Returns:
|
||||
Boolean|int
|
||||
|
||||
"""
|
||||
try:
|
||||
if 'ldap' in connections:
|
||||
connections['ldap'].disconnect()
|
||||
if 'firewall' in connections:
|
||||
connections['firewall'].close()
|
||||
# TODO: Add other services deconnections
|
||||
except YunoHostError, error:
|
||||
display_error(error)
|
||||
return error.code
|
||||
else:
|
||||
return True
|
||||
|
||||
def main(action_map):
|
||||
"""
|
||||
Main instructions
|
||||
|
||||
Parse the action_dict and execute the action-specific function,
|
||||
then print json or pretty result if executed in a tty :)
|
||||
|
||||
Returns:
|
||||
int -- 0 or error code
|
||||
|
||||
"""
|
||||
args = parse_dict(action_map)
|
||||
connections = connect_services(action_map)
|
||||
|
||||
try:
|
||||
if connections:
|
||||
result = parsed['args'].func(vars(parsed['args']), connections)
|
||||
result = args.func(vars(args), connections)
|
||||
else:
|
||||
result = parsed['args'].func(vars(parsed['args']))
|
||||
result = args.func(vars(args))
|
||||
except TypeError:
|
||||
print(_("Not (yet) implemented function"))
|
||||
return 1
|
||||
|
@ -530,12 +568,9 @@ def main():
|
|||
else:
|
||||
print(json.dumps(result))
|
||||
finally:
|
||||
if 'ldap' in required_connections:
|
||||
connections['ldap'].disconnect()
|
||||
if 'firewall' in required_connections:
|
||||
connections['firewall'].close()
|
||||
# TODO: Add other services deconnections
|
||||
disconnect_services(connections)
|
||||
|
||||
return 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
sys.exit(main(action_map))
|
||||
|
|
Loading…
Reference in a new issue