コード例 #1
0
ファイル: Class.py プロジェクト: melviso/beatle
    def updateSources(self, force=False):
        """does source generation"""
        fname = self.abs_path_source
        regenerate = False
        if force or not os.path.exists(fname) or self._lastSrcTime is None:
            regenerate = True
        elif os.path.getmtime(fname) < self._lastSrcTime:
            regenerate = True
        if not regenerate:
            return
        f = open(fname, 'w')
        pf = writer.for_file(f)
        #master include file
        prj = self.project

        pf.writeln("// {user.before.include.begin}")
        pf.writeln(self.user_code_s1)
        pf.writeln("// {user.before.include.end}")
        pf.writenl()
        if prj._useMaster:
            pf.writeln('#include "{0}"'.format(prj._masterInclude))
        else:
            pf.writeln('#include "{0}.h"'.format(self._name))
        pf.writenl()

        # some facility
        pf.writeln("#include <assert.h>")
        pf.writenl()

        self.WriteCode(pf)
        pf.writenl()
        f.close()
コード例 #2
0
ファイル: pyBoostModule.py プロジェクト: melviso/beatle
 def updateSources(self, force=False):
     """does source generation"""
     sources_dir = self.project.sources_dir
     fname = os.path.realpath(os.path.join(sources_dir, self._source))
     if force or not os.path.exists(fname) or self._lastSrcTime is None:
         regenerate = True
     elif os.path.getmtime(fname) < self._lastSrcTime:
         regenerate = True
     project = self.project
     if regenerate:
         with open(fname, 'w') as f:
             pf = writer.for_file(f)
             pf.writeln("// {user.before.include.begin}")
             pf.writenl()
             pf.writeln("// {user.before.include.end}")
             pf.writenl()
             if project._useMaster:
                 pf.writeln('#include "{0}"'.format(project._masterInclude))
                 pf.writenl()
             pf.writeln("// {user.before.code.begin}")
             pf.writenl()
             pf.writeln("// {user.before.code.end}")
             pf.writenl()
             self.WriteCode(pf)
             pf.writenl()
             pf.writeln("// {user.after.code.begin}")
             pf.writenl()
             pf.writeln("// {user.after.code.end}")
             pf.writenl()
コード例 #3
0
ファイル: Module.py プロジェクト: melviso/beatle
    def updateHeaders(self, force=False):
        """Realiza la generacion de fuentes"""
        headers_dir = self.project.headers_dir
        pass
        # we need to do a lot of work here. The name may be from existent header
        # and then, the class is resposible for holding the generation

        fname = os.path.realpath(os.path.join(headers_dir, self._header))
        regenerate = False
        if force or not os.path.exists(fname) or self._lastHdrTime is None:
            regenerate = True
        elif os.path.getmtime(fname) < self._lastHdrTime:
            regenerate = True
        if not regenerate:
            return
        f = open(fname, 'w')
        pf = writer.for_file(f)
        inlines = []
        #create safeguard
        safeguard = self._header.upper() + "_H_INCLUDED"
        pf.writeln("#if !defined({0})".format(safeguard))
        pf.writeln("#define {0}".format(safeguard))

        #we are using master include? if not, include inheritances
        pf.writenl()
        #ok, now we place comments, if any
        if len(self._note) > 0:
            pf.writeln("/**")
            txt = self._note
            txt.replace('\r', '')
            lines = txt.split("\n")
            for line in lines:
                line.replace('*/', '* /')
                pf.writeln("* {0}".format(line))
            pf.writeln("**/")
        #write variables (not static)

        #write methods

        pf.writenl()
        #end safeguard
        pf.writeln("#endif //{0}".format(safeguard))
        #write inlines
        pf.writenl()
        if len(inlines) > 0:
            pf.writeln("#if defined(INCLUDE_INLINES)")
            pf.writeln("#if !defined(INCLUDE_INLINES_{name})".format(name=self._header.upper()))
            pf.writeln("#define INCLUDE_INLINES_{name}".format(name=self._header.upper()))
            pf.writenl()
            #write inlines here

            pf.writeln("#endif //(INCLUDE_INLINES_{name})".format(name=self._header.upper()))
            pf.writeln("#endif //INCLUDE_INLINES")
            pf.writenl()
        self._lastHdrTime = os.path.getmtime(fname)

        pf.writenl()
        f.close()
コード例 #4
0
ファイル: Class.py プロジェクト: melviso/beatle
    def updateHeaders(self, force=False):
        """Realiza la generacion de fuentes"""
        fname = self.abs_path_header
        regenerate = False
        if force or not os.path.exists(fname) or self._lastHdrTime is None:
            regenerate = True
        elif os.path.getmtime(fname) < self._lastHdrTime:
            regenerate = True
        if not regenerate:
            return
        f = open(fname, 'w')
        pf = writer.for_file(f)
        #create safeguard
        safeguard = self._name.upper() + "_H_INCLUDED"
        pf.writeln("#if !defined({0})".format(safeguard))
        pf.writeln("#define {0}".format(safeguard))
        pf.writenl()

        #we are using master include? if not, include inheritances
        p = self.project
        if not p._useMaster and self.outer_class == self:
            #iterate over inheritances
            if len(self._child[model.cc.Inheritance]):
                pf.writeln("//base includes")
                for o in self[model.cc.Inheritance]:
                    pf.writeln("#include \"{0}.h\"".format(o._name))
                pf.writenl()
            #we need to forward references for relations
            if len(self.child[model.cc.RelationFrom]):
                pf.writeln("//forward references of parent classes")
                for p in self[model.cc.RelationFrom]:
                    pf.writeln(p._FROM.reference)
            if len(self.child[model.cc.RelationTo]):
                pf.writeln("//forward references of child classes")
                for p in self[model.cc.RelationFrom]:
                    pf.writeln(p._TO.reference)
        pf.writenl()
        self.WriteDeclaration(pf)
        #end safeguard
        pf.writeln("#endif //{0}".format(safeguard))
        #write inlines
        pf.writenl()
        if len(self._inlines) > 0:
            pf.writeln("#if defined(INCLUDE_INLINES)")
            pf.writeln("#if !defined(INCLUDE_INLINES_{name})".format(name=self._name.upper()))
            pf.writeln("#define INCLUDE_INLINES_{name}".format(name=self._name.upper()))
            pf.writenl()
            for o in self._inlines:
                o.WriteCode(pf)
                pf.writenl()
            pf.writeln("#endif //(INCLUDE_INLINES_{name})".format(name=self._name.upper()))
            pf.writeln("#endif //INCLUDE_INLINES")
            pf.writenl()
        del self._inlines
        self._lastHdrTime = os.path.getmtime(fname)
        pf.writenl()
        f.close()
コード例 #5
0
ファイル: Project.py プロジェクト: melviso/beatle
 def WriteMakefile(self, logger=None):
     """Write the makefile"""
     #open the file
     makefile = os.path.join(self._dir, 'Makefile')
     makefile = os.path.realpath(makefile)
     f = open(makefile, 'w')
     pf = writer.for_file(f)
     # write a very quick makefile
     # a ) definitions
     pf.writeln('# definitions')
     pf.writenl()
     pf.writeln('CC = g++')
     pf.writeln('AR = ar')
     pf.writeln('CFLAGS = -ggdb -fexceptions -Wall -std=c++0x -fPIC')
     pf.writeln('INCLUDE = -I{self._includeDir}'.format(self=self))
     pf.writeln('SRC = {self._srcDir}'.format(self=self))
     pf.writenl()
     # make targets all/clean
     # all : first, the prerequisites
     if self._type == "static library":
         product = self.name
     elif self._type == "dynamic library":
         product = '{name}.so'.format(name=self.name)
     elif self._type == "static library":
         product = 'lib{name}.a'.format(name=self.name)
     elif self._type == "executable":
         product = '{name}'.format(name=self.name)
     pf.writeln('all : {product}'.format(product=product))
     #master target
     pf.writenl()
     self.SortClasses()
     prerequisites = ' '.join(['{name}.o'.format(name=x.name) for x in self.sorted_classes if not x.is_external])
     pf.writeln('{product}: {prerequisites}'.format(product=product, prerequisites=prerequisites))
     if self._type == 'static library':
         pf.writeln('\t$(AR) -r -s ./{product} {prerequisites}'.format(
             product=product, prerequisites=prerequisites))
     elif self._type == 'dynamic library':
         pf.writeln('\t$(CC) -shared  {prerequisites}  -o {product}'.format(
             product=product, prerequisites=prerequisites))
     elif self._type == 'executable':
         pf.writeln('\t$(CC) {prerequisites}  -o {product}'.format(
             product=product, prerequisites=prerequisites))
     pf.writenl()
     # target files
     for cls in self.sorted_classes:
         if cls.is_external:
             continue
         pf.writeln('{name}.o: {src}/{name}.cpp {inc}/{name}.h'.format(name=cls.name,
             inc=self._includeDir, src=self._srcDir))
         pf.writeln('\t$(CC) $(CFLAGS) $(INCLUDE) -c {src}/{name}.cpp -o {name}.o'.format(src=self._srcDir,
             name=cls.name))
         pf.writenl()
     # clean
     pf.writeln('clean:')
     pf.writeln('\trm *.o {product}'.format(product=product))
     pf.writenl()
     f.close()
コード例 #6
0
ファイル: Module.py プロジェクト: melviso/beatle
    def ExportPythonCodeFiles(self, force=False, logger=None):
        """does source generation"""
        #The mission of this method is to generate the required code
        #for the python
        fname = self.abs_path
        logger and logger.AppendReportLine('exporting module {0}'.format(self._name), wx.ICON_INFORMATION)
        try:
            f = open(fname, 'w')
            fw = writer.for_file(f, 'python')

            #first thing: generate module comment
            fw.writeln("# -*- coding: utf-8 -*-")
            fw.writecomment(self._note)
            fw.writenl()

            #we have some problem here with the order the code is generated
            #for solving that, we use nested folders
            for folder in self[model.Folder]:
                self.ExportPythonFolderCodeFiles(fw, folder, force, logger)

            #declare the orderer collections of things
            #that would be exported

            #fw.writeln("#imports")
            for obj in self[ImportsFolder]:
                obj.ExportPythonCode(fw)
            for obj in self[Import]:
                obj.ExportPythonCode(fw)

            from Class import Class
            for obj in self[Class]:
                obj.ExportPythonCode(fw)

            from Function import Function
            for obj in self[Function]:
                obj.ExportPythonCode(fw)

            from Data import Data
            for obj in self[Data]:
                obj.ExportPythonCode(fw)

            #At last, write raw code
            fw.writenl(1)
            fw.writeln("#raw code")
            fw.writeblock(self._content)

            f.close()

        except Exception as inst:
            traceback.print_exc(file=sys.stdout)
            print type(inst)     # the exception instance
            print inst.args      # arguments stored in .args
            print inst
            if logger:
                logger.AppendReportLine('failed opening {0}'.format(fname), wx.NOT_FOUND)
            return False
コード例 #7
0
ファイル: Module.py プロジェクト: melviso/beatle
    def updateSources(self, force=False):
        """does source generation"""
        sources_dir = self.project.sources_dir
        pass
        # we need to do a lot of work here. The name may be from existent source
        # and then, the class is resposible for holding the generation
        fname = os.path.realpath(os.path.join(sources_dir, self._source))
        regenerate = False
        if force or not os.path.exists(fname) or self._lastSrcTime is None:
            regenerate = True
        elif os.path.getmtime(fname) < self._lastSrcTime:
            regenerate = True
        if not regenerate:
            return
        f = open(fname, 'w')
        pf = writer.for_file(f)
        #master include file
        prj = self.project

        pf.writeln("// {user.before.include.begin}")
        pf.writenl()
        pf.writeln("// {user.before.include.end}")
        pf.writenl()
        if prj._useMaster:
            pf.writeln('#include "{0}"'.format(prj._masterInclude))
        else:
            pf.writeln('#include "{0}.h"'.format(self._header))
        pf.writenl()
        pf.writeln("// {user.before.code.begin}")
        pf.writenl()
        pf.writeln("// {user.before.code.end}")
        pf.writenl()
        #self.WriteCode(pf)
        pf.writenl()
        pf.writeln("// {user.after.code.begin}")
        pf.writenl()
        pf.writeln("// {user.after.code.end}")
        pf.writenl()
        f.close()
コード例 #8
0
ファイル: Package.py プロジェクト: melviso/beatle
    def ExportPythonCodeFiles(self, force=False, logger=None):
        """does source generation"""
        # Any package is just a directory. And an init file
        package_dir = self.dir
        logger and logger.AppendReportLine("exporting package {0}".format(self._name), wx.ICON_INFORMATION)
        if not os.path.exists(package_dir):
            os.makedirs(package_dir)
            if not os.path.exists(package_dir):
                e = "Failed creating package directory " + package_dir
                if logger is not None:
                    logger.AppendReportLine(e, wx.ICON_ERROR)
                else:
                    wx.MessageBox(e, "Error", wx.OK | wx.CENTER | wx.ICON_ERROR, context.frame)
                return False
        # write the init file
        init_file = self.abs_path
        try:
            f = open(init_file, "w")
            fw = writer.for_file(f, "python")

            # first thing: generate module comment
            fw.writeln("# -*- coding: utf-8 -*-")
            fw.writecomment(self._note)

            fw.writenl()
            # declare the orderer collections of things
            # that would be exported
            from Import import Import
            from Data import Data
            from Function import Function
            from Class import Class

            # write explicit imports
            fw.writeln("#imports")
            for obj in self[Import]:
                obj.ExportPythonCode(fw)

            # now, for all the exported classes not inside nested package
            package_element = lambda x: x.inner_package == self
            for obj in self(Class, filter=package_element, cut=True):
                if not obj._export:
                    continue
                fw.writeln("from {obj.file_container} import {obj.context_name}".format(obj=obj))

            top = lambda x: not x.inner_module and not x.parent.inner_class
            fw.writenl(2)
            fw.writeln("#data")
            for obj in self(Data):
                obj.ExportPythonCode(fw)

            fw.writenl(2)
            fw.writeln("#functions")
            for obj in self(Function):
                obj.ExportPythonCode(fw)

            fw.writenl(2)
            fw.writeln("#classes")
            for obj in self(Class, filter=top, cut=True):
                obj.ExportPythonCode(fw)
            f.close()

        except Exception as inst:
            traceback.print_exc(file=sys.stdout)
            print type(inst)  # the exception instance
            print inst.args  # arguments stored in .args
            print inst
            if logger:
                logger.AppendReportLine("failed opening {0}".format(init_file), wx.NOT_FOUND)
            return False

        # do the same as for projects

        for obj in self.packages:
            if obj.parent.inner_package != self:
                continue
            obj.ExportPythonCodeFiles(force, logger)
        for obj in self.modules:
            if obj.parent.inner_package != self:
                continue
            obj.ExportPythonCodeFiles(force, logger)
コード例 #9
0
ファイル: Project.py プロジェクト: melviso/beatle
    def WriteMasterHeader(self, force=False, logger=None):
        """Write the master include file"""
        #open the file
        fname = os.path.join(self.headers_dir, self._masterInclude)
        regenerate = False
        if force or not os.path.exists(fname) or self._lastHdrTime is None:
            regenerate = True
        elif os.path.getmtime(fname) < self._lastHdrTime:
            regenerate = True
        if not regenerate:
            return True
        f = open(fname, 'w')
        pf = writer.for_file(f)

        #write a timestamp and version information
        self.WriteTimestamp(pf)

        safe_name = self._name.upper().replace('.', '_')

        #write include safeward
        pf.writeln('#if !defined({name}_H_INCLUDED)'.format(name=safe_name))
        pf.writeln('#define {name}_H_INCLUDED'.format(name=safe_name))
        pf.writenl()

        #write the custom definitions
        if len(self._contexts) > 0:
            for item in self._contexts:
                if item._enable and len(item._define):
                    pf.writeln('/**')
                    pf.writeln('context {name}:'.format(name=item._name))
                    pf.writeln('{note}'.format(note=item.note))
                    pf.writeln('**/')
                    pf.writenl()
                    pf.writeln('{0}'.format(item._define))
                    pf.writenl()

        #write custom types
        for t in self(model.cc.Type, filter=lambda x: type(x.parent) is model.cc.TypesFolder):
            if t._readOnly:
                continue
            if len(t._definition.strip()) == 0:  # skip empty declarations
                continue
            pf.writeln('//type definition for {0}'.format(t._name))
            pf.writeln('{0}'.format(t._definition))
            pf.writenl()

        #write forward references
        self.WriteForwards(pf)

        #write prolog user definitions
        #self.WriteUserProlog()

        #write clases includes without inlines
        for cls in self.sorted_classes:
            if cls.is_external:
                continue
            pf.writeln('#include "{name}.h"'.format(name=cls._name))
        pf.writenl()
        pf.writeln('#define INCLUDE_INLINES')

        #write class includes again for inlines
        for cls in self.sorted_classes:
            if cls.is_external:
                continue
            pf.writeln('#include "{name}.h"'.format(name=cls._name))

        #write modules includes
        pf.writenl()
        for module in self.modules:
            if module.inner_library:
                continue
            pf.writeln('#include "{name}.h"'.format(name=module._header))

        #write end safeguard
        pf.writenl()
        pf.writeln('#endif //{name}_H_INCLUDED'.format(name=safe_name))
        pf.writenl()
        f.close()
        self._lastHdrTime = os.path.getmtime(fname)
        return True