Skip to content

Commit

Permalink
added ability to silence all output -- closes #11
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Kaufman committed Jan 16, 2015
1 parent 5ac9973 commit 1a6119c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
13 changes: 8 additions & 5 deletions fencepy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ def _get_args():
help='Print debug logging')
misc.add_argument('-q', '--quiet', action='store_true',
help='Silence all console output')
misc.add_argument('-s', '--silent', action='store_true',
help='Silence ALL output, including log output')
misc.add_argument("-h", "--help", action="help",
help="Show this help message and exit")

Expand All @@ -69,11 +71,12 @@ def _get_args():
os.mkdir(args['fencepy_root'])

# set up logging
f = l.Formatter('%(asctime)s [%(levelname)s] %(module)s: %(message)s')
h = RotatingFileHandler(os.path.join(args['fencepy_root'], 'fencepy.log'))
h.setFormatter(f)
l.getLogger('').addHandler(h)
if not args['quiet']:
if not args['silent']:
f = l.Formatter('%(asctime)s [%(levelname)s] %(module)s: %(message)s')
h = RotatingFileHandler(os.path.join(args['fencepy_root'], 'fencepy.log'))
h.setFormatter(f)
l.getLogger('').addHandler(h)
if not (args['silent'] or args['quiet']):
f = l.Formatter('[%(levelname)s] %(message)s')
h = l.StreamHandler()
h.setFormatter(f)
Expand Down
6 changes: 4 additions & 2 deletions tests/test_fencepy.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ class TestFencepy(TestCase):

def _fence(self, *args):
# always include the overridden fencepy directory
sys.argv = ['fencepy', '-F', self.fdir] + list(args)
# no logging, since that breaks tests in Windows (with overridden fencepy dir)
sys.argv = ['fencepy', '-F', self.fdir, '-s'] + list(args)
ret = fencepy.fence()
sys.argv = ORIGINAL_ARGV
return ret

def _get_arg_dict(self, *args):
# always include the overridden fencepy directory
sys.argv = ['fencepy', '-F', self.fdir, '-q'] + list(args)
# no logging, since that breaks tests in Windows (with overridden fencepy dir)
sys.argv = ['fencepy', '-F', self.fdir, '-s'] + list(args)
ret = fencepy.main._get_args()
sys.argv = ORIGINAL_ARGV
return ret
Expand Down

0 comments on commit 1a6119c

Please sign in to comment.