Home » snippets

GAE 使用的 jinja2 2.6x 版本的 filesizeformat 过滤器有 bug,2.7版本中已经修复,所以暂时只能自定义过滤器。

def do_filesizeformat(value, binary=False):
    """Format the value like a 'human-readable' file size (i.e. 13 kB,
    4.1 MB, 102 Bytes, etc).  Per default decimal prefixes are used (Mega,
    Giga, etc.), if the second parameter is set to `True` the binary
    prefixes are used (Mebi, Gibi).
    """
    bytes = float(len(value))
    base = binary and 1024 or 1000
    prefixes = [
        (binary and 'KiB' or 'kB'),
        (binary and 'MiB' or 'MB'),
        (binary and 'GiB' or 'GB'),
        (binary and 'TiB' or 'TB'),
        (binary and 'PiB' or 'PB'),
        (binary and 'EiB' or 'EB'),
        (binary and 'ZiB' or 'ZB'),
        (binary and 'YiB' or 'YB')
    ]
    if bytes == 1:
        return '1 Byte'
    elif bytes < base:
        return '%d Bytes' % bytes
    else:
        for i, prefix in enumerate(prefixes):
            unit = base ** (i + 2)
            if bytes < unit:
                return '%.1f %s' % ((base * bytes / unit), prefix)
        return '%.1f %s' % ((base * bytes / unit), prefix)

Google Appengine 通过 SDK 上传要用到代理,直接写成批处理命令,不用每次输入代理地址了。

@echo off 
rem "关闭自动输出"

rem "接收输入"

set input=
set /p input=The proxy port:

rem "输出得到的输入信息"

echo Set the proxy port:%input%
echo Set the the http proxy...
set http_proxy=http://127.0.0.1:%input%
echo http_proxy=http://127.0.0.1:%input%

echo Set the the https proxy...
set https_proxy=http://127.0.0.1:%input%
echo https_proxy=http://127.0.0.1:%input%

:begin

echo.
set /p input1=Which folder do you want to upload:
appcfg.py update ..\codes\%input1% --noauth_local_webserver

rem pause>null

echo.

rem "从begin标签处,再次运行"

goto begin