当前位置: 首页>>代码示例>>Python>>正文


Python dj_database_url.parse方法代码示例

本文整理汇总了Python中dj_database_url.parse方法的典型用法代码示例。如果您正苦于以下问题:Python dj_database_url.parse方法的具体用法?Python dj_database_url.parse怎么用?Python dj_database_url.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dj_database_url的用法示例。


在下文中一共展示了dj_database_url.parse方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: dump_db

# 需要导入模块: import dj_database_url [as 别名]
# 或者: from dj_database_url import parse [as 别名]
def dump_db(self, destination):
        """
        Dump the database to the given directory and return the path to the file created.
        This creates a gzipped SQL file.
        """
        with self.cd(self.project_root):
            env_file = os.path.join(self.envdir_path, "DATABASE_URL")
            db_credentials = self.run("cat " + env_file, hide=True).stdout.strip()

        db_credentials_dict = dj_database_url.parse(db_credentials)

        if not is_supported_db_engine(db_credentials_dict["ENGINE"]):
            raise NotImplementedError(
                "The dump_db task doesn't support the remote database engine"
            )

        outfile = os.path.join(
            destination, datetime.now().strftime("%Y-%m-%d_%H%M%S.sql.gz")
        )

        self.run(
            "pg_dump -O -x -h '{host}' -U '{user}' '{db}'|gzip > {outfile}".format(
                host=db_credentials_dict["HOST"],
                user=db_credentials_dict["USER"],
                db=db_credentials_dict["NAME"],
                outfile=outfile,
            ),
            env={"PGPASSWORD": db_credentials_dict["PASSWORD"].replace("$", "\$")},
        )

        return outfile 
开发者ID:liip,项目名称:django-template,代码行数:33,代码来源:fabfile.py

示例2: _dj_db_url_parser

# 需要导入模块: import dj_database_url [as 别名]
# 或者: from dj_database_url import parse [as 别名]
def _dj_db_url_parser(value: str, **kwargs) -> dict:
    try:
        import dj_database_url
    except ImportError as error:
        raise RuntimeError(
            "The dj_db_url parser requires the dj-database-url package. "
            "You can install it with: pip install dj-database-url"
        ) from error
    return dj_database_url.parse(value, **kwargs) 
开发者ID:sloria,项目名称:environs,代码行数:11,代码来源:__init__.py

示例3: _dj_email_url_parser

# 需要导入模块: import dj_database_url [as 别名]
# 或者: from dj_database_url import parse [as 别名]
def _dj_email_url_parser(value: str, **kwargs) -> dict:
    try:
        import dj_email_url
    except ImportError as error:
        raise RuntimeError(
            "The dj_email_url parser requires the dj-email-url package. "
            "You can install it with: pip install dj-email-url"
        ) from error
    return dj_email_url.parse(value, **kwargs) 
开发者ID:sloria,项目名称:environs,代码行数:11,代码来源:__init__.py

示例4: _dj_cache_url_parser

# 需要导入模块: import dj_database_url [as 别名]
# 或者: from dj_database_url import parse [as 别名]
def _dj_cache_url_parser(value: str, **kwargs) -> dict:
    try:
        import django_cache_url
    except ImportError as error:
        raise RuntimeError(
            "The dj_cache_url parser requires the django-cache-url package. "
            "You can install it with: pip install django-cache-url"
        ) from error
    return django_cache_url.parse(value, **kwargs) 
开发者ID:sloria,项目名称:environs,代码行数:11,代码来源:__init__.py

示例5: test_url_cast

# 需要导入模块: import dj_database_url [as 别名]
# 或者: from dj_database_url import parse [as 别名]
def test_url_cast(self, set_env, env):
        set_env({"URL": "http://stevenloria.com/projects/?foo=42"})
        res = env.url("URL")
        assert isinstance(res, urllib.parse.ParseResult) 
开发者ID:sloria,项目名称:environs,代码行数:6,代码来源:test_environs.py

示例6: test_dj_db_url

# 需要导入模块: import dj_database_url [as 别名]
# 或者: from dj_database_url import parse [as 别名]
def test_dj_db_url(self, env, set_env):
        db_url = "postgresql://localhost:5432/mydb"
        set_env({"DATABASE_URL": db_url})
        res = env.dj_db_url("DATABASE_URL")
        assert res == dj_database_url.parse(db_url) 
开发者ID:sloria,项目名称:environs,代码行数:7,代码来源:test_environs.py

示例7: test_dj_email_url

# 需要导入模块: import dj_database_url [as 别名]
# 或者: from dj_database_url import parse [as 别名]
def test_dj_email_url(self, env, set_env):
        email_url = "smtp://user@domain.com:pass@smtp.example.com:465/?ssl=True"
        set_env({"EMAIL_URL": email_url})
        res = env.dj_email_url("EMAIL_URL")
        assert res == dj_email_url.parse(email_url) 
开发者ID:sloria,项目名称:environs,代码行数:7,代码来源:test_environs.py

示例8: test_dj_cache_url

# 需要导入模块: import dj_database_url [as 别名]
# 或者: from dj_database_url import parse [as 别名]
def test_dj_cache_url(self, env, set_env):
        cache_url = "redis://redis:6379/0"
        set_env({"CACHE_URL": cache_url})
        res = env.dj_cache_url("CACHE_URL")
        assert res == django_cache_url.parse(cache_url) 
开发者ID:sloria,项目名称:environs,代码行数:7,代码来源:test_environs.py

示例9: import_db

# 需要导入模块: import dj_database_url [as 别名]
# 或者: from dj_database_url import parse [as 别名]
def import_db(c, dump_file=None):
    """
    Restore the given database dump.

    The dump must be a gzipped SQL dump. If the dump_file parameter is not set,
    the database will be dumped and retrieved from the remote host.
    """
    db_credentials = os.environ.get("DATABASE_URL")
    if not db_credentials:
        with open("envdir/DATABASE_URL", "r") as db_credentials_file:
            db_credentials = db_credentials_file.read()
    db_credentials_dict = dj_database_url.parse(db_credentials)

    if not is_supported_db_engine(db_credentials_dict["ENGINE"]):
        raise NotImplementedError(
            "The import_db task doesn't support your database engine"
        )

    if dump_file is None:
        dump_file = fetch_db(c)

    pg_opts_mapping = {
        "-h": db_credentials_dict["HOST"],
        "-U": db_credentials_dict["USER"],
    }
    pg_opts = " ".join(
        [f"{option} '{value}'" for option, value in pg_opts_mapping.items() if value]
    )
    db_name = db_credentials_dict["NAME"]
    db_info = {"pg_opts": pg_opts, "db": db_name}

    env = {"PGPASSWORD": db_credentials_dict["PASSWORD"].replace("$", "\\$")}
    close_sessions_command = """
        psql {pg_opts} template1 -c "
            SELECT pg_terminate_backend(pg_stat_activity.pid)
            FROM pg_stat_activity
            WHERE pg_stat_activity.datname = '{db}' AND pid != pg_backend_pid();
        "
    """.strip()
    c.run(close_sessions_command.format(**db_info), env=env, hide="out")
    c.run("dropdb {pg_opts} '{db}'".format(**db_info), env=env)
    c.run("createdb {pg_opts} '{db}'".format(**db_info), env=env)
    c.run(
        "gunzip -c {db_dump}|psql {pg_opts} '{db}'".format(
            db_dump=dump_file, **db_info
        ),
        env=env,
        hide="out",
    ) 
开发者ID:liip,项目名称:django-template,代码行数:51,代码来源:fabfile.py

示例10: push_code_update

# 需要导入模块: import dj_database_url [as 别名]
# 或者: from dj_database_url import parse [as 别名]
def push_code_update(c, git_ref):
    """
    Synchronize the remote code repository
    """
    with c.conn.cd(c.conn.project_root):
        # First, check that the remote deployment directory exists
        try:
            c.conn.run("test -d .", hide=True)
        except UnexpectedExit:
            raise Exit(
                "Provisioning not finished, directory {} doesn't exist!".format(
                    c.config["root"]
                )
            )
        # Now make sure there's git, and a git repository
        try:
            c.conn.git("--version", hide=True)
        except UnexpectedExit:
            raise Exit("Provisioning not finished, git not available!")

        try:
            c.conn.git("rev-parse --git-dir", hide=True)
        except UnexpectedExit:
            c.conn.git("init")

    git_remote_url = "ssh://{user}@{host}:{port}/{directory}".format(
        user=c.conn.user,
        host=c.conn.host,
        port=c.conn.port,
        directory=c.conn.project_root,
    )
    # Delete the FABHEAD branch
    with c.conn.cd(c.conn.project_root):
        try:
            c.conn.git("branch -D FABHEAD", hide=True)
        except UnexpectedExit:
            pass
        c.conn.git("checkout -f -B FABHEAD master", hide=True)

        # Now push our code to the remote, always as FABHEAD branch
        porcelain.push(".", git_remote_url, "{}:FABHEAD".format(git_ref), force=True)
        c.conn.git("checkout -f -B master FABHEAD", hide=True)
        c.conn.git("submodule update --init", hide=True) 
开发者ID:liip,项目名称:django-template,代码行数:45,代码来源:fabfile.py


注:本文中的dj_database_url.parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。