1
# Copyright 2009-2010 Canonical Ltd. This software is licensed under the
1
# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
4
"""Scripts for starting a Python prompt with Launchpad initialized.
22
24
from pytz import utc
25
from storm.expr import *
26
# Bring in useful bits of Storm.
27
from storm.locals import *
25
29
from zope.component import getUtility
30
from zope.interface.verify import verifyObject
26
31
from zope.security.proxy import removeSecurityProxy
28
33
from canonical.launchpad.scripts import execute_zcml_for_scripts
29
34
from canonical.launchpad.webapp import canonical_url
35
from canonical.launchpad.webapp.interfaces import (
31
42
from lp.answers.model.question import Question
32
43
from lp.blueprints.model.specification import Specification
33
44
from lp.bugs.model.bug import Bug
38
49
from lp.registry.model.projectgroup import ProjectGroup
39
50
from lp.testing.factory import LaunchpadObjectFactory
41
from zope.interface.verify import verifyObject
46
# Bring in useful bits of Storm.
47
from storm.locals import *
48
from storm.expr import *
49
from canonical.launchpad.webapp.interfaces import (
50
IStoreSelector, MAIN_STORE, MASTER_FLAVOR, SLAVE_FLAVOR, DEFAULT_FLAVOR)
53
def switch_db_user(dbuser, commit_first=True):
56
transactionmgr.commit()
58
transactionmgr.abort()
59
transactionmgr.uninstall()
60
transactionmgr = initZopeless(dbuser=dbuser)
64
54
if len(sys.argv) > 1:
65
55
dbuser = sys.argv[1]
68
print 'execute_zcml_for_scripts()...'
69
58
execute_zcml_for_scripts()
70
59
readline.parse_and_bind('tab: complete')
71
# Mimic the real interactive interpreter's loading of any $PYTHONSTARTUP file.
72
print 'Reading $PYTHONSTARTUP...'
60
# Mimic the real interactive interpreter's loading of any
61
# $PYTHONSTARTUP file.
73
62
startup = os.environ.get('PYTHONSTARTUP')
76
print 'Initializing storm...'
77
65
store_selector = getUtility(IStoreSelector)
78
66
store = store_selector.get(MAIN_STORE, MASTER_FLAVOR)
80
# Let's get a few handy objects going.
81
68
if dbuser == 'launchpad':
82
print 'Creating a few handy objects...'
69
# Create a few variables "in case they come in handy."
70
# Do we really use these? Are they worth carrying around?
83
71
d = Distribution.get(1)
85
73
ds = DistroSeries.get(1)