reafactor: rearrange for clarity

This commit is contained in:
Daylin Morgan 2023-06-01 15:55:17 -05:00
parent 3cf2dce767
commit 76df12d882
Signed by: daylin
GPG key ID: C1E52E7DD81DF79F

View file

@ -50,42 +50,7 @@ from typing import (
from urllib.error import HTTPError from urllib.error import HTTPError
from urllib.request import urlopen from urllib.request import urlopen
__version__ = "23.5a4-29-g4a1f01f-dev" __version__ = "23.5a4-30-g3cf2dce-dev"
class Config:
"""viv config manager"""
def __init__(self) -> None:
self._cache = Path(os.getenv("XDG_CACHE_HOME", Path.home() / ".cache")) / "viv"
def _ensure(self, p: Path) -> Path:
p.mkdir(parents=True, exist_ok=True)
return p
@property
def venvcache(self) -> Path:
return self._ensure(self._cache / "venvs")
@property
def srccache(self) -> Path:
return self._ensure(self._cache / "src")
@property
def binparent(self) -> Path:
return self._ensure(
Path(os.getenv("VIV_BIN_DIR", Path.home() / ".local" / "bin"))
)
@property
def srcdefault(self) -> Path:
parent = (
Path(os.getenv("XDG_DATA_HOME", Path.home() / ".local" / "share")) / "viv"
)
return self._ensure(parent) / "viv.py"
c = Config()
class Spinner: class Spinner:
@ -391,7 +356,7 @@ if __name__ == "__main__":
t = Template() t = Template()
# TODO: convet the below functions into a proper file/stream logging interface # TODO: convert the below functions into a proper file/stream logging interface
def echo( def echo(
msg: str, style: str = "magenta", newline: bool = True, fd: TextIO = sys.stderr msg: str, style: str = "magenta", newline: bool = True, fd: TextIO = sys.stderr
) -> None: ) -> None:
@ -899,6 +864,41 @@ def make_executable(path: Path) -> None:
os.chmod(path, mode) os.chmod(path, mode)
class Config:
"""viv config manager"""
def __init__(self) -> None:
self._cache = Path(os.getenv("XDG_CACHE_HOME", Path.home() / ".cache")) / "viv"
def _ensure(self, p: Path) -> Path:
p.mkdir(parents=True, exist_ok=True)
return p
@property
def venvcache(self) -> Path:
return self._ensure(self._cache / "venvs")
@property
def srccache(self) -> Path:
return self._ensure(self._cache / "src")
@property
def binparent(self) -> Path:
return self._ensure(
Path(os.getenv("VIV_BIN_DIR", Path.home() / ".local" / "bin"))
)
@property
def srcdefault(self) -> Path:
parent = (
Path(os.getenv("XDG_DATA_HOME", Path.home() / ".local" / "share")) / "viv"
)
return self._ensure(parent) / "viv.py"
c = Config()
class Viv: class Viv:
def __init__(self) -> None: def __init__(self) -> None:
self.vivenvs = get_venvs() self.vivenvs = get_venvs()