]> gitweb.pimeys.fr Git - today.git/blobdiff - today.py
Revert "pimeys est temporairement down" : Il l'est plus \o/
[today.git] / today.py
index 127e41d34d44f19a591688e4dc4d0c261c9a8d88..e430fd881a3030ab8768ced77b3ca24f4ae4366d 100755 (executable)
--- a/today.py
+++ b/today.py
@@ -17,13 +17,14 @@ os.chdir('/home/vincent/scripts/today/')
 class Config(object):
     """Configuration (pas de couleurs si on n'output pas dans un terminal"""
     def __init__(self, color=True):
-        if color:
-            self.endcolor = u"\e[0m"
-            self.blue = u"\e[1;36m"
-            self.red = u"\e[1;31m"
-            self.green = u"\e[1;32m"
-        else:
-            self.endcolor = self.blue = self.red = self.green = ""
+        self.endcolor = u"\e[0m"
+        self.blue = u"\e[1;36m"
+        self.red = u"\e[1;31m"
+        self.green = u"\e[1;32m"
+        if not color:
+            self.nocolor()
+        #: Faut-il contacter le serveur distant
+        self.do_remote = True
         #: Serveur distant où aller récupérer les checks
         self.distant_server = "pimeys"
         #: path de today-server.py sur le serveur distant
@@ -40,6 +41,10 @@ class Config(object):
         self.lasttime_file = ".lasttime"
         #: Fichier contenant un booléen mémorisant si il y a quelquechose dans le today du jour et qu'il n'a pas encore été regardé
         self.something_file = ".something"
+    
+    def nocolor(self):
+        """Passe en mode sans couleur."""
+        self.endcolor = self.blue = self.red = self.green = u""
 
 if "--color" in sys.argv:
     sys.argv.remove("--color")
@@ -303,8 +308,9 @@ def check_all():
     return checks
 
 def get_everything():
-    """Récupère toutes les infos"""
-    work = [action() for action in AUTOMATED_ACTIONS.values()]
+    """Récupère toutes les infos."""
+    work = [action() for (keyword, action) in AUTOMATED_ACTIONS.iteritems()
+            if (config.do_remote or not keyword in REMOTE_ACTIONS)]
     chain = u"\n\n".join([result for result in work if result])
     return chain
 
@@ -422,6 +428,9 @@ OTHER_ACTIONS = {
            "init" : initialize,
            }
 
+#: Les actions qui nécessitent un accès au serveur distant
+REMOTE_ACTIONS = ["check", "sync"]
+
 #: Toutes les actions
 ACTIONS = dict(AUTOMATED_ACTIONS)
 ACTIONS.update(OTHER_ACTIONS)
@@ -431,7 +440,11 @@ ACTIONS[None] = affiche # action par défaut
 if __name__ == "__main__":
     import sys
     if "--no-color" in sys.argv:
-        config.endcolor, config.red, config.blue = u"", u"", u""
+        config.nocolor()
+        sys.argv.remove("--no-color")
+    if "--no-remote" in sys.argv:
+        config.do_remote = False
+        sys.argv.remove("--no-remote")
     if len(sys.argv) == 1:
         # Juste un today
         output = ACTIONS[None]()