谷歌应用引擎本地(开发)IPython Shell
在我本地的Google app engine开发环境中,我希望使用ipython外壳,尤其是能够使用通过谷歌应用引擎本地(开发)IPython Shell,python,google-app-engine,ipython,Python,Google App Engine,Ipython,在我本地的Google app engine开发环境中,我希望使用ipython外壳,尤其是能够使用通过dev_server.py创建的数据检查模型, 非常像django的manage.py shell命令的工作方式 (这意味着应在修复sys.path并读取和分析app.yaml以及本地数据存储就绪后启动ipython外壳) 任何简单的解决方案?对于初学者,您可以将应用程序根目录和SDK根目录(google\u appengine)放在Python路径中。您还需要安装一些库,如yaml,或者从S
dev_server.py
创建的数据检查模型,
非常像django的manage.py shell
命令的工作方式
(这意味着应在修复sys.path
并读取和分析app.yaml
以及本地数据存储就绪后启动ipython外壳)
任何简单的解决方案?对于初学者,您可以将应用程序根目录和SDK根目录(
google\u appengine
)放在Python路径中。您还需要安装一些库,如yaml
,或者从SDK的lib
目录添加到库路径。然后您可以导入模块并调用一些功能
>>> import sys
>>> sys.path.append('/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine')
当然,只要代码路径尝试进行服务调用,库就会引发异常,表示它不绑定任何内容。要将服务库绑定到测试存根,请使用testbed库:
>>> from google.appengine.ext import testbed
>>> tb = testbed.Testbed()
>>> tb.activate()
>>> tb.init_datastore_v3_stub()
>>> from google.appengine.ext import db
>>> import models
>>> m = models.Entry()
>>> m.title = ‘Test’
>>> m.put()
要告诉数据存储测试存根使用开发服务器的数据存储文件,请将文件路径作为datastore\u file
参数传递到init\u datastore\u v3\u stub()
。有关更多信息,请参见google.appengine.ext.testbed
中的方法文档注释
有关测试床的更多信息:基本上,您需要使用: 对于IPython支持,您有两个选项: (1) 如果您使用的是Python 2.7(和IPython 0.13),那么您需要使用它来嵌入IPython shell:
from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell
shell = TerminalInteractiveShell(user_ns=namespace)
shell.mainloop()
from IPython.Shell import IPShellEmbed
ipshell = IPShellEmbed(user_ns=namespace, banner=banner)
ipshell()
(2) 如果您使用的是Python 2.5(和IPython 0.10.2),则需要使用此行来嵌入IPython shell:
from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell
shell = TerminalInteractiveShell(user_ns=namespace)
shell.mainloop()
from IPython.Shell import IPShellEmbed
ipshell = IPShellEmbed(user_ns=namespace, banner=banner)
ipshell()
这是我用的:所以你只需键入
>> python console.py your-app-id
一旦运行了dev_appserver.py 你会得到
starting module "default" running at: http://127.0.0.1:8080
Starting admin server at : http://localhost:8000
因此,基本上你要做的是访问,在那里你会发现“交互式控制台”,你可以用它来玩这是我在干净环境中测试时使用的。我正在寻找一些简单的方法,比如执行
gae_shell
,用“当前”本地数据存储启动本地shell。我所描述的内容似乎可以很容易地用IPython编写脚本,包括将数据存储文件传递给存根初始值设定项。你需要它做更多吗?这似乎是一个好的开始: