twd-m4sc0 3.1.1__tar.gz → 3.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {twd_m4sc0-3.1.1 → twd_m4sc0-3.1.2}/PKG-INFO +1 -1
- twd_m4sc0-3.1.2/src/twd/__init__.py +1 -0
- {twd_m4sc0-3.1.1 → twd_m4sc0-3.1.2}/src/twd/cli.py +1 -1
- {twd_m4sc0-3.1.1 → twd_m4sc0-3.1.2}/src/twd/config.py +19 -1
- {twd_m4sc0-3.1.1 → twd_m4sc0-3.1.2}/src/twd/data.py +20 -12
- {twd_m4sc0-3.1.1 → twd_m4sc0-3.1.2}/src/twd_m4sc0.egg-info/PKG-INFO +1 -1
- twd_m4sc0-3.1.1/src/twd/__init__.py +0 -1
- {twd_m4sc0-3.1.1 → twd_m4sc0-3.1.2}/README.md +0 -0
- {twd_m4sc0-3.1.1 → twd_m4sc0-3.1.2}/pyproject.toml +0 -0
- {twd_m4sc0-3.1.1 → twd_m4sc0-3.1.2}/setup.cfg +0 -0
- {twd_m4sc0-3.1.1 → twd_m4sc0-3.1.2}/src/twd/modals/__init__.py +0 -0
- {twd_m4sc0-3.1.1 → twd_m4sc0-3.1.2}/src/twd/modals/confirm.py +0 -0
- {twd_m4sc0-3.1.1 → twd_m4sc0-3.1.2}/src/twd/modals/edit.py +0 -0
- {twd_m4sc0-3.1.1 → twd_m4sc0-3.1.2}/src/twd/tui.py +0 -0
- {twd_m4sc0-3.1.1 → twd_m4sc0-3.1.2}/src/twd/tui.tcss +0 -0
- {twd_m4sc0-3.1.1 → twd_m4sc0-3.1.2}/src/twd/utils.py +0 -0
- {twd_m4sc0-3.1.1 → twd_m4sc0-3.1.2}/src/twd_m4sc0.egg-info/SOURCES.txt +0 -0
- {twd_m4sc0-3.1.1 → twd_m4sc0-3.1.2}/src/twd_m4sc0.egg-info/dependency_links.txt +0 -0
- {twd_m4sc0-3.1.1 → twd_m4sc0-3.1.2}/src/twd_m4sc0.egg-info/entry_points.txt +0 -0
- {twd_m4sc0-3.1.1 → twd_m4sc0-3.1.2}/src/twd_m4sc0.egg-info/requires.txt +0 -0
- {twd_m4sc0-3.1.1 → twd_m4sc0-3.1.2}/src/twd_m4sc0.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "3.1.2"
|
|
@@ -16,7 +16,7 @@ def cli(ctx):
|
|
|
16
16
|
ctx.ensure_object(dict)
|
|
17
17
|
|
|
18
18
|
ctx.obj['config'] = Config.load() # load config
|
|
19
|
-
ctx.obj['manager'] = TwdManager(ctx.obj['config']
|
|
19
|
+
ctx.obj['manager'] = TwdManager(ctx.obj['config']) # pass config
|
|
20
20
|
|
|
21
21
|
# if no subcommand was provided, launch TUI
|
|
22
22
|
if ctx.invoked_subcommand is None:
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
|
-
|
|
3
2
|
from pathlib import Path
|
|
4
3
|
from pydantic import BaseModel, Field, validator
|
|
4
|
+
from enum import Enum
|
|
5
5
|
import json
|
|
6
6
|
import os
|
|
7
7
|
import sys
|
|
@@ -32,10 +32,28 @@ def get_data_path() -> Path:
|
|
|
32
32
|
|
|
33
33
|
return data_dir / "data.csv"
|
|
34
34
|
|
|
35
|
+
class SortField(str, Enum):
|
|
36
|
+
ALIAS = "alias"
|
|
37
|
+
PATH = "path"
|
|
38
|
+
NAME = "name"
|
|
39
|
+
CREATED_AT = "created_at"
|
|
40
|
+
|
|
41
|
+
class SortDirection(str, Enum):
|
|
42
|
+
ASC = "asc"
|
|
43
|
+
DESC = "desc"
|
|
44
|
+
|
|
45
|
+
class SortOrderSetting(BaseModel):
|
|
46
|
+
field: SortField = SortField.CREATED_AT
|
|
47
|
+
direction: SortDirection = SortDirection.ASC
|
|
48
|
+
|
|
49
|
+
class Settings(BaseModel):
|
|
50
|
+
sort_order: SortOrderSetting = Field(default_factory=SortOrderSetting)
|
|
51
|
+
|
|
35
52
|
class Config(BaseModel):
|
|
36
53
|
"""App configuration"""
|
|
37
54
|
|
|
38
55
|
data_path: Path = Field(default_factory=get_data_path)
|
|
56
|
+
settings: Settings = Field(default_factory=Settings)
|
|
39
57
|
|
|
40
58
|
@validator("data_path")
|
|
41
59
|
def validate_path(cls, v):
|
|
@@ -5,7 +5,7 @@ from pydantic import BaseModel, Field, validator
|
|
|
5
5
|
from typing import List, Optional
|
|
6
6
|
from datetime import datetime
|
|
7
7
|
|
|
8
|
-
from .config import Config
|
|
8
|
+
from .config import Config, SortDirection
|
|
9
9
|
|
|
10
10
|
class Entry(BaseModel):
|
|
11
11
|
"""Data class for a signle TWD Entry"""
|
|
@@ -74,17 +74,17 @@ class TwdManager:
|
|
|
74
74
|
CSV_HEADERS = ["alias", "path", "name", "created_at"]
|
|
75
75
|
CSV_HEADERS_FANCY = ["Alias", "Path", "Description", "Created at"]
|
|
76
76
|
|
|
77
|
-
def __init__(self,
|
|
78
|
-
self.
|
|
77
|
+
def __init__(self, config: Config): # accept config as argument
|
|
78
|
+
self.config = config
|
|
79
79
|
self._ensure_csv_exists()
|
|
80
80
|
self.cwd = str(Path.cwd())
|
|
81
81
|
|
|
82
82
|
def _ensure_csv_exists(self) -> None:
|
|
83
83
|
"""create csv headers"""
|
|
84
|
-
if not self.
|
|
85
|
-
self.
|
|
84
|
+
if not self.config.data_path.exists():
|
|
85
|
+
self.config.data_path.parent.mkdir(parents=True, exist_ok=True)
|
|
86
86
|
|
|
87
|
-
with open(self.
|
|
87
|
+
with open(self.config.data_path, 'w', newline='') as f:
|
|
88
88
|
writer = csv.writer(f)
|
|
89
89
|
writer.writerow(self.CSV_HEADERS)
|
|
90
90
|
|
|
@@ -92,7 +92,7 @@ class TwdManager:
|
|
|
92
92
|
"""read all entries"""
|
|
93
93
|
entries = []
|
|
94
94
|
|
|
95
|
-
with open(self.
|
|
95
|
+
with open(self.config.data_path, 'r', newline='') as f:
|
|
96
96
|
reader = csv.reader(f)
|
|
97
97
|
|
|
98
98
|
next(reader) # skip headers
|
|
@@ -103,7 +103,7 @@ class TwdManager:
|
|
|
103
103
|
return entries
|
|
104
104
|
|
|
105
105
|
def _write_all(self, entries: List[Entry]) -> None:
|
|
106
|
-
with open(self.
|
|
106
|
+
with open(self.config.data_path, 'w', newline='') as f:
|
|
107
107
|
writer = csv.writer(f)
|
|
108
108
|
writer.writerow(self.CSV_HEADERS)
|
|
109
109
|
|
|
@@ -141,10 +141,16 @@ class TwdManager:
|
|
|
141
141
|
if not self.exists(alias):
|
|
142
142
|
return False
|
|
143
143
|
|
|
144
|
-
|
|
145
|
-
|
|
144
|
+
entries = self._read_all()
|
|
145
|
+
|
|
146
|
+
# find and upate
|
|
147
|
+
for i, e in enumerate(entries):
|
|
148
|
+
if e.alias == alias.lower():
|
|
149
|
+
entries[i] = entry
|
|
150
|
+
break
|
|
146
151
|
|
|
147
|
-
self.
|
|
152
|
+
self._write_all(entries)
|
|
153
|
+
return True
|
|
148
154
|
|
|
149
155
|
def remove(self, alias: str) -> None:
|
|
150
156
|
"""remove entry by alias"""
|
|
@@ -161,7 +167,9 @@ class TwdManager:
|
|
|
161
167
|
def list_all(self) -> List[Entry]:
|
|
162
168
|
entries = self._read_all()
|
|
163
169
|
|
|
164
|
-
|
|
170
|
+
sort_config = self.config.settings.sort_order
|
|
171
|
+
reverse = (sort_config.direction == SortDirection.DESC)
|
|
172
|
+
return sorted(entries, key=lambda e: getattr(e, sort_config.field.value), reverse=reverse)
|
|
165
173
|
|
|
166
174
|
def exists(self, alias: str) -> bool:
|
|
167
175
|
return self.get(alias) is not None
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "3.1.1"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|