wordpress_install.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:netsocadmin2 作者: UCCNetworkingSociety 项目源码 文件源码
def create_wordpress_conf(user_dir, db_conf):
    """
    Used to generate a new wordpress configuration file from a jinja2 template.
    Pulls the configuration keys from the wordpress API and injects them into the template.
    Injects the database configuration returned from create_wordpress_database into database details of the template.
    Writes the newly templated configuration file into the wordpress directory.
    """
    logger.debug("Generating wordpress configuration")

    env = Environment(loader=PackageLoader('wordpress_installer', '/resources/templates'))
    template = env.get_template('wp-config.php.j2')     

    def get_wordpress_conf_keys():
        logger.debug("Fetching wordpress configuration")
        response = requests.get("https://api.wordpress.org/secret-key/1.1/salt/")
        return response.text

    wordpress_config = template.render(USER_DIR=user_dir,
                                                DB_NAME=db_conf["db"],
                                                DB_USER=db_conf["user"],
                                                DB_PASSWORD=db_conf["password"],
                                                DB_HOST=db_conf["host"],
                                                KEYS=get_wordpress_conf_keys())
    logger.debug("Wordpress configuration rendered from template, writing to file")

    with open(user_dir + "/public_html/wordpress/wp-config.php", "w") as fh:
        fh.write(wordpress_config)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号