Python return list && Mercurial push -r [branch_name]

这两个是今天的技术点。

Python

def f(x):
    try:
        return {
            'a': 1,
            'b': 2,
        }[x]
    except KeyError:
        return 'default'

Mercurial

如果 hg push 有下面错误的话

abort: push creates new remote head ac23df80aec6 on branch 'current_branch_name'!
(did you forget to merge? use push -f to force)

就这样指定推当前的分支

hg push -r current_branch_name

相关链接

Advertisements

How to deploy Django app to Heroku?

1. Install some packages

pip install psycopg2 dj-database-url gunicorn

2. Create requirements.txt

pip freeze > requirements.txt

3. Config settings([APP_NAME]/settings.py)

import os
PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'ribbit',                      # Or path to database file if using sqlite3.
        'USER': 'username',                      # Not used with sqlite3.
        'PASSWORD': 'password',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}

STATIC_ROOT = os.path.join(PROJECT_PATH, 'static')
STATIC_URL = '/static/'

TEMPLATE_DIRS = (
    os.path.join(PROJECT_PATH, 'templates')
)

import dj_database_url
DATABASES['default'] = dj_database_url.config()

4. Create Procfile

web: gunicorn [APP_NAME].wsgi

5. Add URLs([APP_NAME]/urls.py)

urlpatterns += patterns('django.contrib.staticfiles.views',
    url(r'^static/(?P.*)$', 'serve'),
)

6. Git commit

git commit -a -m 'Configured for Heroku'

7. Push to Heroku

git push heroku master

8. Apply the migrations to the Heroku database

heroku run python manage.py syncdb
heroku run python manage.py migrate ribbit_app

9. Enjoy it

heroku open

Links

Building Ribbit in Django

Django’s South Migration Error –fake

Migration実行

./manage.py syncdb --settings=settings.cho.local
./manage.py schemamigration delivery --auto --settings=settings.cho.local
./manage.py migrate delivery --settings=settings.cho.local

Running migrations for delivery:
 - Migrating forwards to 0112_auto__chg_field_purchase_userid.
 > delivery:0090_auto__add_unlimitedservice__chg_field_unlimitedreleaseitemdata_start_d
…
RuntimeError: Cannot reverse this migration. 'UnlimitedReleaseItemData.start_datetime' and its values cannot be restored.

解決方法

./manage.py migrate delivery --fake 0111 --settings=settings.cho.local
./manage.py migrate delivery 0112 --settings=settings.cho.local

Links

Mercurial在merge时冲突解决方法 && 给branch重命名方法

merge文件冲突时

hg resolve -m test.h

branch重命名

hg update stiging
hg branch staging
hg commit -m"Changing stiging branch to staging."
hg update stiging
hg commit --close-branch -m"This was a typo; use staging instead."
hg push --new-branch