--- orig.mirrorselect 2007-12-20 18:29:50.000000000 -0500 +++ mirrorselect 2007-12-20 19:09:00.000000000 -0500 @@ -4,10 +4,10 @@ Mirrorselect 1.x written by Colin Kingsley (tercel@gentoo.org) Tool for selecting Gentoo source and rsync mirrors. """ -__revision__ = '1.2' +__revision__ = '1.3' import sys -import os, time, popen2, re, shutil, signal +import os, time, popen2, re, shutil, signal, shlex, string from HTMLParser import HTMLParser from optparse import IndentedHelpFormatter, OptionParser @@ -657,6 +657,54 @@ def write_config(hosts, out, path, sync= output.print_info('Done.\n') sys.exit(0) +def get_filesystem_mirrors(out, path, sync=False): + """ + Read the current mirrors and retain mounted filesystems mirrors + """ + fsmirrors = [] + + if sync: + var = 'SYNC' + else: + var = 'GENTOO_MIRRORS' + + try: + f = open(path,'r') + except IOError,e: + return fsmirrors + + """ Search for 'var' in make.conf and extract value """ + try: + lex = shlex.shlex(f, posix=True) + lex.wordchars=string.digits+string.letters+"~!@#$%*_\:;?,./-+{}" + lex.quotes="\"'" + while 1: + key = lex.get_token() + if key == var: + equ = lex.get_token() + + if (equ == ''): + break; + elif (equ != '='): + break; + + val = lex.get_token() + if val is None: + break; + + """ Look for mounted filesystem in value """ + mirrorlist = val.rsplit() + p = re.compile('rsync://|http://|ftp://',re.IGNORECASE) + for mirror in mirrorlist: + if (p.match(mirror) == None): + fsmirrors.append(mirror) + break + elif key is None: + break + except Exception, e: + fsmirrors = [] + + return fsmirrors def parse_args(argv): """ @@ -785,6 +833,7 @@ def main(argv): options = parse_args(argv) output.verbosity = options.verbosity + fsmirrors = get_filesystem_mirrors(options.output, config_path, options.rsync) hosts = Extractor(list_url, options).hosts if options.interactive: @@ -794,7 +843,7 @@ def main(argv): else: selector = Shallow(hosts, options) - write_config(selector.urls, options.output, config_path, options.rsync) + write_config(fsmirrors + selector.urls, options.output, config_path, options.rsync) if __name__ == '__main__':