Skip to content

Commit da5d618

Browse files
committedJan 9, 2025·
join time and date
1 parent e839e4a commit da5d618

File tree

6 files changed

+36
-42
lines changed

6 files changed

+36
-42
lines changed
 

‎.github/workflows/python-publish.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ jobs:
1818
- name: Build the package
1919
run: python3 -m pip install --upgrade build && python3 -m build
2020
- name: Publish package
21-
uses: pypa/gh-action-pypi-publish@v1.8.10
21+
uses: pypa/gh-action-pypi-publish@release/v1
2222
with:
2323
password: ${{ secrets.PYPI_GITHUB_TOUCHTIMESTAMP }}

‎pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "touch-timestamp"
7-
version = "0.4.0"
7+
version = "0.4.1"
88
description = "Change file timestamps with a dialog window."
99
authors = ["Edvard Rejthar <edvard.rejthar@nic.cz>"]
1010
license = "GPL-3.0-or-later"

‎touch_timestamp/app.py

+24-20
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1+
import subprocess
2+
from dataclasses import MISSING, dataclass, field
13
from datetime import datetime
24
from os import utime
3-
import subprocess
5+
from pathlib import Path
6+
from typing import Annotated, get_args
47

58
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
109
from mininterface import Tag
10+
from mininterface.exceptions import ValidationFail
11+
from mininterface.subcommands import Command
1112
from tyro.conf import Positional
12-
from dataclasses import MISSING, dataclass, field
13-
from pathlib import Path
1413

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)
1717

1818
DateFormat = str # Use type as of Python3.12
1919

@@ -52,24 +52,28 @@ def init(self):
5252
class Set(App):
5353
""" Set to a specific time """
5454

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()
5657
""" 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 """
5962

6063
def init(self):
6164
super().init()
6265
# NOTE program fails on wrong date in GUI
6366
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())
6670

6771
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)
7377

7478

7579
@dataclass
@@ -151,7 +155,7 @@ def init(self):
151155
get_args(self.__annotations__["reference"])[1].choices = self.files
152156

153157
def run(self):
154-
reference = count_relative_shift(self.date, self.time, self.reference)
158+
reference = count_relative_shift(self.date, self.reference)
155159

156160
# microsecond precision is neglected here, touch does not takes it
157161
touch_multiple(self.files, f"{reference.days} days {reference.seconds} seconds")

‎touch_timestamp/controller.py

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
import subprocess
2-
from datetime import datetime
3-
from os import utime
1+
from mininterface import Tag
42

5-
import dateutil.parser
6-
from mininterface import Mininterface, Tag
7-
8-
# from .env import Env
9-
from .utils import (count_relative_shift, get_date, set_files_timestamp,
10-
touch_multiple)
3+
from .utils import count_relative_shift, get_date
114

125

136
class Controller:

‎touch_timestamp/touch_timestamp.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/env python3
22
from mininterface import run
33
from mininterface.subcommands import SubcommandPlaceholder
4-
from .app import FromName, RelativeToReference, Set, Exif, Shift
4+
5+
from .app import Exif, FromName, RelativeToReference, Set, Shift
56

67
# NOTE add tests for CLI flags
78

‎touch_timestamp/utils.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,22 @@
33
from pathlib import Path
44
import subprocess
55

6-
import dateutil.parser
7-
86

97
def get_date(path: str | Path):
108
return datetime.fromtimestamp(Path(path).stat().st_mtime)
119

1210

13-
def set_files_timestamp(date, time, files: list[str]):
14-
print("Touching files", date, time)
11+
def set_files_timestamp(date: datetime, files: list[str]):
12+
print("Touching files", date)
1513
print(", ".join(str(f) for f in files))
16-
if date and time:
17-
time = dateutil.parser.parse(f"{date} {time}").timestamp()
14+
if date:
15+
time = date.timestamp()
1816
[utime(f, (time, time)) for f in files]
1917
return True
2018

2119

22-
def count_relative_shift(date, time, path: str | Path):
23-
target = dateutil.parser.parse(f"{date} {time}")
24-
date = get_date(path)
25-
return target - date
20+
def count_relative_shift(date: datetime, path: str | Path):
21+
return date - get_date(path)
2622

2723

2824
def touch_multiple(files: list[Path], relative_str):

0 commit comments

Comments
 (0)
Please sign in to comment.