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
@@ -13,6 +25,20 @@ def sanitize_trailing_slash(
1325 target_dir : str ,
1426 sync_sourcedir_contents : Optional [bool ] = True ,
1527) -> Tuple [str , str ]:
28+ """
29+ Sanitizes the trailing slashes in the source and target directories.
30+
31+ Args:
32+ source_dir (str): The source directory path.
33+ target_dir (str): The target directory path.
34+ sync_sourcedir_contents (bool, optional): Whether to sync the contents of the
35+ source directory. Defaults to True.
36+
37+ Returns:
38+ Tuple[str, str]: A tuple containing the sanitized source directory path and the
39+ sanitized target directory path.
40+ """
41+
1642 target_dir = strip_trailing_slash (target_dir )
1743
1844 if sync_sourcedir_contents is True :
@@ -24,12 +50,30 @@ def sanitize_trailing_slash(
2450
2551
2652def strip_trailing_slash (directory : str ) -> str :
53+ """
54+ Strip the trailing slash from the directory path if it exists.
55+
56+ Args:
57+ directory (str): The directory path.
58+
59+ Returns:
60+ str: The directory path without the trailing slash, if present. Otherwise,
61+ returns the directory path as is.
62+ """
2763 return (directory [:- 1 ]
2864 if directory .endswith ('/' )
2965 else directory )
3066
31-
3267def add_trailing_slash (directory : str ) -> str :
68+ """Add a trailing slash to the directory path if it doesn't already have one.
69+
70+ Args:
71+ directory (str): The directory path.
72+
73+ Returns:
74+ str: The directory path with a trailing slash, if it doesn't already have one.
75+ Otherwise, returns the directory path as is.
76+ """
3377 return (directory
3478 if directory .endswith ('/' )
3579 else f'{ directory } /' )
0 commit comments