--- dispatch-conf 2004-11-08 21:29:29.781212896 -0500 +++ new.dispatch-conf 2004-11-08 21:34:30.389513488 -0500 @@ -14,15 +14,16 @@ from stat import * from random import * +from output import * import os, shutil, sys, string, re, commands, atexit sys.path = ["/usr/lib/portage/pym"]+sys.path import portage, dispatch_conf FIND_EXTANT_CONFIGS = "find %s/ -iname '._cfg????_*' | sed -e 's://:/:g'" -DIFF_CONTENTS = 'diff -Nau %s %s' -DIFF_CVS_INTERP = 'diff -Nau %s %s | grep "^[+-][^+-]" | grep -v "# .Header:.*"' -DIFF_WSCOMMENTS = 'diff -Nau %s %s | grep "^[+-][^+-]" | grep -v "^[-+]#" | grep -v "^[-+][:space:]*$"' +DIFF_CONTENTS = 'diff -Nu %s %s' +DIFF_CVS_INTERP = 'diff -Nu %s %s | grep "^[+-][^+-]" | grep -v "# .Header:.*"' +DIFF_WSCOMMENTS = 'diff -Nu %s %s | grep "^[+-][^+-]" | grep -v "^[-+]#" | grep -v "^[-+][:space:]*$"' MERGE = 'sdiff --suppress-common-lines --output=%s %s %s' # We need a secure scratch dir and python does silly verbose errors on the use of tempnam @@ -88,6 +89,52 @@ return False + # config file freezing support and command like opts for "emerge like" previewing + frozenfiles = [] + if self.options.has_key('frozen'): + frozenfiles = self.options['frozen'].split() + + # -s "show" option to show frozen config files + if '-s' in sys.argv[1:]: + if frozenfiles == []: + print bold('\nNo config files are frozen\n') + sys.exit(0) + else: + print darkgreen('\nThese config files have been frozen:\n') + for file in frozenfiles: + print file + print + sys.exit(0) + + # -f "force" option to allow ignoring of frozen config files + if '-f' in sys.argv[1:]: + frozenfiles = [] + + # -p and -a for "pretend" and "ask", nice color emerge-like output + # new files are in green, frozen files are in blue and followed by a * (for colorless pipe into non-ttys) + # ask is like emerge --ask, it shows a pretend, then asks yes or no to continue or stop + if '-p' in sys.argv[1:] or '-a' in sys.argv[1:]: + if confs == []: + print bold('\nNo files to update\n') + sys.exit(0) + print darkgreen('\nNew files are green, frozen files are blue and followed by a *\nThese are the files that will be updated:\n') + for file in confs: + if file['current'] in frozenfiles: + print blue(file['current'])+'*' + else: + print green(file['current']) + if (not sys.stdout.isatty()) or '-p' in sys.argv[1:]: + print + sys.exit(0) + else: + if '-c' in sys.argv[1:]: + prompt = '\nOverwrite all new files only keeping protected files?' + else: + prompt = '\nInteractivly update these config files?' + if ask(prompt) == 'No': + sys.exit('\nQuitting.\n') + + # # Remove new configs identical to current # and @@ -125,13 +172,15 @@ same_wsc = same_wsc and self.options['replace-wscomments'] == 'yes' unmodified = unmodified and self.options['replace-unmodified'] == 'yes' - if same_file: + # check to keep frozen files + if same_file or conf['current'] in frozenfiles: os.unlink (conf ['new']) self.post_process(conf['current']) if os.path.exists(mrgconf): os.unlink(mrgconf) return False - elif unmodified or same_cvs or same_wsc or conf ['dir'] in portage.settings ['CONFIG_PROTECT_MASK'].split (): + # -c to overwrite all files + elif unmodified or same_cvs or same_wsc or conf ['dir'] in portage.settings ['CONFIG_PROTECT_MASK'].split () or '-c' in sys.argv[1:]: self.replace(newconf, conf['current']) self.post_process(conf['current']) if newconf == mrgconf: @@ -298,12 +347,36 @@ termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) return ch +# simplified prompt function from emerge +def ask(prompt): + """promt = string, this string is the question that will be asked of the user + + ask function, mostly taken from the emerge function userquery + + this function returns (string) Yes or No depending on the users Yes / No response""" + responses = [ 'Yes', 'No' ] + print bold(prompt), + try: + while True: + response = raw_input('[' + green(responses[0]) + '/' + red(responses[1]) + ']') + for key in responses: + if response.upper() == key[:len(response)].upper(): + return key + print "Sorry, response '%s' not understood." % response, + except (EOFError, KeyboardInterrupt): + print "Interrupted." + sys.exit(1) + # run d = dispatch () -if len(sys.argv) > 1: - # for testing - d.grind (string.join (sys.argv [1:])) +# color stuff for ttys but not non-ttys +if (not sys.stdout.isatty()) or (portage.settings["NOCOLOR"] in ["yes","true"]): + nocolor() + +if '-t' in sys.argv[1:]: + # -t for testing + d.grind (sys.argv [sys.argv.index('-t') + 1]) else: d.grind (portage.settings ['CONFIG_PROTECT'])