add Rougail object

This commit is contained in:
egarette@silique.fr 2022-11-06 17:37:38 +01:00
parent a21e39a4d3
commit afd332b2a9
4 changed files with 64 additions and 27 deletions

View file

@ -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
"""
from .convert import RougailConvert
from .template.base import RougailBaseTemplate
from .template.systemd import RougailSystemdTemplate
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')

View file

@ -45,6 +45,7 @@ procedures.
"""
from typing import List
from tiramisu import Config
from .i18n import _
from .config import RougailConfig

View file

@ -467,9 +467,20 @@ class RougailBaseTemplate:
pass
def process(self,
*args,
): # pragma: no cover
raise NotImplementedError(_('cannot processed'))
filename: str,
destfilename: str,
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
pass
@ -480,9 +491,22 @@ class RougailBaseTemplate:
raise NotImplementedError(_('cannot instanciate this service type ip'))
def get_data_files(self,
*args,
filevar: Dict,
destfile: str,
service_name: str,
variable,
idx: int,
) -> 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,
*args,

View file

@ -78,24 +78,6 @@ C %%filename %%file.mode %%file.owner %%file.group - {self.rougailconfig['tmpfil
%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,
filevar: Dict,
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}'))
if group not in [None, self.rougailconfig['default_files_group']]:
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}'))
super().process(filename, destfilename, mode, owner, group)
def post_instance(self):
destfilename = join(self.destinations_dir, ROUGAIL_DEST_FILE[1:])