refactoring
This commit is contained in:
parent
8c5a9f2cd3
commit
7e34709628
|
@ -21,25 +21,9 @@ class Mode(object):
|
||||||
def __init__(self, name, level):
|
def __init__(self, name, level):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.level = level
|
self.level = level
|
||||||
|
|
||||||
def __cmp__(self, other):
|
|
||||||
return cmp(self.level, other.level)
|
|
||||||
|
|
||||||
def __eq__(self, other):
|
|
||||||
return self.level == other.level
|
|
||||||
|
|
||||||
def __ne__(self, other):
|
|
||||||
return self.level != other.level
|
|
||||||
|
|
||||||
def __gt__(self, other):
|
def __gt__(self, other):
|
||||||
return other.level < self.level
|
return other.level < self.level
|
||||||
|
|
||||||
def __ge__(self, other):
|
|
||||||
return not self.level < other.level
|
|
||||||
|
|
||||||
def __le__(self, other):
|
|
||||||
return not other.level < self.level
|
|
||||||
|
|
||||||
|
|
||||||
def mode_factory():
|
def mode_factory():
|
||||||
mode_obj = {}
|
mode_obj = {}
|
||||||
|
|
|
@ -5,34 +5,12 @@ On travaille sur les fichiers cibles
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import imp
|
import imp
|
||||||
import sys
|
|
||||||
from shutil import copy
|
from shutil import copy
|
||||||
import logging
|
import logging
|
||||||
from typing import Dict, Any
|
from typing import Dict, Any
|
||||||
|
|
||||||
from subprocess import call
|
from subprocess import call
|
||||||
from os import listdir, unlink, makedirs
|
from os import listdir, makedirs
|
||||||
from os.path import dirname, basename, join, split, isfile, isdir
|
from os.path import dirname, join, isfile
|
||||||
|
|
||||||
from tempfile import mktemp
|
|
||||||
|
|
||||||
from Cheetah import Parser
|
|
||||||
|
|
||||||
from .annotator import VARIABLE_NAMESPACE
|
|
||||||
|
|
||||||
|
|
||||||
# l'encoding du template est déterminé par une regexp (encodingDirectiveRE dans Parser.py)
|
|
||||||
# il cherche un ligne qui ressemble à '#encoding: utf-8
|
|
||||||
# cette classe simule le module 're' et retourne toujours l'encoding utf-8
|
|
||||||
# 6224
|
|
||||||
class FakeEncoding:
|
|
||||||
def groups(self):
|
|
||||||
return ('utf-8',)
|
|
||||||
|
|
||||||
def search(self, *args):
|
|
||||||
return self
|
|
||||||
Parser.encodingDirectiveRE = FakeEncoding()
|
|
||||||
|
|
||||||
|
|
||||||
from Cheetah.Template import Template as ChtTemplate
|
from Cheetah.Template import Template as ChtTemplate
|
||||||
from Cheetah.NameMapper import NotFound as CheetahNotFound
|
from Cheetah.NameMapper import NotFound as CheetahNotFound
|
||||||
|
@ -40,8 +18,9 @@ from Cheetah.NameMapper import NotFound as CheetahNotFound
|
||||||
from tiramisu import Config
|
from tiramisu import Config
|
||||||
from tiramisu.error import PropertiesOptionError
|
from tiramisu.error import PropertiesOptionError
|
||||||
|
|
||||||
|
from .annotator import VARIABLE_NAMESPACE
|
||||||
from .config import patch_dir
|
from .config import patch_dir
|
||||||
from .error import FileNotFound, TemplateError, TemplateDisabled
|
from .error import FileNotFound, TemplateError
|
||||||
from .i18n import _
|
from .i18n import _
|
||||||
from .utils import normalize_family
|
from .utils import normalize_family
|
||||||
|
|
||||||
|
@ -49,6 +28,7 @@ from .utils import normalize_family
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
log.addHandler(logging.NullHandler())
|
log.addHandler(logging.NullHandler())
|
||||||
|
|
||||||
|
|
||||||
class IsDefined:
|
class IsDefined:
|
||||||
"""
|
"""
|
||||||
filtre permettant de ne pas lever d'exception au cas où
|
filtre permettant de ne pas lever d'exception au cas où
|
||||||
|
@ -71,24 +51,6 @@ class IsDefined:
|
||||||
return varname in self.context
|
return varname in self.context
|
||||||
|
|
||||||
|
|
||||||
class CreoleGet:
|
|
||||||
def __init__(self, context):
|
|
||||||
self.context = context
|
|
||||||
|
|
||||||
def __call__(self, varname):
|
|
||||||
return self.context[varname]
|
|
||||||
|
|
||||||
def __getitem__(self, varname):
|
|
||||||
"""For bracket and dotted notation
|
|
||||||
"""
|
|
||||||
return self.context[varname]
|
|
||||||
|
|
||||||
def __contains__(self, varname):
|
|
||||||
"""Check variable existence in context
|
|
||||||
"""
|
|
||||||
return varname in self.context
|
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def cl_compile(kls, *args, **kwargs):
|
def cl_compile(kls, *args, **kwargs):
|
||||||
kwargs['compilerSettings'] = {'directiveStartToken' : '%',
|
kwargs['compilerSettings'] = {'directiveStartToken' : '%',
|
||||||
|
@ -105,12 +67,6 @@ ChtTemplate.old_compile = ChtTemplate.compile
|
||||||
ChtTemplate.compile = cl_compile
|
ChtTemplate.compile = cl_compile
|
||||||
|
|
||||||
|
|
||||||
class CreoleClient:
|
|
||||||
def __init__(self,
|
|
||||||
config: Config):
|
|
||||||
self.config = config
|
|
||||||
|
|
||||||
|
|
||||||
class CheetahTemplate(ChtTemplate):
|
class CheetahTemplate(ChtTemplate):
|
||||||
"""classe pour personnaliser et faciliter la construction
|
"""classe pour personnaliser et faciliter la construction
|
||||||
du template Cheetah
|
du template Cheetah
|
||||||
|
@ -411,9 +367,6 @@ class CreoleTemplateEngine:
|
||||||
var)
|
var)
|
||||||
else:
|
else:
|
||||||
copy(source, destfilename)
|
copy(source, destfilename)
|
||||||
# if self.tmpfile_name:
|
|
||||||
# systemd_rights.append(f'C {filename} {filevar["mode"]} {filevar["owner"]} {filevar["group"]} - {self.factory_prefix}{filename}')
|
|
||||||
# systemd_rights.append(f'z {filename} - - - - -')
|
|
||||||
|
|
||||||
async def instance_files(self) -> None:
|
async def instance_files(self) -> None:
|
||||||
"""Run templatisation on all files
|
"""Run templatisation on all files
|
||||||
|
@ -445,11 +398,6 @@ class CreoleTemplateEngine:
|
||||||
else:
|
else:
|
||||||
log.debug(_("Instantiation of file '{filename}' disabled"))
|
log.debug(_("Instantiation of file '{filename}' disabled"))
|
||||||
|
|
||||||
#if self.tmpfile_name:
|
|
||||||
# with open(self.tmpfile_name, 'w') as fh:
|
|
||||||
# fh.write('\n'.join(systemd_rights))
|
|
||||||
# fh.write('\n')
|
|
||||||
|
|
||||||
|
|
||||||
async def generate(config: Config,
|
async def generate(config: Config,
|
||||||
eosfunc_file: str,
|
eosfunc_file: str,
|
||||||
|
|
|
@ -1 +1,6 @@
|
||||||
|
%if %%is_defined('mode_conteneur_actif')
|
||||||
%%mode_conteneur_actif
|
%%mode_conteneur_actif
|
||||||
|
%end if
|
||||||
|
%if %%is_defined('mode_conteneur_actif3')
|
||||||
|
%%mode_conteneur_actif3
|
||||||
|
%end if
|
||||||
|
|
Loading…
Reference in New Issue