2012-11-02 12:41:41 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
import os
|
2013-03-02 05:27:52 +00:00
|
|
|
|
2014-12-01 16:43:22 +00:00
|
|
|
base = os.path.normpath(os.path.abspath(os.path.dirname(__file__)))
|
|
|
|
os.chdir(base)
|
2013-03-02 05:27:52 +00:00
|
|
|
|
|
|
|
#using virtualenv's activate_this.py to reorder sys.path
|
2014-12-01 16:43:22 +00:00
|
|
|
activate_this = os.path.join(base, 'bin', 'activate_this.py')
|
2013-03-02 05:27:52 +00:00
|
|
|
if os.path.exists(activate_this):
|
|
|
|
execfile(activate_this, dict(__file__=activate_this))
|
|
|
|
|
2012-11-02 12:41:41 +00:00
|
|
|
import sys
|
|
|
|
import subprocess
|
2014-10-05 20:10:36 +00:00
|
|
|
import urllib2
|
2013-04-18 11:12:42 +00:00
|
|
|
import json
|
2012-11-02 12:41:41 +00:00
|
|
|
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
|
|
|
|
|
2014-10-05 20:10:36 +00:00
|
|
|
def get_json(url):
|
|
|
|
return json.loads(urllib2.urlopen(url).read())
|
|
|
|
|
2013-04-18 11:12:42 +00:00
|
|
|
def get_release():
|
|
|
|
try:
|
2014-10-05 20:10:36 +00:00
|
|
|
return get_json('https://pan.do/json/release.json')
|
2013-04-18 11:12:42 +00:00
|
|
|
except:
|
|
|
|
print "failed to load https://pan.do/ra, check your internet connection"
|
|
|
|
sys.exit(1)
|
|
|
|
|
2012-11-02 12:41:41 +00:00
|
|
|
repos = {
|
2013-04-18 11:12:42 +00:00
|
|
|
"pandora": {
|
|
|
|
"url": "http://code.0x2620.org/pandora/",
|
|
|
|
"path": ".",
|
|
|
|
},
|
|
|
|
"oxjs": {
|
|
|
|
"url": "http://code.0x2620.org/oxjs/",
|
|
|
|
"path": "./static/oxjs",
|
|
|
|
},
|
|
|
|
"oxtimelines": {
|
|
|
|
"url": "http://code.0x2620.org/oxtimelines/",
|
|
|
|
"path": "./src/oxtimelines",
|
|
|
|
},
|
|
|
|
"python-ox": {
|
|
|
|
"url": "http://code.0x2620.org/python-ox/",
|
|
|
|
"path": "./src/python-ox",
|
|
|
|
}
|
2012-11-02 12:41:41 +00:00
|
|
|
}
|
|
|
|
|
2013-03-01 07:09:44 +00:00
|
|
|
def reload_notice(base):
|
2014-10-12 15:10:33 +00:00
|
|
|
print '\nPlease restart pan.do/ra to finish the update:\n\t"sudo %s/ctl reload"\n' % base
|
2012-11-02 12:41:41 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2013-04-30 17:17:48 +00:00
|
|
|
if len(sys.argv) == 2 and sys.argv[1] in ('database', 'db'):
|
2012-11-02 12:41:41 +00:00
|
|
|
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')
|
2014-09-30 13:27:37 +00:00
|
|
|
run('./manage.py', 'sqlfindindex')
|
2012-11-02 12:41:41 +00:00
|
|
|
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"
|
2013-05-29 12:41:13 +00:00
|
|
|
elif len(sys.argv) == 2 and sys.argv[1] == 'static':
|
|
|
|
os.chdir(join(base, 'pandora'))
|
|
|
|
run('./manage.py', 'update_static')
|
2013-05-30 11:17:48 +00:00
|
|
|
elif len(sys.argv) == 4 and sys.argv[1] == 'postupdate':
|
|
|
|
os.chdir(base)
|
|
|
|
old = int(sys.argv[2])
|
|
|
|
new = int(sys.argv[3])
|
|
|
|
if old < 3111:
|
2013-05-30 11:18:48 +00:00
|
|
|
run('bzr', 'resolved', 'pandora/monkey_patch', 'pandora/monkey_patch/migrations')
|
2013-05-30 11:17:48 +00:00
|
|
|
if os.path.exists('pandora/monkey_patch'):
|
|
|
|
run('rm', '-r', 'pandora/monkey_patch')
|
2013-08-03 08:47:58 +00:00
|
|
|
if old < 3448:
|
|
|
|
if os.path.exists('static/pandora'):
|
|
|
|
run('bzr', 'resolved', 'static/pandora')
|
2013-09-19 12:01:40 +00:00
|
|
|
if old < 3651:
|
|
|
|
if os.path.exists('src/django/.git'):
|
|
|
|
os.chdir(os.path.join(base, 'src/django'))
|
|
|
|
run('git', 'checkout', 'stable/1.4.x')
|
|
|
|
run('git', 'pull')
|
|
|
|
os.chdir(base)
|
2013-09-29 13:00:06 +00:00
|
|
|
if old < 3666:
|
|
|
|
run('./bin/pip', 'install', '-r', 'requirements.txt')
|
2013-12-31 09:22:47 +00:00
|
|
|
if old < 3770:
|
|
|
|
run('./bin/pip', 'install', '-r', 'requirements.txt')
|
2014-10-05 19:23:03 +00:00
|
|
|
if old < 4379:
|
|
|
|
run('./bin/pip', 'install', '-r', 'requirements.txt')
|
2014-11-26 20:03:27 +00:00
|
|
|
if old < 4549:
|
|
|
|
import pandora.settings
|
|
|
|
with open('pandora/local_settings.py', 'r') as f:
|
|
|
|
local_settings = f.read()
|
|
|
|
if not 'BROKER_URL' in local_settings:
|
|
|
|
broker_url = 'amqp://%s:%s@%s:%s/%s' % (
|
|
|
|
getattr(pandora.settings, 'BROKER_USER', 'pandora'),
|
|
|
|
getattr(pandora.settings, 'BROKER_PASSWORD', 'box'),
|
|
|
|
getattr(pandora.settings, 'BROKER_HOST', '127.0.0.1'),
|
|
|
|
getattr(pandora.settings, 'BROKER_PORT', 5672),
|
|
|
|
getattr(pandora.settings, 'BROKER_VHOST', '/pandora'),
|
|
|
|
)
|
|
|
|
local_settings = [
|
|
|
|
l for l in local_settings.split('\n') if not l.startswith('BROKER_')
|
|
|
|
] + [
|
|
|
|
'BROKER_URL = "%s"' % broker_url, ''
|
|
|
|
]
|
|
|
|
with open('pandora/local_settings.py', 'w') as f:
|
|
|
|
f.write('\n'.join(local_settings))
|
2012-11-02 12:41:41 +00:00
|
|
|
else:
|
|
|
|
|
2013-04-18 11:12:42 +00:00
|
|
|
if len(sys.argv) == 1:
|
|
|
|
release = get_release()
|
2013-04-18 13:32:28 +00:00
|
|
|
repos = release['repositories']
|
2013-04-18 11:12:42 +00:00
|
|
|
development = False
|
2012-11-14 17:52:26 +00:00
|
|
|
else:
|
2013-04-18 11:12:42 +00:00
|
|
|
release = {
|
|
|
|
'date': 'development'
|
|
|
|
}
|
|
|
|
development = True
|
|
|
|
os.chdir(base)
|
|
|
|
current = ''
|
|
|
|
new = ''
|
2013-07-03 21:14:11 +00:00
|
|
|
for repo in sorted(repos, key=lambda r: repos[r]['path']):
|
2013-04-18 11:12:42 +00:00
|
|
|
path = os.path.join(base, repos[repo]['path'])
|
|
|
|
if exists(path):
|
|
|
|
os.chdir(path)
|
|
|
|
revno = get('bzr', 'revno')
|
2013-05-30 11:17:48 +00:00
|
|
|
if repo == 'pandora':
|
|
|
|
pandora_old_revno = revno
|
2013-04-18 11:12:42 +00:00
|
|
|
current += revno
|
|
|
|
url = repos[repo]['url']
|
|
|
|
if 'revision' in repos[repo]:
|
|
|
|
if int(revno) < repos[repo]['revision']:
|
|
|
|
run('bzr', 'pull', url, '-r', '%s' % repos[repo]['revision'])
|
|
|
|
else:
|
|
|
|
run('bzr', 'pull', url)
|
|
|
|
revno = get('bzr', 'revno')
|
|
|
|
new += revno
|
2013-05-30 11:17:48 +00:00
|
|
|
if repo == 'pandora':
|
|
|
|
pandora_new_revno = revno
|
2013-04-18 11:12:42 +00:00
|
|
|
else:
|
|
|
|
os.chdir(os.path.dirname(path))
|
|
|
|
cmd = ['bzr', 'branch', repos[repo]['url']]
|
|
|
|
if 'revision' in repos[repo]:
|
|
|
|
cmd += ['-r', '%s' % repos[repo]['revision']]
|
|
|
|
run(*cmd)
|
|
|
|
setup = os.path.join(base, repos[repo]['path'], 'setup.py')
|
|
|
|
if repo in ('python-ox', 'oxtimelines') and os.path.exists(setup):
|
|
|
|
os.chdir(os.path.dirname(setup))
|
|
|
|
run(os.path.join(base, 'bin', 'python'), 'setup.py', 'develop')
|
|
|
|
new += '+'
|
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')
|
2013-10-22 20:03:42 +00:00
|
|
|
if pandora_old_revno != pandora_new_revno:
|
|
|
|
os.chdir(base)
|
|
|
|
run('./update.py', 'postupdate', pandora_old_revno, pandora_new_revno)
|
2013-10-28 11:11:58 +00:00
|
|
|
os.chdir(join(base, 'pandora'))
|
2012-11-02 12:41:41 +00:00
|
|
|
diff = get('./manage.py', 'sqldiff', '-a').strip()
|
|
|
|
if diff != '-- No differences':
|
2013-04-30 17:17:48 +00:00
|
|
|
print 'Database has changed, please make a backup and run ./update.py db'
|
2014-10-12 15:10:33 +00:00
|
|
|
elif not development:
|
|
|
|
print 'pan.do/ra is at the latest stable release,\nyou can run "./update.py dev" to update to the development version'
|
2013-10-22 20:03:42 +00:00
|
|
|
elif current != new:
|
2013-03-01 07:09:44 +00:00
|
|
|
reload_notice(base)
|