refs #526 translate my comments
parent
bfe563d902
commit
f25252fcf9
|
@ -281,8 +281,8 @@ with open (subprocs_log, 'ab') as fd: ## TODO improve this logging
|
||||||
def ejecutaArchivo(self,fn):
|
def ejecutaArchivo(self,fn):
|
||||||
logger.debug ('fn ({})'.format (fn))
|
logger.debug ('fn ({})'.format (fn))
|
||||||
|
|
||||||
## TODO hay que entender este codigo (ogAdmClient.c:2111) para poder traducirlo a python
|
## TODO need to understand this code (ogAdmClient.c:2111) before translating it to python
|
||||||
## en una funcion "ejecutaArchivo" esperaba que se ejecutara un archivo, pero solo hay una llamada a gestionaTrama() que no sé dónde termina
|
## in a function called "ejecutaArchivo" I'd expect a file to be run, however there's only a call to gestionaTrama() that I don't know where it leads to
|
||||||
#char* buffer,*lineas[MAXIMAS_LINEAS];
|
#char* buffer,*lineas[MAXIMAS_LINEAS];
|
||||||
#int i,numlin;
|
#int i,numlin;
|
||||||
#char modulo[] = "ejecutaArchivo()";
|
#char modulo[] = "ejecutaArchivo()";
|
||||||
|
@ -302,14 +302,14 @@ with open (subprocs_log, 'ab') as fd: ## TODO improve this logging
|
||||||
# }
|
# }
|
||||||
#liberaMemoria(buffer);
|
#liberaMemoria(buffer);
|
||||||
|
|
||||||
## voy a probar algo, asumiendo que en el archivo no hay simplemente un bash, sino secuencias de parametros tal que "nfn=Funcion\rparam1=foo\rparam2=bar"
|
## let's test something, assuming that in the "file" there's not just some bash, but a sequence of parameters such as "nfn=Function\rparam1=foo\rparam2=bar"
|
||||||
buffer = subprocess.run (['cat', fn], capture_output=True).stdout.strip().decode ('utf-8')
|
buffer = subprocess.run (['cat', fn], capture_output=True).stdout.strip().decode ('utf-8')
|
||||||
logger.debug ('buffer ({})'.format (buffer.replace('\r', '\\r'))) ## sustituimos \r para que el log tenga sentido
|
logger.debug ('buffer ({})'.format (buffer.replace('\r', '\\r'))) ## change \r so as not to mess with the log
|
||||||
if buffer:
|
if buffer:
|
||||||
for l in buffer.split('@'):
|
for l in buffer.split('@'):
|
||||||
if not len(l): continue
|
if not len(l): continue
|
||||||
logger.debug ('line ({})'.format (l))
|
logger.debug ('line ({})'.format (l))
|
||||||
## en este punto, una opción sería pegar un curl a localhost, pero también podemos parsear los parámetros y llamar localmente a la función que sea:
|
## at this point, an option would be fire up a curl to localhost, but we can also parse the params and locally call the desired function:
|
||||||
post_params = {}
|
post_params = {}
|
||||||
for param in l.split("\r"):
|
for param in l.split("\r"):
|
||||||
k, v = param.split('=')
|
k, v = param.split('=')
|
||||||
|
@ -321,7 +321,7 @@ with open (subprocs_log, 'ab') as fd: ## TODO improve this logging
|
||||||
logger.error ('Ha ocurrido algún problema al procesar la trama recibida')
|
logger.error ('Ha ocurrido algún problema al procesar la trama recibida')
|
||||||
break
|
break
|
||||||
func = getattr (self, 'process_' + func_name)
|
func = getattr (self, 'process_' + func_name)
|
||||||
## func ya es una referencia a self.func, de modo que ahora no hay que hacer self.func(...) ni tampoco func(self, ...)
|
## func is already a ref to self.func, so we don't have to call self.func(...) or func(self, ...)
|
||||||
|
|
||||||
logger.debug ('calling function "{}" with post_params "{}"'.format (func_name, post_params))
|
logger.debug ('calling function "{}" with post_params "{}"'.format (func_name, post_params))
|
||||||
output = func ([], {}, post_params, None)
|
output = func ([], {}, post_params, None)
|
||||||
|
@ -396,7 +396,7 @@ with open (subprocs_log, 'ab') as fd: ## TODO improve this logging
|
||||||
|
|
||||||
def comandosPendientes(self):
|
def comandosPendientes(self):
|
||||||
while (True):
|
while (True):
|
||||||
res = self.enviaMensajeServidor ('ComandosPendientes') ## recibe un solo comando
|
res = self.enviaMensajeServidor ('ComandosPendientes') ## receives just one command
|
||||||
if (type(res) is not dict):
|
if (type(res) is not dict):
|
||||||
logger.error ('Ha ocurrido algún problema al enviar una petición de comandos o tareas pendientes al Servidor de Administración')
|
logger.error ('Ha ocurrido algún problema al enviar una petición de comandos o tareas pendientes al Servidor de Administración')
|
||||||
logger.error ('Ha ocurrido algún problema al recibir una petición de comandos o tareas pendientes desde el Servidor de Administración')
|
logger.error ('Ha ocurrido algún problema al recibir una petición de comandos o tareas pendientes desde el Servidor de Administración')
|
||||||
|
@ -406,12 +406,12 @@ with open (subprocs_log, 'ab') as fd: ## TODO improve this logging
|
||||||
if ('NoComandosPtes' == res['nfn']):
|
if ('NoComandosPtes' == res['nfn']):
|
||||||
break
|
break
|
||||||
|
|
||||||
## TODO gestionar los demás casos... igual toca hacer algo parecido a ejecutaArchivo
|
## TODO manage the rest of cases... we might have to do something similar to ejecutaArchivo
|
||||||
#if(!gestionaTrama(ptrTrama)){ // Análisis de la trama
|
#if(!gestionaTrama(ptrTrama)){ // Análisis de la trama
|
||||||
# logger.error ('Ha ocurrido algún problema al procesar la trama recibida')
|
# logger.error ('Ha ocurrido algún problema al procesar la trama recibida')
|
||||||
# return False
|
# return False
|
||||||
#}
|
#}
|
||||||
## de momento le pongo un return False para evitar un posible bucle infinito
|
## ATM let's just return false to avoid a possible infinite loop
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -423,7 +423,7 @@ with open (subprocs_log, 'ab') as fd: ## TODO improve this logging
|
||||||
#p = subprocess.Popen (['/opt/opengnsys/bin/browser', '-qws', url])
|
#p = subprocess.Popen (['/opt/opengnsys/bin/browser', '-qws', url])
|
||||||
p = subprocess.Popen (['/usr/bin/xeyes'])
|
p = subprocess.Popen (['/usr/bin/xeyes'])
|
||||||
try:
|
try:
|
||||||
p.wait (2) ## si el proceso se muere antes de 2 segundos...
|
p.wait (2) ## if the process dies before 2 seconds...
|
||||||
logger.error ('Error al ejecutar la llamada a la interface de administración')
|
logger.error ('Error al ejecutar la llamada a la interface de administración')
|
||||||
logger.error ('Error en la creación del proceso hijo')
|
logger.error ('Error en la creación del proceso hijo')
|
||||||
logger.error ('return code "{}"'.format (p.returncode))
|
logger.error ('return code "{}"'.format (p.returncode))
|
||||||
|
@ -446,8 +446,8 @@ with open (subprocs_log, 'ab') as fd: ## TODO improve this logging
|
||||||
|
|
||||||
logger.info ('Disponibilidad de comandos activada') ## Disponibilidad de cliente activada
|
logger.info ('Disponibilidad de comandos activada') ## Disponibilidad de cliente activada
|
||||||
|
|
||||||
## y hacemos return true y el agente es quien espera peticiones
|
## we now return true and the outer agent code gets to wait for requests from outside
|
||||||
## TODO el tema es, ogAdmClient hace comandosPendientes() cada vez, ¿cómo lo metemos aquí?
|
## TODO thing is, ogAdmClient always calls comandosPendientes() after every received request. How do we do that here?
|
||||||
#
|
#
|
||||||
#ptrTrama=recibeMensaje(&socket_c);
|
#ptrTrama=recibeMensaje(&socket_c);
|
||||||
#if(!ptrTrama){
|
#if(!ptrTrama){
|
||||||
|
|
Loading…
Reference in New Issue