symlink support

This commit is contained in:
Emmanuel Garette 2019-01-18 14:15:05 +01:00
parent 36936edbe1
commit 140fa03592
1 changed files with 19 additions and 8 deletions

View File

@ -36,10 +36,12 @@ class TiramisuOptionOption:
def __init__(self, def __init__(self,
path: str, path: str,
schema: Dict, schema: Dict,
model: Dict) -> None: model: Dict,
form: Dict) -> None:
self._path = path self._path = path
self.schema = schema self.schema = schema
self.model = model self.model = model
self.form = form
def doc(self): def doc(self):
return self.schema['title'] return self.schema['title']
@ -47,8 +49,15 @@ class TiramisuOptionOption:
def path(self): def path(self):
return self._path return self._path
def name(self): def name(self,
return self._path.rsplit('.', 1)[-1] follow_symlink: bool=False) -> str:
if not follow_symlink or \
self.isoptiondescription() or \
not self.issymlinkoption():
path = self._path
else:
path = self.schema['opt_path']
return path.rsplit('.', 1)[-1]
def isoptiondescription(self): def isoptiondescription(self):
return self.schema['type'] in ['object', 'array'] return self.schema['type'] in ['object', 'array']
@ -57,8 +66,7 @@ class TiramisuOptionOption:
return self.schema['type'] == 'array' return self.schema['type'] == 'array'
def issymlinkoption(self) -> bool: def issymlinkoption(self) -> bool:
# FIXME return self.schema['type'] == 'symlink'
return False
def ismulti(self) -> bool: def ismulti(self) -> bool:
return self.schema.get('isMulti', False) return self.schema.get('isMulti', False)
@ -76,7 +84,8 @@ class TiramisuOptionOption:
'domain': 'domainname', 'domain': 'domainname',
'url': 'url', 'url': 'url',
'username': 'username', 'username': 'username',
'string': 'str'} 'string': 'str',
'symlink': 'symlink'}
if self.schema['type'] in types : if self.schema['type'] in types :
return types[self.schema['type']] return types[self.schema['type']]
raise Exception('unsupported type {}'.format(self.schema['type'])) raise Exception('unsupported type {}'.format(self.schema['type']))
@ -313,7 +322,8 @@ class TiramisuOptionDescription(_Option):
if subfunc == 'option': if subfunc == 'option':
return TiramisuOptionOption(self.path, return TiramisuOptionOption(self.path,
self.schema, self.schema,
self.model) self.model,
self.form)
if subfunc == 'property': if subfunc == 'property':
return TiramisuOptionProperty(self.model.get(self.path, {})) return TiramisuOptionProperty(self.model.get(self.path, {}))
raise APIError(_('please specify a valid sub function ({})').format(subfunc)) raise APIError(_('please specify a valid sub function ({})').format(subfunc))
@ -353,7 +363,8 @@ class TiramisuOption:
raise NotImplementedError() raise NotImplementedError()
return TiramisuOptionOption(self.path, return TiramisuOptionOption(self.path,
self.schema, self.schema,
self.model) self.model,
self.form)
if subfunc == 'value': if subfunc == 'value':
return TiramisuOptionValue(self.config, return TiramisuOptionValue(self.config,
self.schema, self.schema,