2012-08-27 17:32:39 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
"""
|
|
|
|
Dirty script for building package for PPA
|
|
|
|
by WangLu
|
|
|
|
2011.01.13
|
|
|
|
|
2013-01-27 17:51:30 +00:00
|
|
|
modified for pdf2htmlEX
|
2012-08-27 17:32:39 +00:00
|
|
|
2012.08.28
|
2013-05-29 16:52:20 +00:00
|
|
|
|
|
|
|
modified for general git repo
|
|
|
|
2013.05.30
|
2012-08-27 17:32:39 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import re
|
|
|
|
import time
|
|
|
|
|
2013-04-30 04:20:31 +00:00
|
|
|
package='pdf2htmlex'
|
2013-05-29 16:52:20 +00:00
|
|
|
ppa_name='pdf2htmlex'
|
2013-11-04 13:19:39 +00:00
|
|
|
supported_distributions=('precise', 'raring', 'saucy')
|
2013-05-29 16:52:20 +00:00
|
|
|
dist_pattern=re.compile('|'.join(['\\) '+i for i in supported_distributions]))
|
|
|
|
archive_cmd='(rm CMakeCache.txt || true) && cmake . && make dist'
|
|
|
|
archive_suffix='.tar.bz2'
|
2013-04-30 04:20:31 +00:00
|
|
|
|
2012-08-27 17:32:39 +00:00
|
|
|
print 'Generating version...'
|
|
|
|
try:
|
2013-05-29 16:52:20 +00:00
|
|
|
version = re.findall(r'set\(PDF2HTMLEX_VERSION\s*"([^"]*)"\)', open('CMakeLists.txt').read())[0]
|
2012-08-27 17:32:39 +00:00
|
|
|
except:
|
2013-05-29 16:52:20 +00:00
|
|
|
print 'Cannot get package name and version number'
|
2012-08-27 17:32:39 +00:00
|
|
|
sys.exit(-1)
|
|
|
|
|
|
|
|
try:
|
2013-05-29 16:52:20 +00:00
|
|
|
rev = open('.git/refs/heads/master').read()[:5]
|
2012-08-27 17:32:39 +00:00
|
|
|
except:
|
2013-05-29 16:52:20 +00:00
|
|
|
print 'Cannot get revision number'
|
2012-08-27 17:32:39 +00:00
|
|
|
sys.exit(-1)
|
|
|
|
|
2013-05-29 16:52:20 +00:00
|
|
|
projectdir=os.getcwd()
|
|
|
|
today_timestr = time.strftime('%Y%m%d%H%M')
|
2012-09-06 09:38:52 +00:00
|
|
|
deb_version = version+'-1~git'+today_timestr+'r'+rev
|
2012-08-27 17:32:39 +00:00
|
|
|
full_deb_version = deb_version+'-0ubuntu1'
|
|
|
|
|
|
|
|
#check if we need to update debian/changelog
|
2013-04-30 04:20:31 +00:00
|
|
|
with open('debian/changelog') as f:
|
|
|
|
if re.findall(r'\(([^)]+)\)', f.readline())[0] == full_deb_version:
|
|
|
|
print
|
|
|
|
print 'No need to update debian/changelog, skipping'
|
|
|
|
else:
|
|
|
|
print
|
|
|
|
print 'Writing debian/changelog'
|
|
|
|
if os.system('dch -v "%s"' % (full_deb_version,)) != 0:
|
|
|
|
print 'Failed when updating debian/changelog'
|
|
|
|
sys.exit(-1)
|
|
|
|
|
2013-05-29 16:52:20 +00:00
|
|
|
# changelog may have been updated, reopen it
|
|
|
|
with open('debian/changelog') as f:
|
2013-04-30 04:20:31 +00:00
|
|
|
#check dist mark of changelog
|
|
|
|
changelog = f.read()
|
|
|
|
m = dist_pattern.search(changelog)
|
|
|
|
if m is None or m.pos >= changelog.find('\n'):
|
|
|
|
print 'Cannot locate the dist name in the first line of changelog'
|
2012-08-27 17:32:39 +00:00
|
|
|
sys.exit(-1)
|
|
|
|
|
|
|
|
print
|
2013-04-30 04:20:31 +00:00
|
|
|
print 'Preparing build ...'
|
2012-08-27 17:32:39 +00:00
|
|
|
# handling files
|
2013-05-29 16:52:20 +00:00
|
|
|
if os.system(archive_cmd) != 0:
|
2012-08-27 17:32:39 +00:00
|
|
|
print 'Failed in creating tarball'
|
|
|
|
sys.exit(-1)
|
|
|
|
|
2013-05-29 16:52:20 +00:00
|
|
|
orig_tar_filename = package+'-'+version+archive_suffix
|
|
|
|
if os.system('test -e %s && cp %s ../build-area/' % (orig_tar_filename, orig_tar_filename)) != 0:
|
2012-08-27 17:32:39 +00:00
|
|
|
print 'Cannot copy tarball file to build area'
|
|
|
|
sys.exit(-1)
|
|
|
|
|
2013-05-29 16:52:20 +00:00
|
|
|
deb_orig_tar_filename = package+'_'+deb_version+'.orig'+archive_suffix
|
2012-08-27 17:32:39 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
os.chdir('../build-area')
|
|
|
|
except:
|
|
|
|
print 'Cannot find ../build-area'
|
|
|
|
sys.exit(-1)
|
|
|
|
|
|
|
|
# remove old dir
|
|
|
|
os.system('rm -rf %s' % (package+'-'+version,))
|
|
|
|
|
|
|
|
if os.system('mv %s %s && tar -xvf %s' % (orig_tar_filename, deb_orig_tar_filename, deb_orig_tar_filename)) != 0:
|
|
|
|
print 'Cannot extract tarball'
|
|
|
|
sys.exit(-1)
|
|
|
|
|
|
|
|
try:
|
|
|
|
os.chdir(package+'-'+version)
|
|
|
|
except:
|
|
|
|
print 'Cannot enter project dir'
|
|
|
|
sys.exit(-1)
|
|
|
|
|
2013-04-30 04:20:31 +00:00
|
|
|
os.system('cp -r %s/debian .' % (projectdir,))
|
2012-08-27 17:32:39 +00:00
|
|
|
|
2013-05-29 16:52:20 +00:00
|
|
|
for cur_dist in supported_distributions:
|
2013-04-30 04:20:31 +00:00
|
|
|
print
|
|
|
|
print 'Building for ' + cur_dist + ' ...'
|
|
|
|
# substitute distribution name
|
|
|
|
with open('debian/changelog', 'w') as f:
|
|
|
|
f.write(dist_pattern.sub('~%s1) %s' % (cur_dist, cur_dist), changelog, 1))
|
|
|
|
|
|
|
|
# building
|
|
|
|
if os.system('debuild -S -sa') != 0:
|
|
|
|
print 'Failed in debuild'
|
|
|
|
sys.exit(-1)
|
2012-08-27 17:32:39 +00:00
|
|
|
|
2013-04-30 04:20:31 +00:00
|
|
|
"""
|
|
|
|
print
|
|
|
|
sys.stdout.write('Everything seems to be good so far, upload?(y/n)')
|
|
|
|
sys.stdout.flush()
|
2012-08-27 17:32:39 +00:00
|
|
|
ans = raw_input().lower()
|
2013-04-30 04:20:31 +00:00
|
|
|
while ans not in ['y', 'n']:
|
|
|
|
sys.stdout.write('I don\'t understand, enter \'y\' or \'n\':')
|
|
|
|
ans = raw_input().lower()
|
|
|
|
|
|
|
|
if ans == 'n':
|
|
|
|
print 'Skipped.'
|
|
|
|
sys.exit(0)
|
|
|
|
"""
|
|
|
|
|
|
|
|
print 'Uploading'
|
2013-05-29 16:52:20 +00:00
|
|
|
if os.system('dput %s ../%s' % (ppa_name, package+'_'+full_deb_version+'~'+cur_dist+'1_source.changes')) != 0:
|
2013-04-30 04:20:31 +00:00
|
|
|
print 'Failed in uploading by dput'
|
|
|
|
sys.exit(-1)
|
2012-08-27 17:32:39 +00:00
|
|
|
|
|
|
|
print 'Build area not cleaned.'
|
|
|
|
print 'All done. Cool!'
|
|
|
|
|
|
|
|
|
|
|
|
|