Пример #1
0
def _getRulesPath():
    d = config.get('rulesdir')
    if not d:
        raise Exception('Must configure main.rulesdir in chains.conf')
    if not os.path.exists(d):
        raise Exception('No such rulesdir: %s' % d)
    return d
Пример #2
0
def _getLogPath(serviceId, filename=None):
    '''Get path to log dir or file for service(s)'''
    dir = '%s/services' % _config.get('logdir')
    if filename: dir += '/' + serviceId
    if not os.path.exists(dir):
        os.makedirs(dir)
    if not filename: filename = '%s.log' % serviceId
    return '%s/%s' % (dir, filename)
Пример #3
0
def _getClassConfigPath(serviceClass=None):
    '''Get path to config dir or file for service class(es)'''
    f = '%s/config/service-classes' % _config.get('libdir')
    if not os.path.exists(f):
        os.makedirs(f)
    if serviceClass:
        f = '%s/%s.conf' % (f, serviceClass)
    return f
Пример #4
0
 def onInit(self):
     self.loggers = {}
     self.logdir = ''
     # Get relative or absolute logdir from config
     try:
         self.logdir = self.config.get('logdir')
     # Use blank if not defined
     except KeyError:
         pass
     # Get absolute logdir
     if not self.logdir or self.logdir == '':
         # Log path root if logdir explicitly defined as empty
         self.logdir = config.get('logdir')
     elif self.logdir[0] != '/':
         # Or log path + logdir if logdir defined
         self.logdir = '%s/%s' % (config.get('logdir'), self.logdir)
     # Or absolute path if logdir starts with /
     log.info('Using logdir: %s' % self.logdir)
Пример #5
0
 def onInit(self):
     self.loggers = {}
     self.logdir = ''
     # Get relative or absolute logdir from config
     try:
         self.logdir = self.config.get('logdir')
     # Use blank if not defined
     except KeyError:
         pass
     # Get absolute logdir
     if not self.logdir or self.logdir == '':
         # Log path root if logdir explicitly defined as empty
         self.logdir = config.get('logdir')
     elif self.logdir[0] != '/':
         # Or log path + logdir if logdir defined
         self.logdir = '%s/%s' % (config.get('logdir'), self.logdir)
     # Or absolute path if logdir starts with /
     log.info('Using logdir: %s' % self.logdir)
Пример #6
0
def getCommandDirs():
    dirs = []

    # If user has configured custom commands dir
    items = config.data('commandline')
    if items:
        for key in items:
            tmp = key.split('.')
            if len(tmp) == 2 and tmp[0] == 'commands':
                dirs.append( items[key] + '/commands' )

    # Build in commands
    dirs.append( config.get('libdir') + '/commandline/commands' )

    return dirs
Пример #7
0
def getUuidFile(serviceId):
    dir = '%s/service-uuids' % _config.get('datadir')
    if not os.path.exists(dir):
        os.makedirs(dir)
    return '%s/%s' % (dir, serviceId)
Пример #8
0
def getSharePath(serviceClass):
    '''Get path to a service's share dir'''
    dir = '%s/services/%s' % (_config.get('sharedir'), serviceClass)
    if not os.path.exists(dir):
        os.makedirs(dir)
    return dir
Пример #9
0
def getDataPath(serviceId):
    '''Get path to a service's data dir'''
    dir = '%s/services/%s' % (_config.get('datadir'), serviceId)
    if not os.path.exists(dir):
        os.makedirs(dir)
    return dir
Пример #10
0
def setFileName(name):
    if not os.path.exists(config.get("logdir")):
        os.makedirs(config.get("logdir"))
    setFilePath(config.get("logdir") + "/" + name + ".log")
Пример #11
0
        for item in arg:
            result.append(formatMessageItem(item))
        return json.dumps(result)
    else:
        return json.dumps(arg)


# can pass f.ex. __name__ to getLogger() to get per-module logmsgs,
# but we don't initialize logger from inside modules
logger = logging.getLogger()

# Start with a basic print-to-console handler

consoleHandler = logging.StreamHandler()
# formatter = logging.Formatter('%(asctime)s   %(levelname)-10s %(name)-20s %(message)s')
formatter = logging.Formatter("%(asctime)s   %(levelname)-10s %(message)s")
consoleHandler.setFormatter(formatter)
logger.addHandler(consoleHandler)


level = config.get("loglevel")
setLevel(level)


if __name__ == "__main__":
    print "loglevel: %s" % level
    debug("debug")
    info("info")
    warn("warn")
    error("error")
Пример #12
0
 def getDataDir(self):
     serviceId = self.get('id')
     dir = '%s/services/%s' % (_config.get('datadir'), serviceId)
     if not os.path.exists(dir):
         os.makedirs(dir)
     return dir
Пример #13
0
 def getDataDir(self):
     serviceId = self.get('id')
     dir = '%s/services/%s' % (_config.get('datadir'), serviceId)
     if not os.path.exists(dir):
         os.makedirs(dir)
     return dir