-
Notifications
You must be signed in to change notification settings - Fork 0
/
valheim_inotify.py
37 lines (28 loc) · 1.11 KB
/
valheim_inotify.py
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
import sys
import os
from pathlib import Path
import inotify.adapters
import logging
from pytz import timezone
from datetime import datetime
VALHEIM_PATH = sys.argv[1] if sys.argv[1] else Path(f"{os.environ['HOME']}/.config/unity3d/IronGate/Valheim")
VALHEIM_WORLDS = VALHEIM_PATH / 'worlds'
VALHEIM_CHARS = VALHEIM_PATH / 'characters'
EVENT='IN_MOVED_TO'
def detect_state(paths):
i = inotify.adapters.Inotify()
for p in paths:
i.add_watch(str(p))
for event in i.event_gen(yield_nones=False):
(_, type_names, path, filename) = event
logger.debug("PATH=[{}] FILENAME=[{}] EVENT_TYPES={}".format(
path, filename, type_names))
if EVENT in type_names:
logger.info("%s: %s", filename, type_names)
def start_logging():
logging.basicConfig(level=logging.INFO, format='%(asctime)-15s %(message)s' )
logging.Formatter.converter = lambda *args: datetime.now(tz=timezone('Europe/Berlin')).timetuple()
return logging.getLogger('_main_')
if __name__ == '__main__':
logger = start_logging()
WORLDFILE = detect_state([VALHEIM_WORLDS, VALHEIM_CHARS])