#!/usr/bin/env python
"""dipy release script.

This should only be run at real release time.
"""

from os.path import join as pjoin
from toollib import get_dipydir, cd, c

# Get main dipy dir, this will raise if it doesn't pass some checks
dipydir = get_dipydir()
tooldir = pjoin(dipydir,'tools')
distdir = pjoin(dipydir,'dist')
#### Where I keep static backups of each release
###nibbackupdir = os.path.expanduser('~/dipy/backup')

# Start in main dipy dir
cd(dipydir)

# Load release info
execfile(pjoin('dipy','info.py'))

print
print "Releasing dipy"
print "================="
print
print 'Source dipy directory:', dipydir
print

# Perform local backup, go to tools dir to run it.
cd(tooldir)
# c('./make_tarball.py')
# c('mv dipy-*.tgz %s' % nibbackupdir)

# Build release files
c('./build_release %s' % dipydir)

# Register with the Python Package Index (PyPI)
print "Registering with PyPI..."
cd(dipydir)
c('./setup.py register')

# Upload all files
c('./setup.py sdist --formats=gztar,zip upload')
c('./setup.py bdist_egg upload')
cd(distdir)
#print "Uploading distribution files..."
#c('scp * dipy@dipy.scipy.org:www/dist/')

# print "Uploading backup files..."
# cd(nibbackupdir)
# c('scp `ls -1tr *tgz | tail -1` dipy@dipy.scipy.org:www/backup/')

print "Done!"
