:tocdepth: 3 :py:mod:`gws.lib.osx` ===================== .. py:module:: gws.lib.osx .. autoapi-nested-parse:: Utilities for os/shell scripting **Source code:** :source:`gws.lib.osx` Package Contents ---------------- .. py:function:: abs_path(path: _Path, base: _Path) -> str Absolutize a relative path with respect to a base directory or file path. :param path: A path. :param base: A path to the base. :raises ``ValueError``: If base is empty :returns: The absolute path. .. py:function:: abs_web_path(path: str, basedir: str) -> Optional[str] Return an absolute path in a base dir and ensure the path is correct. :param path: Path to absolutize. :param basedir: Path to base directory. :returns: Absolute path with respect to base directory. .. py:function:: chown(path: _Path, user: int = None, group: int = None) Changes the UID or GID for a given path. :param path: Filepath. :param user: UID. :param group: GID. .. py:function:: copy(src: _Path, dst: _Path, user: int = None, group: int = None) Copy a file. :param src: Source path. :param dst: Destination path. :param user: UID. :param group: GID. .. py:exception:: Error Bases: :py:obj:`gws.Error` Generic GWS error. .. py:function:: file_age(path: _Path) -> int Returns the amount of seconds since the path has been changed. :param path: Filepath. :returns: Amount of seconds since most recent change in file, if the path is invalid ``-1`` is returned. .. py:function:: file_checksum(path: _Path) -> str Returns the checksum of the file. :param path: Filepath. :returns: Empty string if the path is invalid, otherwise the file's checksum. .. py:function:: file_mtime(path: _Path) -> float Returns the time from epoch when the path was recently changed. :param path: File-/directory-path. :returns: Time since epoch in seconds until most recent change in file. .. py:function:: file_name(path: _Path) -> str Returns the filename. :param path: Filepath. :returns: The filename. .. py:function:: file_size(path: _Path) -> int Returns the file size. :param path: Filepath. :returns: Amount of characters in the file or ``-1`` if the path is invalid. .. py:function:: find_directories(dirname: _Path, pattern=None, deep: bool = True) Finds all directories in a given directory. :param dirname: Path to directory. :param pattern: Pattern to match. :param deep: If true then searches through all subdirectories for directories, otherwise it returns the directories only in the given directory. :returns: A generator object. .. py:function:: find_files(dirname: _Path, pattern=None, ext=None, deep: bool = True) Finds files in a given directory. :param dirname: Path to directory. :param pattern: Pattern to match. :param ext: extension to match. :param deep: If true then searches through all subdirectories for files, otherwise it returns the files only in the given directory. :returns: A generator object. .. py:function:: getenv(key: str, default: str = None) -> Optional[str] Returns the value for a given environment-variable. :param key: An environment-variable. :param default: The default return. :returns: ``default`` if no key has been found, if there is such key then the value for the environment-variable is returned. .. py:function:: is_abs_path(path: _Path) -> bool .. py:function:: kill_pid(pid: int, sig_name='TERM') -> bool Kills a process. :param pid: Process ID. :param sig_name: :returns: ``True`` if the process with the given PID is killed or does not exist.``False `` if the process could not be killed. .. py:function:: mkdir(path: _Path, mode: int = 493, user: int = None, group: int = None) Check a (possibly nested) directory. :param path: Path to a directory. :param mode: Directory creation mode. :param user: Directory user (defaults to gws.c.UID) :param group: Directory group (defaults to gws.c.GID) .. py:function:: parse_path(path: _Path) -> dict[str, str] Parse a path into a dict(path,dirname,filename,name,extension). :param path: Path. :returns: A dict(path,dirname,filename,name,extension). .. py:function:: process_rss_size(unit: str = 'm') -> float Returns the Resident Set Size. :param unit: ``m`` | ``k`` | ``g`` :returns: The Resident Set Size with the given unit. .. py:function:: rel_path(path: _Path, base: _Path) -> str Relativize an absolute path with respect to a base directory or file path. :param path: Path to relativize. :param base: Path to base directory. :returns: Relativized path with respect to base directory. .. py:function:: rename(src: _Path, dst: _Path) Moves and renames the source path according to the given destination. :param src: Path to source. :param dst: Destination. .. py:function:: rmdir(path: _Path) -> bool Remove a directory or a directory tree. :param path: Path to a directory. Can be non-empty .. py:function:: run(cmd: str | list, input: str = None, echo: bool = False, strict: bool = True, timeout: float = None, **kwargs) -> str Run an external command. :param cmd: Command to run. :param input: Input data. :param echo: Echo the output instead of capturing it. :param strict: Raise an error on a non-zero exit code. :param timeout: Timeout. :param kwargs: Arguments to pass to ``subprocess.Popen``. :returns: The command output. .. py:function:: run_nowait(cmd: str | list, **kwargs) -> subprocess.Popen Run a process and return immediately. :param cmd: A process to run. :param kwargs: :returns: The output of the command. .. py:function:: running_pids() -> dict[int, str] Returns the current pids and the corresponding process' name. .. py:exception:: TimeoutError Bases: :py:obj:`Error` Generic GWS error. .. py:function:: unlink(path: _Path) -> bool Deletes a given path. :param path: Filepath. .. py:function:: user_info(uid=None, gid=None) -> dict Get user and group information. :param uid: Optional user ID. Defaults to the current process's user ID. :param gid: Optional group ID. Defaults to the user's primary group ID. :returns: A dictionary containing user and group information (a combination of struct_passwd and struct_group).