Пример #1
0
def main():
    gconffile = os.environ.get(Consts.ENV_CONF_FILE, Consts.DEFAULT_CONF_FILE)
    if not gconffile or not os.path.exists(gconffile):
        print("configuration file is not found!")
        if os.getuid() == 0 or os.access(os.path.dirname(gconffile), os.W_OK):
            setup_conffile(gconffile)
        else:
            print("set env '%s' for user or run as super user" %
                  Consts.ENV_CONF_FILE)
            exit(-1)
    conf = Conf.CoreConf([gconffile])
    if not conf.isValid():
        print("Any config files is not found.")
        print("Now, generating '%s'. Edit it." % Consts.DEFAULT_CONF_FILE)
        shutil.copy(os.path.join(packagedir, Consts.CONF_FILE_BASE_FILE),
                    Consts.DEFAULT_CONF_FILE)
        return
    args = parser.parse_args()
    volume = args.verbose - args.quiet
    if volume == 0:
        logging.basicConfig(level=logging.CRITICAL)
    elif volume == 1:
        logging.basicConfig(level=logging.WARNING)
    elif 2 <= volume:
        logging.basicConfig(level=logging.DEBUG)
    if (not 'init' in args) or (not args.init):
        sub_init.init(conf)
    (b, msg) = args.handler(conf, args)

    if not b:
        print msg