|
| 1 | +import subprocess |
| 2 | +from dataclasses import MISSING, dataclass, field |
1 | 3 | from datetime import datetime
|
2 | 4 | from os import utime
|
3 |
| -import subprocess |
| 5 | +from pathlib import Path |
| 6 | +from typing import Annotated, get_args |
4 | 7 |
|
5 | 8 | import dateutil
|
6 |
| -from .controller import Controller |
7 |
| -from .utils import (count_relative_shift, get_date, set_files_timestamp, |
8 |
| - touch_multiple) |
9 |
| -from typing import Annotated, get_args |
10 | 9 | from mininterface import Tag
|
| 10 | +from mininterface.exceptions import ValidationFail |
| 11 | +from mininterface.subcommands import Command |
11 | 12 | from tyro.conf import Positional
|
12 |
| -from dataclasses import MISSING, dataclass, field |
13 |
| -from pathlib import Path |
14 | 13 |
|
15 |
| -from mininterface.subcommands import Command |
16 |
| -from mininterface.exceptions import ValidationFail |
| 14 | +from .controller import Controller |
| 15 | +from .utils import (count_relative_shift, get_date, set_files_timestamp, |
| 16 | + touch_multiple) |
17 | 17 |
|
18 | 18 | DateFormat = str # Use type as of Python3.12
|
19 | 19 |
|
@@ -52,24 +52,28 @@ def init(self):
|
52 | 52 | class Set(App):
|
53 | 53 | """ Set to a specific time """
|
54 | 54 |
|
55 |
| - date: Annotated[str, Tag(on_change=c.refresh_title)] = "" |
| 55 | + # TODO, should be working with DatetimeTag automatically |
| 56 | + date: Annotated[datetime, Tag(on_change=c.refresh_title)] = datetime.now() |
56 | 57 | """ Set specific date """
|
57 |
| - time: Annotated[str, Tag(on_change=c.refresh_title)] = "" |
58 |
| - """ Set specific time """ |
| 58 | + # date: Annotated[str, Tag(on_change=c.refresh_title)] = "" |
| 59 | + # """ Set specific date """ |
| 60 | + # time: Annotated[str, Tag(on_change=c.refresh_title)] = "" |
| 61 | + # """ Set specific time """ |
59 | 62 |
|
60 | 63 | def init(self):
|
61 | 64 | super().init()
|
62 | 65 | # NOTE program fails on wrong date in GUI
|
63 | 66 | if self.ref_date:
|
64 |
| - self.date = self.date or str(self.ref_date.date()) |
65 |
| - self.time = self.time or str(self.ref_date.time()) |
| 67 | + self.date = self.date or str(self.ref_date.timestamp()) |
| 68 | + # self.date = self.date or str(self.ref_date.date()) |
| 69 | + # self.time = self.time or str(self.ref_date.time()) |
66 | 70 |
|
67 | 71 | def run(self):
|
68 |
| - if bool(self.date) != bool(self.time): |
69 |
| - # NOTE allow only time change (the date would stay) |
70 |
| - print("You have to specify both date and time ") |
71 |
| - quit() |
72 |
| - set_files_timestamp(self.date, self.time, self.files) |
| 72 | + # if bool(self.date) != bool(self.time): |
| 73 | + # # NOTE allow only time change (the date would stay) |
| 74 | + # print("You have to specify both date and time ") |
| 75 | + # quit() |
| 76 | + set_files_timestamp(self.date, self.files) |
73 | 77 |
|
74 | 78 |
|
75 | 79 | @dataclass
|
@@ -151,7 +155,7 @@ def init(self):
|
151 | 155 | get_args(self.__annotations__["reference"])[1].choices = self.files
|
152 | 156 |
|
153 | 157 | def run(self):
|
154 |
| - reference = count_relative_shift(self.date, self.time, self.reference) |
| 158 | + reference = count_relative_shift(self.date, self.reference) |
155 | 159 |
|
156 | 160 | # microsecond precision is neglected here, touch does not takes it
|
157 | 161 | touch_multiple(self.files, f"{reference.days} days {reference.seconds} seconds")
|
0 commit comments