add override and factory support
This commit is contained in:
parent
5b4b43d5f4
commit
dfa0b5678b
|
@ -262,13 +262,17 @@ class CreoleTemplateEngine:
|
||||||
distrib_dir: str,
|
distrib_dir: str,
|
||||||
tmp_dir: str,
|
tmp_dir: str,
|
||||||
dest_dir: str,
|
dest_dir: str,
|
||||||
|
override_dest_dir: str,
|
||||||
tmpfile_name: str,
|
tmpfile_name: str,
|
||||||
|
factory_prefix: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.config = config
|
self.config = config
|
||||||
self.dest_dir = dest_dir
|
self.dest_dir = dest_dir
|
||||||
|
self.override_dest_dir = override_dest_dir
|
||||||
self.tmp_dir = tmp_dir
|
self.tmp_dir = tmp_dir
|
||||||
self.distrib_dir = distrib_dir
|
self.distrib_dir = distrib_dir
|
||||||
self.tmpfile_name = tmpfile_name
|
self.tmpfile_name = tmpfile_name
|
||||||
|
self.factory_prefix = factory_prefix
|
||||||
eos = {}
|
eos = {}
|
||||||
if eosfunc_file is not None:
|
if eosfunc_file is not None:
|
||||||
eosfunc = imp.load_source('eosfunc', eosfunc_file)
|
eosfunc = imp.load_source('eosfunc', eosfunc_file)
|
||||||
|
@ -382,7 +386,7 @@ class CreoleTemplateEngine:
|
||||||
else:
|
else:
|
||||||
variable = None
|
variable = None
|
||||||
if override:
|
if override:
|
||||||
filenames = [f'/system/{service_name}.service.d/rougail.conf']
|
filenames = [f'/systemd/system/{service_name}.service.d/rougail.conf']
|
||||||
else:
|
else:
|
||||||
filenames = filevar['name']
|
filenames = filevar['name']
|
||||||
if not isinstance(filenames, list):
|
if not isinstance(filenames, list):
|
||||||
|
@ -390,8 +394,10 @@ class CreoleTemplateEngine:
|
||||||
if variable:
|
if variable:
|
||||||
variable = [variable]
|
variable = [variable]
|
||||||
for idx, filename in enumerate(filenames):
|
for idx, filename in enumerate(filenames):
|
||||||
destfilename = join(self.dest_dir,
|
if override:
|
||||||
filename[1:])
|
destfilename = join(self.override_dest_dir, filename[1:])
|
||||||
|
else:
|
||||||
|
destfilename = join(self.dest_dir, filename[1:])
|
||||||
makedirs(dirname(destfilename), exist_ok=True)
|
makedirs(dirname(destfilename), exist_ok=True)
|
||||||
if variable:
|
if variable:
|
||||||
var = variable[idx]
|
var = variable[idx]
|
||||||
|
@ -406,7 +412,7 @@ class CreoleTemplateEngine:
|
||||||
else:
|
else:
|
||||||
copy(source, destfilename)
|
copy(source, destfilename)
|
||||||
if not override and self.tmpfile_name:
|
if not override and self.tmpfile_name:
|
||||||
systemd_rights.append(f'C {filename} {filevar["mode"]} {filevar["owner"]} {filevar["group"]} - -')
|
systemd_rights.append(f'C {filename} {filevar["mode"]} {filevar["owner"]} {filevar["group"]} - {self.factory_prefix}{filename}')
|
||||||
systemd_rights.append(f'z {filename} - - - - -')
|
systemd_rights.append(f'z {filename} - - - - -')
|
||||||
|
|
||||||
async def instance_files(self) -> None:
|
async def instance_files(self) -> None:
|
||||||
|
@ -455,11 +461,22 @@ async def generate(config: Config,
|
||||||
distrib_dir: str,
|
distrib_dir: str,
|
||||||
tmp_dir: str,
|
tmp_dir: str,
|
||||||
dest_dir: str,
|
dest_dir: str,
|
||||||
tmpfile_name: str=None) -> None:
|
override_dest_dir: str,
|
||||||
|
tmpfile_name: str=None,
|
||||||
|
factory_prefix: str=None,
|
||||||
|
) -> None:
|
||||||
|
if not tmpfile_name and factory_prefix:
|
||||||
|
raise Exception(_(f'only specify factory_prefix if tmpfile_name is set'))
|
||||||
|
if tmpfile_name and not factory_prefix:
|
||||||
|
raise Exception(_(f'if tmpfile_name is specify, set factory_prefix too'))
|
||||||
|
|
||||||
engine = CreoleTemplateEngine(config,
|
engine = CreoleTemplateEngine(config,
|
||||||
eosfunc_file,
|
eosfunc_file,
|
||||||
distrib_dir,
|
distrib_dir,
|
||||||
tmp_dir,
|
tmp_dir,
|
||||||
dest_dir,
|
dest_dir,
|
||||||
tmpfile_name)
|
override_dest_dir,
|
||||||
|
tmpfile_name,
|
||||||
|
factory_prefix,
|
||||||
|
)
|
||||||
await engine.instance_files()
|
await engine.instance_files()
|
||||||
|
|
Loading…
Reference in New Issue