1 # -*- coding: utf-8 -*-
2 # CONFIGURATION MANAGEMENT OF EDF VERSION
3 # ======================================================================
4 # COPYRIGHT (C) 1991 - 2002 EDF R&D WWW.CODE-ASTER.ORG
5 # THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
6 # IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY
7 # THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR
8 # (AT YOUR OPTION) ANY LATER VERSION.
10 # THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
11 # WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
12 # MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
13 # GENERAL PUBLIC LICENSE FOR MORE DETAILS.
15 # YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE
16 # ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,
17 # 1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.
20 # ======================================================================
22 Ce module sert a retrouver l'ordre des mots cles d'un catalogue de
25 if __name__ == "__main__" :
28 sys.path[:0]=["../Aster"]
29 sys.path[:0]=["../Saturne"]
31 from Accas import NUPL
33 def traite_entiteNUPL(entite):
35 Fonction speciale pour les nuplets (classe NUPL)
36 Cette fonction ajoute a l'objet entite un attribut de nom ordre_mc
37 qui est une liste vide.
41 def traite_entite(entite,liste_simp_reel):
43 Cette fonction ajoute a l'objet entite un attribut de nom ordre_mc
44 qui est une liste contenant le nom des sous entites dans l'ordre
45 de leur apparition dans le catalogue.
46 L'ordre d'apparition dans le catalogue est donné par l'attribut _no
48 La fonction active le meme type de traitement pour les sous entites
52 for k,v in entite.entites.items():
53 if isinstance(v,NUPL):
56 traite_reel(v,liste_simp_reel)
57 traite_entite(v,liste_simp_reel)
61 entite.ordre_mc=[ item for index, item in l ]
63 def traite_cache(objet):
64 if not hasattr(objet, "cache"): return
65 if objet.cache == 0 :return
67 if objet.equiv != None : clef=objet.equiv
68 if hasattr(objet.pere,"mcOblig"):
69 objet.pere.mcOblig[clef]=objet.defaut
72 objet.pere.mcOblig[clef]=objet.defaut
74 def traite_reel(objet,liste_simp_reel):
75 if objet.__class__.__name__ == "SIMP":
76 if ( 'R' in objet.type):
77 if objet.nom not in liste_simp_reel :
78 liste_simp_reel.append(objet.nom)
80 def analyse_niveau(cata_ordonne_dico,niveau,liste_simp_reel):
82 Analyse un niveau dans un catalogue de commandes
84 if niveau.l_niveaux == ():
85 # Il n'y a pas de sous niveaux
86 for oper in niveau.entites:
87 traite_entite(oper,liste_simp_reel)
88 cata_ordonne_dico[oper.nom]=oper
90 for niv in niveau.l_niveaux:
91 analyse_niveau(cata_ordonne_dico,niv)
93 def analyse_catalogue(cata):
95 Cette fonction analyse le catalogue cata pour construire avec l'aide
96 de traite_entite la structure de données ordre_mc qui donne l'ordre
97 d'apparition des mots clés dans le catalogue
98 Elle retourne un dictionnaire qui contient toutes les commandes
99 du catalogue indexées par leur nom
103 if cata.JdC.l_niveaux == ():
104 # Il n'y a pas de niveaux
106 for oper in cata.JdC.commandes:
107 traite_entite(oper,liste_simp_reel)
108 cata_ordonne_dico[oper.nom]=oper
110 for niv in cata.JdC.l_niveaux:
111 analyse_niveau(cata_ordonne_dico,niv,liste_simp_reel)
112 return cata_ordonne_dico,liste_simp_reel
115 if __name__ == "__main__" :
116 from Cata import cata_STA6
117 dico=analyse_catalogue(cata_STA6)
119 #dico=analyse_catalogue(cata_saturne)
121 def print_entite(entite,dec=' '):
122 print dec,entite.nom,entite.__class__.__name__
123 for mocle in entite.ordre_mc:
124 print_entite(entite.entites[mocle],dec=dec+' ')
126 for k,v in dico.items():
127 print_entite(v,dec='')