Compare commits
2 commits
4ecf3627d3
...
7dbd93796d
| Author | SHA1 | Date | |
|---|---|---|---|
| 7dbd93796d | |||
| b0a71e804d |
3 changed files with 26 additions and 34 deletions
|
|
@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
|
||||
- Default paths are only calculated once, though users can now not use specifically '%%%%I_DONT_EXIST_%%%%' as a path for the taskrc file and task data directory.
|
||||
|
||||
## [0.2.0] - 2025-04-09
|
||||
|
||||
### Added
|
||||
|
|
|
|||
54
topen.py
54
topen.py
|
|
@ -22,12 +22,14 @@ import os
|
|||
import subprocess
|
||||
import sys
|
||||
from collections import namedtuple
|
||||
from dataclasses import asdict, dataclass, field
|
||||
from dataclasses import asdict, dataclass
|
||||
from pathlib import Path
|
||||
from typing import Any, Self, cast
|
||||
from typing import Any, Self
|
||||
|
||||
from tasklib import Task, TaskWarrior
|
||||
|
||||
NON_EXISTENT_PATH = Path("%%%%I_DONT_EXIST_%%%%")
|
||||
|
||||
|
||||
def main():
|
||||
"""Runs the cli interface.
|
||||
|
|
@ -118,43 +120,14 @@ class TConf:
|
|||
|
||||
task_id: int
|
||||
"""The id (or uuid) of the task to edit a note for."""
|
||||
task_rc: Path
|
||||
_task_rc: Path | None = field(init=False, repr=False, default=None)
|
||||
task_rc: Path = NON_EXISTENT_PATH
|
||||
"""The path to the taskwarrior taskrc file. Can be absolute or relative to cwd."""
|
||||
|
||||
@property
|
||||
def task_rc(self) -> Path:
|
||||
if self._task_rc:
|
||||
return self._task_rc
|
||||
elif _real_path("~/.taskrc").exists():
|
||||
return _real_path("~/.taskrc")
|
||||
elif _real_path("$XDG_CONFIG_HOME/task/taskrc").exists():
|
||||
return _real_path("$XDG_CONFIG_HOME/task/taskrc")
|
||||
else:
|
||||
return _real_path("~/.config/task/taskrc")
|
||||
|
||||
@task_rc.setter
|
||||
def task_rc(self, value: Path | property | None):
|
||||
if type(value) is property:
|
||||
value = TConf._notes_dir
|
||||
self._task_rc = cast(Path, value)
|
||||
|
||||
task_data: Path = Path("~/.task")
|
||||
"""The path to the taskwarrior data directory. Can be absolute or relative to cwd."""
|
||||
|
||||
notes_dir: Path
|
||||
notes_dir: Path = NON_EXISTENT_PATH
|
||||
"""The path to the notes directory."""
|
||||
_notes_dir: Path | None = field(init=False, repr=False, default=None)
|
||||
|
||||
@property
|
||||
def notes_dir(self) -> Path:
|
||||
return self._notes_dir if self._notes_dir else self.task_data.joinpath("notes")
|
||||
|
||||
@notes_dir.setter
|
||||
def notes_dir(self, value: Path | property | None):
|
||||
if type(value) is property:
|
||||
value = TConf._notes_dir
|
||||
self._notes_dir = cast(Path, value)
|
||||
|
||||
notes_ext: str = "md"
|
||||
"""The extension of note files."""
|
||||
|
|
@ -166,13 +139,28 @@ class TConf:
|
|||
"""If set topen will give no feedback on note editing."""
|
||||
|
||||
def __post_init__(self):
|
||||
if self.task_rc == NON_EXISTENT_PATH:
|
||||
self.task_rc = self._default_task_rc()
|
||||
self.task_rc = _real_path(self.task_rc)
|
||||
self.task_data = _real_path(self.task_data)
|
||||
if self.notes_dir == NON_EXISTENT_PATH:
|
||||
self.notes_dir = self._default_notes_dir()
|
||||
self.notes_dir = _real_path(self.notes_dir)
|
||||
|
||||
def __or__(self, other: Any, /) -> Self:
|
||||
return self.__class__(**asdict(self) | asdict(other))
|
||||
|
||||
def _default_task_rc(self) -> Path:
|
||||
if Path("~/.taskrc").exists():
|
||||
return Path("~/.taskrc")
|
||||
elif Path("$XDG_CONFIG_HOME/task/taskrc").exists():
|
||||
return Path("$XDG_CONFIG_HOME/task/taskrc")
|
||||
else:
|
||||
return Path("~/.config/task/taskrc")
|
||||
|
||||
def _default_notes_dir(self) -> Path:
|
||||
return self.task_data.joinpath("notes")
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, d: dict) -> Self:
|
||||
"""Generate a TConf class from a dictionary.
|
||||
|
|
|
|||
2
uv.lock
generated
2
uv.lock
generated
|
|
@ -73,7 +73,7 @@ sdist = { url = "https://files.pythonhosted.org/packages/3e/50/3e876f39e31bad878
|
|||
|
||||
[[package]]
|
||||
name = "topen"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
source = { editable = "." }
|
||||
dependencies = [
|
||||
{ name = "tasklib" },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue