42 |
42 |
43 self.name = name |
43 self.name = name |
44 self.func = func |
44 self.func = func |
45 self.doc = doc |
45 self.doc = doc |
46 |
46 |
47 def invoke (self, config, gallery, args, options) : |
47 def setup (self, config, gallery) : |
48 """ |
48 """ |
49 Run the command with the given context |
49 Run the command with the given context |
50 """ |
50 """ |
51 |
51 |
52 return CommandContext(self, config, gallery)(*args, **options) |
52 return CommandContext(self, config, gallery) |
53 |
53 |
54 class CommandContext (object) : |
54 class CommandContext (object) : |
55 """ |
55 """ |
56 A CommandContext is the context that a Command executes in |
56 A CommandContext is the context that a Command executes in |
57 |
57 |
99 # output |
99 # output |
100 # XXX: stdout/err? |
100 # XXX: stdout/err? |
101 print msg |
101 print msg |
102 |
102 |
103 def log_debug (self, msg, *args, **kwargs) : |
103 def log_debug (self, msg, *args, **kwargs) : |
104 log_msg(logging.DEBUG, msg, *args, **kwargs) |
104 self.log_msg(logging.DEBUG, msg, *args, **kwargs) |
105 |
105 |
106 def log_info (self, msg, *args, **kwargs) : |
106 def log_info (self, msg, *args, **kwargs) : |
107 log_msg(logging.INFO, msg, *args, **kwargs) |
107 self.log_msg(logging.INFO, msg, *args, **kwargs) |
108 |
108 |
109 def log_warning (self, msg, *args, **kwargs) : |
109 def log_warning (self, msg, *args, **kwargs) : |
110 log_msg(logging.WARNING, msg, *args, **kwargs) |
110 self.log_msg(logging.WARNING, msg, *args, **kwargs) |
111 |
111 |
112 def log_error (self, msg, *args, **kwargs) : |
112 def log_error (self, msg, *args, **kwargs) : |
113 log_msg(logging.ERROR, msg, *args, **kwargs) |
113 self.log_msg(logging.ERROR, msg, *args, **kwargs) |
|
114 |
|
115 def handle_error (self, exc_info=None) : |
|
116 """ |
|
117 Do something to handle an error that occured |
|
118 """ |
|
119 |
|
120 if exc_info : |
|
121 traceback.print_execption(*exc_info) |
|
122 |
|
123 else : |
|
124 traceback.print_exc() |
114 |
125 |
115 def command (func) : |
126 def command (func) : |
116 """ |
127 """ |
117 A function decorator used to define Commands automatically |
128 A function decorator used to define Commands automatically |
118 """ |
129 """ |