Skip to content

Commit

Permalink
✨ SFTPTextualPath
Browse files Browse the repository at this point in the history
  • Loading branch information
juftin committed Mar 13, 2024
1 parent 6b875a8 commit f25f5a9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions textual_universal_directorytree/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from textual_universal_directorytree.alternate_paths import (
GitHubTextualPath,
S3TextualPath,
SFTPTextualPath,
)
from textual_universal_directorytree.universal_directory_tree import (
UniversalDirectoryTree,
Expand All @@ -16,6 +17,8 @@
registry.register_implementation(protocol="github", cls=GitHubTextualPath, clobber=True)
registry.register_implementation(protocol="s3", cls=S3TextualPath, clobber=True)
registry.register_implementation(protocol="s3a", cls=S3TextualPath, clobber=True)
registry.register_implementation(protocol="ssh", cls=SFTPTextualPath, clobber=True)
registry.register_implementation(protocol="sftp", cls=SFTPTextualPath, clobber=True)

__all__ = [
"UniversalDirectoryTree",
Expand All @@ -24,4 +27,5 @@
"GitHubTextualPath",
"S3TextualPath",
"UPath",
"SFTPTextualPath",
]
23 changes: 23 additions & 0 deletions textual_universal_directorytree/alternate_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import re
from typing import Any

from upath import UPath
from upath.implementations.cloud import S3Path
from upath.implementations.github import GitHubPath

Expand Down Expand Up @@ -116,3 +117,25 @@ def name(self) -> str:
return f"{self._url.scheme}://{self._url.netloc}"
else:
return super().name


class SFTPTextualPath(UPath):
"""
SFTPTextualPath
"""

def __str__(self) -> str:
"""
String representation of the SFTPPath
"""
string_representation = f"{self.protocol}://"
if "username" in self.storage_options:
string_representation += f"{self.storage_options['username']}@"
string_representation += f"{self.storage_options['host']}"
if "port" in self.storage_options:
string_representation += f":{self.storage_options['port']}"
if self.path == ".":
string_representation += "/"
else:
string_representation += f"/{self.path}"
return string_representation

0 comments on commit f25f5a9

Please sign in to comment.