mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-02-20 17:13:53 +08:00
* hardware abstraction class
* De Morgan
* Rename pc hardware class
* Fix sound card in controlsd
* Pc get sim info
* fix hardware in test
* two more
* No more random imei on android
* no randomness on android
* Need to return something that looks like imei for registration to work
* Return proper network strength
* Unused import
* Bug fixes + gpsd is only android
old-commit-hash: c7152d5419
35 lines
709 B
Python
35 lines
709 B
Python
import json
|
|
import os
|
|
from common.hardware import PC
|
|
from common.file_helpers import mkdirs_exists_ok
|
|
|
|
|
|
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:
|
|
raise MissingAuthConfigError('Authenticate with tools/lib/auth.py')
|
|
|
|
|
|
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'))
|