mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-02-19 07:44:00 +08:00
version: lp-dp v0.9.5 for EON/C2 date: 2023-09-13T13:36:48 commit: 1d59b81c40b93f37d4a341c5d35b1c3cd293543d
35 lines
673 B
Python
35 lines
673 B
Python
import json
|
|
import os
|
|
from openpilot.common.file_helpers import mkdirs_exists_ok
|
|
from openpilot.system.hardware import PC
|
|
|
|
|
|
class MissingAuthConfigError(Exception):
|
|
pass
|
|
|
|
|
|
if PC:
|
|
CONFIG_DIR = os.path.expanduser('~/.comma')
|
|
else:
|
|
CONFIG_DIR = "/tmp/.comma"
|
|
|
|
mkdirs_exists_ok(CONFIG_DIR)
|
|
|
|
|
|
def get_token():
|
|
try:
|
|
with open(os.path.join(CONFIG_DIR, 'auth.json')) as f:
|
|
auth = json.load(f)
|
|
return auth['access_token']
|
|
except Exception:
|
|
return None
|
|
|
|
|
|
def set_token(token):
|
|
with open(os.path.join(CONFIG_DIR, 'auth.json'), 'w') as f:
|
|
json.dump({'access_token': token}, f)
|
|
|
|
|
|
def clear_token():
|
|
os.unlink(os.path.join(CONFIG_DIR, 'auth.json'))
|