2012-11-02 12:41:41 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
from os.path import join, exists
|
|
|
|
|
|
|
|
def run(*cmd):
|
|
|
|
p = subprocess.Popen(cmd)
|
|
|
|
p.wait()
|
|
|
|
return p.returncode
|
|
|
|
|
|
|
|
def get(*cmd):
|
|
|
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
stdout, error = p.communicate()
|
|
|
|
return stdout
|
|
|
|
|
|
|
|
repos = {
|
|
|
|
"pandora": "http://code.0x2620.org/pandora/",
|
|
|
|
"oxjs": "http://code.0x2620.org/oxjs/",
|
|
|
|
"python-ox": "http://code.0x2620.org/python-ox/",
|
|
|
|
"oxtimelines": "http://code.0x2620.org/oxtimelines/",
|
|
|
|
}
|
|
|
|
|
2013-03-01 07:09:44 +00:00
|
|
|
def reload_notice(base):
|
|
|
|
print '\nYou might need to restart pandora to finish the update:\n\t"sudo %s/reload.sh"\n' % base
|
2012-11-02 12:41:41 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
base = os.path.normpath(os.path.abspath(os.path.dirname(__file__)))
|
|
|
|
if len(sys.argv) == 2 and sys.argv[1] == 'database':
|
|
|
|
os.chdir(join(base, 'pandora'))
|
|
|
|
if get('./manage.py', 'south_installed').strip() == 'yes':
|
|
|
|
run('./manage.py', 'syncdb')
|
2013-03-01 06:50:09 +00:00
|
|
|
print '\nRunning "./manage.py migrate"\n'
|
2012-11-02 12:41:41 +00:00
|
|
|
run('./manage.py', 'migrate')
|
|
|
|
run('./manage.py', 'sync_itemsort')
|
2013-03-01 07:09:44 +00:00
|
|
|
reload_notice(base)
|
2012-11-02 12:41:41 +00:00
|
|
|
else:
|
|
|
|
print "You are upgrading from an older version of pan.do/ra."
|
|
|
|
print "Please use ./manage.py sqldiff -a to check for updates"
|
2012-12-10 17:46:10 +00:00
|
|
|
print "and apply required changes. You might have to set defaults too."
|
2012-12-11 14:52:25 +00:00
|
|
|
print "Once done run:"
|
|
|
|
print "\tcd %s" % os.path.abspath(os.curdir)
|
|
|
|
print "\t./manage.py migrate --all --fake"
|
2012-11-02 12:41:41 +00:00
|
|
|
print "Check http://wiki.0x2620.org/wiki/pandora/DatabaseUpdate for more information"
|
|
|
|
else:
|
|
|
|
os.chdir(base)
|
|
|
|
current = get('bzr', 'revno')
|
|
|
|
run('bzr', 'pull', repos['pandora'])
|
|
|
|
new = get('bzr', 'revno')
|
|
|
|
|
|
|
|
if exists(join(base, 'static', 'oxjs')):
|
|
|
|
os.chdir(join(base, 'static', 'oxjs'))
|
|
|
|
current += get('bzr', 'revno')
|
|
|
|
run('bzr', 'pull', repos['oxjs'])
|
|
|
|
new += get('bzr', 'revno')
|
|
|
|
else:
|
|
|
|
os.chdir(join(base, 'static'))
|
|
|
|
run('bzr', 'branch', repos['oxjs'])
|
|
|
|
new += '+'
|
|
|
|
|
|
|
|
if exists(join(base, 'src', 'python-ox')):
|
|
|
|
os.chdir(join(base, 'src', 'python-ox'))
|
|
|
|
current += get('bzr', 'revno')
|
|
|
|
run('bzr', 'pull', repos['python-ox'])
|
|
|
|
new += get('bzr', 'revno')
|
|
|
|
|
2012-11-16 01:41:48 +00:00
|
|
|
if exists(join(base, 'src', 'oxtimelines')):
|
|
|
|
os.chdir(join(base, 'src', 'oxtimelines'))
|
2012-11-02 12:41:41 +00:00
|
|
|
current += get('bzr', 'revno')
|
2012-11-16 01:41:48 +00:00
|
|
|
run('bzr', 'pull', repos['oxtimelines'])
|
2012-11-02 12:41:41 +00:00
|
|
|
new += get('bzr', 'revno')
|
2012-11-14 17:52:26 +00:00
|
|
|
else:
|
|
|
|
print "oxtimelines is missing. please run:\n\n\tcd %s\n\tpip -E . install -r requirements.txt\n" % (base)
|
2012-11-02 12:41:41 +00:00
|
|
|
os.chdir(join(base, 'pandora'))
|
|
|
|
if current != new:
|
|
|
|
run('./manage.py', 'update_static')
|
|
|
|
run('./manage.py', 'compile_pyc')
|
|
|
|
diff = get('./manage.py', 'sqldiff', '-a').strip()
|
|
|
|
if diff != '-- No differences':
|
2012-12-10 17:46:10 +00:00
|
|
|
print 'Database has changed, please make a backup and run ./update.py database'
|
2013-03-01 07:09:44 +00:00
|
|
|
else:
|
|
|
|
reload_notice(base)
|