@@ -101,23 +101,34 @@ def build(klass, year: Optional[int], day: Optional[int], watch: bool, timeout:
101
101
102
102
@property
103
103
def base (self ):
104
- return pathlib .Path (__file__ ).parent / str (self .year )
104
+ return pathlib .Path (__file__ ).parent
105
+
106
+ @property
107
+ def year_path (self ) -> pathlib .Path :
108
+ return self .base / f"{ self .year } "
109
+
110
+ @property
111
+ def code_path (self ) -> pathlib .Path :
112
+ return self .year_path / f"d{ day :02} .py"
113
+
114
+ @property
115
+ def solution_path (self ) -> pathlib .Path :
116
+ return self .base / f"solutions/{ self .year } .txt"
105
117
106
118
def from_template (self , day : int ) -> None :
107
119
"""Create a new exercise file from template."""
108
- filename = self .base / f"d { day :02 } .py"
120
+ filename = self .code_path
109
121
if filename .exists ():
110
122
print (f"{ filename .name } already exists" )
111
123
return
112
- template_file = self .base / "../ shared/tmpl.py"
124
+ template_file = self .base / "shared/tmpl.py"
113
125
template = string .Template (template_file .read_text ())
114
126
website = site .Website (self .year , day )
115
127
out = template .substitute (
116
128
day = f"{ day :02} " ,
117
129
sample = website .codeblocks (),
118
130
title = website .title ().strip ("- " ),
119
131
)
120
- filename = self .base / f"d{ day :02} .py"
121
132
filename .write_text (out )
122
133
filename .chmod (0o700 )
123
134
@@ -127,7 +138,7 @@ def december(self, timeout: int) -> None:
127
138
start = datetime .datetime (year , 11 , 30 , tzinfo = EST )
128
139
end = datetime .datetime (year , 12 , 25 , 1 , tzinfo = EST )
129
140
while start < self .now () < end :
130
- solved = [int (line .split ()[0 ]) for line in ( self .base / "solutions.txt" ) .read_text ().splitlines ()]
141
+ solved = [int (line .split ()[0 ]) for line in self .solution_path .read_text ().splitlines ()]
131
142
if self .now ().day in solved :
132
143
print ("Wait for tomorrow's problem to start and solve it." )
133
144
self .wait_solve (timeout )
@@ -188,7 +199,7 @@ def live_solve(self) -> None:
188
199
else :
189
200
# Watch the file.
190
201
inotify = inotify_simple .INotify ()
191
- inotify .add_watch (self .base , inotify_simple .flags .CLOSE_WRITE )
202
+ inotify .add_watch (self .year_path , inotify_simple .flags .CLOSE_WRITE )
192
203
while events := inotify .read ():
193
204
if not any (i .name == f"d{ day :02} .py" for i in events ):
194
205
continue
@@ -251,7 +262,7 @@ def live_solve(self) -> None:
251
262
if not solutions :
252
263
solutions = {part : obj .run_solver (part , raw_data ) for part in (1 , 2 )}
253
264
inotify = inotify_simple .INotify ()
254
- inotify .add_watch (self .base , inotify_simple .flags .CLOSE_WRITE )
265
+ inotify .add_watch (self .year_path , inotify_simple .flags .CLOSE_WRITE )
255
266
256
267
stop_at = self .now () + datetime .timedelta (hours = 6 )
257
268
while self .now () < stop_at :
@@ -273,7 +284,7 @@ def live_solve(self) -> None:
273
284
def read_solutions (self ) -> dict [int , dict [int , int | str ]]:
274
285
"""Return solutions from file."""
275
286
solutions : dict [int , dict [int , int | str ]] = {}
276
- for line in ( self .base / "solutions.txt" ) .read_text ().splitlines ():
287
+ for line in self .solution_path .read_text ().splitlines ():
277
288
if not line :
278
289
continue
279
290
parts = line .split ()
@@ -319,8 +330,7 @@ def update_solutions(self, day: int, solutions: Optional[dict[int, int | str]] =
319
330
for line_day in sorted (existing )
320
331
]
321
332
322
- solution_file = self .base / "solutions.txt"
323
- solution_file .write_text ("\n " .join (lines ) + "\n " )
333
+ self .solution_path .write_text ("\n " .join (lines ) + "\n " )
324
334
325
335
326
336
@click .command ()
0 commit comments