|
|
Mirrorselect 1.x written by Colin Kingsley (tercel@gentoo.org) | Mirrorselect 1.x written by Colin Kingsley (tercel@gentoo.org) |
Tool for selecting Gentoo source and rsync mirrors. | Tool for selecting Gentoo source and rsync mirrors. |
""" | """ |
__revision__ = '1.2' |
__revision__ = '1.3' |
| |
import sys | import sys |
import os, time, popen2, re, shutil, signal |
import os, time, popen2, re, shutil, signal, shlex, string |
from HTMLParser import HTMLParser | from HTMLParser import HTMLParser |
from optparse import IndentedHelpFormatter, OptionParser | from optparse import IndentedHelpFormatter, OptionParser |
| |
|
Lines 657-662
def write_config(hosts, out, path, sync=
|
Link Here
|
|---|
|
output.print_info('Done.\n') | output.print_info('Done.\n') |
sys.exit(0) | 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): | def parse_args(argv): |
""" | """ |
|
|
options = parse_args(argv) | options = parse_args(argv) |
output.verbosity = options.verbosity | output.verbosity = options.verbosity |
| |
|
fsmirrors = get_filesystem_mirrors(options.output, config_path, options.rsync) |
hosts = Extractor(list_url, options).hosts | hosts = Extractor(list_url, options).hosts |
| |
if options.interactive: | if options.interactive: |
|
|
else: | else: |
selector = Shallow(hosts, options) | 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__': | if __name__ == '__main__': |