#NEWLINE# def upgrade( self , version , name = 'database_version' , pkg = None ) : #NEWLINE# #INDENT# 'Invokes `do_upgrade(env, version, cursor)` in module\n        `"%s/db%i.py" % (pkg, version)`, for each required version upgrade.\n\n        :param version: the expected integer database version.\n        :param name: the name of the entry in the SYSTEM table that contains\n                     the database version. Defaults to `database_version`,\n                     which contains the database version for Trac.\n        :param pkg: the package containing the upgrade modules.\n\n        :raises TracError: if the package or module doesn\'t exist.\n        ' #NEWLINE# dbver = self . get_database_version ( name ) #NEWLINE# for i in range ( ( dbver + 1 ) , ( version + 1 ) ) : #NEWLINE# #INDENT# module = ( 'db%i' % i ) #NEWLINE# try : #NEWLINE# #INDENT# upgrades = __import__ ( pkg , globals ( ) , locals ( ) , [ module ] ) #NEWLINE# #UNINDENT# except ImportError : #NEWLINE# #INDENT# raise TracError ( _ ( 'No upgrade package %(pkg)s' , pkg = pkg ) ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# script = getattr ( upgrades , module ) #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# raise TracError ( _ ( 'No upgrade module %(module)s.py' , module = module ) ) #NEWLINE# #UNINDENT# with self . env . db_transaction as db : #NEWLINE# #INDENT# cursor = db . cursor ( ) #NEWLINE# script . do_upgrade ( self . env , i , cursor ) #NEWLINE# self . set_database_version ( i , name )