- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit_auto_upload.py
More file actions
Latest commit
42 lines (38 loc) · 1.34 KB
/
Copy pathgit_auto_upload.py
File metadata and controls
42 lines (38 loc) · 1.34 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
importtime
importsubprocess
fromwatchdog.observersimportObserver
fromwatchdog.eventsimportFileSystemEventHandler
PROJECT_PATH=r"C:\Users\mursa\PycharmProjects\ai_job"
GIT_PATH=r"C:\Program Files\Git\cmd\git.exe"
classGitAutoUploader(FileSystemEventHandler):
defon_modified(self, event):
ifevent.is_directoryor".git"inevent.src_path:
return
print(f"Detected change in: {event.src_path}")
# Stage files
run_git("add", ".")
# Commit changes (ignore if nothing to commit)
run_git("commit", "-m", "Auto update")
# Push to GitHub
run_git("push", "origin", "main")
defrun_git(*args):
result=subprocess.run([GIT_PATH, "-C", PROJECT_PATH] +list(args), capture_output=True, text=True)
ifresult.returncode!=0:
if"nothing to commit"inresult.stderr.lower():
print("Nothing to commit.")
else:
print("❌ Git error:", result.stderr)
else:
print(result.stdout)
if__name__=="__main__":
print(f"👀 Watching: {PROJECT_PATH}")
event_handler=GitAutoUploader()
observer=Observer()
observer.schedule(event_handler, path=PROJECT_PATH, recursive=True)
observer.start()
try:
whileTrue:
time.sleep(5)
exceptKeyboardInterrupt:
observer.stop()
observer.join()