Skip to content

Utils

copy_to(src, dst)

Copies the contents form src to dst .

Parameters:

Name Type Description Default
src Path

[description]

required
dst Path

[description]

required
Source code in omoospace\utils.py
def copy_to(src: PathLike, dst: PathLike):
    """Copies the contents form src to dst .

    Args:
        src (Path): [description]
        dst (Path): [description]
    """
    src = Path(src).resolve()
    dst = Path(dst).resolve()
    dst.parent.mkdir(parents=True, exist_ok=True)
    if src.is_dir():
        shutil.copytree(src, dst)
    else:
        shutil.copy(src, dst)

copy_to_clipboard(string)

Copy to clipboard

Parameters:

Name Type Description Default
string str

The string want to be copyed.

required
Source code in omoospace\utils.py
def copy_to_clipboard(string: str):
    """Copy to clipboard

    Args:
        string (str): The string want to be copyed.
    """

    pyperclip.copy(string)

is_subpath(child, parent, or_equal=False)

Return True if child is a subpath of parent .

Parameters:

Name Type Description Default
child PathLike

Child path

required
parent PathLike

Parent path

required
or_equal bool

[description]. Defaults to False.

False

Returns:

Name Type Description
bool bool

Result.

Source code in omoospace\utils.py
def is_subpath(child: PathLike, parent: PathLike, or_equal=False) -> bool:
    """Return True if child is a subpath of parent .

    Args:
        child (PathLike): Child path
        parent (PathLike): Parent path
        or_equal (bool, optional): [description]. Defaults to False.

    Returns:
        bool: Result.
    """
    parent = Path(parent).resolve()
    child = Path(child).resolve()
    is_subpath = parent in child.parents
    is_equal = parent == child
    if or_equal:
        return is_subpath or is_equal
    else:
        return is_subpath

reveal_in_explorer(dst)

Open the directory in file exploarer

Parameters:

Name Type Description Default
dst PathLike

The directory want to open

required
Source code in omoospace\utils.py
def reveal_in_explorer(dst: PathLike):
    """Open the directory in file exploarer

    Args:
        dst (PathLike): The directory want to open
    """
    try:
        os.startfile(Path(dst))
    except Exception as err:
        print("Fail to reveal", err)