跳转至

Functions

create_omoospace(name, under='.', brief=None, contents_dir='Contents', subspaces_dir='Subspaces', language=None, readme=False, gitfiles=False, chinese_to_pinyin=False, reveal_in_explorer=False)

Create an omoospace.

Parameters:

Name Type Description Default
name str

The name of the omoospace.

required
under str

The directory under which to create the omoospace. Defaults to ".".

'.'
brief str

A brief description of the omoospace. Defaults to None.

None
contents_dir str

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

'Contents'
subspaces_dir str

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

'Subspaces'
language Language

The language of the omoospace profile. Defaults to None.

None
readme bool

Whether to create a README.md file. Defaults to False.

False
gitfiles bool

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

False
chinese_to_pinyin bool

Whether to convert Chinese characters in the name to Pinyin. 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(
    name: str,
    under: str = ".",
    brief: str = None,
    contents_dir: str = "Contents",
    subspaces_dir: str = "Subspaces",
    language: Language = None,
    readme: bool = False,
    gitfiles: bool = False,
    chinese_to_pinyin: bool = False,
    reveal_in_explorer: bool = False,
) -> Omoospace:
    """Create an omoospace.

    Args:
        name (str): The name of the omoospace.
        under (str, optional): The directory under which to create the omoospace. Defaults to ".".
        brief (str, optional): A brief description of the omoospace. Defaults to None.
        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".
        language (Language, optional): The language of the omoospace profile. Defaults to None.
        readme (bool, optional): Whether to create a README.md file. Defaults to False.
        gitfiles (bool, optional): Whether to create .gitattributes and .gitignore files. Defaults to False.
        chinese_to_pinyin (bool, optional): Whether to convert Chinese characters in the name to Pinyin. 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.
    """

    if language and language not in ALLOWED_LANGS:
        raise ValueError(f"{language} is not a valid language.")
    language = language or "en"

    dirname = normalize_name(name, chinese_to_pinyin=chinese_to_pinyin)
    root_dir = Opath(under, dirname).resolve()

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

    except FileNotFoundError:
        pass

    profile_file = f"Omoospace.{language}.yml" if language != "en" else "Omoospace.yml"
    contents_dir = contents_dir or "Contents"

    paths = [profile_file, f"{contents_dir}/"]

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

    if readme:
        readme_content = f"""# {name}
{brief or ""}"""
        paths.append({"README.md": readme_content})

    if gitfiles:
        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)
    omoospace.brief = brief or name

    if 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:
        return None
    except ValueError:
        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:
        return None
    except ValueError:
        return ""