51 lines
1.1 KiB
Python
51 lines
1.1 KiB
Python
import os
|
|
from pathlib import Path
|
|
from urllib.parse import urlparse, urlunparse
|
|
|
|
import env
|
|
from rwx import fs
|
|
from rwx.log import stream as log
|
|
|
|
|
|
def add_url_path(url: str, extra_path: str) -> str:
|
|
parts = urlparse(url)
|
|
parts = parts._replace(path=str(Path(parts.path) / extra_path))
|
|
return urlunparse(parts)
|
|
|
|
|
|
def browse(root: str) -> None:
|
|
paths = []
|
|
for directory, _, files in os.walk(root):
|
|
for file in files:
|
|
absolute_path = Path(directory) / file
|
|
relative_path = os.path.relpath(absolute_path, start=root)
|
|
paths.append(relative_path)
|
|
frame(root)
|
|
for path in sorted(paths):
|
|
log.info(path)
|
|
shut(root)
|
|
|
|
|
|
def cat(file: str) -> None:
|
|
frame(file)
|
|
log.info(fs.read_file_text(file).rstrip())
|
|
shut(file)
|
|
|
|
|
|
def frame(text: str) -> None:
|
|
log.info(f"{env.SPCD_OPEN}{text}")
|
|
|
|
|
|
def shut(text: str) -> None:
|
|
log.info(f"{env.SPCD_SHUT}{text}")
|
|
|
|
|
|
def split() -> None:
|
|
log.info(env.SPCD_SPLT)
|
|
|
|
|
|
def step(text: str) -> None:
|
|
env.SPCD_STEP += 1
|
|
log.info(env.SPCD_DOWN)
|
|
log.info(f"{env.SPCD_VERT} {env.SPCD_STEP} {text}")
|
|
log.info(env.SPCD___UP)
|