|
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
|
|
|
4 |
|
|
|
5 |
from pylons import c
|
|
|
6 |
import pylons
|
|
|
7 |
import webob
|
|
|
8 |
|
2 |
from ming.orm import session
|
9 |
from ming.orm import session
|
3 |
from pylons import c
|
10 |
from allura.lib import helpers as h
|
|
|
11 |
from allura.lib import utils
|
4 |
from . import base
|
12 |
from . import base
|
5 |
from allura.lib import helpers as h
|
|
|
6 |
|
13 |
|
7 |
class ScriptCommand(base.Command):
|
14 |
class ScriptCommand(base.Command):
|
8 |
min_args=2
|
15 |
min_args=2
|
9 |
max_args=None
|
16 |
max_args=None
|
10 |
usage = '<ini file> <script> ...'
|
17 |
usage = '<ini file> <script> ...'
|
11 |
summary = 'Run a script as if it were being run at the paster shell prompt'
|
18 |
summary = 'Run a script as if it were being run at the paster shell prompt'
|
12 |
parser = base.Command.standard_parser(verbose=True)
|
19 |
parser = base.Command.standard_parser(verbose=True)
|
|
|
20 |
parser.add_option('--profile', action='store_true', dest='profile',
|
|
|
21 |
help='Dump profiling data to <script>.profile')
|
|
|
22 |
parser.add_option('--pdb', action='store_true', dest='pdb',
|
|
|
23 |
help='Drop to a debugger on error')
|
13 |
|
24 |
|
14 |
def command(self):
|
25 |
def command(self):
|
15 |
self.basic_setup()
|
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
|
16 |
with open(self.args[1]) as fp:
|
33 |
with open(self.args[1]) as fp:
|
17 |
ns = dict(__name__='__main__')
|
34 |
ns = dict(__name__='__main__')
|
18 |
sys.argv = self.args[1:]
|
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:
|
19 |
exec fp in ns
|
39 |
exec fp in ns
|
20 |
|
40 |
|
21 |
class SetToolAccessCommand(base.Command):
|
41 |
class SetToolAccessCommand(base.Command):
|
22 |
min_args=3
|
42 |
min_args=3
|
23 |
max_args=None
|
43 |
max_args=None
|
24 |
usage = '<ini file> <project_shortname> <access_level>...'
|
44 |
usage = '<ini file> <project_shortname> <access_level>...'
|