⌈⌋ ⎇ branch:  Bitrhythm


Artifact Content

Artifact b29a232af5deed55d0203a705644df66dc944cbfec746d22992d3e3a3d9a67a7:

  • File autocommit.py — part of check-in [fa4745a0a7] at 2021-11-08 06:21:09 on branch trunk — Added cue Changed Support link Working example for p5 Added dsl for tracking Added autocommit Various Fixes for Save Improve Docs and Bookmarks WebGL Demo (user: dev size: 1367)


import time
from watchdog.observers import Observer
from watchdog.events import RegexMatchingEventHandler
import os

def on_created(event):
    print(f"{event.src_path} has been created")
    os.system(f"git add {event.src_path}")
    os.system(f"git commit -m '{event.src_path} created'")

def on_deleted(event):
    print(f"Delete {event.src_path}!")
    os.system(f"git commit -m '{event.src_path} deleted'")


def on_modified(event):
    print(f"{event.src_path} has been modified")
    os.system(f"git add .")
    os.system(f"git commit -m '{event.src_path} modified'")

if __name__ == "__main__":
    # create the event handler
    ignore_patterns = [r"^.+/\.git.*"]
    ignore_directories = False
    case_sensitive = True
    my_event_handler = RegexMatchingEventHandler(ignore_regexes=ignore_patterns, ignore_directories=ignore_directories, case_sensitive=case_sensitive)

    my_event_handler.on_created = on_created
    my_event_handler.on_deleted = on_deleted
    my_event_handler.on_modified = on_modified

    # create an observer
    path = "."
    go_recursively = True
    my_observer = Observer()
    my_observer.schedule(my_event_handler, path, recursive=go_recursively)

    my_observer.start()
    try:
        while True:
            time.sleep(5)
    except:
        my_observer.stop()
        print("Observer Stopped")
    my_observer.join()