How to use:
- Install Python
- Install Python Watchdog:
pip install watchdog
- Put
undertailer.py
next toundertale.ini
- Run it from the commandline:
python undertailer.py
- Play undertale and watch the commandline output
import os | |
import sys | |
import time | |
import logging | |
import ConfigParser | |
from watchdog.observers import Observer | |
from watchdog.events import PatternMatchingEventHandler | |
UNDERTALE_PATH = os.path.dirname(__file__) | |
def get_with_default(config, section, option, default): | |
return config.get(section, option) if config.has_section(section) and config.has_option(section, option) else default | |
class UndertaleEventHandler(PatternMatchingEventHandler): | |
def __init__(self, path): | |
super(UndertaleEventHandler, self).__init__(patterns=[path]) | |
self.path = path | |
self.config = self.read_config() | |
self.print_config() | |
print "Ready" | |
def read_config(self): | |
with open(self.path) as config_file: | |
config = ConfigParser.RawConfigParser() | |
config.readfp(config_file) | |
return config | |
def print_config(self): | |
for section in self.config.sections(): | |
for option, value in self.config.items(section): | |
print "{section}: {option}: {value}".format(section=section, option=option, value=value) | |
def on_modified(self, event): | |
new_config = self.read_config() | |
old_config = self.config | |
new_sections = set(new_config.sections()) | |
old_sections = set(old_config.sections()) | |
all_sections = new_sections.union(old_sections) | |
changes = [] | |
for section in all_sections: | |
old_options = set(old_config.options(section)) | |
new_options = set(new_config.options(section)) | |
all_options = old_options.union(new_options) | |
for option in all_options: | |
old_value = get_with_default(old_config, section, option, None) | |
new_value = get_with_default(new_config, section, option, None) | |
if old_value != new_value: | |
changes.append(dict(section=section, option=option, old_value=old_value, new_value=new_value)) | |
if changes: | |
print "\n\nCHANGES!\n" | |
for change in changes: | |
print "{section}: {option}: {old_value} => {new_value}".format(**change) | |
self.config = new_config | |
if __name__ == "__main__": | |
event_handler = UndertaleEventHandler(UNDERTALE_PATH + 'undertale.ini') | |
observer = Observer() | |
observer.schedule(event_handler, UNDERTALE_PATH, recursive=False) | |
observer.start() | |
try: | |
while True: | |
time.sleep(1) | |
except KeyboardInterrupt: | |
observer.stop() | |
observer.join() |