fix params on PC and when reading path from env (#2340)
* fix params when reading path from env * fix pcpull/2318/head^2
parent
a1037b5334
commit
707a670f42
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue