-
Notifications
You must be signed in to change notification settings - Fork 5
/
gen_src_to_bin_deps.py
executable file
·118 lines (92 loc) · 3.51 KB
/
gen_src_to_bin_deps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/python
import sys
from debian import deb822
import re
import os
arch="i386"
if "ARCH" in os.environ.keys():
arch=os.environ['ARCH']
arch_override = {
'xcp-eliloader':'all',
'xcp':'all'
}
def get_arch(name,default):
try:
return arch_override[name]
except:
return default
def find(f, seq):
"""Return first item in sequence where f(item) == True."""
for item in seq:
if f(item):
return item
def gen_package(binstr, version, release,arch):
packages = map(lambda x: {'name':x.strip(), 'version':version, 'release':release, 'arch':get_arch(x.strip(), arch)}, binstr.split(','))
filtered = filter(lambda x: "doc" not in x['name'], packages)
filtered = filter(lambda x: "xen-hypervisor-4.1-i386" not in x['name'], filtered)
return filtered
def flatten(listOfLists):
return reduce(list.__add__, listOfLists)
def get_all_pkg_names(deps):
dep_pkgs = map(lambda spkg: map(lambda pkg: pkg['name'], spkg['Binary']), deps)
return flatten(dep_pkgs)
def process_dsc(fname):
f = file(fname)
pkg = deb822.Sources(f)
version=pkg['Version'].split('-')[0]
release=pkg['Version'].split('-')[1]
return {'Source':pkg['Source'],
'Dsc':fname,
'Version':version,
'Release':release,
'Binary':gen_package(pkg['Binary'],version,release,arch),
'Build-Depends':map(lambda x: x.strip(), pkg['Build-Depends'].split(','))}
def get_binary_deb_name_from_package(pkg):
return ("%s_%s-%s_%s.deb" % (pkg['name'], pkg['version'], pkg['release'], pkg['arch']))
def find_spkg_from_pkg_name(pkg_name, deps):
return find(lambda spkg: pkg_name in map(lambda pkg: pkg['name'], spkg['Binary']), deps)
def find_pkg_from_pkg_name(pkg_name, deps):
spkg = find_spkg_from_pkg_name(pkg_name, deps)
if spkg:
return find(lambda pkg: pkg['name']==pkg_name, spkg['Binary'])
def get_binary_deb_name_from_pkg_name(pkg_name,deps):
package = find_pkg_from_pkg_name(pkg_name,deps)
if package:
return get_binary_deb_name_from_package(package)
def gen_deps(spkg, deps):
pkg_names = get_all_pkg_names(deps)
pkg_deps = filter(lambda name: name in pkg_names, spkg['Build-Depends'])
all = ""
for pkg in spkg['Binary']:
debname=get_binary_deb_name_from_package(pkg)
all = "%s \"%s\"" % (all, debname)
for pkg in spkg['Binary']:
debname=get_binary_deb_name_from_package(pkg)
mydeps = map(lambda pkg_name: get_binary_deb_name_from_pkg_name(pkg_name,deps), pkg_deps)
# deps = filter(lambda depname: depname <> None, deps)
deps_str = ' '.join(mydeps)
print "%s: %s %s" % (debname,spkg['Dsc'],deps_str)
print "\techo Building %s depends upon: %s" % (debname,deps_str)
print "\tls -la"
print "\trm -f %s\n\t../build_deb.sh %s" % (all,spkg['Dsc'] )
print "\tls -la"
def gen_default_target(deps):
pkg_names = get_all_pkg_names(deps)
default=""
for spkg in deps:
for pkg in spkg['Binary']:
default = "%s %s" % (default, get_binary_deb_name_from_package(pkg))
print ".PHONY: default\ndefault : %s\n" % default
print ".PHONY: fromcache\nfromcache : \n"
for spkg in deps:
for pkg in spkg['Binary']:
print "\t../fromcache.sh \"%s\"" % get_binary_deb_name_from_package(pkg)
print ".PHONY: tocache\ntocache : \n"
for spkg in deps:
for pkg in spkg['Binary']:
print "\t../tocache.sh \"%s\"" % get_binary_deb_name_from_package(pkg)
print "\t../update_latest.sh\n"
deps=map(process_dsc, sys.argv[1:])
gen_default_target(deps)
for spkg in deps:
gen_deps(spkg, deps)