allura
修訂 | 23f55a39ea529fb2111b99944cd457733b95c3a2 (tree) |
---|---|
時間 | 2012-07-04 02:52:42 |
作者 | Cory Johns <johnsca@geek...> |
Commiter | Cory Johns |
Suppress warnings when running scripts
Signed-off-by: Cory Johns <johnsca@geek.net>
@@ -1,10 +1,12 @@ | ||
1 | 1 | import sys |
2 | 2 | import os.path |
3 | 3 | import cProfile |
4 | +import warnings | |
4 | 5 | |
5 | 6 | from pylons import c |
6 | 7 | import pylons |
7 | 8 | import webob |
9 | +from sqlalchemy import exc | |
8 | 10 | |
9 | 11 | from ming.orm import session |
10 | 12 | from allura.lib import helpers as h |
@@ -23,20 +25,22 @@ class ScriptCommand(base.Command): | ||
23 | 25 | help='Drop to a debugger on error') |
24 | 26 | |
25 | 27 | def command(self): |
26 | - self.basic_setup() | |
27 | - request = webob.Request.blank('--script--', environ={ | |
28 | - 'paste.registry':self.registry}) | |
29 | - self.registry.register(pylons.request, request) | |
30 | - if self.options.pdb: | |
31 | - base.log.info('Installing exception hook') | |
32 | - sys.excepthook = utils.postmortem_hook | |
33 | - with open(self.args[1]) as fp: | |
34 | - ns = dict(__name__='__main__') | |
35 | - sys.argv = self.args[1:] | |
36 | - if self.options.profile: | |
37 | - cProfile.run(fp, '%s.profile' % os.path.basename(self.args[1])) | |
38 | - else: | |
39 | - exec fp in ns | |
28 | + with warnings.catch_warnings(): | |
29 | + warnings.simplefilter("ignore", category=exc.SAWarning) | |
30 | + self.basic_setup() | |
31 | + request = webob.Request.blank('--script--', environ={ | |
32 | + 'paste.registry':self.registry}) | |
33 | + self.registry.register(pylons.request, request) | |
34 | + if self.options.pdb: | |
35 | + base.log.info('Installing exception hook') | |
36 | + sys.excepthook = utils.postmortem_hook | |
37 | + with open(self.args[1]) as fp: | |
38 | + ns = dict(__name__='__main__') | |
39 | + sys.argv = self.args[1:] | |
40 | + if self.options.profile: | |
41 | + cProfile.run(fp, '%s.profile' % os.path.basename(self.args[1])) | |
42 | + else: | |
43 | + exec fp in ns | |
40 | 44 | |
41 | 45 | class SetToolAccessCommand(base.Command): |
42 | 46 | min_args=3 |