當前位置: 首頁>>代碼示例>>Python>>正文


Python RosePopener.which方法代碼示例

本文整理匯總了Python中rose.popen.RosePopener.which方法的典型用法代碼示例。如果您正苦於以下問題:Python RosePopener.which方法的具體用法?Python RosePopener.which怎麽用?Python RosePopener.which使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rose.popen.RosePopener的用法示例。


在下文中一共展示了RosePopener.which方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: write_source_vc_info

# 需要導入模塊: from rose.popen import RosePopener [as 別名]
# 或者: from rose.popen.RosePopener import which [as 別名]
def write_source_vc_info(run_source_dir, output=None, popen=None):
    """Write version control information of sources used in run time.

    run_source_dir -- The source directory we are interested in.
    output -- An open file handle or a string containing a writable path.
              If not specified, use sys.stdout.
    popen -- A rose.popen.RosePopener instance for running vc commands.
             If not specified, use a new local instance.

    """
    if popen is None:
        popen = RosePopener()
    if output is None:
        handle = sys.stdout
    elif hasattr(output, "write"):
        handle = output
    else:
        handle = open(output, "wb")
    msg = "%s\n" % run_source_dir
    _write_safely(msg, handle)
    environ = dict(os.environ)
    environ["LANG"] = "C"
    for vcs, args_list in [
            ("svn", [
                ["info", "--non-interactive"],
                ["status", "--non-interactive"],
                ["diff", "--internal-diff", "--non-interactive"]]),
            ("git", [["describe"], ["status"], ["diff"]])]:
        if not popen.which(vcs):
            continue
        cwd = os.getcwd()
        os.chdir(run_source_dir)
        try:
            for args in args_list:
                cmd = [vcs] + args
                ret_code, out, _ = popen.run(*cmd, env=environ)
                if out:
                    _write_safely(("#" * 80 + "\n"), handle)
                    _write_safely(("# %s\n" % popen.list_to_shell_str(cmd)),
                                  handle)
                    _write_safely(("#" * 80 + "\n"), handle)
                    _write_safely(out, handle)
                if ret_code:  # If cmd fails once, it will likely fail again
                    break
        finally:
            os.chdir(cwd)
開發者ID:benfitzpatrick,項目名稱:rose,代碼行數:48,代碼來源:run_source_vc.py

示例2: write_source_vc_info

# 需要導入模塊: from rose.popen import RosePopener [as 別名]
# 或者: from rose.popen.RosePopener import which [as 別名]
def write_source_vc_info(run_source_dir, output=None, popen=None):
    """Write version control information of sources used in run time.

    run_source_dir -- The source directory we are interested in.
    output -- An open file handle or a string containing a writable path.
              If not specified, use sys.stdout.
    popen -- A rose.popen.RosePopener instance for running vc commands.
             If not specified, use a new local instance.

    """
    if popen is None:
        popen = RosePopener()
    if output is None:
        handle = sys.stdout
    elif hasattr(output, "write"):
        handle = output
    else:
        handle = open(output, "wb")
    environ = dict(os.environ)
    environ["LANG"] = "C"
    for vcs, cmds in [("svn", ["info", "status", "diff"]),
                      ("git", ["describe", "status", "diff"])]:
        if not popen.which(vcs):
            continue
        cwd = os.getcwd()
        os.chdir(run_source_dir)
        try:
            for cmd in cmds:
                rc, out, err = popen.run(vcs, cmd, env=environ)
                if out:
                    handle.write("#" * 80 + "\n")
                    handle.write(("# %s %s\n" % (vcs, cmd)).upper())
                    handle.write("#" * 80 + "\n")
                    handle.write(out)
                if rc: # If cmd fails once, chances are, it will fail again
                    break
        finally:
            os.chdir(cwd)
開發者ID:ScottWales,項目名稱:rose,代碼行數:40,代碼來源:run_source_vc.py

示例3: except

# 需要導入模塊: from rose.popen import RosePopener [as 別名]
# 或者: from rose.popen.RosePopener import which [as 別名]
    'auto_cli_doc',
    'cylc_lang',
    'minicylc',
    'practical',
    'rose_lang',
    'rose_domain',
    'script_include',
    'sub_lang'
]

# Select best available SVG image converter.
for svg_converter, extension in [
        ('rsvg', 'sphinxcontrib.rsvgconverter'),
        ('inkscape', 'sphinxcontrib.inkscapeconverter')]:
    try:
        assert RosePopener.which(svg_converter)
        __import__(extension)
    except (AssertionError, ImportError):
        # converter or extension not available
        pass
    else:
        extensions.append(extension)
        break
else:
    # no extensions or converters available, fall-back to default
    # vector graphics will be converted to bitmaps in all documents
    extensions.append('sphinx.ext.imgconverter')

# Slide (hieroglyph) settings.
slide_theme = 'single-level'
slide_link_to_html = True
開發者ID:benfitzpatrick,項目名稱:rose,代碼行數:33,代碼來源:conf.py


注:本文中的rose.popen.RosePopener.which方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。