3 import os, os.path, sys, urllib, subprocess, shutil
5 def retrieve_file(url):
6 '''Download file (by URL) to the current directory.
8 If the file is already present, this function does nothing.'''
10 fname = os.path.basename(url)
11 if not os.path.exists(fname):
12 print 'downloading', url
13 urllib.urlretrieve(url, fname)
15 def cur_version(sourcepkg, release):
16 madison = subprocess.Popen(['apt-cache', 'madison', sourcepkg], stdout=subprocess.PIPE)
17 out = madison.communicate()[0]
18 assert (madison.returncode == 0)
20 for l in out.splitlines():
21 (pkg, version, aptsrc) = l.split('|')
22 if aptsrc.endswith('Sources') and aptsrc.find(release) > 0:
23 return version.strip()
25 raise Exception('apt-cache madison does not contain %s/%s' % (sourcepkg, release))
27 def dsc_getfiles(dsc):
28 '''Return list of files in a .dsc file (excluding the .dsc file itself).'''
35 if l.strip() == 'Files:':
41 if not l.startswith(' '):
44 if not fname.endswith('.dsc'):
54 if len(sys.argv) != 3:
55 print 'Usage: syncpackage <.dsc URL or path> <target release>'
58 (dscurl, release) = sys.argv[1:]
59 dscname = os.path.basename(dscurl)
60 basepath = os.path.dirname(dscurl)
61 (srcpkg, new_ver) = dscname.split('_')
62 new_ver = new_ver[:-4] # strip off '.dsc'
64 cur_ver = cur_version(srcpkg, release)
67 files = dsc_getfiles(dscname)
69 # do we need the orig.tar.gz?
71 if cur_ver.find('-') > 0 and new_ver.find('-') > 0 and \
72 cur_ver.split('-')[0] == new_ver.split('-')[0]:
74 #files = [f for f in files if not f.endswith('orig.tar.gz')]
76 print 'Source %s: current version %s, new version %s' % (srcpkg, cur_ver, new_ver)
77 print 'needs orig.tar.gz', need_orig
80 retrieve_file(os.path.join(basepath, f))
82 uidx = cur_ver.find('ubuntu')
84 cur_ver = cur_ver[:uidx]
85 print 'WARNING! Overwriting modified Ubuntu version, setting current version to', cur_ver
87 uidx = cur_ver.find('build')
89 cur_ver = cur_ver[:uidx]
95 # extract package, build Source
96 assert subprocess.call(['dpkg-source', '-x', dscname]) == 0
97 os.chdir(srcpkg + '-' + new_ver.split('-')[0])
98 assert subprocess.call("dpkg-genchanges -q -S %s -v%s -e\"$(getent passwd $(id -u)|cut -f5 -d:|cut -f1 -d,) <$DEBEMAIL>\" | \
99 sed 's/^Distribution:.*$/Distribution: %s/; 1 i\Origin: debian/unstable' > ../%s_%s_source.changes" %
100 (orig_arg, cur_ver, release, srcpkg, new_ver), shell=True) == 0
102 shutil.rmtree(srcpkg + '-' + new_ver.split('-')[0], True)
103 assert subprocess.call("debsign %s_%s_source.changes" % (srcpkg, new_ver), shell=True) == 0