示例#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()
示例#2
0
文件: argparser.py 项目: jpmens/ants
 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()
示例#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()
示例#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)
示例#5
0
文件: logger.py 项目: uqperryk/ants
"""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)