mirror of https://github.com/devine-dl/devine.git
refactor(env): Shorten paths on Windows with env vars
This commit is contained in:
parent
3bfd96d53c
commit
af95ba062a
|
@ -1,5 +1,8 @@
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
@ -38,10 +41,20 @@ def info() -> None:
|
||||||
table.add_column("Name", no_wrap=True)
|
table.add_column("Name", no_wrap=True)
|
||||||
table.add_column("Path")
|
table.add_column("Path")
|
||||||
|
|
||||||
|
path_vars = {
|
||||||
|
x: Path(os.getenv(x))
|
||||||
|
for x in ("TEMP", "APPDATA", "LOCALAPPDATA", "USERPROFILE")
|
||||||
|
if sys.platform == "win32" and os.getenv(x)
|
||||||
|
}
|
||||||
|
|
||||||
for name in sorted(dir(config.directories)):
|
for name in sorted(dir(config.directories)):
|
||||||
if name.startswith("__") or name == "app_dirs":
|
if name.startswith("__") or name == "app_dirs":
|
||||||
continue
|
continue
|
||||||
path = getattr(config.directories, name).resolve()
|
path = getattr(config.directories, name).resolve()
|
||||||
|
for var, var_path in path_vars.items():
|
||||||
|
if path.is_relative_to(var_path):
|
||||||
|
path = rf"%{var}%\{path.relative_to(var_path)}"
|
||||||
|
break
|
||||||
table.add_row(name.title(), str(path))
|
table.add_row(name.title(), str(path))
|
||||||
|
|
||||||
console.print(Padding(
|
console.print(Padding(
|
||||||
|
|
Loading…
Reference in New Issue