add Rougail object
This commit is contained in:
parent
a21e39a4d3
commit
afd332b2a9
4 changed files with 64 additions and 27 deletions
|
@ -28,8 +28,39 @@ along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
"""
|
"""
|
||||||
from .convert import RougailConvert
|
from .convert import RougailConvert
|
||||||
|
from .template.base import RougailBaseTemplate
|
||||||
from .template.systemd import RougailSystemdTemplate
|
from .template.systemd import RougailSystemdTemplate
|
||||||
from .config import RougailConfig
|
from .config import RougailConfig
|
||||||
from rougail.update import RougailUpgrade
|
from tiramisu import Config
|
||||||
|
from .update import RougailUpgrade
|
||||||
|
|
||||||
__ALL__ = ('RougailConvert', 'RougailSystemdTemplate', 'RougailConfig', 'RougailUpgrade')
|
|
||||||
|
class Rougail:
|
||||||
|
def __init__(self,
|
||||||
|
rougailconfig: RougailConfig=None,
|
||||||
|
) -> None:
|
||||||
|
if rougailconfig is None:
|
||||||
|
rougailconfig = RougailConfig
|
||||||
|
self.rougailconfig = rougailconfig
|
||||||
|
self.converted = RougailConvert(self.rougailconfig)
|
||||||
|
self.config = None
|
||||||
|
|
||||||
|
async def get_config(self):
|
||||||
|
if not self.config:
|
||||||
|
tiram_obj = self.converted.save(None)
|
||||||
|
optiondescription = {}
|
||||||
|
exec(tiram_obj, None, optiondescription)
|
||||||
|
self.config = await Config(optiondescription['option_0'])
|
||||||
|
return self.config
|
||||||
|
|
||||||
|
async def template(self,
|
||||||
|
type: str='base',
|
||||||
|
) -> None:
|
||||||
|
config = await self.get_config()
|
||||||
|
if type == 'base':
|
||||||
|
engine = RougailBaseTemplate(config, self.rougailconfig)
|
||||||
|
else:
|
||||||
|
engine = RougailSystemdTemplate(config, self.rougailconfig)
|
||||||
|
await engine.instance_files()
|
||||||
|
|
||||||
|
__ALL__ = ('Rougail', 'RougailConvert', 'RougailBaseTemplate', 'RougailSystemdTemplate', 'RougailConfig', 'RougailUpgrade')
|
||||||
|
|
|
@ -45,6 +45,7 @@ procedures.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from typing import List
|
from typing import List
|
||||||
|
from tiramisu import Config
|
||||||
|
|
||||||
from .i18n import _
|
from .i18n import _
|
||||||
from .config import RougailConfig
|
from .config import RougailConfig
|
||||||
|
|
|
@ -467,9 +467,20 @@ class RougailBaseTemplate:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def process(self,
|
def process(self,
|
||||||
*args,
|
filename: str,
|
||||||
): # pragma: no cover
|
destfilename: str,
|
||||||
raise NotImplementedError(_('cannot processed'))
|
mode: str,
|
||||||
|
owner: str,
|
||||||
|
group: str,
|
||||||
|
) -> None:
|
||||||
|
if owner not in [None, self.rougailconfig['default_files_owner']]:
|
||||||
|
#FIXME
|
||||||
|
raise TemplateError(_(f'cannot change owner of file {destfilename}'))
|
||||||
|
if group not in [None, self.rougailconfig['default_files_group']]:
|
||||||
|
#FIXME
|
||||||
|
raise TemplateError(_(f'cannot change group of file {destfilename}'))
|
||||||
|
if mode not in [None, self.rougailconfig['default_files_mode']]:
|
||||||
|
chmod(destfilename, eval(f'0o{mode}'))
|
||||||
|
|
||||||
def post_instance(self): # pragma: no cover
|
def post_instance(self): # pragma: no cover
|
||||||
pass
|
pass
|
||||||
|
@ -480,9 +491,22 @@ class RougailBaseTemplate:
|
||||||
raise NotImplementedError(_('cannot instanciate this service type ip'))
|
raise NotImplementedError(_('cannot instanciate this service type ip'))
|
||||||
|
|
||||||
def get_data_files(self,
|
def get_data_files(self,
|
||||||
*args,
|
filevar: Dict,
|
||||||
|
destfile: str,
|
||||||
|
service_name: str,
|
||||||
|
variable,
|
||||||
|
idx: int,
|
||||||
) -> None: # pragma: no cover
|
) -> None: # pragma: no cover
|
||||||
raise NotImplementedError(_('cannot instanciate this service type file'))
|
source = filevar['source']
|
||||||
|
if not isfile(source): # pragma: no cover
|
||||||
|
raise FileNotFound(_(f'Source file "{source}" does not exist in {", ".join(self.templates_dir)}'))
|
||||||
|
tmp_file = join(self.tmp_dir, source)
|
||||||
|
#self.instance_file(fill, 'files')
|
||||||
|
if variable:
|
||||||
|
var = variable[idx]
|
||||||
|
else:
|
||||||
|
var = None
|
||||||
|
return tmp_file, None, destfile, var
|
||||||
|
|
||||||
def get_data_service(self,
|
def get_data_service(self,
|
||||||
*args,
|
*args,
|
||||||
|
|
|
@ -78,24 +78,6 @@ C %%filename %%file.mode %%file.owner %%file.group - {self.rougailconfig['tmpfil
|
||||||
%end for
|
%end for
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def get_data_files(self,
|
|
||||||
filevar: Dict,
|
|
||||||
destfile: str,
|
|
||||||
service_name: str,
|
|
||||||
variable,
|
|
||||||
idx: int,
|
|
||||||
) -> tuple:
|
|
||||||
source = filevar['source']
|
|
||||||
if not isfile(source): # pragma: no cover
|
|
||||||
raise FileNotFound(_(f'Source file "{source}" does not exist in {", ".join(self.templates_dir)}'))
|
|
||||||
tmp_file = join(self.tmp_dir, source)
|
|
||||||
#self.instance_file(fill, 'files')
|
|
||||||
if variable:
|
|
||||||
var = variable[idx]
|
|
||||||
else:
|
|
||||||
var = None
|
|
||||||
return tmp_file, None, destfile, var
|
|
||||||
|
|
||||||
def get_data_overrides(self,
|
def get_data_overrides(self,
|
||||||
filevar: Dict,
|
filevar: Dict,
|
||||||
destfile,
|
destfile,
|
||||||
|
@ -196,8 +178,7 @@ C %%filename %%file.mode %%file.owner %%file.group - {self.rougailconfig['tmpfil
|
||||||
raise TemplateError(_(f'cannot change owner of file {destfilename}'))
|
raise TemplateError(_(f'cannot change owner of file {destfilename}'))
|
||||||
if group not in [None, self.rougailconfig['default_files_group']]:
|
if group not in [None, self.rougailconfig['default_files_group']]:
|
||||||
raise TemplateError(_(f'cannot change group of file {destfilename}'))
|
raise TemplateError(_(f'cannot change group of file {destfilename}'))
|
||||||
if mode not in [None, self.rougailconfig['default_files_mode']]:
|
super().process(filename, destfilename, mode, owner, group)
|
||||||
chmod(destfilename, eval(f'0o{mode}'))
|
|
||||||
|
|
||||||
def post_instance(self):
|
def post_instance(self):
|
||||||
destfilename = join(self.destinations_dir, ROUGAIL_DEST_FILE[1:])
|
destfilename = join(self.destinations_dir, ROUGAIL_DEST_FILE[1:])
|
||||||
|
|
Loading…
Reference in a new issue