Ver Mensaje Individual
  #5 (permalink)  
Antiguo 18/12/2013, 10:13
Montes28
 
Fecha de Ingreso: septiembre-2010
Mensajes: 1.853
Antigüedad: 13 años, 7 meses
Puntos: 6
Respuesta: Duda con respecto a pyinotify - Monitoreando sistemas de archivos

estoy utilizando el evento IN_CLOSE_WRITE pero obtengo el siguiente error

Cita:
psycopg2.connect(database="python", user="postgres", password="hoe798css", host="192.168.102.6", port="5432")
^
IndentationError: unexpected indent
este es mi codigo
Código Python:
Ver original
  1. import pyinotify
  2. import psycopg2
  3.  
  4. class MyEventHandler(pyinotify.ProcessEvent):
  5.  
  6.     def process_IN_CLOSE_WRITE(self, event):
  7.         print "CLOSE_WRITE event:", event.pathname
  8.         print "Nombre :", event.name
  9.         print "Ruta", event.pathname
  10.         archivo = event.name
  11.         ruta = event.pathname
  12.         url = "http://192.168.102.8/repo_webcam/balcones-ruiz/"+archivo
  13.         tamano = len(archivo)
  14.         if tamano == 25:
  15.             anno=archivo[5:9]
  16.             mes=archivo[9:11]
  17.             dia=archivo[11:13]
  18.             hora=archivo[14:16]
  19.             minuto=archivo[16:18]
  20.             segundo=archivo[18:20]
  21.             archi=open('balcones-ruiz.txt','a')
  22.             archi.write('archivo:'+ ' '+ event.name + ' ' + 'ruta:'+ ' '+ event.pathname)
  23.             archi.write('\n')
  24.             archi.close()
  25.             conn = psycopg2.connect(database="python", user="postgres", password="hoe798css", host="192.168.102.6", port="5432")
  26.             print "Opened database successfully"
  27.             cur = conn.cursor()
  28.             cur.execute("INSERT INTO prueba VALUES(nextval('prueba_id_seq'), %s, %s, %s)", (anno+"-"+ mes +"-" + dia +" " + hora +":"+ minuto +":"  +segundo,url,ruta))
  29.             conn.commit()
  30.             print "Records created successfully";
  31.             conn.close()
  32.            
  33. def main():
  34.     # watch manager
  35.     wm = pyinotify.WatchManager()
  36.     wm.add_watch('/monitoreo/camip/balcones-ruiz', pyinotify.ALL_EVENTS, rec=True)
  37.  
  38.     # event handler
  39.     eh = MyEventHandler()
  40.  
  41.     # notifier
  42.     notifier = pyinotify.Notifier(wm, eh)
  43.     notifier.loop()
  44.  
  45. if __name__ == '__main__':
  46.     main()

Última edición por Montes28; 18/12/2013 a las 11:30