1+ """Directory helper functions for sysrsync."""
12from typing import Tuple , Optional
23
34
45def get_directory_with_ssh (directory : str , ssh : Optional [str ]) -> str :
6+ """
7+ Return the directory path with SSH prefix if SSH is provided.
8+
9+ Args:
10+ directory (str): The directory path.
11+ ssh (Optional[str]): The SSH prefix. Defaults to None.
12+
13+ Returns:
14+ str: The directory path with SSH prefix if SSH is provided, otherwise the
15+ directory path itself.
16+ """
517 if ssh is None :
618 return directory
719
@@ -10,6 +22,19 @@ def get_directory_with_ssh(directory: str, ssh: Optional[str]) -> str:
1022
1123def sanitize_trailing_slash (source_dir , target_dir , sync_sourcedir_contents = True ):
1224 # type: (str, str, bool) -> Tuple[str, str]
25+ """
26+ Sanitizes the trailing slashes in the source and target directories.
27+
28+ Args:
29+ source_dir (str): The source directory path.
30+ target_dir (str): The target directory path.
31+ sync_sourcedir_contents (bool, optional): Whether to sync the contents of the
32+ source directory. Defaults to True.
33+
34+ Returns:
35+ Tuple[str, str]: A tuple containing the sanitized source directory path and the
36+ sanitized target directory path.
37+ """
1338 target_dir = strip_trailing_slash (target_dir )
1439
1540 if sync_sourcedir_contents is True :
@@ -21,12 +46,30 @@ def sanitize_trailing_slash(source_dir, target_dir, sync_sourcedir_contents=True
2146
2247
2348def strip_trailing_slash (directory : str ) -> str :
49+ """
50+ Strip the trailing slash from the directory path if it exists.
51+
52+ Args:
53+ directory (str): The directory path.
54+
55+ Returns:
56+ str: The directory path without the trailing slash, if present. Otherwise,
57+ returns the directory path as is.
58+ """
2459 return (directory [:- 1 ]
2560 if directory .endswith ('/' )
2661 else directory )
2762
28-
2963def add_trailing_slash (directory : str ) -> str :
64+ """Add a trailing slash to the directory path if it doesn't already have one.
65+
66+ Args:
67+ directory (str): The directory path.
68+
69+ Returns:
70+ str: The directory path with a trailing slash, if it doesn't already have one.
71+ Otherwise, returns the directory path as is.
72+ """
3073 return (directory
3174 if directory .endswith ('/' )
3275 else f'{ directory } /' )
0 commit comments