Lines 1-7
Link Here
|
1 |
#!/usr/bin/python -O |
1 |
#!/usr/bin/python -O |
2 |
# Copyright 1999-2004 Gentoo Foundation |
2 |
# Copyright 1999-2006 Gentoo Foundation |
3 |
# Distributed under the terms of the GNU General Public License v2 |
3 |
# Distributed under the terms of the GNU General Public License v2 |
4 |
# $Header: /var/cvsroot/gentoo-src/portage/bin/dispatch-conf,v 1.7.2.10 2005/05/12 15:20:22 jstubbs Exp $ |
4 |
# $Id: /var/cvsroot/gentoo-src/portage/bin/dispatch-conf,v 1.7.2.10 2005/05/12 15:20:22 jstubbs Exp $ |
5 |
|
5 |
|
6 |
# |
6 |
# |
7 |
# dispatch-conf -- Integrate modified configs, post-emerge |
7 |
# dispatch-conf -- Integrate modified configs, post-emerge |
Lines 17-23
from random import *
Link Here
|
17 |
import os, shutil, sys, string, re, commands, atexit |
17 |
import os, shutil, sys, string, re, commands, atexit |
18 |
sys.path = ["/usr/lib/portage/pym"]+sys.path |
18 |
sys.path = ["/usr/lib/portage/pym"]+sys.path |
19 |
|
19 |
|
20 |
import portage, dispatch_conf |
20 |
import portage, portage.dispatch_conf |
21 |
|
21 |
|
22 |
FIND_EXTANT_CONFIGS = "find %s/ -iname '._cfg????_*' | sed -e 's://:/:g'" |
22 |
FIND_EXTANT_CONFIGS = "find %s/ -iname '._cfg????_*' | sed -e 's://:/:g'" |
23 |
DIFF_CONTENTS = 'diff -Nu %s %s' |
23 |
DIFF_CONTENTS = 'diff -Nu %s %s' |
Lines 48-54
os.umask(oldmask)
Link Here
|
48 |
|
48 |
|
49 |
# Ensure the scratch dir is deleted |
49 |
# Ensure the scratch dir is deleted |
50 |
def cleanup(mydir=SCRATCH_DIR): |
50 |
def cleanup(mydir=SCRATCH_DIR): |
51 |
shutil.rmtree(SCRATCH_DIR) |
51 |
shutil.rmtree(mydir) |
52 |
atexit.register(cleanup) |
52 |
atexit.register(cleanup) |
53 |
|
53 |
|
54 |
MANDATORY_OPTS = [ 'archive-dir', 'diff', 'replace-cvs', 'replace-wscomments', 'merge' ] |
54 |
MANDATORY_OPTS = [ 'archive-dir', 'diff', 'replace-cvs', 'replace-wscomments', 'merge' ] |
Lines 61-72
class dispatch:
Link Here
|
61 |
count = 0 |
61 |
count = 0 |
62 |
|
62 |
|
63 |
|
63 |
|
64 |
self.options = dispatch_conf.read_config(MANDATORY_OPTS) |
64 |
self.options = portage.dispatch_conf.read_config(MANDATORY_OPTS) |
65 |
|
65 |
|
66 |
if self.options.has_key("log-file"): |
66 |
if self.options.has_key("log-file"): |
67 |
if os.path.exists(self.options["log-file"]): |
67 |
if os.path.isfile(self.options["log-file"]): |
68 |
shutil.copyfile(self.options["log-file"], self.options["log-file"] + '.old') |
68 |
shutil.copy(self.options["log-file"], self.options["log-file"] + '.old') |
69 |
os.remove(self.options["log-file"]) |
69 |
if os.path.isfile(self.options["log-file"]) \ |
|
|
70 |
or not os.path.exists(self.options["log-file"]): |
71 |
open(self.options["log-file"], 'w').close() # Truncate it |
72 |
os.chmod(self.options["log-file"], 0600) |
70 |
else: |
73 |
else: |
71 |
self.options["log-file"] = "/dev/null" |
74 |
self.options["log-file"] = "/dev/null" |
72 |
|
75 |
|
Lines 100-108
class dispatch:
Link Here
|
100 |
mrgconf = re.sub(r'\._cfg', '._mrg', conf['new']) |
103 |
mrgconf = re.sub(r'\._cfg', '._mrg', conf['new']) |
101 |
archive = os.path.join(self.options['archive-dir'], conf['current'].lstrip('/')) |
104 |
archive = os.path.join(self.options['archive-dir'], conf['current'].lstrip('/')) |
102 |
if self.options['use-rcs'] == 'yes': |
105 |
if self.options['use-rcs'] == 'yes': |
103 |
mrgfail = dispatch_conf.rcs_archive(archive, conf['current'], conf['new'], mrgconf) |
106 |
mrgfail = portage.dispatch_conf.rcs_archive(archive, conf['current'], conf['new'], mrgconf) |
104 |
else: |
107 |
else: |
105 |
mrgfail = dispatch_conf.file_archive(archive, conf['current'], conf['new'], mrgconf) |
108 |
mrgfail = portage.dispatch_conf.file_archive(archive, conf['current'], conf['new'], mrgconf) |
106 |
if os.path.exists(archive + '.dist'): |
109 |
if os.path.exists(archive + '.dist'): |
107 |
unmodified = len(commands.getoutput(DIFF_CONTENTS % (conf['current'], archive + '.dist'))) == 0 |
110 |
unmodified = len(commands.getoutput(DIFF_CONTENTS % (conf['current'], archive + '.dist'))) == 0 |
108 |
else: |
111 |
else: |
Lines 145-221
class dispatch:
Link Here
|
145 |
confs = filter (f, confs) |
148 |
confs = filter (f, confs) |
146 |
|
149 |
|
147 |
# |
150 |
# |
148 |
# Interactively process remaining |
151 |
# No interactive stuff, stop here! |
149 |
# |
152 |
# |
150 |
|
153 |
|
151 |
for conf in confs: |
|
|
152 |
count = count + 1 |
153 |
|
154 |
newconf = conf['new'] |
155 |
mrgconf = re.sub(r'\._cfg', '._mrg', newconf) |
156 |
if os.path.exists(mrgconf): |
157 |
newconf = mrgconf |
158 |
show_new_diff = 0 |
159 |
|
160 |
while 1: |
161 |
if show_new_diff: |
162 |
os.system((self.options['diff']) % (conf['new'], mrgconf)) |
163 |
show_new_diff = 0 |
164 |
else: |
165 |
os.system((self.options['diff']) % (conf['current'], newconf)) |
166 |
|
167 |
print |
168 |
print '>> (%i of %i) -- %s' % (count, len(confs), conf ['current']) |
169 |
print '>> q quit, h help, n next, e edit-new, z zap-new, u use-new\n m merge, t toggle-merge, l look-merge: ', |
170 |
|
171 |
c = getch () |
172 |
|
173 |
if c == 'q': |
174 |
sys.exit (0) |
175 |
if c == 'h': |
176 |
self.do_help () |
177 |
continue |
178 |
elif c == 't': |
179 |
if newconf == mrgconf: |
180 |
newconf = conf['new'] |
181 |
elif os.path.exists(mrgconf): |
182 |
newconf = mrgconf |
183 |
continue |
184 |
elif c == 'n': |
185 |
break |
186 |
elif c == 'm': |
187 |
merged = SCRATCH_DIR+"/"+os.path.basename(conf['current']) |
188 |
print |
189 |
os.system (self.options['merge'] % (merged, conf ['current'], newconf)) |
190 |
shutil.copyfile(merged, mrgconf) |
191 |
os.remove(merged) |
192 |
mystat = os.lstat(conf['new']) |
193 |
os.chmod(mrgconf, mystat[ST_MODE]) |
194 |
os.chown(mrgconf, mystat[ST_UID], mystat[ST_GID]) |
195 |
newconf = mrgconf |
196 |
continue |
197 |
elif c == 'l': |
198 |
show_new_diff = 1 |
199 |
continue |
200 |
elif c == 'e': |
201 |
os.system(os.environ['EDITOR'] + ' ' + newconf) |
202 |
continue |
203 |
elif c == 'z': |
204 |
os.unlink(conf['new']) |
205 |
if os.path.exists(mrgconf): |
206 |
os.unlink(mrgconf) |
207 |
break |
208 |
elif c == 'u': |
209 |
self.replace(newconf, conf ['current']) |
210 |
self.post_process(conf['current']) |
211 |
if newconf == mrgconf: |
212 |
os.unlink(conf['new']) |
213 |
elif os.path.exists(mrgconf): |
214 |
os.unlink(mrgconf) |
215 |
break |
216 |
else: |
217 |
continue |
218 |
|
219 |
|
154 |
|
220 |
def replace (self, newconf, curconf): |
155 |
def replace (self, newconf, curconf): |
221 |
"""Replace current config with the new/merged version. Also logs |
156 |
"""Replace current config with the new/merged version. Also logs |
Lines 232-240
class dispatch:
Link Here
|
232 |
def post_process(self, curconf): |
167 |
def post_process(self, curconf): |
233 |
archive = os.path.join(self.options['archive-dir'], curconf.lstrip('/')) |
168 |
archive = os.path.join(self.options['archive-dir'], curconf.lstrip('/')) |
234 |
if self.options['use-rcs'] == 'yes': |
169 |
if self.options['use-rcs'] == 'yes': |
235 |
dispatch_conf.rcs_archive_post_process(archive) |
170 |
portage.dispatch_conf.rcs_archive_post_process(archive) |
236 |
else: |
171 |
else: |
237 |
dispatch_conf.file_archive_post_process(archive) |
172 |
portage.dispatch_conf.file_archive_post_process(archive) |
238 |
|
173 |
|
239 |
|
174 |
|
240 |
def massage (self, newconfigs): |
175 |
def massage (self, newconfigs): |
Lines 267-306
class dispatch:
Link Here
|
267 |
|
202 |
|
268 |
return configs |
203 |
return configs |
269 |
|
204 |
|
270 |
|
|
|
271 |
def do_help (self): |
272 |
print; print |
273 |
|
274 |
print ' u -- update current config with new config and continue' |
275 |
print ' z -- zap (delete) new config and continue' |
276 |
print ' n -- skip to next config, leave all intact' |
277 |
print ' e -- edit new config' |
278 |
print ' m -- interactively merge current and new configs' |
279 |
print ' l -- look at diff between pre-merged and merged configs' |
280 |
print ' t -- toggle new config between merged and pre-merged state' |
281 |
print ' h -- this screen' |
282 |
print ' q -- quit' |
283 |
|
284 |
print; print 'press any key to return to diff...', |
285 |
|
286 |
getch () |
287 |
|
288 |
|
289 |
def getch (): |
290 |
# from ASPN - Danny Yoo |
291 |
# |
292 |
import sys, tty, termios |
293 |
|
294 |
fd = sys.stdin.fileno() |
295 |
old_settings = termios.tcgetattr(fd) |
296 |
try: |
297 |
tty.setraw(sys.stdin.fileno()) |
298 |
ch = sys.stdin.read(1) |
299 |
finally: |
300 |
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) |
301 |
return ch |
302 |
|
303 |
|
304 |
# run |
205 |
# run |
305 |
d = dispatch () |
206 |
d = dispatch () |
306 |
|
207 |
|