• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python path.which函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中monty.os.path.which函数的典型用法代码示例。如果您正苦于以下问题:Python which函数的具体用法?Python which怎么用?Python which使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: run_task

    def run_task(self, fw_spec):

        fw_env = fw_spec.get("_fw_env", {})

        if "mpi_cmd" in fw_env:
            mpi_cmd = fw_spec["_fw_env"]["mpi_cmd"]
        elif which("mpirun"):
            mpi_cmd = "mpirun"
        elif which("aprun"):
            mpi_cmd = "aprun"
        else:
            raise ValueError("No MPI command found!")

        nproc = os.environ['PBS_NP']

        v_exe = shlex.split('{} -n {} {}'.format(mpi_cmd, nproc, fw_env.get("vasp_cmd", "vasp")))
        gv_exe = shlex.split('{} -n {} {}'.format(mpi_cmd, nproc, fw_env.get("gvasp_cmd", "gvasp")))

        # override vasp executable in custodian jobs
        for job in self.jobs:
            job.vasp_cmd = v_exe
            job.gamma_vasp_cmd = gv_exe

        # run the custodian
        c = Custodian(self.handlers, self.jobs, self.max_errors)
        c.run()

        update_spec = {'prev_vasp_dir': os.getcwd(),
                       'prev_task_type': fw_spec['task_type']}

        return FWAction(update_spec=update_spec)
开发者ID:aykol,项目名称:MPWorks,代码行数:31,代码来源:firetasks_ex.py


示例2: run_task

    def run_task(self, fw_spec):

        # write a file containing the formula and task_type for somewhat
        # easier file system browsing
        self._write_formula_file(fw_spec)

        fw_env = fw_spec.get("_fw_env", {})

        if "mpi_cmd" in fw_env:
            mpi_cmd = fw_spec["_fw_env"]["mpi_cmd"]
        elif which("mpirun"):
            mpi_cmd = "mpirun"
        elif which("aprun"):
            mpi_cmd = "aprun"
        else:
            raise ValueError("No MPI command found!")

        nproc = os.environ['PBS_NP']

        v_exe = shlex.split('{} -n {} {}'.format(mpi_cmd, nproc, fw_env.get("vasp_cmd", "vasp")))
        gv_exe = shlex.split('{} -n {} {}'.format(mpi_cmd, nproc, fw_env.get("gvasp_cmd", "gvasp")))

        print 'host:', os.environ['HOSTNAME']

        for job in self.jobs:
            job.vasp_cmd = v_exe
            job.gamma_vasp_cmd = gv_exe

        incar_errors = check_incar(fw_spec['task_type'])
        if incar_errors:
            raise ValueError("Critical error: INCAR does not pass checks: {}".format(incar_errors))

        logging.basicConfig(level=logging.DEBUG)
        c = Custodian(self.handlers, self.jobs, max_errors=self.max_errors, gzipped_output=False, validators=[VasprunXMLValidator()])  # manual gzip
        custodian_out = c.run()

        if self.gzip_output:
            for f in os.listdir(os.getcwd()):
                if not f.lower().endswith("gz") and not f.endswith(".OU") and not f.endswith(".ER"):
                    with open(f, 'rb') as f_in, \
                            GzipFile('{}.gz'.format(f), 'wb') as f_out:
                        f_out.writelines(f_in)
                    os.remove(f)

        all_errors = set()
        for run in custodian_out:
            for correction in run['corrections']:
                all_errors.update(correction['errors'])

        stored_data = {'error_list': list(all_errors)}
        update_spec = {'prev_vasp_dir': os.getcwd(),
                       'prev_task_type': fw_spec['task_type'],
                       'mpsnl': fw_spec['mpsnl'],
                       'snlgroup_id': fw_spec['snlgroup_id'],
                       'run_tags': fw_spec['run_tags'],
                       'parameters': fw_spec.get('parameters')}

        return FWAction(stored_data=stored_data, update_spec=update_spec)
开发者ID:ctoher,项目名称:MPWorks,代码行数:58,代码来源:custodian_task.py


示例3: write_open_notebook

def write_open_notebook(flow, options):
    """
    Generate an ipython notebook and open it in the browser.
    Return system exit code.

    See also:
        http://nbviewer.jupyter.org/github/maxalbert/auto-exec-notebook/blob/master/how-to-programmatically-generate-and-execute-an-ipython-notebook.ipynb
    """
    import nbformat
    nbf = nbformat.v4
    nb = nbf.new_notebook()

    nb.cells.extend([
        #nbf.new_markdown_cell("This is an auto-generated notebook for %s" % os.path.basename(pseudopath)),
        nbf.new_code_cell("""\
##%%javascript
##IPython.OutputArea.auto_scroll_threshold = 9999;

from __future__ import print_function, division, unicode_literals
from abipy import abilab
%matplotlib notebook

import pylab
pylab.rcParams['figure.figsize'] = (25.0, 10.0)
import seaborn as sns"""),

        nbf.new_code_cell("flow = abilab.Flow.pickle_load('%s')" % flow.workdir),
        nbf.new_code_cell("flow.show_dependencies()"),
        nbf.new_code_cell("flow.check_status(show=True, verbose=0)"),
        nbf.new_code_cell("flow.show_inputs(nids=None, wslice=None)"),
        nbf.new_code_cell("flow.inspect(nids=None, wslice=None)"),
        nbf.new_code_cell("flow.show_abierrors()"),
        nbf.new_code_cell("flow.show_qouts()"),
    ])

    # Next, we write it to a file on disk that we can then open as a new notebook.
    # Note: This should be as easy as: nbf.write(nb, fname), but the current api
    # is a little more verbose and needs a real file-like object.
    import tempfile, io
    _, nbpath = tempfile.mkstemp(suffix='.ipynb', text=True)

    with io.open(nbpath, 'wt', encoding="utf8") as f:
        nbformat.write(nb, fh)

    if which("jupyter") is not None:
        return os.system("jupyter notebook %s" % nbpath)

    if which("ipython") is not None:
        return os.system("ipython notebook %s" % nbpath)

    raise RuntimeError("Cannot find neither jupyther nor ipython. Install them with `pip install`")
开发者ID:temok-mx,项目名称:abipy,代码行数:51,代码来源:abirun.py


示例4: __init__

    def __init__(self, input_str, calc_type, workdir=None):
        super(OncvGenerator, self).__init__(workdir=workdir)
        self._input_str = input_str
        self.calc_type = calc_type

        calctype2exec = {
            "non-relativistic": which("oncvpspnr.x"),
            "scalar-relativistic": which("oncvpsp.x"),
            "fully-relativistic": which("oncvpspr.x")}

        self._executable = calctype2exec[calc_type]
        if self.executable is None:
            msg = "Cannot find executable for oncvpsp is PATH. Use `export PATH=dir_with_executable:$PATH`"
            raise RuntimeError(msg)
开发者ID:vormar,项目名称:pseudo_dojo,代码行数:14,代码来源:ppgen.py


示例5: has_abinit

def has_abinit(version=None, op=">="):
    """
    True if abinit is in $PATH.
    If version is not None, abinit version op version is evaluated and the result is returned.
    False if condition is not fulfilled or the execution of ``abinit -v`` raised CalledProcessError
    """
    abinit = which("abinit")
    if abinit is None: return False
    if version is None: return abinit is not None

    try:
        abinit_version = str(subprocess.check_output(["abinit", "-v"]))

    except subprocess.CalledProcessError:
        # Some MPI implementations require the mpirunner.
        try:
            abinit_version = subprocess.check_output(["mpirun", "-n", "1", "abinit", "-v"])
        except subprocess.CalledProcessError:
            try:
                abinit_version = subprocess.check_output(["mpiexec", "-n", "1", "abinit", "-v"])
            except subprocess.CalledProcessError as exc:
                logger.warning(exc.output)
                return False

    return cmp_version(abinit_version, version, op=op)
开发者ID:gpetretto,项目名称:abipy,代码行数:25,代码来源:testing.py


示例6: make_open_notebook

def make_open_notebook(options):
    """
    Generate an ipython notebook and open it in the browser.
    Return system exit code.

    Raise:
        RuntimeError if jupyther is not in $PATH
    """
    import nbformat
    nbf = nbformat.v4
    nb = nbf.new_notebook()

    nb.cells.extend([
        nbf.new_markdown_cell("# This is an auto-generated notebook for %s" % os.path.relpath(filepath)),
        nbf.new_code_cell("""\
from __future__ import print_function, division, unicode_literals, absolute_import
%matplotlib notebook
#import numpy as np
#import seaborn as sns
from abipy import abilab\
"""),

    nbf.new_code_cell("abifile = abilab.abiopen('%s')" % options.filepath)
    ])

    _, nbpath = tempfile.mkstemp(suffix='.ipynb', text=True)

    with io.open(nbpath, 'wt', encoding="utf8") as f:
        nbformat.write(nb, f)

    if which("jupyter") is None:
        raise RuntimeError("Cannot find jupyter in PATH. Install it with `pip install`")
    return os.system("jupyter notebook %s" % nbpath)
开发者ID:temok-mx,项目名称:abipy,代码行数:33,代码来源:abiopen.py


示例7: __init__

    def __init__(self):
        self._figures = collections.OrderedDict()

        self.animate_bin = which("animate")

        if self.animate_bin is None:
            raise RuntimeError("Cannot find animate executable in $PATH.\n Please install the ImageMagick suite of tools.")
开发者ID:GkAntonius,项目名称:abipy,代码行数:7,代码来源:animator.py


示例8: _find_loc

def _find_loc(app_name):
    # Try command line version
    path = which(app_name)
    if path is not None: return path

    # Treat Mac OsX applications.
    if is_macosx():

        system_apps = [f.lower() for f in os.listdir("/Applications")]
        try:
            i = system_apps.index(app_name)
            return os.path.join("/Applications", system_apps[i])
        except ValueError:
            try:
                i = system_apps.index(app_name + ".app")
                return os.path.join("/Applications", system_apps[i] + ".app")
            except ValueError:
                pass

        try:
            user_dir = os.path.expanduser("~/Applications/")
            user_apps = [f.lower() for f in os.listdir(user_dir)]
            try:
                i = user_apps.index(app_name)
                return os.path.join(user_dir, user_apps[i])
            except ValueError:
                try:
                    i = user_apps.index(app_name + ".app")
                    return os.path.join("/Applications", user_apps[i] + ".app")
                except ValueError:
                    pass
        except Exception:
            pass

    return None
开发者ID:temok-mx,项目名称:abipy,代码行数:35,代码来源:visualizer.py


示例9: has_abinit

def has_abinit(version, cmp=">="):
    """
    Return True if abinit is in $PATH and version is cmp version.
    False if condition is not fulfilled or the execution of `abinit -v` 
    raised CalledProcessError 
    """
    if which("abinit") is None:
        return False

    try:
        abiver = str(subprocess.check_output(["abinit", "-v"]))

    except subprocess.CalledProcessError:
        # Some MPI implementations require the mpirunner.
        try:
            abiver = subprocess.check_output(["mpirun", "-n", "1", "abinit", "-v"])
        except subprocess.CalledProcessError:
            try:
                abiver = subprocess.check_output(["mpiexec", "-n", "1", "abinit", "-v"])
            except subprocess.CalledProcessError as exc:
                logger.warning(exc.output)
                return False

    return {">=": abiver.strip() >= version.strip(),
            "==": abiver.strip() == version.strip()}[cmp]
开发者ID:antoinedewandre,项目名称:abipy,代码行数:25,代码来源:testing.py


示例10: __init__

    def __init__(self, username, hostname, workdir, sshfs_mountpoint=None):
        """
        Args:
            username:
                Username used to login on the cluster.
            hostname:
                Name of the host.
            workdir:
                Absolute path (on the remote host) where the `AbinitFlows` will be produced.
            sshfs_mountpoint:
                Absolute path (on the local host) where the file system of 
                the remote host will be mounted via sshfs.
        """
        self.username, self.hostname, self.workdir = username, hostname, workdir

        if not os.path.isabs(self.workdir):
            raise ValueError("Please use an absolute path for the remote workdir")

        self.port = 22    # Port for SSH connection
        self.timeout = 30 # Timeout in seconds.

        self.sshfs_mountpoint = os.path.expanduser(sshfs_mountpoint) if sshfs_mountpoint else None

        if self.sshfs_mountpoint is not None and which("sshfs") is None:
            warnings.warn("Cannot locate sshfs in $PATH, cannot mount remote filesystem without SSHFS")
开发者ID:GkAntonius,项目名称:abipy,代码行数:25,代码来源:clusters.py


示例11: __init__

    def __init__(self, fft_input, executable="fftprof"):
        self.verbose = 1
        self.fft_input = fft_input

        self.executable = which(executable)
        if self.executable is None:
            raise self.Error("Cannot find executable %s in $PATH" % executable)
开发者ID:GkAntonius,项目名称:abipy,代码行数:7,代码来源:fftbench.py


示例12: dojo_nbcompare

    def dojo_nbcompare(self, what="all", **kwargs):
        """
        Generate an ipython notebook to compare the results in the dojoreport (calls dojo_compare).
        """
        paths = [p.path for p in self]
        import nbformat
        nbf = nbformat.v4
        nb = nbf.new_notebook()

        nb.cells.extend([
            #nbf.new_markdown_cell("# This is an auto-generated notebook for %s" % os.path.basename(pseudopath)),
            nbf.new_code_cell("""\
from __future__ import print_function, division, unicode_literals
%matplotlib notebook"""),

            nbf.new_code_cell("""\
from pseudo_dojo.core.pseudos import DojoTable
pseudos = DojoTable(%s)""" % str(paths)),
            nbf.new_code_cell("pseudos.dojo_compare(what='%s')" % what),
        ])

        _, nbpath = tempfile.mkstemp(suffix='.ipynb', text=True)

        import io
        with io.open(nbpath, 'wt', encoding="utf8") as f:
            nbformat.write(nb, f)

        if which("jupyter") is None:
            raise RuntimeError("Cannot find jupyter in PATH. Install it with `pip install`")
        return os.system("jupyter notebook %s" % nbpath)
开发者ID:gmatteo,项目名称:pseudo_dojo,代码行数:30,代码来源:pseudos.py


示例13: make_and_open_notebook

    def make_and_open_notebook(self, nbpath=None, foreground=False):  # pragma: no cover
        """
        Generate an jupyter_ notebook and open it in the browser.

        Args:
            nbpath: If nbpath is None, a temporay file is created.
            foreground: By default, jupyter is executed in background and stdout, stderr are redirected
            to devnull. Use foreground to run the process in foreground

        Return:
            system exit code.

        Raise:
            `RuntimeError` if jupyter_ is not in $PATH
        """
        nbpath = self.write_notebook(nbpath=nbpath)

        if which("jupyter") is None:
            raise RuntimeError("Cannot find jupyter in $PATH. Install it with `conda install jupyter or `pip install jupyter`")

        if foreground:
            return os.system("jupyter notebook %s" % nbpath)
        else:
            fd, tmpname = tempfile.mkstemp(text=True)
            print(tmpname)
            cmd = "jupyter notebook %s" % nbpath
            print("Executing:", cmd)
            print("stdout and stderr redirected to %s" % tmpname)
            import subprocess
            process = subprocess.Popen(cmd.split(), shell=False, stdout=fd, stderr=fd)
            cprint("pid: %s" % str(process.pid), "yellow")
            return 0
开发者ID:gpetretto,项目名称:abipy,代码行数:32,代码来源:mixins.py


示例14: open_terminal

        def open_terminal():
            """Try to figure which terminal is available."""
            retcode = 1

            if retcode and which("gnome-terminal") is not None:
                retcode = os.system("gnome-terminal -e 'ssh %s -X'" % cluster.hostname)

            if retcode and which("konsole") is not None:
                retcode = os.system("konsole -e 'ssh %s -X'" % cluster.hostname)

            # This does not work
            #retcode = os.system('open -a Terminal -n --args %s -X" % cluster.hostname")
                
            if retcode: # Fallback to xterm.
                retcode = os.system("xterm -e ssh %s -X" % cluster.hostname)

            return retcode
开发者ID:GkAntonius,项目名称:abipy,代码行数:17,代码来源:flowsdb.py


示例15: abicheck

def abicheck():
    """
    This function tests if the most important ABINIT executables
    can be found in $PATH and whether the python modules needed
    at run-time can be imported.

    Raises:
        RuntimeError if not all the dependencies are fulfilled.
    """
    import os
    # Executables must be in $PATH. Unfortunately we cannot
    # test the version of the binaries.
    # A possible approach would be to execute "exe -v"
    # but supporting argv in Fortran is not trivial.
    # Dynamic linking is tested by calling `ldd exe`
    executables = [
        "abinit",
        "mrgddb",
        "mrggkk",
        "anaddb",
    ]

    has_ldd = which("ldd") is not None

    err_lines = []
    app = err_lines.append
    for exe in executables:
        exe_path = which(exe)

        if exe_path is None:
            app("Cannot find %s in $PATH" % exe)
        else:
            if has_ldd and os.system("ldd %s > /dev/null " % exe_path) != 0:
                app("Missing shared library dependencies for %s" % exe)

    try:    
        software_stack()
    except:
        app(_straceback())

    if err_lines:
        header = "The environment on the local machine is not properly setup\n"
        raise RuntimeError(header + "\n".join(err_lines))

    return 0
开发者ID:ldamewood,项目名称:abipy,代码行数:45,代码来源:abilab.py


示例16: __init__

 def __init__(self, *nc_args, **nc_kwargs):
     """
     Args:
         nc_args: Arguments passed to ncdump.
         nc_kwargs: Keyword arguments passed to ncdump
     """
     self.nc_args = nc_args
     self.nc_kwargs = nc_kwargs
     self.ncdump = which("ncdump")
开发者ID:gmatteo,项目名称:abipy,代码行数:9,代码来源:mixins.py


示例17: has_python_graphviz

    def has_python_graphviz(need_dotexec=False):
        """
        True if python-graphviz package is installed and dot executable in path.
        """
        try:
            from graphviz import Digraph
        except ImportError:
            return False

        return which("dot") is not None if need_dotexec else True
开发者ID:gpetretto,项目名称:abipy,代码行数:10,代码来源:testing.py


示例18: OnNetcdf_NcView

    def OnNetcdf_NcView(self, event):
        """Call ncview in an subprocess."""
        if which("ncview") is None:
            return awx.showErrorMessage(self, "Cannot find ncview in $PATH")

        for path in self.nc_filepaths:
            def target():
                os.system("ncview %s" % path)

            thread = awx.WorkerThread(self, target=target)
            thread.start()
开发者ID:gmatteo,项目名称:abipy,代码行数:11,代码来源:mixins.py


示例19: run

    def run(self):
        """
        Perform the actual VASP run.

        Returns:
            (subprocess.Popen) Used for monitoring.
        """
        cmd = list(self.vasp_cmd)
        if self.auto_gamma:
            vi = VaspInput.from_directory(".")
            kpts = vi["KPOINTS"]
            if kpts.style == "Gamma" and tuple(kpts.kpts[0]) == (1, 1, 1):
                if self.gamma_vasp_cmd is not None and which(
                        self.gamma_vasp_cmd[-1]):
                    cmd = self.gamma_vasp_cmd
                elif which(cmd[-1] + ".gamma"):
                    cmd[-1] += ".gamma"
        logging.info("Running {}".format(" ".join(cmd)))
        with open(self.output_file, 'w') as f:
            p = subprocess.Popen(cmd, stdout=f)
        return p
开发者ID:image-tester,项目名称:custodian,代码行数:21,代码来源:jobs.py


示例20: make_open_notebook

def make_open_notebook(pseudopath, with_validation=False, with_eos=True):
    """
    Generate an ipython notebook from the pseudopotential path and
    open it in the browser. Return system exit code.

    Raise:
        RuntimeError if jupyther or ipython are not in $PATH
    """
    path = write_notebook(pseudopath, with_validation=with_validation, with_eos=with_eos, tmpfile=True)

    if which("jupyter") is None:
        raise RuntimeError("Cannot find jupyter in PATH. Install it with `pip install`")
    return os.system("jupyter notebook %s" % path)
开发者ID:ebousq,项目名称:pseudo_dojo,代码行数:13,代码来源:notebook.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python path.zpath函数代码示例发布时间:2022-05-27
下一篇:
Python os.cd函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap