Good design is design that changes behavior for the better.

Managing files for GAE with Git and Dropbox

At last, I started to use git to manage files that are hosting on GAE. For backup and remote access, I use Dropbox for the git repository. Here is the memo.

Resources

Steps

Actually what I did is just setting up Git in Dropbox directory. By default, GAE ignores unix hidden files whose names begin with dot from the deployment. I don’t need to care about files in the directory where GAE local server is referring to.

  1. Download Dropbox and launch it. (Create account if you don’t have the one.)
  2. Install Git. If you use Mac, you can install it with MacPorts

    $ sudo port install git-core
    
  3. Create a bare repository in Dropbox directory

    $ cd ~/Dropbox
    $ mkdir repo
    $ cd repo
    $ mkdir project_name.git
    $ cd project_name.git
    $ git --bare init
    
  4. Go to the directory that contains source files, and then push the files to the git repository

    $ cd ~/project_name
    $ git init
    $ git add .
    $ git commit -m "initial commit"
    $ git push ~/Dropbox/repo/project_name.git master
    $ git remote add origin ~/Dropbox/repo/project_name.git
    

Markdown Wiki (3) Memcache

  1. ユーザーサービス
  2. データストア
  3. Memcache

Memcache

今回勉強がてらにやってみたことの最後は Memcache。

デモサイトでは、常に右側のメニューにページ一覧が出ているので、そのリストを取得する時に cache を利用。以下、コードの抜粋。

from django.utils import simplejson
from google.appengine.ext import db
from google.appengine.api import memcache
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class PageList(webapp.RequestHandler):
    def get(self):
        permission = Permission()
        data       = []

        if permission.get():
            pagelist = memcache.get("pagelist")

            if pagelist is not None:
                data = pagelist
            else:
                query = WikiPage.all()
                query.order("title")

                for record in query:
                    data.append({"keyname":record.key().name(), "title": record.title })

                memcache.add("pagelist", data, 3600)

        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write(simplejson.dumps(data))

呼び出す側の JavaScript は、単に GET してるだけ。

var Connect = YAHOO.util.Connect;

var oCallback = {
    success: _create
};
Connect.asyncRequest("GET", "/wiki/list", oCallback);

デモページは Gmail のアカウントがあれば誰でも使えるが、データは 1 日に 1 回リセットされる。

Page 1 of 56