py_ext/PythonFileCTNMixin.py
changeset 1740 b789b695b5c6
parent 1739 ec153828ded2
child 1742 92932cd370a4
equal deleted inserted replaced
1739:ec153828ded2 1740:b789b695b5c6
    85     def PythonFileName(self):
    85     def PythonFileName(self):
    86         return os.path.join(self.CTNPath(), "py_ext.xml")
    86         return os.path.join(self.CTNPath(), "py_ext.xml")
    87 
    87 
    88     PreSectionsTexts = {}
    88     PreSectionsTexts = {}
    89     PostSectionsTexts = {}
    89     PostSectionsTexts = {}
    90     def GetSection(self,section):
    90     def GetSection(self, section):
    91         return self.PreSectionsTexts.get(section,"") + "\n" + \
    91         return self.PreSectionsTexts.get(section, "") + "\n" + \
    92                getattr(self.CodeFile, section).getanyText() + "\n" + \
    92                getattr(self.CodeFile, section).getanyText() + "\n" + \
    93                self.PostSectionsTexts.get(section,"")
    93                self.PostSectionsTexts.get(section, "")
    94 
    94 
    95     def CTNGenerate_C(self, buildpath, locations):
    95     def CTNGenerate_C(self, buildpath, locations):
    96         # location string for that CTN
    96         # location string for that CTN
    97         location_str = "_".join(map(lambda x:str(x),
    97         location_str = "_".join(map(lambda x: str(x),
    98                                 self.GetCurrentLocation()))
    98                                 self.GetCurrentLocation()))
    99         configname = self.GetCTRoot().GetProjectConfigNames()[0]
    99         configname = self.GetCTRoot().GetProjectConfigNames()[0]
   100 
   100 
   101         pyextname = self.CTNName()
   101         pyextname = self.CTNName()
   102         varinfos = map(lambda variable: {
   102         varinfos = map(lambda variable: {
   241         varret = "\n".join([varretfmt % varinfo for varinfo in varinfos])
   241         varret = "\n".join([varretfmt % varinfo for varinfo in varinfos])
   242         varpub = "\n".join([(varpubonchangefmt if varinfo["onchange"] else
   242         varpub = "\n".join([(varpubonchangefmt if varinfo["onchange"] else
   243                              varpubfmt) % varinfo
   243                              varpubfmt) % varinfo
   244                             for varinfo in varinfos])
   244                             for varinfo in varinfos])
   245         varinit = "\n".join([varinitonchangefmt % dict(
   245         varinit = "\n".join([varinitonchangefmt % dict(
   246                                 onchangelen = len(varinfo["onchangecode"]),**varinfo)
   246                                 onchangelen = len(varinfo["onchangecode"]), **varinfo)
   247                             for varinfo in varinfos if varinfo["onchange"]])
   247                             for varinfo in varinfos if varinfo["onchange"]])
   248 
   248 
   249         # TODO : use config name obtained from model instead of default
   249         # TODO : use config name obtained from model instead of default
   250         # "config.h". User cannot change config name, but project imported
   250         # "config.h". User cannot change config name, but project imported
   251         # or created in older beremiz vesion could use different name.
   251         # or created in older beremiz vesion could use different name.
   279 %(varpub)s
   279 %(varpub)s
   280 }
   280 }
   281 """ % locals()
   281 """ % locals()
   282 
   282 
   283         Gen_PyCfile_path = os.path.join(buildpath, "PyCFile_%s.c" % location_str)
   283         Gen_PyCfile_path = os.path.join(buildpath, "PyCFile_%s.c" % location_str)
   284         pycfile = open(Gen_PyCfile_path,'w')
   284         pycfile = open(Gen_PyCfile_path, 'w')
   285         pycfile.write(PyCFileContent)
   285         pycfile.write(PyCFileContent)
   286         pycfile.close()
   286         pycfile.close()
   287 
   287 
   288         matiec_CFLAGS = '"-I%s"' % os.path.abspath(
   288         matiec_CFLAGS = '"-I%s"' % os.path.abspath(
   289             self.GetCTRoot().GetIECLibPath())
   289             self.GetCTRoot().GetIECLibPath())
   290 
   290 
   291         return ([(Gen_PyCfile_path, matiec_CFLAGS)],
   291         return ([(Gen_PyCfile_path, matiec_CFLAGS)],
   292                 "",
   292                 "",
   293                 True,
   293                 True,
   294                 ("runtime_%s.py" % location_str, file(runtimefile_path,"rb")))
   294                 ("runtime_%s.py" % location_str, file(runtimefile_path, "rb")))
   295 
   295