Switch to unified view

a/Allura/allura/command/script.py b/Allura/allura/command/script.py
1
import sys
1
import sys
2
import os.path
2
import os.path
3
import cProfile
3
import cProfile
4
import warnings
4
5
5
from pylons import c
6
from pylons import c
6
import pylons
7
import pylons
7
import webob
8
import webob
9
from sqlalchemy import exc
8
10
9
from ming.orm import session
11
from ming.orm import session
10
from allura.lib import helpers as h
12
from allura.lib import helpers as h
11
from allura.lib import utils
13
from allura.lib import utils
12
from . import base
14
from . import base
...
...
21
                      help='Dump profiling data to <script>.profile')
23
                      help='Dump profiling data to <script>.profile')
22
    parser.add_option('--pdb', action='store_true', dest='pdb',
24
    parser.add_option('--pdb', action='store_true', dest='pdb',
23
                      help='Drop to a debugger on error')
25
                      help='Drop to a debugger on error')
24
26
25
    def command(self):
27
    def command(self):
28
        with warnings.catch_warnings():
29
            warnings.simplefilter("ignore", category=exc.SAWarning)
26
        self.basic_setup()
30
            self.basic_setup()
27
        request = webob.Request.blank('--script--', environ={
31
            request = webob.Request.blank('--script--', environ={
28
                'paste.registry':self.registry})
32
                    'paste.registry':self.registry})
29
        self.registry.register(pylons.request, request)
33
            self.registry.register(pylons.request, request)
30
        if self.options.pdb:
34
            if self.options.pdb:
31
            base.log.info('Installing exception hook')
35
                base.log.info('Installing exception hook')
32
            sys.excepthook = utils.postmortem_hook
36
                sys.excepthook = utils.postmortem_hook
33
        with open(self.args[1]) as fp:
37
            with open(self.args[1]) as fp:
34
            ns = dict(__name__='__main__')
38
                ns = dict(__name__='__main__')
35
            sys.argv = self.args[1:]
39
                sys.argv = self.args[1:]
36
            if self.options.profile:
40
                if self.options.profile:
37
                cProfile.run(fp, '%s.profile' % os.path.basename(self.args[1]))
41
                    cProfile.run(fp, '%s.profile' % os.path.basename(self.args[1]))
38
            else:
42
                else:
39
                exec fp in ns
43
                    exec fp in ns
40
44
41
class SetToolAccessCommand(base.Command):
45
class SetToolAccessCommand(base.Command):
42
    min_args=3
46
    min_args=3
43
    max_args=None
47
    max_args=None
44
    usage = '<ini file> <project_shortname> <neighborhood_name> <access_level>...'
48
    usage = '<ini file> <project_shortname> <neighborhood_name> <access_level>...'