Esempio n. 1
0
def which(command, env=None):
    """Get the full path to a command.

    Parameters
    ----------
    command: str
        The command name or path.
    env: dict, optional
        The environment variables, defaults to `os.environ`.
    """
    env = env or os.environ
    path = env.get('PATH') or os.defpath
    command_with_path = _which(command, path=path)

    # Allow nodejs as an alias to node.
    if command == 'node' and not command_with_path:
        command = 'nodejs'
        command_with_path = _which('nodejs', path=path)

    if not command_with_path:
        if command in ['nodejs', 'node', 'npm']:
            msg = 'Please install nodejs 5+ and npm before continuing installation. nodejs may be installed using conda or directly from the nodejs website.'
            raise ValueError(msg)
        raise ValueError('The command was not found or was not ' +
                         'executable: %s.' % command)
    return command_with_path
Esempio n. 2
0
def which(command, env=None):
    """Get the full path to a command.

    Parameters
    ----------
    command: str
        The command name or path.
    env: dict, optional
        The environment variables, defaults to `os.environ`.
    """
    env = env or os.environ
    path = env.get('PATH') or os.defpath
    command_with_path = _which(command, path=path)

    # Allow nodejs as an alias to node.
    if command == 'node' and not command_with_path:
        command = 'nodejs'
        command_with_path = _which('nodejs', path=path)

    if not command_with_path:
        if command in ['nodejs', 'node', 'npm']:
            msg = 'Please install Node.js and npm before continuing installation. You may be able to install Node.js from your package manager, from conda, or directly from the Node.js website (https://nodejs.org).'
            raise ValueError(msg)
        raise ValueError('The command was not found or was not ' +
                         'executable: %s.' % command)
    return os.path.abspath(command_with_path)
Esempio n. 3
0
    def __init__(self, sequence, database=None, executable='jackhmmer', **kwargs):

        # Empty container for parsed/validated sequences
        self.sequences = []

        self.database = database

        # Setup logging with module name
        self.logger = logging.getLogger(__name__)

        # Iterate over kwargs and define defaults if not user-provided
        _defaults = {'evalue': 1E-20,
                     'ncpus': 2,
                     'niter': 5,
                     'mock': False}

        for kwarg in _defaults:
            kwarg_val = kwargs.get(kwarg)
            if not kwarg_val:
                kwarg_val = _defaults[kwarg]
            setattr(self, kwarg, kwarg_val)

        # Validate sequence data and locate executable
        self.__validate(sequence)

        if not _which(executable):
            raise OSError("HMMER executable not found in PATH: '{}'".format(executable))
Esempio n. 4
0
def get_external_executable(_exec):
    _exec_path = _which(_exec)
    if _exec_path:
        return _exec_path
    else:
        sys.exit("Required executable '{}' not found on this system. "
                 "Please install or add to PATH".format(_exec))
Esempio n. 5
0
 def change_wallpaper(path: str):
     file = _which("feh")
     if file is None:
         # I did the checking here not to seem we don't support i3
         print("feh not found, you need it to set the background in i3.")
         _exit(0)
     _system(f'feh --bg-fill "{path}"')
Esempio n. 6
0
 def _check_binary():
     """
     Make sure that the `gsutil` cli is present
     """
     if not _which(GCSProxy._GS_UTIL_CLI):
         raise _FlyteUserException(
             "gsutil (gcloud cli) not found! Please install.")
Esempio n. 7
0
def get_external_executable(_exec):
    _exec_path = _which(_exec)
    if _exec_path:
        return _exec_path
    else:
        sys.exit("Required executable '{}' not found on this system. "
                 "Please install or add to PATH".format(_exec))
Esempio n. 8
0
def _maybe_register(executable, **kw):
    if _which(executable):
        return _partial(register_terminal, **kw)
    else:

        def wrapper(fn, *args, **kwargs):
            return fn

        return wrapper
Esempio n. 9
0
def which(file, mode=os.F_OK | os.X_OK):
    """A wrapper around shutil.which() that searches a predictable set of
    paths and is more verbose about what is happening. See get_path()
    for more information.
    """
    path = get_path()
    rv = _which(file, mode, path)
    if rv:
        debug2("which() found '%s' at %s" % (file, rv))
    else:
        debug2("which() could not find '%s' in %s" % (file, path))
    return rv
Esempio n. 10
0
File: _utils.py Progetto: zooba/perf
def which(*args, **kw):
    # Wrapper to which() to use lazy import for 'import shutil'
    global _which

    if _which is None:
        try:
            # Python 3.3
            from shutil import which as _which
        except ImportError:
            # Backport shutil.which() from Python 3.6,
            # comments/docstring stripped
            def _which(cmd, mode=os.F_OK | os.X_OK, path=None):
                def _access_check(fn, mode):
                    return (os.path.exists(fn) and os.access(fn, mode)
                            and not os.path.isdir(fn))

                if os.path.dirname(cmd):
                    if _access_check(cmd, mode):
                        return cmd
                    return None

                if path is None:
                    path = os.environ.get("PATH", os.defpath)
                if not path:
                    return None
                path = path.split(os.pathsep)

                if sys.platform == "win32":
                    if os.curdir not in path:
                        path.insert(0, os.curdir)

                    pathext = os.environ.get("PATHEXT", "").split(os.pathsep)
                    if any(cmd.lower().endswith(ext.lower())
                           for ext in pathext):
                        files = [cmd]
                    else:
                        files = [cmd + ext for ext in pathext]
                else:
                    files = [cmd]

                seen = set()
                for dir in path:
                    normdir = os.path.normcase(dir)
                    if normdir not in seen:
                        seen.add(normdir)
                        for thefile in files:
                            name = os.path.join(dir, thefile)
                            if _access_check(name, mode):
                                return name
                return None

    return _which(*args, **kw)
Esempio n. 11
0
def which(cmd):
    """Return full path to specified command, or raise OSError if missing."""
    try:
        # For Python 3
        from shutil import which as _which
    except ImportError:
        # For Python 2
        from backports.shutil_which import which as _which
    full_path = _which(cmd)
    if full_path is None:
        raise OSError('Cannot find {!r} in $PATH'.format(cmd))
    log.debug('which %r => %r', cmd, full_path)
    return full_path
Esempio n. 12
0
File: _utils.py Progetto: haypo/perf
def which(*args, **kw):
    # Wrapper to which() to use lazy import for 'import shutil'
    global _which

    if _which is None:
        try:
            # Python 3.3
            from shutil import which as _which
        except ImportError:
            # Backport shutil.which() from Python 3.6,
            # comments/docstring stripped
            def _which(cmd, mode=os.F_OK | os.X_OK, path=None):
                def _access_check(fn, mode):
                    return (os.path.exists(fn) and os.access(fn, mode)
                            and not os.path.isdir(fn))

                if os.path.dirname(cmd):
                    if _access_check(cmd, mode):
                        return cmd
                    return None

                if path is None:
                    path = os.environ.get("PATH", os.defpath)
                if not path:
                    return None
                path = path.split(os.pathsep)

                if sys.platform == "win32":
                    if os.curdir not in path:
                        path.insert(0, os.curdir)

                    pathext = os.environ.get("PATHEXT", "").split(os.pathsep)
                    if any(cmd.lower().endswith(ext.lower()) for ext in pathext):
                        files = [cmd]
                    else:
                        files = [cmd + ext for ext in pathext]
                else:
                    files = [cmd]

                seen = set()
                for dir in path:
                    normdir = os.path.normcase(dir)
                    if normdir not in seen:
                        seen.add(normdir)
                        for thefile in files:
                            name = os.path.join(dir, thefile)
                            if _access_check(name, mode):
                                return name
                return None

    return _which(*args, **kw)
Esempio n. 13
0
def which(cmd, mode=os.F_OK | os.X_OK, path=None, **kwargs):
    """Given a command, mode, and a PATH string, return the path which
    conforms to the given mode on the PATH, or None if there is no such
    file.

    `mode` defaults to ``os.F_OK | os.X_OK``. `path` defaults to the result
    of ``os.environ.get("PATH")``, or can be overridden with a custom search
    path.

    Backported from :py:func:`shutil.which`
    (`<https://docs.python.org/3.3/library/shutil.html#shutil.which>`_),
    available in Python 3.3.
    """
    kwargs.update({'mode': mode, 'path': path})
    global _which
    if _which is not None:
        return _which(cmd, **kwargs)
    return _which_backport(cmd, **kwargs)
Esempio n. 14
0
def which(cmd, mode=os.F_OK | os.X_OK, path=None, **kwargs):
    """Given a command, mode, and a PATH string, return the path which
    conforms to the given mode on the PATH, or None if there is no such
    file.

    `mode` defaults to ``os.F_OK | os.X_OK``. `path` defaults to the result
    of ``os.environ.get("PATH")``, or can be overridden with a custom search
    path.

    Backported from :py:func:`shutil.which`
    (`<https://docs.python.org/3.3/library/shutil.html#shutil.which>`_),
    available in Python 3.3.
    """
    kwargs.update({'mode': mode, 'path': path})
    global _which
    if _which is not None:
        return _which(cmd, **kwargs)
    return _which_backport(cmd, **kwargs)
def bash_command_exists(bash_command_name):
    """Check whether `name` is on PATH and marked as executable.
    """

    return _which(bash_command_name) is not None
Esempio n. 16
0
def which(binary):
    path = _which(binary)
    if path:
        realpath = os.path.realpath(path)
        return realpath
    return None
Esempio n. 17
0
def which(binary):
    path = _which(binary)
    if path:
        realpath = os.path.realpath(path)
        return realpath
    return None
Esempio n. 18
0
 def _check_binary():
     """
     Make sure that the AWS cli is present
     """
     if not _which(AwsS3Proxy._AWS_CLI):
         raise _FlyteUserException('AWS CLI not found at Please install.')