]> gitweb.pimeys.fr Git - today.git/blobdiff - today_server.py
[server] Meilleur débugging des exceptions
[today.git] / today_server.py
index 7e31652e9d049afb771de33c3857478d499db901..882b43b0f431fa0f4407f2b07f822a8ae95b8b32 100755 (executable)
@@ -18,6 +18,8 @@ import sys
 import urllib
 import json
 import traceback
+import inspect
+import pprint
 os.chdir('/home/vincent/scripts/today/')
 sys.path.append("/home/vincent/scripts/dtc/")
 import dtc
@@ -102,7 +104,7 @@ def last_noob_warpzone():
     for serie in [noobs, warpzones]:
         # Les titres sont dans l'ordre antichronologique, on s'arrête donc au premier qu'on comprend
         for titre in serie:
-            if "noob le film" in titre or "making of" in titre:
+            if "noob le film" in titre or "making of" in titre or "noob versus rct" == titre:
                 continue
             try:
                 if DEBUG:
@@ -182,8 +184,14 @@ def fetch_all():
         try:
             news[k] = f()
         except Exception as e:
-            print "Erreur à la récupération de %s :" % k
-            traceback.print_exc()
+            errmsg = "Erreur à la récupération de %s :\n" % k
+            errmsg += traceback.format_exc()
+            # On dumpe le contenu local de la mémoire au moment de l'exception
+            fobj = inspect.trace()[-1][0]
+            # On fait un peu de ménage
+            d = {k:v for (k,v) in fobj.f_locals.items() if not k.startswith("_")}
+            errmsg += "\nContexte : %s\n\n" % (pprint.pformat(d))
+            print errmsg
     return news
 
 def sync():
@@ -209,8 +217,11 @@ if __name__ == "__main__":
         DEBUG = True
     if sys.argv[1] == "check":
         news = fetch_all()
-        olds = get_file()
-        olds.update(news)
+        if "--init" in sys.argv:
+            olds = news
+        else:
+            olds = get_file()
+            olds.update(news)
         update_file(olds)
     elif sys.argv[1] == "whatsup":
         news = get_file()