MobileBlur

update_web2py.py at [2ac904a27b]
Login

update_web2py.py at [2ac904a27b]

File scripts/update_web2py.py artifact 15d639cdcd part of check-in 2ac904a27b


#!/usr/bin/env python                                                        
# -*- coding: utf-8 -*-

"""
crontab -e
* 3 * * * root path/to/this/file 
"""

USER = 'www-data'
TMPFILENAME = 'web2py_src_update.zip'

import sys
import os
import urllib
import zipfile

if len(sys.argv)>1 and sys.argv[1] == 'nightly':
    version = 'http://web2py.com/examples/static/nightly/web2py_src.zip'
else:
    version = 'http://web2py.com/examples/static/web2py_src.zip'

realpath = os.path.realpath(__file__)
path = os.path.dirname(os.path.dirname(os.path.dirname(realpath)))
os.chdir(path)
try:
    old_version = open('web2py/VERSION','r').read().strip()
except IOError:
    old_version = ''
open(TMPFILENAME,'wb').write(urllib.urlopen(version).read())
new_version = zipfile.ZipFile(TMPFILENAME).read('web2py/VERSION').strip()
if new_version>old_version:
    os.system('sudo -u %s unzip -o %s' % (USER,TMPFILENAME))
    os.system('apachectl restart | apache2ctl restart')