51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
from core.Constants import Constants
|
|
from core.models.BaseProfile import BaseProfile
|
|
from core.models.session.ApplicationVersion import ApplicationVersion
|
|
from core.models.session.ProxyConfiguration import ProxyConfiguration
|
|
from core.models.session.SessionConnection import SessionConnection
|
|
from dataclasses import dataclass
|
|
from json import JSONDecodeError
|
|
from typing import Optional
|
|
import json
|
|
import os
|
|
|
|
|
|
@dataclass
|
|
class SessionProfile(BaseProfile):
|
|
resolution: str
|
|
application_version: Optional[ApplicationVersion]
|
|
connection: Optional[SessionConnection]
|
|
|
|
def attach_proxy_configuration(self, proxy_configuration):
|
|
|
|
proxy_configuration_file_contents = f'{proxy_configuration.to_json(indent=4)}\n'
|
|
os.makedirs(Constants.SP_CONFIG_HOME, exist_ok=True)
|
|
|
|
proxy_configuration_file_path = self.get_proxy_configuration_path()
|
|
|
|
with open(proxy_configuration_file_path, 'w') as proxy_configuration_file:
|
|
|
|
proxy_configuration_file.write(proxy_configuration_file_contents)
|
|
proxy_configuration_file.close()
|
|
|
|
def get_proxy_configuration_path(self):
|
|
return f'{self.get_config_path()}/proxy.json'
|
|
|
|
def get_proxy_configuration(self):
|
|
|
|
try:
|
|
config_file_contents = open(self.get_proxy_configuration_path(), 'r').read()
|
|
except FileNotFoundError:
|
|
return None
|
|
|
|
try:
|
|
proxy_configuration = json.loads(config_file_contents)
|
|
except JSONDecodeError:
|
|
return None
|
|
|
|
proxy_configuration = ProxyConfiguration.from_dict(proxy_configuration)
|
|
|
|
return proxy_configuration
|
|
|
|
def has_proxy_configuration(self):
|
|
return os.path.exists(f'{self.get_config_path()}/proxy.json')
|