#!/usr/pkg/bin/python2.7
from xml.dom import minidom, Node
import os, sys

sfuser='tal197'
if len(sys.argv)>1:
	sfuser=sys.argv[1]

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])

sys.path.append(os.path.dirname(__file__) + '/python')
import rox
if rox.roxlib_version != (a, b, c):
	print 'Version mismatch!'
	print 'AppInfo    : (%d.%d.%d)' % (a, b, c)
	print '__init__.py: (%d.%d.%d)' % rox.roxlib_version
	raise SystemExit(1)

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('cvs -d%s@cvs.sourceforge.net:/cvsroot/rox export -r Release-%d-%d-%d ROX-Lib2' % (sfuser, a, b, c))
os.system('cd ROX-Lib2/Messages; ./update-po; ./dist; rm *.old')
os.system('cd ROX-Lib2/python; ./make_docs.py; rm rox/.cvsignore rox/*.pyc rox/messages.pot')
os.chdir(os.environ['HOME'])
os.system('tar czf %s.tgz %s' % (dir, dir))
print "%s.tgz is ready!" % dir

