def cmpLogRecords(msg, expected): strStream = StringIO() sHandler = logging.StreamHandler(strStream) log.addHandler(sHandler) log.info(msg) log.removeHandler(sHandler) got = strStream.getvalue() assert got == ("%s\n" % expected), (got, expected)
def __init__(self, script): # Setup error handling stuff first so any errors during driver loading # or the main bits gets handled correctly. global tty6Handler sys.excepthook = lambda type, value, tb: \ exception.handleException(self, (type, value, tb), traceInDetails=False) try: # The scui uses logging to write out user-visible output so we need # another logger for tty6 (which stdout is redirected to by # weasel.py). tty6Handler = logging.StreamHandler(sys.stdout) tty6Handler.setFormatter(formatterForHuman) tty6Handler.setLevel(LOGLEVEL_HUMAN) log.addHandler(tty6Handler) except IOError: #Could not open for writing. Probably not the root user pass self._execute(script)
#!/usr/bin/python """Generator for various formats from a CSV list of IP / hostnames / aliases.""" import sys import argparse import os import pprint try: from log import log except ImportError: import logging log = logging.getLogger() log.addHandler(logging.StreamHandler()) class HostsInfo(object): """Host info class, keeping hostnames, IP addresses, groups and so on.""" def __init__(self, infile): self.hosts = dict() self.groups = dict() log.debug("Initializing hosts object from file '%s'.", infile) self.parse_hostsfile(infile) log.debug("Done initializing hosts object.") def parse_line(self, line): """Split a single line into its tokens (IP, name, aliases, hosts)."""
sys.argv[i] = arg.replace('--', '-') parser = argparse.ArgumentParser(description=__doc__, epilog=epi) add = parser.add_argument # shorthand to improve readability add("--mosaiclog", metavar='FILE', required=True, help='FluoView "MATL_Mosaic.log" XML file with stage positions') add("--templates", required=False, help='path containing the "templates/" subdirectory') add("--dry-run", action="store_true", dest="dryrun", default=False, help="print generated macro but don't run stitcher") add("--verbose", action="count", default=0) try: args = parser.parse_args() except IOError as err: parser.error(str(err)) return args # only run if we're called explicitly from the commandline or as a plugin from # Fiji's menu, this allows being imported in the Jython console for testing # and debugging purposes: if (__name__ == '__main__'): ijlogger = IJLogHandler() log.addHandler(ijlogger) log.warn("FluoView OIF / OIB stitcher (%s)." % imcf.VERSION) log.warn("Arguments (sys.argv): %s" % sys.argv) if (len(sys.argv) > 0): sys.exit(main_noninteractive()) else: main_interactive()