Skip to content

Commit

Permalink
πŸ› SFTPTextualPath
Browse files Browse the repository at this point in the history
  • Loading branch information
juftin committed Mar 14, 2024
1 parent 9d8fd48 commit fb24f6f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
20 changes: 15 additions & 5 deletions textual_universal_directorytree/alternate_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,28 @@ class SFTPTextualPath(UPath):
SFTPTextualPath
"""

@property
def path(self) -> str:
"""
Always return the path relative to the root
"""
pth = super().path
if pth.startswith("."):
return f"/{pth[1:]}"
elif pth.startswith("/"):
return pth
else:
return "/" + pth

def __str__(self) -> str:
"""
String representation of the SFTPPath
Add the protocol prefix + extras to the string representation
"""
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}"
string_representation += self.path
return string_representation
8 changes: 6 additions & 2 deletions textual_universal_directorytree/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from __future__ import annotations

import argparse
import os
from typing import Any, ClassVar

from rich.syntax import Syntax
Expand Down Expand Up @@ -46,6 +47,7 @@ def handle_file_selected(self, message: DirectoryTree.FileSelected) -> None:
Objects returned by the FileSelected event are upath.UPath objects and
they are compatible with the familiar pathlib.Path API built into Python.
"""
self.sub_title = str(message.path)
try:
file_content = message.path.read_text()
except UnicodeDecodeError:
Expand All @@ -63,9 +65,11 @@ def cli() -> None:
parser = argparse.ArgumentParser(description="Universal Directory Tree")
parser.add_argument("path", type=str, help="Path to open", default=".")
args = parser.parse_args()
app = UniversalDirectoryTreeApp(path=args.path)
app.run()
cli_app = UniversalDirectoryTreeApp(path=args.path)
cli_app.run()


app = UniversalDirectoryTreeApp(path=os.getenv("UDT_PATH", os.getcwd()))

if __name__ == "__main__":
cli()

0 comments on commit fb24f6f

Please sign in to comment.