2 # -*- coding: iso-8859-1 -*-
4 # This module helps you to dynamically add a catalog in the list of
5 # Aster catalogs and then start Eficas with this catalog
7 # WARN: this requires that <EFICAS_ROOT> and <EFICAS_ROOT>/Aster are
8 # both in the PYTHONPATH
10 # WARN: This python module is a prototype. For industrial usage, it
11 # should be integrated in a package outside from the Aster specific
12 # package ==> define a generic prefs
14 # (gboulant - 23/03/2012)
19 # ===================================================================
20 # This part is to manage the catalog that defines the data structure
22 def addCatalog(catalogName, catalogPath):
24 Function to add a catalog caraterized by a name (for the -c option
25 of the command line) and a path (the location of the python module
26 that corresponds to the catalog).
28 prefs_ASTER.addCatalog(catalogName, catalogPath)
32 from InterfaceQT4 import eficas_go
33 def start(catalogName=None):
35 This simply start Eficas as usual, and passing the catalog name as
36 an argument if not already present on the command line.
38 if catalogName is not None and not "-c" in sys.argv:
39 # The catalogName can be consider as the -c option
41 sys.argv.append(catalogName)
42 eficas_go.lance_eficas(code=prefs.code)
44 # ===================================================================
45 # This part is to manage the data saved from Eficas to comm file.
46 # The text contained in a comm file defines a JdC ("Jeu de Commandes").
48 def loadJdc(filename):
50 This function loads the text from the specified JdC file. A JdC
51 file is the persistence file of Eficas (*.comm).
53 fcomm=open(filename,'r')
55 for line in fcomm.readlines():
58 # Warning, we have to make sure that the jdc comes as a simple
59 # string without any extra spaces/newlines
62 def getJdcParameters(jdc,macro):
64 This function converts the data from the specified macro of the
65 specified jdc text to a python dictionnary whose keys are the
66 names of the data of the macro.
69 source = "def args_to_dict(**kwargs): return kwargs \n"
70 source+= "%s = _F = args_to_dict \n"%macro
71 source+= "parameters="+jdc+" \n"
72 source+= "context['parameters'] = parameters \n"
74 code = compile(source, 'file.py', 'exec')
76 parameters = context['parameters']
80 # ===========================================================
82 # ===========================================================
85 addCatalog(catalogName="demo", catalogPath="mycata.py")
89 def TEST_getJdcParameters_fromString():
90 jdc="S_EP_INTERNE(dir_name='/tmp', \n \
91 TYPE_SEP='TUBE_SOUS_EPAISSEUR', \n \
92 MAIL_TUBE=_F(UNITE_LONGUEUR='MM', \n \
94 EP_NOMINALE=22.0, \n \
95 NB_SEG_AMORTISSEMENT=11, \n \
96 NB_SEG_TRANSITION=4, \n \
97 NB_SEG_GENERATRICES=5, \n \
98 DIST_PTS_GEN_MIN=100.0, \n \
99 NB_SEG_GEN_MIN=3, \n \
103 parameters=getJdcParameters(jdc,"S_EP_INTERNE")
104 print "parameters = ",parameters
105 print parameters['MAIL_TUBE']['R_EXT']
108 def TEST_getJdcParameters_fromFile():
109 jdc = loadJdc('data.comm')
110 parameters=getJdcParameters(jdc,"EPREUVE_ENCEINTE")
114 if __name__ == "__main__":
116 TEST_getJdcParameters_fromString()
117 TEST_getJdcParameters_fromFile()