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
3
import cProfile
2
from ming.orm import session
4
from ming.orm import session
3
from pylons import c
5
from pylons import c
4
from . import base
6
from . import base
5
from allura.lib import helpers as h
7
from allura.lib import helpers as h
8
from allura.lib import utils
6
9
7
class ScriptCommand(base.Command):
10
class ScriptCommand(base.Command):
8
    min_args=2
11
    min_args=2
9
    max_args=None
12
    max_args=None
10
    usage = '<ini file> <script> ...'
13
    usage = '<ini file> <script> ...'
11
    summary = 'Run a script as if it were being run at the paster shell prompt'
14
    summary = 'Run a script as if it were being run at the paster shell prompt'
12
    parser = base.Command.standard_parser(verbose=True)
15
    parser = base.Command.standard_parser(verbose=True)
16
    parser.add_option('--profile', action='store_true', dest='profile',
17
                      help='Dump profiling data to <script>.profile')
18
    parser.add_option('--pdb', action='store_true', dest='pdb',
19
                      help='Drop to a debugger on error')
13
20
14
    def command(self):
21
    def command(self):
15
        self.basic_setup()
22
        self.basic_setup()
23
        if self.options.pdb:
24
            base.log.info('Installing exception hook')
25
            sys.excepthook = utils.postmortem_hook
16
        with open(self.args[1]) as fp:
26
        with open(self.args[1]) as fp:
17
            ns = dict(__name__='__main__')
27
            ns = dict(__name__='__main__')
18
            sys.argv = self.args[1:]
28
            sys.argv = self.args[1:]
29
            if self.options.profile:
30
                cProfile.run(fp, '%s.profile' % os.path.basename(self.args[1]))
31
            else:
19
            exec fp in ns
32
                exec fp in ns
20
33
21
class SetToolAccessCommand(base.Command):
34
class SetToolAccessCommand(base.Command):
22
    min_args=3
35
    min_args=3
23
    max_args=None
36
    max_args=None
24
    usage = '<ini file> <project_shortname> <access_level>...'
37
    usage = '<ini file> <project_shortname> <access_level>...'