Esempio n. 1
0
 def register(self):
     duplicate_commands = ''
     for cls in get_subclasses(DBCommand):
         commands = cls.get()
         for command, value in commands.items():
             if command in self._commands:
                 duplicate_commands += ' %s' % command
             self._commands.update({command: value})
     if duplicate_commands:
         raise CommandError('duplicate commands:%s' % duplicate_commands)
Esempio n. 2
0
def available_action_list(include_keyword=True):
    """Available action objects as list
    @param include_keyword: include keyword action or not
    @return a list of action objects
    """
    slist = sorted(get_subclasses(Action), key=lambda action: action.get_id())
    if include_keyword == True:
        return slist
    else:
        return [action for action in slist if action.keyword == None]
Esempio n. 3
0
def available_action_dict(include_keyword=True):
    """Available action objects as dictionary
    @param include_keyword: include keyword action or not
    @return a dictionary of action objects
    """
    clsdict = {}
    for cls in get_subclasses(Action):
        if include_keyword == False and cls.keyword != None:
            continue
        clsdict.update({cls.get_name(): cls})
    return clsdict
Esempio n. 4
0
def reload_janua(signum, stack):
    internal_actions = [
        action for action in get_subclasses(Action)
        if 'janua.actions' in action.__module__
    ]
    log.info('Reload custom actions')
    try:
        reload(janua_action)
        janua_action.action_ref['id'] = len(internal_actions)
    except Exception, err:
        log.error('Failed to reload action: %s', err)
        return
Esempio n. 5
0
 def register(self, db):
     for cls in get_subclasses(AuthBackend):
         backend = cls(db)
         name = backend.name
         self._pool_backend.update({name: backend})
         self._pool_backend_name.append(name)
Esempio n. 6
0
    os.makedirs(bin_dir)

if januapath not in sys.path:
    sys.path.append(januapath)

os.environ['PATH'] = ':'.join([os.environ['PATH'], os.path.join(januapath, 'bin')])

try:
    import_available_modules('custom.engine', januapath)
except Exception, err:
    exit_error('Failed to import custom SMS engine: %s', err)

sms_engines = {}
cfg_spec = configspec

for sms_engine in get_subclasses(SMSEngine):
    if sms_engine.config_spec.startswith('\n'):
        cfg_spec += sms_engine.config_spec
    else:
        cfg_spec += '\n%s' % sms_engine.config_spec
    sms_engines.update({sms_engine.name: sms_engine})

cfg = Config(os.path.join(januapath, 'conf', 'server.cfg'), config_spec=cfg_spec)

try:
    cfg.create()
except Exception, err:
    exit_error('Failed to create configuration file: %s' % err)

try:
    config = cfg.parse()