Commit 62b18aa1 authored by Boers, Frank's avatar Boers, Frank
Browse files

under develop => updates for path cls

parent 57988f24
......@@ -441,7 +441,7 @@ class DCNN_CONFIG(object):
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
class DCNN_PATH(_SLOTS):
__slots__= ("expandvars","exit_on_error","logmsg","mkdir","overwrite","path_list","add_basedir",
__slots__= ("expandvars","exit_on_error","logmsg","mkdir","overwrite","add_basedir",
"_basedir","_data_meg","_data_train","_report")
def __init__(self,**kwargs):
......@@ -470,8 +470,8 @@ class DCNN_PATH(_SLOTS):
#self.__set_slots_attr_hidden(**kwargs) # sets hidden slots e.g. _data-xyz
@property
def basedir(self):
self._get_path(self._basedir)
def basedir(self): return self._basedir
# self._get_path(self._basedir)
@basedir.setter
def basedir(self,v):
self._set_path(v,"basedir")
......@@ -503,25 +503,39 @@ class DCNN_PATH(_SLOTS):
return v
def _set_path(self,path,label):
if not path:
logger.warning("Warning {} can not set path, not defined for: {}".format(self._cls_name,label))
return None
if self.add_basedir and self.basedir:
logger.warning("2 ADD basedir: {} {}".format(self.basedir,path))
if not path.startswith(self.basedir):
path = op.join(self.basedir,path)
if not self.overwrite:
msg=["Warning {} not allowed to overwrite path settings for: {}".format(self._cls_name,label),
" -> overwrite: {}".format(self.overwrite),
" -> path orig: {}".format(getattr(self,"_".label)),
" -> path : {}".format(path)]
logger.warning("\n".join(msg))
logger.warning(" ADD basedir: {} {}".format(self.basedir,path))
is_path = isPath(path,head="{} check path: {}".format(self._cls_name,label),
exit_on_error=self.exit_on_error,logmsg=self.logmsg,mkdir=self.mkdir)
if self.overwrite:
if not getattr(self,"_" +label) or self.overwrite:
self.__setattr__("_" +label,path)
else:
pass
msg = ["Warning in {} not allowed to overwrite path settings for: {}".format(self._cls_name,label),
" -> path orig: {}".format(getattr(self,"_"+label)),
" -> path : {}".format(path),
" -> overwrite : {}".format(self.overwrite),
" -> add basedir: {}".format(self.add_basedir),
" -> basedir : {}".format(self.basedir)]
logger.warning("\n".join(msg))
return is_path
ToDO
add base function
save path if add_base path without base
def dump(self):
d1 = super().dump()
d2 = self.__get_slots_attr_hidden()
......
......@@ -38,11 +38,11 @@ def run(fnconfig=None,basedir=None,data_meg=None,data_train=None,pattern='-raw.f
#---
if basedir: # FB test
cfg.config['path']['basedir'] = expandvars(basedir)
cfg.config['path']['basedir'] = basedir
if data_meg:
cfg.config['path']['data_meg']= expandvars(data_meg) # input directory
cfg.config['path']['data_meg']= data_meg # input directory
if data_train:
cfg.config['path']['data_train']= expandvars(data_train) # input directory
cfg.config['path']['data_train']= data_train # input directory
#-- init dcnn CLS
dcnn = DCNN(**cfg.config) # init object with config details
......@@ -55,7 +55,7 @@ def run(fnconfig=None,basedir=None,data_meg=None,data_train=None,pattern='-raw.f
if do_label_ica:
#path_in = os.path.join(cfg.config['path']['basedir'],cfg.config['path']['data_meg'])
path_in = dcnn.path.data_meg
dcnn.path.get_info()
# -- looper catch error via try/exception setup log2file
for fnraw in file_looper(rootdir=path_in,pattern=pattern,version=__version__,verbose=verbose,logoverwrite=True,log2file=log2file):
......
......@@ -154,6 +154,10 @@ def expandvars(v):
for i in range(len(v)):
v[i] = os.path.expandvars(os.path.expanduser( str(v[i]) ))
return v
else:
return os.path.expandvars(os.path.expanduser(str(v)))
return os.path.expandvars(os.path.expanduser( str(v) ))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment