equal
deleted
inserted
replaced
95 return cube |
95 return cube |
96 |
96 |
97 return [drop_prefix(cube) for cube in cwcfg.available_cubes()] |
97 return [drop_prefix(cube) for cube in cwcfg.available_cubes()] |
98 |
98 |
99 |
99 |
|
100 def get_pdb(): |
|
101 try: |
|
102 import ipdb |
|
103 except ImportError: |
|
104 import pdb |
|
105 return pdb |
|
106 else: |
|
107 return ipdb |
|
108 |
|
109 |
100 class InstanceCommand(Command): |
110 class InstanceCommand(Command): |
101 """base class for command taking one instance id as arguments""" |
111 """base class for command taking one instance id as arguments""" |
102 arguments = '<instance>' |
112 arguments = '<instance>' |
103 |
113 |
104 # enforce having one instance |
114 # enforce having one instance |
107 options = ( |
117 options = ( |
108 ("force", |
118 ("force", |
109 {'short': 'f', 'action': 'store_true', |
119 {'short': 'f', 'action': 'store_true', |
110 'default': False, |
120 'default': False, |
111 'help': 'force command without asking confirmation', |
121 'help': 'force command without asking confirmation', |
|
122 } |
|
123 ), |
|
124 ("pdb", |
|
125 {'action': 'store_true', 'default': False, |
|
126 'help': 'launch pdb on exception', |
112 } |
127 } |
113 ), |
128 ), |
114 ) |
129 ) |
115 actionverb = None |
130 actionverb = None |
116 |
131 |
128 appid, self.actionverb, ex)) |
143 appid, self.actionverb, ex)) |
129 status = 4 |
144 status = 4 |
130 except Exception as ex: |
145 except Exception as ex: |
131 import traceback |
146 import traceback |
132 traceback.print_exc() |
147 traceback.print_exc() |
|
148 |
133 sys.stderr.write('instance %s not %s: %s\n' % ( |
149 sys.stderr.write('instance %s not %s: %s\n' % ( |
134 appid, self.actionverb, ex)) |
150 appid, self.actionverb, ex)) |
135 status = 8 |
151 status = 8 |
136 |
152 |
137 except (KeyboardInterrupt, SystemExit): |
153 except (KeyboardInterrupt, SystemExit): |
138 sys.stderr.write('%s aborted\n' % self.name) |
154 sys.stderr.write('%s aborted\n' % self.name) |
139 status = 2 # specific error code |
155 status = 2 # specific error code |
|
156 |
|
157 if status != 0 and self.config.pdb: |
|
158 exception_type, exception, traceback_ = sys.exc_info() |
|
159 pdb = get_pdb() |
|
160 pdb.post_mortem(traceback_) |
140 |
161 |
141 sys.exit(status) |
162 sys.exit(status) |
142 |
163 |
143 |
164 |
144 # base commands ############################################################### |
165 # base commands ############################################################### |