from util.config import options, define from util import importutils define('--db_driver', name='db_driver', type='string') class DBBase(object): """DB driver is injected in the init method.""" def __init__(self, db_driver=None): if not db_driver: db_driver=options.db_driver self.db=importutils.import_module(db_driver) super(DBBase, self).__init__()
''' Created on 2013-2-25 @author: zhangbin ''' import os import re from util.config import options, define define('--nginx_conf_path', name='nginx_conf_path', type='string') class DomainEditor(object): ''' classdocs ''' def __init__(self, DomainName): ''' Constructor ''' self.DomainName = DomainName self.ofd = open(options.nginx_conf_path+DomainName+'.conf', 'r+') self.nfd = file(options.nginx_conf_path+DomainName+'-new.conf', 'w+') def addDNS(self, name, ip, port): ''' ''' if self.findDNS(name): return False
''' Created on 2013-4-1 @author: zhangbin ''' import os import logging import logging.handlers import traceback from util.config import options, define define('--log-dir', name='logdir', type='string') def setup(product_name): try: log_dir = options.logdir if not log_dir: log_dir = os.path.normpath(os.path.join(__file__, os.pardir, os.pardir, os.pardir, 'log')) logger=logging.getLogger() logger.setLevel(logging.DEBUG) formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(module)s.%(funcName)s:%(lineno)d - %(message)s', '') _console=logging.StreamHandler(); _file=logging.FileHandler(log_dir+'/'+product_name+'.log') _file.setFormatter(formatter) _console.setFormatter(formatter)
''' Created on 2013-2-26 @author: zhangbin ''' import os import re from subprocess import Popen, PIPE from util.config import options, define define('--nginx_bin_path', name='nginx_bin_path', type='string') class NginxController(object): ''' classdocs ''' def __init__(self, DomainName): ''' Constructor ''' self.DomainName = DomainName def _TestConf(self): f = Popen((options.nginx_bin_path+'nginx', '-t'), stderr=PIPE).stderr err = f.read() regex = re.compile('test is successful') ret = re.search(regex, err)