fix params on PC and when reading path from env (#2340)

* fix params when reading path from env

* fix pc
pull/2318/head^2
Adeeb Shihadeh 2020-10-14 13:45:24 -07:00 committed by GitHub
parent a1037b5334
commit 707a670f42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 14 deletions

View File

@ -1,10 +1,13 @@
# distutils: langauge = c++
import threading
import os
# cython: language_level = 3
from libcpp cimport bool
from libcpp.string cimport string
from params_pxd cimport Params as c_Params
import os
import threading
from common.basedir import PARAMS
cdef enum TxType:
PERSISTENT = 1
CLEAR_ON_MANAGER_START = 2
@ -81,11 +84,11 @@ class UnknownKeyName(Exception):
cdef class Params:
cdef c_Params* p
def __cinit__(self, d=None, persistent_params=False):
if d is not None:
self.p = new c_Params(<string>d.encode())
def __cinit__(self, d=PARAMS, bool persistent_params=False):
if persistent_params:
self.p = new c_Params(True)
else:
self.p = new c_Params(<bool>persistent_params)
self.p = new c_Params(<string>d.encode())
def __dealloc__(self):
del self.p

View File

@ -23,17 +23,17 @@
namespace {
template <typename T>
T* null_coalesce(T* a, T* b) {
return a != NULL ? a : b;
std::string getenv_default(const char* env_var, const char* default_val) {
const char* env_val = getenv(env_var);
return std::string(env_val != NULL ? env_val : default_val);
}
static const char* default_params_path = null_coalesce(const_cast<const char*>(getenv("PARAMS_PATH")), "/data/params");
const std::string default_params_path = getenv_default("PARAMS_PATH", "/data/params");
#ifdef QCOM
static const char* persistent_params_path = null_coalesce(const_cast<const char*>(getenv("PERSISTENT_PARAMS_PATH")), "/persist/comma/params");
const std::string persistent_params_path = getenv_default("PERSISTENT_PARAMS_PATH", "/persist/comma/params");
#else
static const char* persistent_params_path = default_params_path;
const std::string persistent_params_path = default_params_path;
#endif
} //namespace
@ -99,8 +99,7 @@ static int ensure_dir_exists(std::string path) {
Params::Params(bool persistent_param){
const char * path = persistent_param ? persistent_params_path : default_params_path;
params_path = std::string(path);
params_path = persistent_param ? persistent_params_path : default_params_path;
}
Params::Params(std::string path) {