把GAE的sa3album相簿從python2.5升級到2.7

我部落格上使用的相簿,叫做sa3album,是一款在Google App Engine上跑的相簿程式。

或許現在大家都不需要這些軟體,但我不喜歡用其他有的沒的部落格用的圖床,所以當初

選擇用這款GAE上的程式。最近GAE因為升級的關係,python2.5的應用程式通通都需要

強迫更新到2.7,否則將會被強制關閉。所以我要趕快趁有空的時候升級一下。

因為現在也沒啥人在用了,所以從2010年之後再也沒有被更新過。要如何更新到2.7。

我是看著google的教學與錯誤訊息來找。有興趣可以看看

https://developers.google.com/appengine/docs/python/python25/migrate27

這邊就直接說原本的代碼需要修改那些地方。

1・app.yaml上需要修改以下項目

...

runtime: python27
threadsafe: true
derived_file_type:
- python_precompiled
builtins:
- remote_api: on
- appstats: on
- deferred: on
libraries:
- name: django
  version: "1.9"

...

- url: /_ah/remote_api(/.*)?
  script: google.appengine.ext.remote_api.handler.application
  login: admin

...

2・app.yaml上所有script的地方,把xxx.py改成xxx.app

...

- url: /api/.*
  script: api.app

...

3・admin.py api.py main.py 除掉main(),並改用webapp2
這三個檔案的最上方的

from google.appengine.ext import webapp
from google.appengine.ext.webapp import template

改為

import webapp2

然後最下方的

def main():
    application = webapp2.WSGIApplication ([
        ......
    ],debug=settings.DEBUG)
    util.run_wsgi_app(application)

if __name__=='__main__':
    main()

改成

app = webapp2.WSGIApplication ([
    ......
    ],debug=settings.DEBUG)

4・所有python檔案中有

from django.utils import json as simplejson 

的地方通通改成

import json as simplejson

5・unit/handler.py 中的 webapp 保留,但追加 import webapp2,並把代碼中有

webapp.RequestHandler

的地方換成

webapp2.RequestHandler

6・admin.py中的 ImageUploadHandler()方法中的傳遞參數 album-select 改為 album_select

7・themes/admin/upload.html 第12行中的

ifequal album.slug album-select

改為

ifequal album.slug album_select

8・更新GAE上的程式就大功告成:)