affichage userfriendly si plantage serveur
This commit is contained in:
parent
624722ad30
commit
97025265ee
1 changed files with 34 additions and 10 deletions
44
client.py
44
client.py
|
@ -245,9 +245,15 @@ class simple_memoize(object):
|
||||||
######
|
######
|
||||||
## Remote commands
|
## Remote commands
|
||||||
|
|
||||||
def ssh(command, options, arg=None):
|
def remote_proc(options, command, arg=None):
|
||||||
"""Lance ssh avec les arguments donnés. Renvoie son entrée
|
"""
|
||||||
standard et sa sortie standard."""
|
Fabrique un process distant pour communiquer avec le serveur.
|
||||||
|
Cela consiste à lancer une commande (indiquée dans la config)
|
||||||
|
qui va potentiellement lancer ssh.
|
||||||
|
``command`` désigne l'action à envoyer au serveur
|
||||||
|
``arg`` est une chaîne (str) accompagnant la commande en paramètre
|
||||||
|
``options`` contient la liste usuelle d'options
|
||||||
|
"""
|
||||||
full_command = list(options.serverdata['server_cmd'])
|
full_command = list(options.serverdata['server_cmd'])
|
||||||
full_command.append(command)
|
full_command.append(command)
|
||||||
if arg:
|
if arg:
|
||||||
|
@ -257,18 +263,36 @@ def ssh(command, options, arg=None):
|
||||||
stdout = subprocess.PIPE,
|
stdout = subprocess.PIPE,
|
||||||
stderr = sys.stderr,
|
stderr = sys.stderr,
|
||||||
close_fds = True)
|
close_fds = True)
|
||||||
return proc.stdin, proc.stdout
|
return proc
|
||||||
|
|
||||||
def remote_command(options, command, arg=None, stdin_contents=None):
|
def remote_command(options, command, arg=None, stdin_contents=None):
|
||||||
"""Exécute la commande distante, et retourne la sortie de cette
|
"""Exécute la commande distante, et retourne la sortie de cette
|
||||||
commande"""
|
commande"""
|
||||||
|
detail = options.verbose and not options.quiet
|
||||||
|
|
||||||
sshin, sshout = ssh(command, options, arg)
|
proc = remote_proc(options, command, arg)
|
||||||
if not stdin_contents is None:
|
if stdin_contents is not None:
|
||||||
sshin.write(json.dumps(stdin_contents))
|
proc.stdin.write(json.dumps(stdin_contents))
|
||||||
sshin.close()
|
proc.close()
|
||||||
raw_out = sshout.read()
|
ret = proc.wait()
|
||||||
return json.loads(raw_out)
|
raw_out = proc.stdout.read()
|
||||||
|
if ret != 0:
|
||||||
|
if not options.quiet:
|
||||||
|
print((u"Mauvais code retour côté serveur, voir erreur " +
|
||||||
|
u"ci-dessus").encode('utf-8'),
|
||||||
|
file=sys.stderr)
|
||||||
|
if options.verbose:
|
||||||
|
print("raw_output: %s" % raw_out)
|
||||||
|
sys.exit(ret)
|
||||||
|
try:
|
||||||
|
return json.loads(raw_out)
|
||||||
|
except ValueError:
|
||||||
|
if not options.quiet:
|
||||||
|
print(u"Impossible de parser le résultat".encode('utf-8'),
|
||||||
|
file=sys.stderr)
|
||||||
|
if options.verbose:
|
||||||
|
print("raw_output: %s" % raw_out)
|
||||||
|
sys.exit(42)
|
||||||
|
|
||||||
@simple_memoize
|
@simple_memoize
|
||||||
def all_keys(options):
|
def all_keys(options):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue