Skip to content

Functions

create_omoospace(dirname, name=None, description=None, contents_dir=None, subspaces_dir=None, gitfiles=False, reveal_in_explorer=False)

Create an omoospace.

Parameters:

Name Type Description Default
dirname str

The directory name of the omoospace.

required
name str

The name of the omoospace.

None
description str

The description of the omoospace.

None
contents_dir str

The name of the contents directory. Defaults to "contents".

None
subspaces_dir str

The name of the subspaces directory. Defaults to "subspaces".

None
gitfiles bool

Whether to create .gitattributes and .gitignore files. Defaults to False.

False
reveal_in_explorer bool

Whether to reveal the created omoospace in file explorer. Defaults to False.

False

Returns:

Name Type Description
Omoospace Omoospace

The created omoospace.

Source code in src\omoospace\functions.py
def create_omoospace(
    dirname: str,
    name: str = None,
    description: str = None,
    contents_dir: str = None,
    subspaces_dir: str = None,
    gitfiles: bool = False,
    reveal_in_explorer: bool = False,
) -> Omoospace:
    """Create an omoospace.

    Args:
        dirname (str): The directory name of the omoospace.
        name (str, optional): The name of the omoospace.
        description (str, optional): The description of the omoospace.
        contents_dir (str, optional): The name of the contents directory. Defaults to "contents".
        subspaces_dir (str, optional): The name of the subspaces directory. Defaults to "subspaces".
        gitfiles (bool, optional): Whether to create .gitattributes and .gitignore files. Defaults to False.
        reveal_in_explorer (bool, optional): Whether to reveal the created omoospace in file explorer. Defaults to False.

    Returns:
        Omoospace: The created omoospace.
    """

    root_dir = Opath(dirname).resolve()

    # Check if root_dir is in a omoospace
    try:
        Omoospace(root_dir)
        raise FileExistsError(f"{root_dir} already exists.")

    except FileNotFoundError:
        pass

    contents_dir = contents_dir or "contents"

    paths = [
        "OMOOSPACE.md",
        f"{contents_dir}/",
    ]

    if subspaces_dir:
        paths.append(f"{subspaces_dir}/")

    if gitfiles:
        readme_content = f"""# {name}
{description or ""}"""

        paths.append({"README.md": readme_content})
        paths.append({".gitattributes": gitattributes_content})
        paths.append({".gitignore": gitignore_content})

    make_path(
        *paths,
        under=root_dir,
    )

    if reveal_in_explorer:
        root_dir.reveal_in_explorer()

    omoospace = Omoospace(root_dir)

    if name:
        omoospace.name = name
    if description:
        omoospace.description = description
    if subspaces_dir != "subspaces" and subspaces_dir:
        omoospace.subspaces_dir = subspaces_dir
    if contents_dir != "contents":
        omoospace.contents_dir = contents_dir

    return omoospace

extract_objective(path)

Returns the objective.

Parameters:

Name Type Description Default
path AnyPath

The giving path.

required

Returns:

Name Type Description
Objective Objective

Objective.

Source code in src\omoospace\functions.py
def extract_objective(path: AnyPath) -> Objective:
    """Returns the objective.

    Args:
        path (AnyPath): The giving path.

    Returns:
        Objective: Objective.

    """

    try:
        return Subspace(path).objective
    except FileNotFoundError:
        # Not in omoospace
        raise FileNotFoundError(f"Path is not in an omoospace")
    except ValueError:
        # Not a subspace
        return None

extract_pathname(path)

Returns the pathname of a path.

Parameters:

Name Type Description Default
path AnyPath

The giving path.

required

Returns:

Name Type Description
ObjectivePath str

Objective path.

Source code in src\omoospace\functions.py
def extract_pathname(path: AnyPath) -> str:
    """Returns the pathname of a path.

    Args:
        path (AnyPath): The giving path.

    Returns:
        ObjectivePath: Objective path.

    """

    try:
        return Subspace(path).pathname
    except FileNotFoundError:
        # Not in omoospace
        raise FileNotFoundError(f"Path is not in an omoospace")
    except ValueError:
        # Not a subspace
        return None