Example #1
0
 def __call__(self, parser, namespace, values, option_string=None):
     cfg_sections = ['main', 'ad']
     for section in cfg_sections:
         sys.stdout.write('[%s]\n' % (section))
         c = configer.read_config(section)
         for key in c:
             sys.stdout.write('%s: %s\n' % (key, c[key]))
         sys.stdout.write('\n')
     parser.exit()
Example #2
0
 def __call__(self, parser, namespace, values, option_string=None):
     if not configer.is_root():
         sys.exit('Script must be run as root')
     cfg_sections = ['main', 'ad', 'callback_plugins']
     for section in cfg_sections:
         sys.stdout.write('[%s]\n' % (section))
         c = configer.read_config(section)
         for key in c:
             sys.stdout.write('%s: %s\n' % (key, c[key]))
         sys.stdout.write('\n')
     parser.exit()
Example #3
0
 def __call__(self, parser, namespace, values, option_string=None):
     if not configer.is_root():
         sys.exit("Script must be run as root")
     cfg_sections = ["main", "ad", "callback_plugins"]
     for section in cfg_sections:
         sys.stdout.write("[%s]\n" % (section))
         c = configer.read_config(section)
         for key in c:
             sys.stdout.write("%s: %s\n" % (key, c[key]))
         sys.stdout.write("\n")
     parser.exit()
Example #4
0
"""logger
================

Handle logging.
"""

import os
import sys
import logging
import logging.handlers

from antslib import configer

CFG = configer.read_config('main')
logfile_main = os.path.join(CFG['log_dir'], 'ants.log')
logfile_ok = os.path.join(CFG['log_dir'], 'ok.log')
logfile_changed = os.path.join(CFG['log_dir'], 'changed.log')
logfile_failed = os.path.join(CFG['log_dir'], 'failed.log')
logfile_recap = os.path.join(CFG['log_dir'], 'recap.log')


def get_logger(name, logfile=False, maxBytes=0, formatter='default'):
    """Return logging object with handler and formatter."""
    if logfile:
        handler = logging.handlers.RotatingFileHandler(logfile,
                                                       maxBytes=maxBytes,
                                                       backupCount=5,
                                                       delay=True)
        handler.setLevel(logging.INFO)
    else:
        handler = logging.StreamHandler(sys.stdout)
Example #5
0
"""logger
================

Handle logging.
"""

import logging
import logging.handlers
import os
import sys

from antslib import configer

CFG = configer.read_config("main")
logfile_main = os.path.join(CFG["log_dir"], "ants.log")
logfile_ok = os.path.join(CFG["log_dir"], "ok.log")
logfile_changed = os.path.join(CFG["log_dir"], "changed.log")
logfile_failed = os.path.join(CFG["log_dir"], "failed.log")
logfile_recap = os.path.join(CFG["log_dir"], "recap.log")


def get_logger(name, logfile=False, maxBytes=0, formatter="default"):
    """Return logging object with handler and formatter."""
    if logfile:
        handler = logging.handlers.RotatingFileHandler(logfile,
                                                       maxBytes=maxBytes,
                                                       backupCount=5,
                                                       delay=True)
        handler.setLevel(logging.INFO)
    else:
        handler = logging.StreamHandler(sys.stdout)