2012年10月26日 星期五

Force write temporary file to disk while uploading in django

vim setting.py
FILE_UPLOAD_MAX_MEMORY_SIZE=0
FILE_UPLOAD_TEMP_DIR=/tmp
FILE_UPLOAD_PERMISSIONS=0644
If you do not want to use memory for cache, just set the FILE_UPLOAD_MAX_MEMORY_SIZE to 0. And all file will be uploaded with a temporary file.

Disable file upload limitation in apache

vim /etc/httpd/conf/httpd.conf
LimitRequestBody 0

If you does not have this setting, it will set to 2G as default.

Create a usb key with grub multiboot from iso files

Create a bootable usb key:
Use fdisk to partition usb key and toggle bootable.
fdisk ${usb_key_device}
d => delete partition
n => create partition
a => toggle bootable flag
w => write change to device

Format file system to fat32
mkfs.vfat -F 32 -n ${usb_key_label} ${usb_key_device}

Mount usb key
mkdir -p ${abs_mount_point}
mount ${usb_key_device} ${abs_mount_point}

Install grub to usb key
grub-install --force --no-floppy --root-directory=${abs_mount_point} --boot-directory=${abs_mount_point} ${usb_key_device}

Edit grub configuration
vim ${abs_mount_point}/grub/grub.cfg
set default=0
set timeout=10

function mount_iso {
    loopback loop ${1}
}

menuentry "Tinycore ISO" {
    set src=/tinycore.iso
    mount_iso ${src}
    linux (loop)/boot/vmlinuz base superuser quiet waitusb=5
    initrd (loop)/boot/core.gz
}

menuentry "Ubuntu 12.04.1 i386" {
    set src=/ubuntu-12.04.1-dvd-i386.iso
    mount_iso ${src}
    linux (loop)/casper/vmlinuz boot=casper file=/cdrom/preseed/ubuntu.seed iso-scan/filename=${src} only-ubiquity quiet splash --
    initrd (loop)/casper/initrd.lz
}

menuentry "Ubuntu 12.04.1 amd64" {
    set src=/ubuntu-12.04.1-dvd-amd64.iso
    mount_iso ${src}
    linux (loop)/casper/vmlinuz boot=casper file=/cdrom/preseed/ubuntu.seed iso-scan/filename=${src} only-ubiquity quiet splash --
    initrd (loop)/casper/initrd.lz
}
menuentry "Ubuntu 12.10 Desktop i386" {
    set src=/ubuntu-12.10-desktop-i386.iso
    mount_iso ${src}
    linux (loop)/casper/vmlinuz boot=casper file=/cdrom/preseed/ubuntu.seed iso-scan/filename=${src} only-ubiquity quiet splash --
    initrd (loop)/casper/initrd.lz
}

menuentry "Ubuntu 12.10 Desktop amd64" {
    set src=/ubuntu-12.10-desktop-amd64.iso
    mount_iso ${src}
    linux (loop)/casper/vmlinuz boot=casper file=/cdrom/preseed/ubuntu.seed iso-scan/filename=${src} only-ubiquity quiet splash --
    initrd (loop)/casper/initrd.lz
}

menuentry "Ubuntu 12.10 Server i386" {
    set src=/ubuntu-12.10-server-i386.iso
    mount_iso ${src}
    linux (loop)/casper/vmlinuz boot=casper file=/cdrom/preseed/ubuntu.seed iso-scan/filename=${src} only-ubiquity quiet splash --
    initrd (loop)/casper/initrd.lz
}

menuentry "Ubuntu 12.10 Server amd64" {
    set src=/ubuntu-12.10-server-amd64.iso
    mount_iso ${src}
    linux (loop)/casper/vmlinuz boot=casper file=/cdrom/preseed/ubuntu.seed iso-scan/filename=${src} only-ubiquity quiet splash --
    initrd (loop)/casper/initrd.lz
}

SQLAlchemy disconnect from database immediately

from sqlalchemy import *

session = Session(bind = Engine("postgres://username:password@server:port/database"))
session.close()
session.bind.dispose()

Use dispose will disconnect from database immediately