#!/usr/bin/env python
from xml.dom import minidom, Node
import os

appinfo = minidom.parse('AppInfo.xml')
root = appinfo.documentElement
assert root.localName == 'AppInfo'
for x in root.childNodes:
	if x.nodeType != Node.ELEMENT_NODE: continue
	if x.localName == 'About': break
else:
	assert 0
for y in x.childNodes:
	if y.nodeType != Node.ELEMENT_NODE: continue
	if y.localName == 'Version': break
else:
	assert 0
version = ''.join([text.nodeValue for text in y.childNodes
			if text.nodeType == Node.TEXT_NODE])

a, b, c = map(int, version.split(' ')[0].split('.')[:3])

raw_input("Create rox-lib-%s (%d.%d.%d)?" % (version, a, b, c))

os.system('cvs rel .')
os.system('cvs tag -F Release-%d-%d-%d' % (a, b, c))

os.chdir(os.environ['HOME'])
dir = 'rox-lib-%d.%d.%d' % (a, b, c)
os.mkdir(dir)
os.chdir(dir)
os.system('cvs -d:pserver:anonymous@cvs.rox.sourceforge.net:/cvsroot/rox export -r Release-%d-%d-%d ROX-Lib2' % (a, b, c))
os.system('cd ROX-Lib2/python; ./make_docs.py; rm rox/.cvsignore rox/*.pyc')
os.chdir(os.environ['HOME'])
os.system('tar czf %s.tgz %s' % (dir, dir))
print "%s.tgz is ready!" % dir

