Params path only in one place (#2344)

* fix params paths

* Qcom & qcom2

* This env variable is not used anywhere

* params path in only one place

* fix other PARAMS_PATH references

* absolute path is probably better
old-commit-hash: 3dd9448981
This commit is contained in:
Willem Melching 2020-10-15 13:15:22 +02:00 committed by GitHub
parent 8531345bf9
commit 789d5176cb
8 changed files with 40 additions and 21 deletions

View File

@ -4,7 +4,5 @@ BASEDIR = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__
from common.hardware import PC
if PC:
PERSIST = os.path.join(BASEDIR, "persist")
PARAMS = os.path.join(BASEDIR, "persist", "params")
else:
PERSIST = "/persist"
PARAMS = "/data/params"

View File

@ -6,7 +6,8 @@ from params_pxd cimport Params as c_Params
import os
import threading
from common.basedir import PARAMS
from common.basedir import BASEDIR
os.environ['BASEDIR'] = BASEDIR
cdef enum TxType:
PERSISTENT = 1
@ -84,9 +85,9 @@ class UnknownKeyName(Exception):
cdef class Params:
cdef c_Params* p
def __cinit__(self, d=PARAMS, bool persistent_params=False):
if persistent_params:
self.p = new c_Params(True)
def __cinit__(self, d=None, bool persistent_params=False):
if d is None:
self.p = new c_Params(persistent_params)
else:
self.p = new c_Params(<string>d.encode())
@ -150,7 +151,7 @@ cdef class Params:
self.p.delete_db_value(key)
def put_nonblocking(key, val, d=PARAMS):
def put_nonblocking(key, val, d=None):
def f(key, val):
params = Params(d)
params.put(key, val)

View File

@ -1,12 +1,24 @@
import os
import subprocess
from distutils.core import Extension, setup
from Cython.Build import cythonize
from common.cython_hacks import BuildExtWithoutPlatformSuffix
from common.basedir import BASEDIR
from common.hardware import TICI
ARCH = subprocess.check_output(["uname", "-m"], encoding='utf8').rstrip() # pylint: disable=unexpected-keyword-arg
sourcefiles = ['params_pyx.pyx']
extra_compile_args = ["-std=c++11"]
if ARCH == "aarch64":
if TICI:
extra_compile_args += ["-DQCOM2"]
else:
extra_compile_args += ["-DQCOM"]
setup(name='common',
cmdclass={'build_ext': BuildExtWithoutPlatformSuffix},
ext_modules=cythonize(

View File

@ -21,6 +21,11 @@ class TestParams(unittest.TestCase):
self.params.put("DongleId", "cb38263377b873ee")
assert self.params.get("DongleId") == b"cb38263377b873ee"
def test_persist_params_put_and_get(self):
p = Params(persistent_params=True)
p.put("DongleId", "cb38263377b873ee")
assert p.get("DongleId") == b"cb38263377b873ee"
def test_params_non_ascii(self):
st = b"\xe1\x90\xff"
self.params.put("CarParams", st)

View File

@ -7,7 +7,7 @@ from functools import wraps
import cereal.messaging as messaging
from cereal import car
from common.basedir import PARAMS
from common.basedir import BASEDIR
from common.hardware import ANDROID
from common.params import Params
from common.spinner import Spinner
@ -30,7 +30,7 @@ def reset_panda(fn):
os.environ['STARTED'] = '1'
os.environ['BOARDD_LOOPBACK'] = '1'
os.environ['PARAMS_PATH'] = PARAMS
os.environ['BASEDIR'] = BASEDIR
@reset_panda
@with_processes(['boardd'])

View File

@ -21,23 +21,27 @@
#include "common/utilpp.h"
namespace {
std::string getenv_default(const char* env_var, const char* default_val) {
std::string getenv_default(const char* env_var, const char * suffix, const char* default_val) {
const char* env_val = getenv(env_var);
return std::string(env_val != NULL ? env_val : default_val);
if (env_val != NULL){
return std::string(env_val) + std::string(suffix);
} else{
return std::string(default_val);
}
}
const std::string default_params_path = getenv_default("PARAMS_PATH", "/data/params");
#if defined(QCOM) || defined(QCOM2)
const std::string default_params_path = "/data/params";
#else
const std::string default_params_path = getenv_default("BASEDIR", "persists/params", "/data/params");
#endif
#ifdef QCOM
const std::string persistent_params_path = getenv_default("PERSISTENT_PARAMS_PATH", "/persist/comma/params");
#if defined(QCOM) || defined(QCOM2)
const std::string persistent_params_path = "/persist/comma/params";
#else
const std::string persistent_params_path = default_params_path;
#endif
} //namespace
volatile sig_atomic_t params_do_exit = 0;
void params_sig_handler(int signal) {

View File

@ -13,12 +13,11 @@ from typing import Dict, List
from selfdrive.swaglog import cloudlog, add_logentries_handler
from common.basedir import BASEDIR, PARAMS
from common.basedir import BASEDIR
from common.hardware import HARDWARE, ANDROID, PC
WEBCAM = os.getenv("WEBCAM") is not None
sys.path.append(os.path.join(BASEDIR, "pyextra"))
os.environ['BASEDIR'] = BASEDIR
os.environ['PARAMS_PATH'] = PARAMS
TOTAL_SCONS_NODES = 1005
prebuilt = os.path.exists(os.path.join(BASEDIR, 'prebuilt'))

View File

@ -108,7 +108,7 @@ Usage:
python carcontrols/joystickd.py
# In another terminal:
PARAMS_PATH=persist/params selfdrive/boardd/boardd
BASEDIR=$(pwd) selfdrive/boardd/boardd
# In another terminal:
python carcontrols/debug_controls.py