def set_globals(web2py_path,app): """ This function sets the environment variables like database , dbengine etc . @param web2py_path : The path to the web2py congaing the Eden app (i.e "/home/web2py") @param app : The name of the eden application of whose database needs to be migrated (i.e "eden") It loads the models all the models to get the database and also sets the other global variable which are required by all of the functions for database operations """ global WEB2PY_PATH,APP,dbengine WEB2PY_PATH = web2py_path APP = app os.chdir(WEB2PY_PATH) sys.path.append(WEB2PY_PATH) from gluon.custom_import import custom_import_install custom_import_install(WEB2PY_PATH) from gluon.shell import env from gluon import DAL, Field old_env = env(APP, c=None, import_models=True) old_str =''' try: s3db.load_all_models() except NameError: print "s3db not defined" ''' globals().update(**old_env) exec old_str in globals(), locals() if settings.database.db_type: dbengine = settings.database.db_type else: dbengine = "sqlite"
def wsgiapp(env, res): """Return the wsgiapp""" env['PATH_INFO'] = env['PATH_INFO'].decode('latin1').encode('utf8') #this deals with a problem where GAE development server seems to forget # the path between requests if global_settings.web2py_runtime == 'gae:development': gluon.admin.create_missing_folders() from gluon.custom_import import custom_import_install web2py_path = global_settings.applications_parent # backward compatibility custom_import_install(web2py_path) return gluon.main.wsgibase(env, res)
def wsgiapp(env, res): """Return the wsgiapp""" env['PATH_INFO'] = env['PATH_INFO'].decode('latin1').encode('utf8') #this deals with a problem where GAE development server seems to forget # the path between requests if global_settings.web2py_runtime == 'gae:development': gluon.admin.create_missing_folders() from gluon.custom_import import custom_import_install web2py_path = global_settings.applications_parent # backward compatibility custom_import_install(web2py_path) return gluon.main.wsgibase(env, res)
def build_environment(request, response, session, store_current=True): """ Build the environment dictionary into which web2py files are executed. """ #h,v = html,validators environment = dict(_base_environment_) if not request.env: request.env = Storage() # Enable standard conditional models (i.e., /*.py, /[controller]/*.py, and # /[controller]/[function]/*.py) response.models_to_run = [ r'^\w+\.py$', r'^%s/\w+\.py$' % request.controller, r'^%s/%s/\w+\.py$' % (request.controller, request.function) ] t = environment['T'] = translator( os.path.join(request.folder, 'languages'), request.env.http_accept_language) c = environment['cache'] = Cache(request) if store_current: current.globalenv = environment current.request = request current.response = response current.session = session current.T = t current.cache = c global __builtins__ if is_jython: # jython hack __builtins__ = mybuiltin() elif is_pypy: # apply the same hack to pypy too __builtins__ = mybuiltin() elif PY2: __builtins__['__import__'] = builtin.__import__ # WHY? environment['request'] = request environment['response'] = response environment['session'] = session environment['local_import'] = \ lambda name, reload=False, app=request.application:\ local_import_aux(name, reload, app) BaseAdapter.set_folder(pjoin(request.folder, 'databases')) response._view_environment = copy.copy(environment) custom_import_install() return environment
def build_environment(request, response, session, store_current=True): """ Build the environment dictionary into which web2py files are executed. """ # h,v = html,validators environment = dict(_base_environment_) if not request.env: request.env = Storage() # Enable standard conditional models (i.e., /*.py, /[controller]/*.py, and # /[controller]/[function]/*.py) response.models_to_run = [ r'^\w+\.py$', r'^%s/\w+\.py$' % request.controller, r'^%s/%s/\w+\.py$' % (request.controller, request.function) ] T = environment['T'] = TranslatorFactory( os.path.join(request.folder, 'languages'), request.env.http_accept_language) c = environment['cache'] = Cache(request) # configure the validator to use the t translator Validator.translator = staticmethod(lambda text: None if text is None else str(T(text))) if store_current: current.globalenv = environment current.request = request current.response = response current.session = session current.T = T current.cache = c if is_jython: # jython hack global __builtins__ __builtins__ = mybuiltin() environment['request'] = request environment['response'] = response environment['session'] = session environment['local_import'] = \ lambda name, reload=False, app=request.application:\ local_import_aux(name, reload, app) BaseAdapter.set_folder(pjoin(request.folder, 'databases')) custom_import_install() return environment
def build_environment(request, response, session, store_current=True): """ Build the environment dictionary into which web2py files are executed. """ #h,v = html,validators environment = dict(_base_environment_) if not request.env: request.env = Storage() # Enable standard conditional models (i.e., /*.py, /[controller]/*.py, and # /[controller]/[function]/*.py) response.models_to_run = [ r'^\w+\.py$', r'^%s/\w+\.py$' % request.controller, r'^%s/%s/\w+\.py$' % (request.controller, request.function) ] t = environment['T'] = translator(os.path.join(request.folder,'languages'), request.env.http_accept_language) c = environment['cache'] = Cache(request) if store_current: current.globalenv = environment current.request = request current.response = response current.session = session current.T = t current.cache = c global __builtins__ if is_jython: # jython hack __builtins__ = mybuiltin() elif is_pypy: # apply the same hack to pypy too __builtins__ = mybuiltin() elif PY2: __builtins__['__import__'] = builtin.__import__ # WHY? environment['request'] = request environment['response'] = response environment['session'] = session environment['local_import'] = \ lambda name, reload=False, app=request.application:\ local_import_aux(name, reload, app) BaseAdapter.set_folder(pjoin(request.folder, 'databases')) response._view_environment = copy.copy(environment) custom_import_install() return environment
def chdir(self): try: h = _winreg.OpenKey( _winreg.HKEY_LOCAL_MACHINE, r'SYSTEM\CurrentControlSet\Services\%s' % self._svc_name_) try: cls = _winreg.QueryValue(h, 'PythonClass') finally: _winreg.CloseKey(h) dir = os.path.dirname(cls) os.chdir(dir) from gluon.settings import global_settings global_settings.gluon_parent = dir from gluon.custom_import import custom_import_install custom_import_install(dir) return True except: self.log("Can't change to web2py working path; server is stopped") return False
def chdir(self): try: h = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r'SYSTEM\CurrentControlSet\Services\%s' % self._svc_name_) try: cls = _winreg.QueryValue(h, 'PythonClass') finally: _winreg.CloseKey(h) dir = os.path.dirname(cls) os.chdir(dir) from gluon.settings import global_settings global_settings.gluon_parent = dir from gluon.custom_import import custom_import_install custom_import_install(dir) return True except: self.log("Can't change to web2py working path; server is stopped") return False
def get_old_db(): """ This function let up view how the database was before the migration scripts were called , the relevant data is displayed during the tests """ os.chdir(WEB2PY_PATH) sys.path.append(WEB2PY_PATH) from gluon.custom_import import custom_import_install custom_import_install(WEB2PY_PATH) from gluon.shell import env from gluon import DAL, Field old_env = env(APP, c=None, import_models=True) old_str = ''' try: s3db.load_all_models() except NameError: print "s3db not defined" ''' globals().update(**old_env) exec old_str in globals(), locals() return db
def get_old_db(): """ This function let up view how the database was before the migration scripts were called , the relevant data is displayed during the tests """ os.chdir(WEB2PY_PATH) sys.path.append(WEB2PY_PATH) from gluon.custom_import import custom_import_install custom_import_install(WEB2PY_PATH) from gluon.shell import env from gluon import DAL, Field old_env = env(APP, c=None, import_models=True) old_str =''' try: s3db.load_all_models() except NameError: print "s3db not defined" ''' globals().update(**old_env) exec old_str in globals(), locals() return db
"--allargs", dest="allargs", default=True, help="If True (the default), run task with all scheduled arg sets. If False, run with first set encountered only.") args = vars(parser.parse_args()) app = args["app"] task = args["task"] allargs = args["allargs"] adir = os.path.join('applications', app) if not os.path.exists(adir): print >> sys.stderr, "Application not found: %s" % adir sys.exit(1) from gluon.custom_import import custom_import_install try: # Web2py post revision b8afce7 2012-10-11 custom_import_install() except: # Web2py pre revision b8afce7 2012-10-11 custom_import_install(os.environ['WEB2PY_PATH']) from gluon.shell import env _env = env(app, c=None, import_models=True) globals().update(**_env) # This is present in case this is a first run of the models. db.commit() from gluon import current # Get tasks from the scheduler_task table. if task: query = (db.scheduler_task.task_name == task) else:
import copy import subprocess WEB2PY_PATH = sys.argv[1] APP = sys.argv[2] changed_table = "org_organisation" new_field = "type_id" new_table = "org_organisation_type" old_field = "type" new_table_field = "name" os.chdir(WEB2PY_PATH) sys.path.append(WEB2PY_PATH) from gluon.custom_import import custom_import_install custom_import_install(WEB2PY_PATH) from gluon.shell import env from gluon import DAL, Field old_env = env(APP, c=None, import_models=True) old_str = ''' try: s3db.load_all_models() except NameError: print "s3db not defined" ''' globals().update(**old_env) exec old_str in globals(), locals() database_string = "sqlite://storage.db" old_database_folder = "%s/applications/%s/databases" % (WEB2PY_PATH, APP)
def build_environment(request, response, session, store_current=True): """ Build the environment dictionary into which web2py files are executed. """ # h,v = html,validators environment = dict(_base_environment_) if not request.env: request.env = Storage() # Enable standard conditional models (i.e., /*.py, /[controller]/*.py, and # /[controller]/[function]/*.py) response.models_to_run = [ r'^\w+\.py$', r'^%s/\w+\.py$' % request.controller, r'^%s/%s/\w+\.py$' % (request.controller, request.function) ] T = environment['T'] = TranslatorFactory( pjoin(request.folder, 'languages'), request.env.http_accept_language) c = environment['cache'] = Cache(request) # configure the validator to use the t translator Validator.translator = staticmethod(lambda text: None if text is None else str(T(text))) if store_current: current.globalenv = environment current.request = request current.response = response current.session = session current.T = T current.cache = c if global_settings.is_jython: # jython hack class mybuiltin(object): """ NOTE could simple use a dict and populate it, NOTE not sure if this changes things though if monkey patching import..... """ # __builtins__ def __getitem__(self, key): try: return getattr(builtin, key) except AttributeError: raise KeyError(key) def __setitem__(self, key, value): setattr(self, key, value) global __builtins__ __builtins__ = mybuiltin() environment['request'] = request environment['response'] = response environment['session'] = session environment['local_import'] = \ lambda name, reload=False, app=request.application:\ local_import_aux(name, reload, app) BaseAdapter.set_folder(pjoin(request.folder, 'databases')) custom_import_install() return environment
def build_environment(request, response, session, store_current=True): """ Build the environment dictionary into which web2py files are executed. """ # h,v = html,validators environment = dict(_base_environment_) if not request.env: request.env = Storage() # Enable standard conditional models (i.e., /*.py, /[controller]/*.py, and # /[controller]/[function]/*.py) response.models_to_run = [ r'^\w+\.py$', r'^%s/\w+\.py$' % request.controller, r'^%s/%s/\w+\.py$' % (request.controller, request.function) ] T = environment['T'] = TranslatorFactory(pjoin(request.folder, 'languages'), request.env.http_accept_language) c = environment['cache'] = Cache(request) # configure the validator to use the t translator Validator.translator = staticmethod(lambda text: None if text is None else str(T(text))) if store_current: current.globalenv = environment current.request = request current.response = response current.session = session current.T = T current.cache = c if global_settings.is_jython: # jython hack class mybuiltin(object): """ NOTE could simple use a dict and populate it, NOTE not sure if this changes things though if monkey patching import..... """ # __builtins__ def __getitem__(self, key): try: return getattr(builtin, key) except AttributeError: raise KeyError(key) def __setitem__(self, key, value): setattr(self, key, value) global __builtins__ __builtins__ = mybuiltin() environment['request'] = request environment['response'] = response environment['session'] = session environment['local_import'] = \ lambda name, reload=False, app=request.application:\ local_import_aux(name, reload, app) BaseAdapter.set_folder(pjoin(request.folder, 'databases')) custom_import_install() return environment
"--task", dest="task", default=None, help="Task name") parser.add_argument( "--allargs", dest="allargs", default=True, help="If True (the default), run task with all scheduled arg sets. If False, run with first set encountered only.") args = vars(parser.parse_args()) app = args["app"] task = args["task"] allargs = args["allargs"] adir = os.path.join("applications", app) if not os.path.exists(adir): print >> sys.stderr, "Application not found: %s" % adir sys.exit(1) from gluon.custom_import import custom_import_install custom_import_install() from gluon.shell import env _env = env(app, c=None, import_models=True) globals().update(**_env) # This is present in case this is a first run of the models. db.commit() from gluon import current # Get tasks from the scheduler_task table. if task: query = (db.scheduler_task.task_name == task) else: query = (db.scheduler_task.id > 0) scheduled_tasks = db(query).select(orderby=db.scheduler_task.task_name)
WEB2PY_PATH = sys.argv[1] if not "WEB2PY_PATH" in os.environ: os.environ["WEB2PY_PATH"] = WEB2PY_PATH NEW_APP = sys.argv[3] OLD_APP = sys.argv[2] NEW_PATH = "%s/applications/%s" % (os.environ["WEB2PY_PATH"], NEW_APP) OLD_PATH = "%s/applications/%s" % (os.environ["WEB2PY_PATH"], OLD_APP) #WE ARE LOADING THE 2 ENVIRONMENTS WITH ALL THERE MODELS os.chdir(os.environ["WEB2PY_PATH"]) sys.path.append(os.environ["WEB2PY_PATH"]) from gluon.custom_import import custom_import_install custom_import_install(os.environ["WEB2PY_PATH"]) from gluon.shell import env from gluon import DAL, Field new_env = env(NEW_APP, c=None, import_models=True) d = globals().copy() d.update(**new_env) new_str = ''' try: s3db.load_all_models() except NameError: print "s3db not defined" new_db = db ''' exec new_str in d, locals()
import copy import subprocess WEB2PY_PATH = sys.argv[1] APP = sys.argv[2] changed_table = "org_organisation" new_field = "type_id" new_table = "org_organisation_type" old_field = "type" new_table_field = "name" os.chdir(WEB2PY_PATH) sys.path.append(WEB2PY_PATH) from gluon.custom_import import custom_import_install custom_import_install(WEB2PY_PATH) from gluon.shell import env from gluon import DAL, Field old_env = env(APP, c=None, import_models=True) old_str =''' try: s3db.load_all_models() except NameError: print "s3db not defined" ''' globals().update(**old_env) exec old_str in globals(), locals() database_string = "sqlite://storage.db"
WEB2PY_PATH = sys.argv[1] if not "WEB2PY_PATH" in os.environ: os.environ["WEB2PY_PATH"] = WEB2PY_PATH NEW_APP = sys.argv[3] OLD_APP = sys.argv[2] NEW_PATH = "%s/applications/%s" % (os.environ["WEB2PY_PATH"], NEW_APP) OLD_PATH = "%s/applications/%s" % (os.environ["WEB2PY_PATH"], OLD_APP) # Load the 2 environments with all their models os.chdir(os.environ["WEB2PY_PATH"]) sys.path.append(os.environ["WEB2PY_PATH"]) from gluon.custom_import import custom_import_install custom_import_install(os.environ["WEB2PY_PATH"]) from gluon.shell import env from gluon import DAL, Field new_env = env(NEW_APP, c=None, import_models=True) d = globals().copy() d.update(**new_env) new_str = """ try: s3db.load_all_models() except NameError: print "s3db not defined" new_db = db """ exec new_str in d, locals()
default=True, help= "If True (the default), run task with all scheduled arg sets. If False, run with first set encountered only." ) args = vars(parser.parse_args()) app = args["app"] task = args["task"] allargs = args["allargs"] adir = os.path.join('applications', app) if not os.path.exists(adir): print >> sys.stderr, "Application not found: %s" % adir sys.exit(1) from gluon.custom_import import custom_import_install custom_import_install(os.environ['WEB2PY_PATH']) from gluon.shell import env _env = env(app, c=None, import_models=True) globals().update(**_env) # This is present in case this is a first run of the models. db.commit() from gluon import current # Get tasks from the scheduler_task table. if task: query = (db.scheduler_task.task_name == task) else: query = (db.scheduler_task.id > 0) scheduled_tasks = db(query).select(orderby=db.scheduler_task.task_name) # Pick up the associated function objects from the scheduler's task list.
default=True, help= "If True (the default), run task with all scheduled arg sets. If False, run with first set encountered only." ) args = vars(parser.parse_args()) app = args["app"] task = args["task"] allargs = args["allargs"] adir = os.path.join("applications", app) if not os.path.exists(adir): sys.stderr.write("Application not found: %s\n" % adir) sys.exit(1) from gluon.custom_import import custom_import_install custom_import_install() from gluon.shell import env _env = env(app, c=None, import_models=True) globals().update(**_env) # This is present in case this is a first run of the models. db.commit() from gluon import current # Get tasks from the scheduler_task table. if task: query = (db.scheduler_task.task_name == task) else: query = (db.scheduler_task.id > 0) scheduled_tasks = db(query).select(orderby=db.scheduler_task.task_name)