diff options
author | Arun Raghavan <ford_prefect@gentoo.org> | 2009-08-05 23:37:03 +0530 |
---|---|---|
committer | Arun Raghavan <ford_prefect@gentoo.org> | 2009-08-05 23:37:03 +0530 |
commit | 7252fa1927374bee410c49ad53fddb1b4b3fee82 (patch) | |
tree | 2cb55a6802c3e2e23b69eb556f69070206bece9e | |
parent | Fix releases timestamp check (missing '/') (diff) | |
download | gard-7252fa1927374bee410c49ad53fddb1b4b3fee82.tar.gz gard-7252fa1927374bee410c49ad53fddb1b4b3fee82.tar.bz2 gard-7252fa1927374bee410c49ad53fddb1b4b3fee82.zip |
Make log outputs more parseable - should make wrangling easier
-rw-r--r-- | check.py | 2 | ||||
-rwxr-xr-x | gard-v2.py | 49 |
2 files changed, 31 insertions, 20 deletions
@@ -18,7 +18,7 @@ class GardCheck: self.url = url.rstrip('/') if log: - self.logger = logging.getLogger('') + self.logger = logging.getLogger() else: self.logger = None @@ -25,19 +25,27 @@ HOME = os.getenv('HOME') reportpath = HOME + "/gentoo/mirrors/gard/reports" bugurl = "http://bugs.gentoo.org/buglist.cgi?query_format=advanced&product=Mirrors&status_whiteboard_type=allwordssubstr&status_whiteboard=due&bug_status=ASSIGNED&columnlist=bug_id,opendate,bug_status,resolution,short_desc,status_whiteboard&ctype=csv" -logformat = '%(levelname)s:\t%(message)s' -logging.basicConfig(stream=sys.stdout, level=logging.DEBUG, format=logformat) +def start_logging(logfile, bugnum, proto): + logger = logging.getLogger() + logger.setLevel(logging.INFO) + + logformat = '%(levelname)s\t%(message)s' + format = '%s\t%s\t%s' % (bugnum, proto, logformat) + formatter = logging.Formatter(format) + + console = logging.StreamHandler(sys.stdout) + console.setFormatter(formatter) + logger.addHandler(console) -def add_handler(logfile): file = logging.FileHandler(logfile) - file.setLevel(logging.INFO) - formatter = logging.Formatter(logformat) file.setFormatter(formatter) - logging.getLogger('').addHandler(file) - return file + logger.addHandler(file) + + return (console, file) -def remove_handler(handler): - logging.getLogger('').removeHandler(handler) +def stop_logging(handlerss): + for handler in handlers: + logging.getLogger().removeHandler(handler) # See if we got a specific bug number to check if (len(sys.argv) == 2): @@ -48,8 +56,6 @@ _ = urllib2.urlopen(bugurl) file = _.readlines() _.close() -logging.debug("Initializing G(entoo)A(utomated)R(sync)D(istfiles) checker script, version 2 (Katrina) - kicking mirror ass for Gentoo") - # Format of CSV = 234083,"2008-08-06 13:01:32","ASSIGNED",,"[rsync,distfiles|all] New mirror Cambrium BV (The Netherlands)","due:2008/09/01;dist:http://mirror.cambrium.nl/pub/os/linux/gentoo/|ftp://mirror.cambrium.nl/pub/os/linux/gentoo/|rsync://mirror.cambrium.nl/gentoo/;portage:mirror.cambrium.nl" for line in file: @@ -90,7 +96,9 @@ for line in file: pass else: os.makedirs(reportpath) - handler = add_handler(fname) + + handlers = start_logging(fname, bugnum, 'rsync') + info4=grsync+" wants to be a gentoo-portage mirror and is being checked as per Bug #"+bugnum logging.info(info4) prsync = 'rsync://%s/' % addy @@ -105,14 +113,14 @@ for line in file: # New line for the prettiness logging.info('') - remove_handler(handler) + stop_logging(handlers) if len(http) > 0: fname=reportpath+"/"+addy if os.path.isdir(reportpath): pass else: os.makedirs(reportpath) - handler = add_handler(fname) + handlers = start_logging(fname, bugnum, 'http ') info5 = addy+" wants to be source mirror and is being checked as per Bug #"+bugnum+ " over http" logging.info(info5) @@ -131,14 +139,16 @@ for line in file: # New line for the prettiness logging.info('') - remove_handler(handler) + stop_logging(handlers) if len(ftp) > 0: fname=reportpath+"/"+addy if os.path.isdir(reportpath): pass else: os.makedirs(reportpath) - add_handler(fname) + + handlers = start_logging(fname, bugnum, 'ftp ') + info6 = addy+" wants to be a source mirror and is being checked as per Bug #"+bugnum+ " over ftp" logging.info(info6) @@ -157,7 +167,7 @@ for line in file: # New line for the prettiness logging.info('') - remove_handler(handler) + stop_logging(handlers) if len(drsync) > 0: # Replace with check.DistfilesCheck(drsyync).check() # after testing @@ -166,7 +176,8 @@ for line in file: pass else: os.makedirs(reportpath) - add_handler(fname) + + handlers = start_logging(fname, bugnum, 'rsync') info7 = addy+" wants to be a source mirror and is being checked as per Bug #"+bugnum+ " over rsync" logging.info(info7) @@ -182,4 +193,4 @@ for line in file: # New line for the prettiness logging.info('') - remove_handler(handler) + stop_logging(handlers) |