1 |
On Wed, 2007-09-12 at 03:04 +0300, Daniel Iliev wrote: |
2 |
> Hi, list |
3 |
> |
4 |
> I'd like to automate a full re-emerging and to get a record of all |
5 |
> packages that failed. Something like: |
6 |
> |
7 |
> ## |
8 |
> |
9 |
> emerge -e world || { |
10 |
> |
11 |
> echo "$CATEGORY/$PN" >>failed.txt |
12 |
> |
13 |
> while ! emerge --resume --skipfirst |
14 |
> do |
15 |
> echo "$CATEGORY/$PN" >> failed.txt |
16 |
> done |
17 |
> } |
18 |
> |
19 |
> ## |
20 |
> |
21 |
> |
22 |
> Any ideas how to achieve this? |
23 |
> |
24 |
> |
25 |
> -- |
26 |
> Best regards, |
27 |
> Daniel |
28 |
|
29 |
Here's a script that I use. I use it to build all my packages at the |
30 |
end of the month. Works ok for me. YMMV: |
31 |
|
32 |
---- CUT HERE 8<----- |
33 |
#!/usr/bin/python |
34 |
|
35 |
""" |
36 |
Like my emptytree bash script, but more reliable and written in Python. |
37 |
""" |
38 |
|
39 |
|
40 |
import datetime |
41 |
import os |
42 |
import sys |
43 |
import time |
44 |
|
45 |
import portage |
46 |
|
47 |
|
48 |
LOGDIR = '/var/log/emptytree' |
49 |
PKGLIST = LOGDIR + '/packages' |
50 |
FAILED = LOGDIR + '/failed' |
51 |
EMERGE_FLAGS = '--oneshot --nodeps' |
52 |
TCOLS = 80 |
53 |
|
54 |
|
55 |
def get_list_of_packages(args=None): |
56 |
"""Get list of packages to emerge, in order""" |
57 |
|
58 |
packages = [] |
59 |
|
60 |
if args is None: |
61 |
command = "emerge --nospinner --pretend --emptytree world" |
62 |
else: |
63 |
command = "emerge --nospinner --pretend " + args |
64 |
pipe = os.popen(command, 'r') |
65 |
|
66 |
for line in pipe: |
67 |
if line.startswith('[ebuild'): |
68 |
try: |
69 |
right_bracket = line.index(']') |
70 |
ebuild_start = right_bracket + 2 |
71 |
space = line.index(' ', ebuild_start) |
72 |
except ValueError: |
73 |
continue |
74 |
|
75 |
ebuild = line[ebuild_start:space] |
76 |
packages.append(ebuild) |
77 |
return packages |
78 |
|
79 |
|
80 |
class PackageList(list): |
81 |
"""List of packages read/written to a flat file""" |
82 |
|
83 |
def __init__(self, filename): |
84 |
list.__init__(self) |
85 |
self.filename = filename |
86 |
|
87 |
|
88 |
def write_to_file(self): |
89 |
"""Write package list file""" |
90 |
|
91 |
package_file = open(self.filename, 'w') |
92 |
for package in self: |
93 |
package_file.write(package + '\n') |
94 |
|
95 |
package_file.close() |
96 |
|
97 |
|
98 |
def read_from_file(self): |
99 |
"""Load packages from file""" |
100 |
|
101 |
del self[0:-1] # clear |
102 |
try: |
103 |
package_file = open(self.filename, 'r') |
104 |
except OSError: |
105 |
return |
106 |
|
107 |
for line in package_file: |
108 |
package = line.strip() |
109 |
if package: |
110 |
self.append(package) |
111 |
|
112 |
|
113 |
def set_links(current): |
114 |
"""Create current.out current.err symlinks""" |
115 |
|
116 |
current_out = LOGDIR + '/current.stdout' |
117 |
current_err = LOGDIR + '/current.stderr' |
118 |
|
119 |
if os.path.exists(current_out): |
120 |
os.remove(current_out) |
121 |
if os.path.exists(current_err): |
122 |
os.remove(current_err) |
123 |
|
124 |
os.symlink('%s.stdout' % current, current_out) |
125 |
os.symlink('%s.stderr' % current, current_err) |
126 |
|
127 |
|
128 |
def main(argv): |
129 |
"""Main program entry point""" |
130 |
|
131 |
if len(argv) > 1: |
132 |
args = ' '.join(argv[1:]) |
133 |
else: |
134 |
args = None |
135 |
packages = PackageList(PKGLIST) |
136 |
packages.extend(get_list_of_packages(args)) |
137 |
failed = PackageList(FAILED) |
138 |
|
139 |
total = len(packages) |
140 |
packages.write_to_file() |
141 |
failed.write_to_file() |
142 |
|
143 |
start_time = time.gmtime() |
144 |
pkg_num = 0 |
145 |
while len(packages) > 0: |
146 |
package = packages.pop(0) |
147 |
pkg_num = pkg_num + 1 |
148 |
print '[%03d/%03d] %s' % (pkg_num, total, package), |
149 |
sys.stdout.flush() |
150 |
split = portage.pkgsplit(package) |
151 |
pname = split[0].split('/')[1] + '-' + split[1] + '-' + split[1] |
152 |
command = ('emerge %s =%s ' |
153 |
'> %s/%s.stdout 2> %s/%s.stderr' |
154 |
% (EMERGE_FLAGS, package, LOGDIR, pname, LOGDIR, pname)) |
155 |
#command = 'echo %s' % package |
156 |
set_links(pname) |
157 |
status = os.system(command) |
158 |
plen = len(package) |
159 |
if status == 0: |
160 |
print '[SUCCESS]'.rjust(TCOLS - 11 - plen) |
161 |
else: |
162 |
# emerge failed |
163 |
print '[FAILURE]'.rjust(TCOLS - 11 - plen) |
164 |
failed.append(package) |
165 |
failed.write_to_file() |
166 |
|
167 |
packages.write_to_file() |
168 |
end_time = time.gmtime() |
169 |
time_diff = datetime.datetime(*end_time[:6]) - \ |
170 |
datetime.datetime(*start_time[:6]) |
171 |
print 'Finished!' |
172 |
print 'Total: %d packages. %d failed' % (total, len(failed)) |
173 |
print 'Completed in %s' % time_diff |
174 |
|
175 |
|
176 |
if __name__ == '__main__': |
177 |
|
178 |
sys.exit(main(sys.argv)) |
179 |
|
180 |
|
181 |
# 2007-07-10 marduk Took out "resume" and "failed" command-line |
182 |
# arguments, since "resume" can be accomplished by |
183 |
# "emptytree `cat /var/log/emptytree/packages`" and failed by |
184 |
# "emptytree `cat /var/log/emptytree/failed`". |
185 |
# Removed "empty" contructor parameter from PackageList since it |
186 |
# was only used by "resume" and "failed" |
187 |
------------------------------ |
188 |
-- |
189 |
raise SystemExit |
190 |
|
191 |
|
192 |
-- |
193 |
gentoo-user@g.o mailing list |