equal
deleted
inserted
replaced
1 import os, re, traceback, sys |
1 import os, re, traceback, sys, signal |
2 from mercurial import fancyopts, ui, hg |
2 from mercurial import fancyopts, ui, hg |
3 |
3 |
4 class UnknownCommand(Exception): pass |
4 class UnknownCommand(Exception): pass |
5 |
5 |
6 def filterfiles(list, files): |
6 def filterfiles(list, files): |
157 if re.match(e + "$", cmd): |
157 if re.match(e + "$", cmd): |
158 return table[e] |
158 return table[e] |
159 |
159 |
160 raise UnknownCommand(cmd) |
160 raise UnknownCommand(cmd) |
161 |
161 |
|
162 class SignalInterrupt(Exception): pass |
|
163 |
|
164 def catchterm(*args): |
|
165 raise SignalInterrupt |
|
166 |
162 def dispatch(args): |
167 def dispatch(args): |
163 options = {} |
168 options = {} |
164 opts = [('v', 'verbose', None, 'verbose'), |
169 opts = [('v', 'verbose', None, 'verbose'), |
165 ('d', 'debug', None, 'debug'), |
170 ('d', 'debug', None, 'debug'), |
166 ('q', 'quiet', None, 'quiet'), |
171 ('q', 'quiet', None, 'quiet'), |
179 not options["noninteractive"]) |
184 not options["noninteractive"]) |
180 |
185 |
181 # deal with unfound commands later |
186 # deal with unfound commands later |
182 i = find(cmd) |
187 i = find(cmd) |
183 |
188 |
|
189 signal.signal(signal.SIGTERM, catchterm) |
|
190 |
184 cmdoptions = {} |
191 cmdoptions = {} |
185 args = fancyopts.fancyopts(args, i[1], cmdoptions, i[2]) |
192 args = fancyopts.fancyopts(args, i[1], cmdoptions, i[2]) |
186 |
193 |
187 if cmd not in norepo.split(): |
194 if cmd not in norepo.split(): |
188 repo = hg.repository(ui = u) |
195 repo = hg.repository(ui = u) |
190 else: |
197 else: |
191 d = lambda: i[0](u, *args, **cmdoptions) |
198 d = lambda: i[0](u, *args, **cmdoptions) |
192 |
199 |
193 try: |
200 try: |
194 d() |
201 d() |
|
202 except SignalInterrupt: |
|
203 u.warn("killed!\n") |
195 except KeyboardInterrupt: |
204 except KeyboardInterrupt: |
196 u.warn("interrupted!\n") |
205 u.warn("interrupted!\n") |
197 except TypeError, inst: |
206 except TypeError, inst: |
198 # was this an argument error? |
207 # was this an argument error? |
199 tb = traceback.extract_tb(sys.exc_info()[2]) |
208 tb = traceback.extract_tb(sys.exc_info()[2]) |