当前位置:首页 > 网站制作 > 正文内容

Google App Engine 文件代码备份

admin15年前 (2009-10-19)网站制作256

Google App Engine 不支持直接下载代码文件,所以我们无法直接将服务器上的代码进行备份。如果本地的代码一旦丢失,就很难找回,这点对GAE的用户来说,是相当麻烦的。

好在有人编写了一个工具,用于将GAE站点的代码打包成zip格式并下载

步骤如下:

1.在根目录下根据manatlan的代码建立zipme.py

2.在app.yaml中加入

- url: /zipme
script: zipme.py3.访问youapp.appspot.com/zipme

zipme.py脚本

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
##########################################################################
ZipMe : GAE Content Downloader
##########################################################################
Just add this lines in your app.yaml :

- url: /zipme
script: zipme.py

##########################################################################
""" # manatlan

from google.appengine.ext import webapp
from google.appengine.api import users

import wsgiref.handlers
import zipfile
import os,re,sys,stat
from cStringIO import StringIO

def createZip(path):

def walktree (top = ".", depthfirst = True):
names = os.listdir(top)
if not depthfirst:
yield top, names
for name in names:
try:
st = os.lstat(os.path.join(top, name))
except os.error:
continue
if stat.S_ISDIR(st.st_mode):
for (newtop, children) in walktree (os.path.join(top, name),
depthfirst):
yield newtop, children
if depthfirst:
yield top, names

list=[]
for (basepath, children) in walktree(path,False):
for child in children:
f=os.path.join(basepath,child)
if os.path.isfile(f):
f = f.encode(sys.getfilesystemencoding())
list.append( f )

f=StringIO()
file = zipfile.ZipFile(f, "w")
for fname in list:
nfname=os.path.join(os.path.basename(path),fname[len(path)+1:])
file.write(fname, nfname , zipfile.ZIP_DEFLATED)
file.close()

f.seek(0)
return f


class ZipMaker(webapp.RequestHandler):
def get(self):
if users.is_current_user_admin():
folder = os.path.dirname(__file__)
self.response.headers['Content-Type'] = 'application/zip'
self.response.headers['Content-Disposition'] = \
'attachment; filename="%s.zip"' % os.path.basename(folder)
fid=createZip(folder)
while True:
buf=fid.read(2048)
if buf=="": break
self.response.out.write(buf)
fid.close()
else:
self.response.headers['Content-Type'] = 'text/html'
self.response.out.write("<a href=\"%s\">You must be admin</a>." %
users.create_login_url("/zipme"))

def main():
application = webapp.WSGIApplication(
[('/zipme', ZipMaker)],
debug=False)
wsgiref.handlers.CGIHandler().run(application)

if __name__ == "__main__":
main()
这段代码会通过google的身份认证来判断访问者是否可以下载代码,所以不用担心代码泄漏。不过还是希望Google可以提供代码备份和数据库备份的功能。
 

扫描二维码推送至手机访问。

版权声明:本文由博赚恋吧资源站发布,如需转载请注明出处。

本文链接:https://432l.com/post/1511.html

分享给朋友:

相关文章

[网站推广|网赚|技巧]--10个针对博客的搜索引擎提交地址

1. Google博客搜索提交: http://blogsearch.google.com/ping?hl=zh-CNGoogle网站提交: http://www.google.com/intl/zh-CN/add_url.html2. 百度博客搜索提交:http://utility.baidu.com/blogsearch/submit.phpbaidu网站提交: http://www.baid...

网站提交入口及网站优化工具

 以下是可以快速提交到中文各大搜索引擎的工具:http://db.sohu.com/regurl/regform.asphttp://www.yisou.com/search_submit.htmlhttp://www.google.com/intl/zh-CN/add_url.htmlhttp://service.chinasearch.com.cn/NetSearch/user_re...

恋吧偶见—FeedJIT:可实时显示访问者来源的Blog Widget

FeedJIT提供的是一个可实时显示访问者来源Blog Widget 服务,与变通的Widget一样,只需在Blog模版中插入一段JS代码就能安装完成。在FeedJIT Widget中可实时显示出访问者从哪里进入到你的Blog,并查看了哪个页面,来自哪个国家及地理位置等信息,功能虽然简单,但还挺实用。效果如右:进入:http://feedjit.com/join/...

恋吧谈web2.0—SocialGo,创建你的社会化网络

现在貌似SNS挺火的,好多Blog都在讨论SNS,SNS网站也是做的很火热,从Facebook,Myspace,到国内蜂拥而来的数都数不过来的SNS网站们,开心网依靠SNS加上几个小游戏捕获N多白领的心,还有康盛创想的Ucenter让你自己轻松也能搞个SNS网站。貌似不搞点SNS就有点落伍了,今天站长时髦一点,来介绍一个可以自己创建SNS网站的服务SocialGo是一个提供创建社会化网络服务的网站...

Spottt—一个很好的免费链接互换提高流量服务

如果你也是经营网站部落格的站长,一定听过“流量就是金钱” ,如何让网站拥有更多的访客就显得相当重要。除了提供最优质的服务功能,不断更新网站内容外,透过交换连结的方式也可以让网站能见度提升不少。 Spottt目前的交换赚取/付出比例为3点04分。 当一位访客进入你的网站,你可以获取3个点数; 而让你的连结显示在其他网站,则必须付出4个点数。 Spottt提供免费的连结交换服务,只要在注册后将原始码放...

恋吧发现并推荐一个华丽的Blog Widgets服务—Wowzio

首先输入你的 Blog Feed 地址,Wowzio 就会自动从 Blog 文章中提取出文字、图片,生成 6 种效果华丽的 Widgets 供你选择。并且 Widgets 的颜色和尺寸都是可以自定义的,这可以让 Widgets 和 Blog 的风格趋于一致。这 6 种Widgets 分别是(点击链接可查看具体效果)——Panoramic Slideshow、SlideShow、Photo Gall...

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。