如何从命令行访问 Google App Engine 的开发服务器数据
我定期在本地下载 Google App Engine 生产数据(使用基本上调用 appcfg.py download_data
的自定义脚本)并将其上传到开发服务器,以便我的开发环境中的数据与生产相匹配。您可以在 Launchpad 上找到脚本:
这就是启动器脚本的作用:
- 启动开发服务器(刷新数据库)
- 将之前下载的模型加载到本地数据库
- 更改所有正常和管理员的密码用户,这样我们就可以在开发环境中使用密码“toto”登录任何用户。这是通过 脚本完成的直接访问新加载的数据存储数据。
在 GAE 1.5.2 之前一切都工作正常。此时,开发服务器更改为前缀 dev~
,因此我添加了 --default_partition=''
来启动开发服务器。然而现在密码更改脚本似乎无法访问加载的数据,它总是为普通或管理员用户返回 0 实体。我想知道如何从命令行访问数据,因此明确不是从 url 访问数据,以防止这种情况在生产服务器上发生。 ./extra
中的脚本不会上传到 GAE,因此无法从那里执行。
脚本过去所做的事情(并且一直工作到 GAE <= 1.5.1):
args, option_dict = ParseArguments(['', colCasaBasePath])
config, matcher = LoadAppConfig(colCasaBasePath, {})
SetupStubs(config.application, **option_dict)
可以正常访问应用程序的模型:
from src.models import WebUser, ScyllaUser
for tipo in (WebUser, ScyllaUser):
usuarios = tipo.all()
# Now len(usuarios) == 0
为了给您一个想法(但请查看脚本以了解更多上下文),这就是 是否已更改(在 GAE 1.5.1 之后)会破坏我的 GAE 数据访问脚本?您将如何执行这样的工作流程?
I regularly download my Google App Engine production data locally (using a custom script that basically calls appcfg.py download_data
) and upload it to the development server so that the data in my development environment matches production. You can find the scripts on Launchpad:
- Download script (called with
./extra/manipular-datos.py --download
) - Launcher script (called with
./extra/launcher.py
)
This is what the launcher script does:
- Start the dev server (flushing the database)
- Load the previously downloaded models to the local database
- Change the passwords of all normal and admin users so that we can log in with a password of "toto" for any user in the development environment. This is done with a script that accesses the freshly-loaded datastore data directly.
Everything was working fine until GAE 1.5.2. At that point the development server changed to prefix dev~
, so I added --default_partition=''
to launch the dev server. However now the password-changing script seems to not access the loaded data, it always returns 0 entities for normal or admin users. I'm wondering how to access the data from the command line, so explicitely not from an url to prevent this from ever happening on the production server. The scripts in ./extra
are not uploaded to GAE, they can thus not be executed from there.
To give you an idea (but look at the script for more context), this is what the script used to do (and was working until GAE <= 1.5.1):
args, option_dict = ParseArguments(['', colCasaBasePath])
config, matcher = LoadAppConfig(colCasaBasePath, {})
SetupStubs(config.application, **option_dict)
The the application's models can be accessed just normally:
from src.models import WebUser, ScyllaUser
for tipo in (WebUser, ScyllaUser):
usuarios = tipo.all()
# Now len(usuarios) == 0
What has been changed (after GAE 1.5.1) that breaks my GAE data-accessing script? How would you perform such a workflow?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
诀窍是将
--default_partition=
参数添加到访问 GAE 数据的脚本中的ParseArguments()
调用中:请注意,
后面没有任何内容=
,这就是让我失望的原因。我首先尝试添加"--default_partition=''"
,但这没有任何效果(但也没有导致错误)。添加该调用后,脚本再次能够循环访问开发数据存储中已加载的所有用户。您可以在 Launchpad 上看到我必须进行的更改。
The trick is to add the
--default_partition=
argument to theParseArguments()
call in the script that accesses the GAE data:Note that there is nothing after the
=
, that's what put me off. I first tried adding"--default_partition=''"
, but that didn't have any effect (but also didn't result in errors).After adding that call the script is again able to loop over all the users that have been loaded in the dev datastore. You can see the changes I had to make on Launchpad.