Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ __pycache__/
venv/
.pybuild
*.egg-info
*.code-workspace
*.code-workspace
docker-compose.yaml
/.DS_Store
146 changes: 80 additions & 66 deletions chimera_app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,31 @@ def merge_single_level(src1, src2):

result = {}
for key in keys:
if key in src1 and key in src2:
result[key] = src1[key] | src2[key]
elif key in src1:
result[key] = src1[key]
else:
result[key] = src2[key]
if key in src1 and key in src2:
result[key] = src1[key] | src2[key]
elif key in src1:
result[key] = src1[key]
else:
result[key] = src2[key]

return result

CONTENT_SHARE_ONLY = os.environ.get('CONTENT_SHARE_ONLY') == 'true'

CONTENT_SHARE_ONLY = os.environ.get("CONTENT_SHARE_ONLY") == "true"

RESOURCE_DIR = os.getcwd()
if not os.path.isfile(os.path.join(RESOURCE_DIR, 'views/base.tpl')):
if not os.path.isfile(os.path.join(RESOURCE_DIR, "views/base.tpl")):
RESOURCE_DIR = "/usr/share/chimera"

BIN_PATH = os.path.abspath('libexec')
BIN_PATH = os.path.abspath("libexec")
if not os.path.isdir(BIN_PATH):
BIN_PATH = "/usr/libexec/chimera"

BANNER_DIR = context.DATA_HOME + '/chimera/images'
DATA_DIR = context.DATA_HOME + '/chimera/data'
CONTENT_DIR = context.DATA_HOME + '/chimera/content'
SETTINGS_DIR = context.CONFIG_HOME + '/chimera'
UPLOADS_DIR = os.path.join(context.CACHE_HOME, 'chimera', 'uploads')
BANNER_DIR = context.DATA_HOME + "/chimera/images"
DATA_DIR = context.DATA_HOME + "/chimera/data"
CONTENT_DIR = context.DATA_HOME + "/chimera/content"
SETTINGS_DIR = context.CONFIG_HOME + "/chimera"
UPLOADS_DIR = os.path.join(context.CACHE_HOME, "chimera", "uploads")

SETTINGS_DEFAULT = {
"enable_remote_launch": False,
Expand All @@ -46,23 +47,25 @@ def merge_single_level(src1, src2):
"ftp_password": generate_password(12),
"ftp_port": 2121,
"keep_password": False,
"steamgriddb_api_key": "423ef7be0f4b9f8cfa1a471149c5b72c",
"user_steamgriddb_key_set": False,
}

SESSION_OPTIONS = {
'session.cookie_expires': True,
'session.httponly': True,
'session.timeout': 3600 * 2,
'session.type': 'memory',
'session.validate_key': True,
"session.cookie_expires": True,
"session.httponly": True,
"session.timeout": 3600 * 2,
"session.type": "memory",
"session.validate_key": True,
}

SETTINGS_HANDLER = Settings(SETTINGS_DIR, SETTINGS_DEFAULT)

# settings overrides for exclusive content sharing mode
if CONTENT_SHARE_ONLY:
SETTINGS_HANDLER.set_setting('enable_content_sharing', True)
SETTINGS_HANDLER.set_setting('enable_remote_launch', False)
SETTINGS_HANDLER.set_setting('enable_ftp_server', False)
SETTINGS_HANDLER.set_setting("enable_content_sharing", True)
SETTINGS_HANDLER.set_setting("enable_remote_launch", False)
SETTINGS_HANDLER.set_setting("enable_ftp_server", False)
FTP_SERVER = None
STORAGE_HANDLER = None
SSH_KEY_HANDLER = None
Expand All @@ -73,12 +76,13 @@ def merge_single_level(src1, src2):

FTP_SERVER = FTPServer(SETTINGS_HANDLER)
STORAGE_HANDLER = StorageConfig()
SSH_KEY_HANDLER = SSHKeys(os.path.expanduser('~/.ssh/authorized_keys'))
SSH_KEY_HANDLER = SSHKeys(os.path.expanduser("~/.ssh/authorized_keys"))

AUTHENTICATOR = Authenticator(BIN_PATH, password_length=5)


STEAMGRID_HANDLER = Steamgrid("423ef7be0f4b9f8cfa1a471149c5b72c")
STEAMGRID_HANDLER = Steamgrid(SETTINGS_HANDLER.get_setting("steamgriddb_api_key"))


PLATFORMS_DEFAULT = {
"32x": {
Expand Down Expand Up @@ -225,42 +229,48 @@ def merge_single_level(src1, src2):

# set a default cmd property on all default platforms
for platform_id in PLATFORMS_DEFAULT:
PLATFORMS_DEFAULT[platform_id]['cmd'] = platform_id
PLATFORMS_DEFAULT[platform_id]["cmd"] = platform_id

# merge user settings with default platforms
PLATFORMS = PLATFORMS_DEFAULT
PLATFORM_SETTINGS = SETTINGS_HANDLER.get_setting('platforms')
PLATFORM_SETTINGS = SETTINGS_HANDLER.get_setting("platforms")
if PLATFORM_SETTINGS:
PLATFORMS = merge_single_level(PLATFORMS_DEFAULT, PLATFORM_SETTINGS)

# set id property on all platforms
for platform_id in PLATFORMS:
PLATFORMS[platform_id]['id'] = platform_id
PLATFORMS[platform_id]["id"] = platform_id

# these platforms do not support content sharing so disable them when running in exclusive content sharing mode
if CONTENT_SHARE_ONLY:
PLATFORMS['epic-store']['enabled'] = False
PLATFORMS['gog']['enabled'] = False
PLATFORMS['flathub']['enabled'] = False
PLATFORMS["epic-store"]["enabled"] = False
PLATFORMS["gog"]["enabled"] = False
PLATFORMS["flathub"]["enabled"] = False

# drop disabled and invalid platforms
FILTERED_PLATFORMS = {}
for key, value in PLATFORMS.items():
if 'enabled' not in value or not value['enabled'] or 'name' not in value or 'cmd' not in value:
if (
"enabled" not in value
or not value["enabled"]
or "name" not in value
or "cmd" not in value
):
continue

FILTERED_PLATFORMS[key] = value

PLATFORMS = dict(sorted(FILTERED_PLATFORMS.items(), key=lambda item: item[1]['name']))
PLATFORMS = dict(sorted(FILTERED_PLATFORMS.items(), key=lambda item: item[1]["name"]))


GAMEDB = {
'gog' : {},
'epic-store' : {},
'flathub' : {},
'steam' : {},
"gog": {},
"epic-store": {},
"flathub": {},
"steam": {},
}


@dataclass
class GameDbEntry:
name: str
Expand All @@ -284,42 +294,46 @@ class GameDbEntry:

@property
def status_icon(self):
if self.status == 'verified':
return '🟢'
elif self.status == 'playable':
return '🟡'
elif self.status == 'unsupported':
return '🔴'
if self.status == "verified":
return "🟢"
elif self.status == "playable":
return "🟡"
elif self.status == "unsupported":
return "🔴"
else:
return '⚫'
return "⚫"


try:
with open(os.path.join(DATA_DIR, 'gamedb.yaml')) as yaml_file:
with open(os.path.join(DATA_DIR, "gamedb.yaml")) as yaml_file:
game_list = yaml.load(yaml_file, Loader=yaml.FullLoader)

for game in game_list:
if 'id' in game:
game['id'] = str(game['id'])
GAMEDB[game['platform']][game['id']] = GameDbEntry(
name=game['name'],
platform=game['platform'],
id=game['id'],
banner=game['banner'] if 'banner' in game else None,
poster=game['poster'] if 'poster' in game else None,
background=game['background'] if 'background' in game else None,
logo=game['logo'] if 'logo' in game else None,
icon=game['icon'] if 'icon' in game else None,
compat_tool=game['compat_tool'] if 'compat_tool' in game else None,
compat_config=game['compat_config'] if 'compat_config' in game else None,
launch_options=game['launch_options'] if 'launch_options' in game else None,
status=game['status'] if 'status' in game else None,
store=game['store'] if 'store' in game else None,
steam_input=game['steam_input'] if 'steam_input' in game else None,
notes=game['notes'] if 'notes' in game else None,
priority=game['priority'] if 'priority' in game else None,
patch_dir=game['patch_dir'] if 'patch_dir' in game else None,
patches=game['patches'] if 'patches' in game else None,
if "id" in game:
game["id"] = str(game["id"])
GAMEDB[game["platform"]][game["id"]] = GameDbEntry(
name=game["name"],
platform=game["platform"],
id=game["id"],
banner=game["banner"] if "banner" in game else None,
poster=game["poster"] if "poster" in game else None,
background=game["background"] if "background" in game else None,
logo=game["logo"] if "logo" in game else None,
icon=game["icon"] if "icon" in game else None,
compat_tool=game["compat_tool"] if "compat_tool" in game else None,
compat_config=(
game["compat_config"] if "compat_config" in game else None
),
launch_options=(
game["launch_options"] if "launch_options" in game else None
),
status=game["status"] if "status" in game else None,
store=game["store"] if "store" in game else None,
steam_input=game["steam_input"] if "steam_input" in game else None,
notes=game["notes"] if "notes" in game else None,
priority=game["priority"] if "priority" in game else None,
patch_dir=game["patch_dir"] if "patch_dir" in game else None,
patches=game["patches"] if "patches" in game else None,
)
except:
print('WARNING: Failed to load game database')
print("WARNING: Failed to load game database")
Loading