Première version de la refonte du plugin bcfg2
This commit is contained in:
parent
7e5cd649eb
commit
f67d38baee
8 changed files with 1441 additions and 0 deletions
33
bcfg2new/Plugins/Python/PythonFactories.py
Normal file
33
bcfg2new/Plugins/Python/PythonFactories.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/env python2.7
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Ce module est prévu pour héberger des factories, stockant toute
|
||||
instance d'un fichier Python déjà compilé."""
|
||||
|
||||
class PythonFileFactory(object):
|
||||
"""Cette Factory stocke l'ensemble des fichiers Python déjà instanciés.
|
||||
Elle garantit entre autre leur unicité dans le fonctionnement du plugin"""
|
||||
|
||||
#: Stocke la liste des instances avec leur chemin absolu.
|
||||
files = {}
|
||||
|
||||
@classmethod
|
||||
def get(cls, path):
|
||||
"""Récupère l'instance si elle existe, ou renvoit None"""
|
||||
return cls.files.get(path, None)
|
||||
|
||||
@classmethod
|
||||
def record(cls, path, instance):
|
||||
"""Enregistre l'instance dans la Factory"""
|
||||
cls.files[path] = instance
|
||||
|
||||
@classmethod
|
||||
def flush_one(cls, path):
|
||||
"""Vire une instance du dico"""
|
||||
instance_to_delete = cls.files.pop(path, None)
|
||||
del instance_to_delete
|
||||
|
||||
@classmethod
|
||||
def flush(cls):
|
||||
"""Vire toutes les instances du dico"""
|
||||
for path in cls.files.keys():
|
||||
cls.flush_one(path)
|
Loading…
Add table
Add a link
Reference in a new issue