def __init__(self, userdata_cls=None): logger.debug("mk backend") cls = self.__class__ if userdata_cls: if isinstance(userdata_cls, str): userdata_cls = minibelt.import_from_path(userdata_cls) else: userdata_cls = cls.get_user_data_cls() if not cls.User: cls.User = get_user_model() self.userdata_cls = userdata_cls
def main(): """ the main function """ args = sys.argv[1:] parser = mk_parser() options = parser.parse_args(args) cmd = options.cmd if not cmd: show_commands(options) return cmd_name = cmd[0] if cmd_name not in cmd_dict: print("ERROR: command %s is unnown:\n" % cmd_name) show_commands(options) sys.exit(255) mod, _help_text = cmd_dict[cmd_name] func = minibelt.import_from_path(mod) sys.argv = args func()
def setup_logging(name=''): """ sets up logging if name is None, then a null logger will be configured otherwise a default logger will be set up """ log_config = os.environ.get('LOG_CONFIG', name) # is no logging desired ? if log_config is None or log_config.lower() is 'none': logger = logging.getLogger('') logger.addHandler(logging.NullHandler()) return if os.path.isfile(log_config): # found a log config file? suffix = os.path.splitext(log_config)[1].lower() if suffix in ['.ini', '.conf']: logging.config.fileConfig(log_config) elif suffix == '.json': with open(log_config) as fin: cfg = json.load(fin) logging.config.dictConfig(cfg) return try: # can I find a log config module ? cfg_module = minibelt.import_from_path(log_config) if hasattr(cfg_module, 'setup_logging'): cfg_module.setup_logging() except: # basic logging of warnings to stderr? logging.basicConfig( stream=sys.stdout, #level=logging.WARNING, level=logging.INFO, format="%(asctime)s %(levelname)-8s %(name)7s: %(message)s", datefmt="%H:%M:%S", )
def get_notifier_cls(cls_name): notifiers[cls_name] = notifier = (notifiers.get(cls_name) or import_from_path(cls_name)) return notifier
def get_probe_cls(cls_name): """ cache for probe modules """ probes[cls_name] = probe = probes.get(cls_name) or import_from_path(cls_name) return probe
def get_user_data_cls(cls): if not cls.UserDataCls: cls.UserDataCls = minibelt.import_from_path(PWDTK_USER_PARAMS) return cls.UserDataCls