2017-10-21 21:46:46 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
2018-05-13 05:38:18 +00:00
|
|
|
import sys
|
|
|
|
import re
|
|
|
|
import subprocess
|
2017-10-21 21:46:46 +00:00
|
|
|
from launchpadlib.launchpad import Launchpad
|
|
|
|
|
2018-05-13 05:38:18 +00:00
|
|
|
if sys.version_info[0] > 2:
|
|
|
|
xrange = range
|
|
|
|
|
2017-10-21 21:46:46 +00:00
|
|
|
cachedir = '/.launchpadlib/cache/'
|
2018-05-13 05:38:18 +00:00
|
|
|
launchpad = Launchpad.login_anonymously(
|
|
|
|
'grab build info', 'production', cachedir, version='devel')
|
2017-10-21 21:46:46 +00:00
|
|
|
|
|
|
|
processed_packages = []
|
|
|
|
deb_file_list = []
|
|
|
|
|
2018-05-13 05:38:18 +00:00
|
|
|
|
2017-10-21 21:46:46 +00:00
|
|
|
def get_url(pkg, distro):
|
2018-05-13 05:38:18 +00:00
|
|
|
build_ref = launchpad.archives.getByReference(reference='ubuntu').getPublishedBinaries(
|
|
|
|
binary_name=pkg[0], distro_arch_series='https://api.launchpad.net/devel/ubuntu/' + distro + '/amd64', version=pkg[1], exact_match=True, order_by_date=True).entries[0]
|
|
|
|
build_link = build_ref['build_link']
|
|
|
|
deb_name = '{}_{}_{}.deb'.format(pkg[0], pkg[1], 'amd64' if build_ref['architecture_specific'] else 'all')
|
2017-10-21 21:46:46 +00:00
|
|
|
deb_link = build_link + '/+files/' + deb_name
|
|
|
|
return [deb_link, deb_name]
|
|
|
|
|
2018-05-13 05:38:18 +00:00
|
|
|
|
2017-10-21 21:46:46 +00:00
|
|
|
def list_dependencies(deb_file):
|
2018-05-13 05:38:18 +00:00
|
|
|
t = subprocess.check_output(
|
|
|
|
['bash', '-c', '(dpkg -I {} | grep -oP "^ Depends\: \K.*$") || true'.format(deb_file)])
|
|
|
|
deps = [i.strip() for i in t.split(',')]
|
2017-10-21 21:46:46 +00:00
|
|
|
equals_re = re.compile(r'^(.*) \(= (.*)\)$')
|
|
|
|
return [equals_re.sub(r'\1=\2', i).split('=') for i in filter(equals_re.match, deps)]
|
|
|
|
|
2018-05-13 05:38:18 +00:00
|
|
|
|
2017-10-21 21:46:46 +00:00
|
|
|
def get_package(pkg, distro):
|
|
|
|
if pkg in processed_packages:
|
|
|
|
return
|
2018-05-13 05:38:18 +00:00
|
|
|
print('Getting {}...'.format(pkg[0]))
|
2017-10-21 21:46:46 +00:00
|
|
|
url = get_url(pkg, distro)
|
|
|
|
subprocess.check_call(['wget', '--quiet', url[0], '-O', url[1]])
|
|
|
|
for dep in list_dependencies(url[1]):
|
|
|
|
get_package(dep, distro)
|
|
|
|
processed_packages.append(pkg)
|
|
|
|
deb_file_list.append('./' + url[1])
|
|
|
|
|
2018-05-13 05:38:18 +00:00
|
|
|
|
2017-10-21 21:46:46 +00:00
|
|
|
for i in xrange(1, len(sys.argv), 3):
|
|
|
|
get_package([sys.argv[i], sys.argv[i + 1]], sys.argv[i + 2])
|
|
|
|
|
2018-05-13 05:38:18 +00:00
|
|
|
subprocess.check_call(
|
|
|
|
['apt-get', 'install', '-y', '--force-yes'] + deb_file_list)
|