-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdev_player.py
More file actions
64 lines (51 loc) · 2.21 KB
/
Copy pathdev_player.py
File metadata and controls
64 lines (51 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os
import json
import shutil
def get_clean_path():
p = input("где проект? (Enter если тут): ").strip()
if not p or p == '.': return os.getcwd()
if p.startswith('home/'): p = '/' + p
return os.path.abspath(os.path.expanduser(p))
def replay_time(project_path, target_time):
replay_dir = os.path.join(project_path, '.dev-replay')
log_file = os.path.join(replay_dir, 'log.jsonl')
machine_dir = os.path.join(replay_dir, 'time_machine')
if not os.path.exists(log_file):
print("логов нет. ты точно запускал dev log тут?")
return
file_states = {}
matched = 0
try:
with open(log_file, 'r', encoding='utf-8') as f:
for line in f:
data = json.loads(line)
if data.get('file') == '[TERMINAL]' or 'content' not in data: continue
if data['ts'] <= target_time:
matched += 1
file_states[data['file']] = data['content']
except Exception:
print("ошибка при чтении логов. проверь файл log.jsonl")
return
if not file_states:
print("на это время ничего нет. попробуй попозже.")
return
try:
if os.path.exists(machine_dir):
shutil.rmtree(machine_dir)
os.makedirs(machine_dir, exist_ok=True)
for filepath, content in file_states.items():
target_path = os.path.join(machine_dir, os.path.basename(filepath))
with open(target_path, 'w', encoding='utf-8') as f:
f.write(content)
except Exception:
print("не вышло собрать файлы. проверь права доступа.")
return
print(f"\nготово. восстановил {matched} слепков.")
print(f"твой код из прошлого лежит тут: {machine_dir}")
def main():
project_path = get_clean_path()
target_time = input("на какое время мотаем? (например 20:35): ").strip()
if len(target_time) == 5: target_time += ":59"
replay_time(project_path, target_time)
if __name__ == "__main__":
main()