Ver Mensaje Individual
  #1 (permalink)  
Antiguo 06/02/2012, 14:40
kalel_jairo
 
Fecha de Ingreso: febrero-2012
Mensajes: 1
Antigüedad: 12 años, 3 meses
Puntos: 0
invalid syntax por que?

olap alguien me puede ayudar con el mismo error, pero en estas lineas:

Código Python:
Ver original
  1. #!/usr/bin/env python
  2. # -- coding: utf8 --
  3.  
  4. import os
  5. import sys
  6. import codecs
  7. import platform
  8. import threading
  9. import traceback
  10. import webbrowser
  11.  
  12. # fix path if needed
  13. if os.path.exists("cdpedia"):
  14.     sys.path.append("cdpedia")
  15.  
  16. # Logeamos stdout y stderr si estamos en windows
  17. if platform.system() == 'Windows':
  18.     log_filename = os.path.join(os.path.expanduser('~'), 'cdpedia.log')
  19.     try:
  20.         log = codecs.open(log_filename, 'w', 'utf8', errors='replace')
  21.         sys.stdout = log
  22.         sys.stderr = log
  23.     except:     # Si no podemos logear ni mostrar el error porque no
  24.         pass    # tenemos una consola no podemos hacer nada.
  25.  
  26. from src.armado import server
  27. from src.utiles import WatchDog
  28. import config
  29.  
  30. server_up = threading.Event()
  31. browser_up = threading.Event()
  32.  
  33. # WatchDog timer
  34. wd_timer = None
  35.  
  36. # Tiempo entre llamadas a cd_watch_dog en segundos
  37. CD_WD_SECONDS = 10
  38.  
  39. def handle_crash(type, value, tb):
  40.     '''Function to handle any exception that is not addressed explicitly.'''
  41.     if issubclass(type, KeyboardInterrupt):
  42.         # Nos vamos!
  43.         wd_timer.cancel()
  44.         sys.exit(0)
  45.     else:
  46.         exception = traceback.format_exception(type, value, tb)
  47.         exception = "".join(exception)
  48.         print exception
  49.  
  50. sys.excepthook = handle_crash
  51.  
  52. def close():
  53.     ''' Cierra el servidor y termina cdpedia '''
  54.     server.shutdown()
  55.     sys.exit(0)
  56.  
  57. def cd_watch_dog():
  58.     ''' Comprueba que el CD está puesto '''
  59.     global wd_timer
  60.  
  61.     try:
  62.         archivos = os.listdir('.')
  63.     except OSError:
  64.         # El CD no esta disponible
  65.         close()
  66.  
  67.     if not 'cdpedia.py' in archivos:
  68.         # El CD no es CDPedia
  69.         close()
  70.  
  71.     # Sigue andando, probemos mas tarde
  72.     wd_timer = threading.Timer(CD_WD_SECONDS, cd_watch_dog)
  73.     wd_timer.start()
  74.  
  75. def sleep_and_browse():
  76.     global wd_timer
  77.     server_up.wait()
  78.     port = server.serving_port
  79.     wd_timer = threading.Timer(CD_WD_SECONDS, cd_watch_dog)
  80.     wd_timer.start()
  81.     if config.EDICION_ESPECIAL is None:
  82.         index = "http://localhost:%d/" % (port,)
  83.     else:
  84.         index = "http://localhost:%d/%s/%s" % (port, config.EDICION_ESPECIAL,
  85.                                                                 config.INDEX)
  86.     webbrowser.open(index)
  87.     browser_up.set()
  88.  
  89.  
  90. def start_browser_watchdog():
  91.     browser_up.wait()
  92.     browser_watchdog.start()
  93.  
  94.  
  95. threading.Thread(target=sleep_and_browse).start()
  96.  
  97. browser_watchdog = WatchDog(callback=close, sleep=config.BROWSER_WD_SECONDS)
  98. threading.Thread(target=start_browser_watchdog).start()
  99.  
  100. print "Levantando el server..."
  101. server.run(server_up, browser_watchdog.update,
  102.                       debug_destacados=config.DEBUG_DESTACADOS)
  103. print "Terminado, saliendo."
  104. wd_timer.cancel()

Última edición por razpeitia; 06/02/2012 a las 17:11