forked from semplice/meta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metabuilder.py
126 lines (100 loc) · 3.92 KB
/
metabuilder.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
118
119
120
121
122
123
124
125
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# metabuilder: get files ready to be included into the metapackages!
# Copyright (C) 2013 Eugenio "g7" Paolantonio. All rights reserved.
# Work released under the terms of the GNU GPL license, version 3 or
# later.
#
import os, sys, shutil, commands, fileinput
if len(sys.argv) == 1:
ARCH = commands.getoutput("dpkg-architecture -qDEB_HOST_ARCH")
else:
ARCH = sys.argv[1]
print("I: metabuilder.py: started")
def base_list(obj):
""" Creates the base include list. Based on generate.py.
obj is an opened file object. """
ignore_list = ("debian-multimedia-keyring", "libept0", "libept1", "libxapian5", "liblzma2")
# Get package list via aptitude
package_list = commands.getoutput('aptitude search "~pimportant (?not(?obsolete))" "~prequired (?not(?obsolete))"').split("\n")
GCC = []
# Ok, so we have the package_list variable correctly declared.
# Now we should parse the lines and then the single packages.
# A 'for' loop really helps.
for line in package_list:
col = line.split(" ")
if col[0] == "c":
continue
if col[1] == "A":
pkg = col[2] + "\n"
else:
pkg = col[3] + "\n"
if pkg.replace("\n","") in ignore_list:
print("I: base_list(): pkg is %s, skipping." % (pkg))
elif pkg[:3] == "gcc":
# GCC packages will be wrote after the loop, the user needs only one gcc, no two or three.
GCC.append(pkg)
else:
obj.write(pkg)
# Write the last package in the 'GCC' list.
# WARNING: If there is experimental activated, the last gcc version
# will not be the same present in sid and, therefore, will break system-base.
# Please run this script only in chroot enviroinment, such as pbuilder.
# The package *should* automagically create a list of packages. See debian/rules for more details.
obj.write(GCC[-1])
obj.close()
# Loop through src/ in search of common package lists...
for item in os.listdir("src/"):
fullpath = os.path.join("src/", item)
if os.path.isfile(fullpath):
# Found one! Process it...
# Check if it has an extension (so it is a one-arch package):
if len(item.split(".")) > 1:
# Check arch
if item.split(".")[-1] != ARCH:
print("I: skipping %s as we aren't onto the right arch."
% item)
continue
print("I: processing %s" % item)
# Firstly, copy the common list to . and change its name
mainpath = os.path.join(os.getcwd(), "%s-%s" %
(item.replace(".%s" % ARCH,""), ARCH))
shutil.copy(fullpath, mainpath)
# Also create a recommends file, otherwise germinate will
# complain.
with open(os.path.join(os.getcwd(), "%s-recommends-%s" %
(item.replace(".%s" % ARCH,""), ARCH)), "w") as f:
f.write("")
# If this is "base", we need to obtain a list of "required" and
# "important" packages. To do this, we use a custom method.
if item.replace(".%s" % ARCH,"") == "base":
if not os.path.exists("src/%s" % ARCH):
os.makedirs("src/%s" % ARCH)
base_list(open("src/%s/base.include" % ARCH, "w"))
# Check in arch dirs if we need to further process this list
if os.path.isdir("src/%s" % ARCH):
for architem in os.listdir("src/%s" % ARCH):
# Check if we are talking about our package
if ".".join(architem.split(".")[:-1]) == item:
# Yeah!
# Should exclude?
if architem.endswith(".exclude"):
# Get excludes list
excludes = []
with open(os.path.join(os.getcwd(), "src/%s/%s" %
(ARCH, architem))) as f:
for line in f.readlines():
excludes.append(line.replace("\n",""))
for line in fileinput.input(mainpath, inplace=1):
if not line.replace("\n","") in excludes:
sys.stdout.write(line)
elif architem.endswith(".include"):
# Should include!
mainopen = open(mainpath, "a")
with open(os.path.join(os.getcwd(), "src/%s/%s" %
(ARCH, architem))) as f:
for line in f.readlines():
mainopen.write(line)
mainopen.close()
print("I: metabuilder.py: closing...")