move Command exception handling into command.py, and handle KeyboardInterrupt
authorTero Marttila <terom@fixme.fi>
Thu, 11 Jun 2009 21:40:39 +0300
changeset 92 eb50b4f7812d
parent 91 17ae33501289
child 93 d3872a673fbe
move Command exception handling into command.py, and handle KeyboardInterrupt
degal/command.py
degal/main.py
--- a/degal/command.py	Thu Jun 11 21:40:12 2009 +0300
+++ b/degal/command.py	Thu Jun 11 21:40:39 2009 +0300
@@ -67,12 +67,27 @@
         self.config = config
         self.gallery = gallery
 
-    def __call__ (self, *args, **kwargs) :
+    def execute (self, *args, **kwargs) :
         """
             Run the command in this context
         """
 
         return self.command.func(self, *args, **kwargs)
+    
+    def run (self, *args, **kwargs) :
+        """
+            Run the command with error handling
+        """
+
+        try :
+            # run it
+            return self.execute(*args, **kwargs)
+        
+        except KeyboardInterrupt :
+            self.log_error("Interrupted")
+
+        except :
+            command_ctx.handle_error()
 
     def log_msg (self, level, msg, *args, **kwargs) :
         """
--- a/degal/main.py	Thu Jun 11 21:40:12 2009 +0300
+++ b/degal/main.py	Thu Jun 11 21:40:39 2009 +0300
@@ -71,13 +71,9 @@
     
     # setup the command execution context
     command_ctx = command.setup(config, gallery)
-    
-    try :
-        # run it
-        return command_ctx(*args, **kwargs)
-    
-    except :
-        command_ctx.handle_error()
+  
+    # run with error handling
+    return command_ctx.run()
 
 def main (argv) :
     """