def GetConfiguration(): if None == Configuration._ConfigurationInstance: Configuration._ConfigurationInstance = Configuration() return Configuration._ConfigurationInstance
def main(): parser = argparse.ArgumentParser(description='Minion Data Collector.') parser.add_argument("-i", "--input", dest='argFilename', help='specifies input file', type=extant_file, metavar="FILE") parser.add_argument("-v", "--verbose", help="prints information, values 0-3", type=int) parser.add_argument("-r", "--runonce", help="calls all collectors once and exits", action="store_true") parser.add_argument( "-a", "--aliasfile", help="specify an external file that has alias defintions", type=str) try: args = parser.parse_args() if None == args.verbose: _VerboseLevel = 0 else: _VerboseLevel = args.verbose _RunOnce = args.runonce except: return ShowVersion() if not VersionCheck.CheckVersion(): Log.getLogger().error("Invalid version of Python") return if 3 <= _VerboseLevel: Log.setLevel(logging.DEBUG) elif 2 == _VerboseLevel: Log.setLevel(logging.WARNING) elif 1 == _VerboseLevel: Log.setLevel(logging.INFO) else: Log.setLevel(logging.ERROR) curr_dir_path = os.path.dirname(os.path.realpath(__file__)) Alias.AliasMgr.AddAlias("WORKING_DIR", curr_dir_path) Alias.AliasMgr.AddEnvironmentVariables() if None != args.aliasfile: if not Alias.AliasMgr.LoadExternalAliasFile(args.aliasfile): return signal.signal( signal.SIGINT, signal.SIG_IGN ) # turn of Ctrl+C signal handler (will get inherted by sub processes if not os.path.exists(_ConfigFilename): Log.getLogger().error("Config file [" + _ConfigFilename + "] not found!") return config = Configuration.Configuration(_ConfigFilename, True) if None == config or not config.IsValid(): pass else: print("Starting Collectors...") totalCollectors = 0 for namespace in config.GetNamespaces(): totalCollectors += namespace.Begin(_RunOnce) signal.signal(signal.SIGINT, signal_handler) # make my own Ctrl+C handler now print(str(totalCollectors) + " Collectors started.") if False == _RunOnce: print("Press CTRL+C to Exit") else: print("Running Once") if False == _RunOnce: while _ThreadActive: if 0 == _VerboseLevel: for c in spinning_cursor(): countStr = '[' + str(config.GetCollectorCount()) + '] ' sys.stdout.write(countStr) sys.stdout.write(c) Sleep.SleepMs(100) sys.stdout.flush() sys.stdout.write('\b') for c in countStr: sys.stdout.write('\b') else: Sleep.SleepMs(100) print("Shutting down...") try: ThreadManager.GetThreadManager().StopAllThreads() except: pass