def setup_test_env(): """Sets up App Engine/Django test environment.""" global _INITIALIZED if _INITIALIZED: raise Exception('Do not call test_env.setup_test_env() twice.') _INITIALIZED = True # For 'from components import ...' and 'from test_support import ...'. sys.path.insert(0, ROOT_DIR) sys.path.insert(0, os.path.join(ROOT_DIR, '..', 'third_party_local')) from tool_support import gae_sdk_utils gae_sdk_utils.setup_gae_env() gae_sdk_utils.setup_env(None, 'sample-app', 'v1a', None)
def setup_test_env(): """Sets up App Engine/Django test environment.""" global _INITIALIZED if _INITIALIZED: raise Exception('Do not call test_env.setup_test_env() twice.') _INITIALIZED = True # For 'from components import ...' and 'from test_support import ...'. sys.path.insert(0, ROOT_DIR) sys.path.insert(0, os.path.join(ROOT_DIR, '..', 'third_party_local')) from tool_support import gae_sdk_utils gae_sdk_utils.setup_gae_env() gae_sdk_utils.setup_env(None, 'sample-app', 'v1a', None)
def setup_test_env(app_id='sample-app'): """Sets up App Engine test environment.""" global _INITIALIZED if _INITIALIZED: raise Exception('Do not call test_env.setup_test_env() twice.') _INITIALIZED = True # For depot_tools. sys.path.insert( 0, os.path.join(ROOT_DIR, '..', '..', 'client', 'third_party')) # For 'from components import ...' and 'from test_support import ...'. sys.path.insert(0, ROOT_DIR) sys.path.insert(0, os.path.join(ROOT_DIR, '..', 'third_party_local')) from tool_support import gae_sdk_utils gae_sdk_utils.setup_gae_env() gae_sdk_utils.setup_env(None, app_id, 'v1a', None) from components import utils utils.fix_protobuf_package()
def CMDshell(parser, args): """Opens interactive remote shell with app's GAE environment. Connects to a specific version of a specific module (an active version of 'default' module by default). The app must have 'remote_api: on' builtin enabled in app.yaml. Always uses password based authentication. """ parser.allow_positional_args = True parser.add_option('-H', '--host', help='Only necessary if not hosted on .appspot.com') parser.add_option('--local', action='store_true', help='Operates locally on an empty dev instance') app, options, args = parser.parse_args(args) module = 'default' version = None if len(args) == 2: module, version = args elif len(args) == 1: module = args[0] elif args: parser.error('Unknown args: %s' % args) if module not in app.modules: parser.error('No such module: %s' % module) if not options.host and not options.local: prefixes = filter(None, (version, module, app.app_id)) options.host = '%s.appspot.com' % '-dot-'.join(prefixes) # Ensure remote_api is initialized and GAE sys.path is set. gae_sdk_utils.setup_env(app.app_dir, app.app_id, version, module, remote_api=True) if options.host: # Open the connection. from google.appengine.ext.remote_api import remote_api_stub try: print('Connecting...') remote_api_stub.ConfigureRemoteApi( None, '/_ah/remote_api', gae_sdk_utils.get_authentication_function(), options.host, save_cookies=True, secure=True) except urllib2.URLError: print >> sys.stderr, 'Failed to access %s' % options.host return 1 remote_api_stub.MaybeInvokeAuthentication() def register_sys_path(*path): abs_path = os.path.abspath(os.path.join(*path)) if os.path.isdir(abs_path) and not abs_path in sys.path: sys.path.insert(0, abs_path) # Simplify imports of app modules (with dependencies). This code is optimized # for layout of apps that use 'components'. register_sys_path(app.app_dir) register_sys_path(app.app_dir, 'third_party') register_sys_path(app.app_dir, 'components', 'third_party') # Import some common modules into interactive console namespace. def setup_context(): # pylint: disable=unused-variable from google.appengine.api import app_identity from google.appengine.api import memcache from google.appengine.api import urlfetch from google.appengine.ext import ndb return locals().copy() context = setup_context() # Fancy readline support. if readline is not None: readline.parse_and_bind('tab: complete') history_file = os.path.expanduser('~/.config/gae_tool/remote_api_%s' % app.app_id) if not os.path.exists(os.path.dirname(history_file)): os.makedirs(os.path.dirname(history_file)) atexit.register(lambda: readline.write_history_file(history_file)) if os.path.exists(history_file): readline.read_history_file(history_file) prompt = [ 'App Engine interactive console for "%s".' % app.app_id, 'Available symbols:', ] prompt.extend(sorted(' %s' % symbol for symbol in context)) code.interact('\n'.join(prompt), None, context) return 0
def CMDshell(parser, args): """Opens interactive remote shell with app's GAE environment. Connects to a specific version of a specific module (an active version of 'default' module by default). The app must have 'remote_api: on' builtin enabled in app.yaml. Always uses password based authentication. """ parser.allow_positional_args = True parser.add_option("-H", "--host", help="Only necessary if not hosted on .appspot.com") app, options, args = parser.parse_args(args) module = "default" version = None if len(args) == 2: module, version = args elif len(args) == 1: module = args[0] elif args: parser.error("Unknown args: %s" % args) if module not in app.modules: parser.error("No such module: %s" % module) if not options.host: prefixes = filter(None, (version, module, app.app_id)) options.host = "%s.appspot.com" % "-dot-".join(prefixes) # Ensure remote_api is initialized and GAE sys.path is set. gae_sdk_utils.setup_env(app.app_dir, app.app_id, version, module, remote_api=True) # Open the connection. from google.appengine.ext.remote_api import remote_api_stub try: print("Connecting...") remote_api_stub.ConfigureRemoteApi( None, "/_ah/remote_api", gae_sdk_utils.get_authentication_function(), options.host, save_cookies=True, secure=True, ) except urllib2.URLError: print >>sys.stderr, "Failed to access %s" % options.host return 1 remote_api_stub.MaybeInvokeAuthentication() def register_sys_path(*path): abs_path = os.path.abspath(os.path.join(*path)) if os.path.isdir(abs_path) and not abs_path in sys.path: sys.path.insert(0, abs_path) # Simplify imports of app modules (with dependencies). This code is optimized # for layout of apps that use 'components'. register_sys_path(app.app_dir) register_sys_path(app.app_dir, "third_party") register_sys_path(app.app_dir, "components", "third_party") # Import some common modules into interactive console namespace. def setup_context(): # pylint: disable=unused-variable from google.appengine.api import app_identity from google.appengine.api import memcache from google.appengine.api import urlfetch from google.appengine.ext import ndb return locals().copy() context = setup_context() # Fancy readline support. if readline is not None: readline.parse_and_bind("tab: complete") history_file = os.path.expanduser("~/.config/gae_tool/remote_api_%s" % app.app_id) if not os.path.exists(os.path.dirname(history_file)): os.makedirs(os.path.dirname(history_file)) atexit.register(lambda: readline.write_history_file(history_file)) if os.path.exists(history_file): readline.read_history_file(history_file) prompt = ['App Engine interactive console for "%s".' % app.app_id, "Available symbols:"] prompt.extend(sorted(" %s" % symbol for symbol in context)) code.interact("\n".join(prompt), None, context) return 0