From c4c3bee8d74abaa8029c01f68e3a49c739a3bc42 Mon Sep 17 00:00:00 2001 From: Sol Jerome Date: Sun, 12 Aug 2012 13:31:26 -0500 Subject: Options: Suppress warnings in bcfg2-admin init The warning for missing bcfg2.conf is just ugly when trying to initialize your bcfg2-server via bcfg2-admin init. This commit prevents us from spamming the new user with irrelevant information. Signed-off-by: Sol Jerome --- src/lib/Bcfg2/Options.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/lib/Bcfg2/Options.py b/src/lib/Bcfg2/Options.py index a1684dac9..d437bf868 100644 --- a/src/lib/Bcfg2/Options.py +++ b/src/lib/Bcfg2/Options.py @@ -1,11 +1,12 @@ """Option parsing library for utilities.""" -import re -import os -import sys import copy -import shlex import getopt +import inspect +import os +import re +import shlex +import sys import Bcfg2.Client.Tools # Compatibility imports from Bcfg2.Bcfg2Py3k import ConfigParser @@ -160,8 +161,14 @@ class OptionSet(dict): self.cfp = DefaultConfigParser() if (len(self.cfp.read(self.cfile)) == 0 and ('quiet' not in kwargs or not kwargs['quiet'])): - print("Warning! Unable to read specified configuration file: %s" % - self.cfile) + # suppress warnings if called from bcfg2-admin init + caller = inspect.stack()[-1][1].split('/')[-1] + if caller == 'bcfg2-admin' and len(sys.argv) > 1: + if sys.argv[1] == 'init': + return + else: + print("Warning! Unable to read specified configuration file: %s" % + self.cfile) def buildGetopt(self): return ''.join([opt.buildGetopt() for opt in list(self.values())]) -- cgit v1.2.3-1-g7c22