refactoring

This commit is contained in:
Emmanuel Garette 2020-07-08 16:32:10 +02:00
parent 8c5a9f2cd3
commit 7e34709628
3 changed files with 10 additions and 73 deletions

View file

@ -21,25 +21,9 @@ class Mode(object):
def __init__(self, name, level):
self.name = name
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):
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():
mode_obj = {}

View file

@ -5,34 +5,12 @@ On travaille sur les fichiers cibles
"""
import imp
import sys
from shutil import copy
import logging
from typing import Dict, Any
from subprocess import call
from os import listdir, unlink, makedirs
from os.path import dirname, basename, join, split, isfile, isdir
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 os import listdir, makedirs
from os.path import dirname, join, isfile
from Cheetah.Template import Template as ChtTemplate
from Cheetah.NameMapper import NotFound as CheetahNotFound
@ -40,8 +18,9 @@ from Cheetah.NameMapper import NotFound as CheetahNotFound
from tiramisu import Config
from tiramisu.error import PropertiesOptionError
from .annotator import VARIABLE_NAMESPACE
from .config import patch_dir
from .error import FileNotFound, TemplateError, TemplateDisabled
from .error import FileNotFound, TemplateError
from .i18n import _
from .utils import normalize_family
@ -49,6 +28,7 @@ from .utils import normalize_family
log = logging.getLogger(__name__)
log.addHandler(logging.NullHandler())
class IsDefined:
"""
filtre permettant de ne pas lever d'exception au cas où
@ -71,24 +51,6 @@ class IsDefined:
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
def cl_compile(kls, *args, **kwargs):
kwargs['compilerSettings'] = {'directiveStartToken' : '%',
@ -105,12 +67,6 @@ ChtTemplate.old_compile = ChtTemplate.compile
ChtTemplate.compile = cl_compile
class CreoleClient:
def __init__(self,
config: Config):
self.config = config
class CheetahTemplate(ChtTemplate):
"""classe pour personnaliser et faciliter la construction
du template Cheetah
@ -411,9 +367,6 @@ class CreoleTemplateEngine:
var)
else:
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:
"""Run templatisation on all files
@ -445,11 +398,6 @@ class CreoleTemplateEngine:
else:
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,
eosfunc_file: str,

View file

@ -1 +1,6 @@
%if %%is_defined('mode_conteneur_actif')
%%mode_conteneur_actif
%end if
%if %%is_defined('mode_conteneur_actif3')
%%mode_conteneur_actif3
%end if