def __enter__(cls): def handler(signum, frame): # We raise an exception **and** schedule a call to exit the # process hard. This is because we cannot rely on the exception # being raised during useful code. Sometimes, it will be raised # while the reactor is looping, which means that it will be # ignored. # # If the exception is raised during the actual job, then we'll get # a nice traceback indicating what timed out, and that will be # logged as an OOPS. # # Regardless of where the exception is raised, we'll hard exit the # process and have a TimeoutError OOPS logged, although that will # have a crappy traceback. See the job_raised callback in # TwistedJobRunner.runJobInSubprocess for the other half of that. reactor.callFromThread( reactor.callLater, 0, os._exit, TwistedJobRunner.TIMEOUT_CODE) raise TimeoutError scripts.execute_zcml_for_scripts(use_web_security=False) signal(SIGHUP, handler) dbconfig.override(dbuser=cls.dbuser, isolation_level='read_committed') # XXX wgrant 2011-09-24 bug=29744: initZopeless used to do this. # Should be removed from callsites verified to not need it. set_immediate_mail_delivery(True)
def __enter__(cls): def handler(signum, frame): # We raise an exception **and** schedule a call to exit the # process hard. This is because we cannot rely on the exception # being raised during useful code. Sometimes, it will be raised # while the reactor is looping, which means that it will be # ignored. # # If the exception is raised during the actual job, then we'll get # a nice traceback indicating what timed out, and that will be # logged as an OOPS. # # Regardless of where the exception is raised, we'll hard exit the # process and have a TimeoutError OOPS logged, although that will # have a crappy traceback. See the job_raised callback in # TwistedJobRunner.runJobInSubprocess for the other half of that. reactor.callFromThread(reactor.callLater, 0, os._exit, TwistedJobRunner.TIMEOUT_CODE) raise TimeoutError scripts.execute_zcml_for_scripts(use_web_security=False) signal(SIGHUP, handler) dbconfig.override(dbuser=cls.dbuser, isolation_level='read_committed') # XXX wgrant 2011-09-24 bug=29744: initZopeless used to do this. # Should be removed from callsites verified to not need it. set_immediate_mail_delivery(True)
def switch_dbuser(new_name): """Change the current database user. If new_name is None, the default will be restored. """ transaction.commit() dbconfig.override(dbuser=new_name) update_store_connections()
def _init_db(self, isolation): """Initialize the database transaction. Can be overridden for testing purposes. """ dbuser = self.dbuser if dbuser is None: connstr = ConnectionString(dbconfig.main_master) dbuser = connstr.user or dbconfig.dbuser dbconfig.override(dbuser=dbuser, isolation_level=isolation) self.txn = transaction
def _init_db(self, isolation): """Initialize the database transaction. Can be overridden for testing purposes. """ dbuser = self.dbuser if dbuser is None: connstr = ConnectionString(dbconfig.main_master) dbuser = connstr.user or dbconfig.dbuser dbconfig.override(dbuser=dbuser, isolation_level=isolation) self.txn = transaction
def task_init(dbuser): """Prepare to run a task. :param dbuser: The database user to use for running the task. """ ensure_zcml() transaction.abort() store = IStore(Job) getUtility(IZStorm).remove(store) store.close() dbconfig.override(dbuser=dbuser, isolation_level='read_committed') install_feature_controller(make_script_feature_controller('celery'))
def task_init(dbuser): """Prepare to run a task. :param dbuser: The database user to use for running the task. """ ensure_zcml() transaction.abort() store = IStore(Job) getUtility(IZStorm).remove(store) store.close() dbconfig.override(dbuser=dbuser, isolation_level='read_committed') install_feature_controller(make_script_feature_controller('celery'))
def _get_locals(): if len(sys.argv) > 1: dbuser = sys.argv[1] else: dbuser = None dbconfig.override(dbuser=dbuser) execute_zcml_for_scripts() readline.parse_and_bind('tab: complete') # Mimic the real interactive interpreter's loading of any # $PYTHONSTARTUP file. startup = os.environ.get('PYTHONSTARTUP') if startup: execfile(startup) store = IMasterStore(Person) if dbuser == 'launchpad': # Create a few variables "in case they come in handy." # Do we really use these? Are they worth carrying around? d = Distribution.get(1) p = Person.get(1) ds = DistroSeries.get(1) prod = Product.get(1) proj = ProjectGroup.get(1) b2 = Bug.get(2) b1 = Bug.get(1) s = Specification.get(1) q = Question.get(1) # Silence unused name warnings d, p, ds, prod, proj, b2, b1, s, q # Having a factory instance is handy. factory = LaunchpadObjectFactory() def browser_open(obj, *args, **kwargs): """Open a (possibly newly-created) object's view in a web browser. Accepts the same parameters as canonical_url. Performs a commit before invoking the browser, so "browser_open(factory.makeFoo())" works. """ transaction.commit() webbrowser.open(canonical_url(obj, *args, **kwargs)) # Silence unused name warnings factory, store res = {} res.update(locals()) res.update(globals()) del res['_get_locals'] return res
def _get_locals(): if len(sys.argv) > 1: dbuser = sys.argv[1] else: dbuser = None dbconfig.override(dbuser=dbuser) execute_zcml_for_scripts() readline.parse_and_bind('tab: complete') # Mimic the real interactive interpreter's loading of any # $PYTHONSTARTUP file. startup = os.environ.get('PYTHONSTARTUP') if startup: execfile(startup) store = IMasterStore(Person) if dbuser == 'launchpad': # Create a few variables "in case they come in handy." # Do we really use these? Are they worth carrying around? d = Distribution.get(1) p = Person.get(1) ds = DistroSeries.get(1) prod = Product.get(1) proj = ProjectGroup.get(1) b2 = Bug.get(2) b1 = Bug.get(1) s = Specification.get(1) q = Question.get(1) # Silence unused name warnings d, p, ds, prod, proj, b2, b1, s, q # Having a factory instance is handy. factory = LaunchpadObjectFactory() def browser_open(obj, *args, **kwargs): """Open a (possibly newly-created) object's view in a web browser. Accepts the same parameters as canonical_url. Performs a commit before invoking the browser, so "browser_open(factory.makeFoo())" works. """ transaction.commit() webbrowser.open(canonical_url(obj, *args, **kwargs)) # Silence unused name warnings factory, store res = {} res.update(locals()) res.update(globals()) del res['_get_locals'] return res
from lp.services.config import dbconfig from lp.services.database.sqlbase import cursor from lp.services.scripts import execute_zcml_for_scripts from lp.testing.layers import disconnect_stores execute_zcml_for_scripts() def check(): cur = cursor() cur.execute("UPDATE Person SET homepage_content='foo' WHERE name='mark'") cur.execute("SHOW transaction_isolation") print cur.fetchone()[0] transaction.abort() transaction.begin() cur = cursor() cur.execute("UPDATE Person SET homepage_content='bar' WHERE name='mark'") cur.execute("SHOW transaction_isolation") print cur.fetchone()[0] dbconfig.override(dbuser='******', isolation_level='read_committed') disconnect_stores() check() dbconfig.override(isolation_level='repeatable_read') disconnect_stores() check()
def set_isolation_level(isolation): dbconfig.override(isolation_level=isolation) disconnect_stores()
from lp.services.config import dbconfig from lp.services.database.sqlbase import cursor from lp.services.scripts import execute_zcml_for_scripts from lp.testing.layers import disconnect_stores execute_zcml_for_scripts() def check(): cur = cursor() cur.execute("UPDATE Person SET homepage_content='foo' WHERE name='mark'") cur.execute("SHOW transaction_isolation") print cur.fetchone()[0] transaction.abort() transaction.begin() cur = cursor() cur.execute("UPDATE Person SET homepage_content='bar' WHERE name='mark'") cur.execute("SHOW transaction_isolation") print cur.fetchone()[0] dbconfig.override(dbuser='******', isolation_level='read_committed') disconnect_stores() check() dbconfig.override(isolation_level='repeatable_read') disconnect_stores() check()
def set_isolation_level(isolation): dbconfig.override(isolation_level=isolation) disconnect_stores()