File size: 991 Bytes
d4159be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Launch the bundled, read-only data library with local logs and settings."""
from pathlib import Path
from contextlib import redirect_stderr, redirect_stdout
import os
import sys
import traceback

ROOT = Path(__file__).resolve().parents[1]
os.chdir(ROOT / 'player')
for variable, folder in [('APPDATA', 'settings'), ('LOCALAPPDATA', 'local-settings')]:
    directory = ROOT / 'player/runtime' / folder
    directory.mkdir(parents=True, exist_ok=True)
    os.environ[variable] = str(directory)
logs = ROOT / 'player/runtime/logs'
logs.mkdir(parents=True, exist_ok=True)

def main():
    with (logs / 'player.log').open('w', encoding='utf-8', buffering=1) as log:
        with redirect_stdout(log), redirect_stderr(log):
            try:
                from compact_player import serve
                serve(ROOT / 'data')
                return 0
            except Exception:
                traceback.print_exc()
                return 1

if __name__ == '__main__':
    sys.exit(main())