--- dispatch-conf 2012-05-21 14:23:51.000000000 +0000 +++ dispatch-conf-auto 2012-05-21 14:22:36.000000000 +0000 @@ -1,7 +1,7 @@ #!/usr/bin/python -O -# Copyright 1999-2004 Gentoo Foundation +# Copyright 1999-2006 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo-src/portage/bin/dispatch-conf,v 1.7.2.10 2005/05/12 15:20:22 jstubbs Exp $ +# $Id: /var/cvsroot/gentoo-src/portage/bin/dispatch-conf,v 1.7.2.10 2005/05/12 15:20:22 jstubbs Exp $ # # dispatch-conf -- Integrate modified configs, post-emerge @@ -17,7 +17,7 @@ from random import * import os, shutil, sys, string, re, commands, atexit sys.path = ["/usr/lib/portage/pym"]+sys.path -import portage, dispatch_conf +import portage, portage.dispatch_conf FIND_EXTANT_CONFIGS = "find %s/ -iname '._cfg????_*' | sed -e 's://:/:g'" DIFF_CONTENTS = 'diff -Nu %s %s' @@ -48,7 +48,7 @@ os.umask(oldmask) # Ensure the scratch dir is deleted def cleanup(mydir=SCRATCH_DIR): - shutil.rmtree(SCRATCH_DIR) + shutil.rmtree(mydir) atexit.register(cleanup) MANDATORY_OPTS = [ 'archive-dir', 'diff', 'replace-cvs', 'replace-wscomments', 'merge' ] @@ -61,12 +61,15 @@ class dispatch: count = 0 - self.options = dispatch_conf.read_config(MANDATORY_OPTS) + self.options = portage.dispatch_conf.read_config(MANDATORY_OPTS) if self.options.has_key("log-file"): - if os.path.exists(self.options["log-file"]): - shutil.copyfile(self.options["log-file"], self.options["log-file"] + '.old') - os.remove(self.options["log-file"]) + if os.path.isfile(self.options["log-file"]): + shutil.copy(self.options["log-file"], self.options["log-file"] + '.old') + if os.path.isfile(self.options["log-file"]) \ + or not os.path.exists(self.options["log-file"]): + open(self.options["log-file"], 'w').close() # Truncate it + os.chmod(self.options["log-file"], 0600) else: self.options["log-file"] = "/dev/null" @@ -100,9 +103,9 @@ class dispatch: mrgconf = re.sub(r'\._cfg', '._mrg', conf['new']) archive = os.path.join(self.options['archive-dir'], conf['current'].lstrip('/')) if self.options['use-rcs'] == 'yes': - mrgfail = dispatch_conf.rcs_archive(archive, conf['current'], conf['new'], mrgconf) + mrgfail = portage.dispatch_conf.rcs_archive(archive, conf['current'], conf['new'], mrgconf) else: - mrgfail = dispatch_conf.file_archive(archive, conf['current'], conf['new'], mrgconf) + mrgfail = portage.dispatch_conf.file_archive(archive, conf['current'], conf['new'], mrgconf) if os.path.exists(archive + '.dist'): unmodified = len(commands.getoutput(DIFF_CONTENTS % (conf['current'], archive + '.dist'))) == 0 else: @@ -145,77 +148,9 @@ class dispatch: confs = filter (f, confs) # - # Interactively process remaining + # No interactive stuff, stop here! # - for conf in confs: - count = count + 1 - - newconf = conf['new'] - mrgconf = re.sub(r'\._cfg', '._mrg', newconf) - if os.path.exists(mrgconf): - newconf = mrgconf - show_new_diff = 0 - - while 1: - if show_new_diff: - os.system((self.options['diff']) % (conf['new'], mrgconf)) - show_new_diff = 0 - else: - os.system((self.options['diff']) % (conf['current'], newconf)) - - print - print '>> (%i of %i) -- %s' % (count, len(confs), conf ['current']) - 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: ', - - c = getch () - - if c == 'q': - sys.exit (0) - if c == 'h': - self.do_help () - continue - elif c == 't': - if newconf == mrgconf: - newconf = conf['new'] - elif os.path.exists(mrgconf): - newconf = mrgconf - continue - elif c == 'n': - break - elif c == 'm': - merged = SCRATCH_DIR+"/"+os.path.basename(conf['current']) - print - os.system (self.options['merge'] % (merged, conf ['current'], newconf)) - shutil.copyfile(merged, mrgconf) - os.remove(merged) - mystat = os.lstat(conf['new']) - os.chmod(mrgconf, mystat[ST_MODE]) - os.chown(mrgconf, mystat[ST_UID], mystat[ST_GID]) - newconf = mrgconf - continue - elif c == 'l': - show_new_diff = 1 - continue - elif c == 'e': - os.system(os.environ['EDITOR'] + ' ' + newconf) - continue - elif c == 'z': - os.unlink(conf['new']) - if os.path.exists(mrgconf): - os.unlink(mrgconf) - break - elif c == 'u': - self.replace(newconf, conf ['current']) - self.post_process(conf['current']) - if newconf == mrgconf: - os.unlink(conf['new']) - elif os.path.exists(mrgconf): - os.unlink(mrgconf) - break - else: - continue - def replace (self, newconf, curconf): """Replace current config with the new/merged version. Also logs @@ -232,9 +167,9 @@ class dispatch: def post_process(self, curconf): archive = os.path.join(self.options['archive-dir'], curconf.lstrip('/')) if self.options['use-rcs'] == 'yes': - dispatch_conf.rcs_archive_post_process(archive) + portage.dispatch_conf.rcs_archive_post_process(archive) else: - dispatch_conf.file_archive_post_process(archive) + portage.dispatch_conf.file_archive_post_process(archive) def massage (self, newconfigs): @@ -267,40 +202,6 @@ class dispatch: return configs - - def do_help (self): - print; print - - print ' u -- update current config with new config and continue' - print ' z -- zap (delete) new config and continue' - print ' n -- skip to next config, leave all intact' - print ' e -- edit new config' - print ' m -- interactively merge current and new configs' - print ' l -- look at diff between pre-merged and merged configs' - print ' t -- toggle new config between merged and pre-merged state' - print ' h -- this screen' - print ' q -- quit' - - print; print 'press any key to return to diff...', - - getch () - - -def getch (): - # from ASPN - Danny Yoo - # - import sys, tty, termios - - fd = sys.stdin.fileno() - old_settings = termios.tcgetattr(fd) - try: - tty.setraw(sys.stdin.fileno()) - ch = sys.stdin.read(1) - finally: - termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) - return ch - - # run d = dispatch ()