-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
62 lines (46 loc) · 1.37 KB
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os.path as op
import typer
import yaml
from yaml import Loader
from typing import Any, Dict
from sorter import FolderCleaner, __app_name__, __version__
from rich import print
app = typer.Typer()
class Config:
file: str
data: Dict[str, Any]
def __init__(self) -> None:
self.file = "cleaners.yaml"
with open(self.file) as stream:
self.data = yaml.load(stream, Loader=Loader)
@property
def cleaners(self):
return list(self.data.keys())
def get_cleaner(self, cleaner_name: str) -> dict:
if cleaner_name in self.cleaners:
return FolderCleaner(self.data.get(cleaner_name, {}))
@app.command()
def cleaners():
conf = Config()
print(f"Available cleaners (defined in {op.abspath(conf.file)}):")
for cleaner in conf.cleaners:
print(f" - [bold yellow]{cleaner}[/bold yellow]")
@app.command()
def clean(cleaner_name: str):
conf = Config()
cleaner = conf.get_cleaner(cleaner_name)
if not cleaner:
print("[red]Unknown cleaner[/red]:\n")
cleaners()
exit()
print(
f"Starting cleaner [bold yellow]{cleaner_name}[/bold yellow] in"
f" {cleaner.path}"
)
cleaner.start()
@app.command()
def verify():
print("[red]NOT IMPLEMENTED[/red]")
print("Will check for conflict in cleaners.yaml")
if __name__ == "__main__":
app()