2010-04-13 23:18:24 +02:00
|
|
|
#!/usr/bin/python
|
2010-04-13 23:22:32 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# Copyright (C) 2008-2010 Martin Pitt <martin.pitt@canonical.com>
|
|
|
|
#
|
|
|
|
# ##################################################################
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; version 3.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# See file /usr/share/common-licenses/GPL-3 for more details.
|
|
|
|
#
|
|
|
|
# ##################################################################
|
2010-04-13 23:18:24 +02:00
|
|
|
|
2010-04-13 23:53:07 +02:00
|
|
|
import apt_pkg
|
2010-04-13 23:18:24 +02:00
|
|
|
import os, os.path, sys, urllib, subprocess, shutil
|
2010-04-13 23:35:13 +02:00
|
|
|
from ubuntutools.requestsync.lp import getUbuntuSrcPkg
|
2010-04-13 23:18:24 +02:00
|
|
|
|
|
|
|
def retrieve_file(url):
|
2010-05-09 19:11:50 +02:00
|
|
|
'''Download file (by URL) to the current directory.
|
2010-04-13 23:18:24 +02:00
|
|
|
|
2010-05-09 19:11:50 +02:00
|
|
|
If the file is already present, this function does nothing.'''
|
2010-04-13 23:18:24 +02:00
|
|
|
|
2010-05-09 19:11:50 +02:00
|
|
|
fname = os.path.basename(url)
|
|
|
|
if not os.path.exists(fname):
|
|
|
|
print 'downloading', url
|
|
|
|
urllib.urlretrieve(url, fname)
|
2010-04-13 23:18:24 +02:00
|
|
|
|
|
|
|
def dsc_getfiles(dsc):
|
2010-05-09 19:11:50 +02:00
|
|
|
'''Return list of files in a .dsc file (excluding the .dsc file itself).'''
|
2010-04-13 23:18:24 +02:00
|
|
|
|
2010-05-09 19:11:50 +02:00
|
|
|
f = open(dsc)
|
|
|
|
files = []
|
2010-04-13 23:18:24 +02:00
|
|
|
|
2010-05-09 19:11:50 +02:00
|
|
|
# skip until 'Files:'
|
|
|
|
for l in f:
|
|
|
|
if l.strip() == 'Files:':
|
|
|
|
break
|
2010-04-13 23:18:24 +02:00
|
|
|
|
2010-05-09 19:11:50 +02:00
|
|
|
for l in f:
|
|
|
|
if not l.startswith(' '):
|
|
|
|
continue
|
|
|
|
if l.strip() == '':
|
|
|
|
break
|
|
|
|
fname = l.split()[2]
|
|
|
|
if not fname.endswith('.dsc'):
|
|
|
|
files.append(fname)
|
2010-04-13 23:18:24 +02:00
|
|
|
|
2010-05-09 19:11:50 +02:00
|
|
|
f.close()
|
|
|
|
return files
|
2010-04-13 23:18:24 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# entry point
|
|
|
|
#
|
|
|
|
|
|
|
|
if len(sys.argv) != 3:
|
2010-05-09 19:11:50 +02:00
|
|
|
print 'Usage: syncpackage <.dsc URL or path> <target release>'
|
|
|
|
sys.exit (1)
|
2010-04-13 23:18:24 +02:00
|
|
|
|
|
|
|
(dscurl, release) = sys.argv[1:]
|
|
|
|
dscname = os.path.basename(dscurl)
|
|
|
|
basepath = os.path.dirname(dscurl)
|
|
|
|
(srcpkg, new_ver) = dscname.split('_')
|
|
|
|
new_ver = new_ver[:-4] # strip off '.dsc'
|
|
|
|
|
2010-04-13 23:35:13 +02:00
|
|
|
cur_ver = getUbuntuSrcPkg(srcpkg, release).getVersion()
|
2010-04-13 23:18:24 +02:00
|
|
|
|
2010-04-13 23:53:07 +02:00
|
|
|
# No need to continue if version is not greater than current one
|
|
|
|
apt_pkg.init()
|
|
|
|
if not apt_pkg.check_dep(new_ver, '>', cur_ver):
|
2010-05-09 19:11:50 +02:00
|
|
|
raise Exception('%s version %s is not greater than already available %s' % (srcpkg, new_ver, cur_ver))
|
2010-04-13 23:53:07 +02:00
|
|
|
|
2010-04-13 23:18:24 +02:00
|
|
|
retrieve_file(dscurl)
|
|
|
|
files = dsc_getfiles(dscname)
|
|
|
|
|
|
|
|
# do we need the orig.tar.gz?
|
|
|
|
need_orig = True
|
|
|
|
if cur_ver.find('-') > 0 and new_ver.find('-') > 0 and \
|
2010-05-09 19:11:50 +02:00
|
|
|
cur_ver.split('-')[0] == new_ver.split('-')[0]:
|
|
|
|
need_orig = False
|
|
|
|
#files = [f for f in files if not f.endswith('orig.tar.gz')]
|
2010-04-13 23:18:24 +02:00
|
|
|
|
|
|
|
print 'Source %s: current version %s, new version %s' % (srcpkg, cur_ver, new_ver)
|
|
|
|
print 'needs orig.tar.gz', need_orig
|
|
|
|
print 'Files:', files
|
|
|
|
for f in files:
|
2010-05-09 19:11:50 +02:00
|
|
|
retrieve_file(os.path.join(basepath, f))
|
2010-04-13 23:18:24 +02:00
|
|
|
|
|
|
|
uidx = cur_ver.find('ubuntu')
|
|
|
|
if uidx > 0:
|
2010-05-09 19:11:50 +02:00
|
|
|
cur_ver = cur_ver[:uidx]
|
|
|
|
print 'WARNING! Overwriting modified Ubuntu version, setting current version to', cur_ver
|
2010-04-13 23:18:24 +02:00
|
|
|
|
|
|
|
uidx = cur_ver.find('build')
|
|
|
|
if uidx > 0:
|
2010-05-09 19:11:50 +02:00
|
|
|
cur_ver = cur_ver[:uidx]
|
2010-04-13 23:18:24 +02:00
|
|
|
|
|
|
|
orig_arg = ''
|
|
|
|
if need_orig:
|
2010-05-09 19:11:50 +02:00
|
|
|
orig_arg = '-sa'
|
2010-04-13 23:18:24 +02:00
|
|
|
|
|
|
|
# extract package, build Source
|
|
|
|
assert subprocess.call(['dpkg-source', '-x', dscname]) == 0
|
|
|
|
os.chdir(srcpkg + '-' + new_ver.split('-')[0])
|
|
|
|
assert subprocess.call("dpkg-genchanges -q -S %s -v%s -e\"$(getent passwd $(id -u)|cut -f5 -d:|cut -f1 -d,) <$DEBEMAIL>\" | \
|
2010-05-09 19:11:50 +02:00
|
|
|
sed 's/^Distribution:.*$/Distribution: %s/; 1 i\Origin: debian/unstable' > ../%s_%s_source.changes" %
|
|
|
|
(orig_arg, cur_ver, release, srcpkg, new_ver), shell=True) == 0
|
2010-04-13 23:18:24 +02:00
|
|
|
os.chdir('..')
|
|
|
|
shutil.rmtree(srcpkg + '-' + new_ver.split('-')[0], True)
|
|
|
|
assert subprocess.call("debsign %s_%s_source.changes" % (srcpkg, new_ver), shell=True) == 0
|