コード例 #1
0
ファイル: pi_generator.py プロジェクト: wxWidgets/Phoenix
    def writeSection(self, destFile, sectionName, sectionText):
        """
        Read all the lines from destFile, remove those currently between
        begin/end markers for sectionName (if any), and write the lines back
        to the file with the new text in sectionText.
        """
        sectionBeginLine = -1
        sectionEndLine = -1
        sectionBeginMarker = "#-- begin-%s --#" % sectionName
        sectionEndMarker = "#-- end-%s --#" % sectionName

        lines = textfile_open(destFile, "rt").readlines()
        for idx, line in enumerate(lines):
            if line.startswith(sectionBeginMarker):
                sectionBeginLine = idx
            if line.startswith(sectionEndMarker):
                sectionEndLine = idx

        if sectionBeginLine == -1:
            # not there already, add to the end
            lines.append(sectionBeginMarker + "\n")
            lines.append(sectionText)
            lines.append(sectionEndMarker + "\n")
        else:
            # replace the existing lines
            lines[sectionBeginLine + 1 : sectionEndLine] = [sectionText]

        f = textfile_open(destFile, "wt")
        f.writelines(lines)
        f.close()
コード例 #2
0
    def writeSection(self, destFile, sectionName, sectionText):
        """
        Read all the lines from destFile, remove those currently between
        begin/end markers for sectionName (if any), and write the lines back
        to the file with the new text in sectionText.
        """
        sectionBeginLine = -1
        sectionEndLine = -1
        sectionBeginMarker = '#-- begin-%s --#' % sectionName
        sectionEndMarker = '#-- end-%s --#' % sectionName

        lines = textfile_open(destFile, 'rt').readlines()
        for idx, line in enumerate(lines):
            if line.startswith(sectionBeginMarker):
                sectionBeginLine = idx
            if line.startswith(sectionEndMarker):
                sectionEndLine = idx

        if sectionBeginLine == -1:
            # not there already, add to the end
            lines.append(sectionBeginMarker + '\n')
            lines.append(sectionText)
            lines.append(sectionEndMarker + '\n')
        else:
            # replace the existing lines
            lines[sectionBeginLine+1:sectionEndLine] = [sectionText]

        f = textfile_open(destFile, 'wt')
        f.writelines(lines)
        f.close()
コード例 #3
0
 def _checkAndWriteHeader(destFile, header, docstring):
     if not os.path.exists(destFile):
         # create the file and write the header
         with textfile_open(destFile, 'wt') as f:
             f.write(header)
             if docstring:
                 f.write('\n"""\n%s"""\n' % docstring)
コード例 #4
0
ファイル: pi_generator.py プロジェクト: wxWidgets/Phoenix
 def _checkAndWriteHeader(destFile, header, docstring):
     if not os.path.exists(destFile):
         # create the file and write the header
         f = textfile_open(destFile, "wt")
         f.write(header)
         if docstring:
             f.write('\n"""\n%s"""\n' % docstring)
         f.close()
コード例 #5
0
    def generate(self, module, destFile=None):
        stream = Utf8EncodingStream()

        # generate SIP code from the module and its objects
        self.generateModule(module, stream)

        # Write the contents of the stream to the destination file
        if not destFile:
            destFile = os.path.join(phoenixRoot, 'sip/gen', module.name + '.sip')
        with textfile_open(destFile, 'wt') as f:
            f.write(stream.getvalue())
コード例 #6
0
ファイル: sip_generator.py プロジェクト: erhuabushuo/Phoenix
 def generate(self, module, destFile=None):
     stream = Utf8EncodingStream()
     
     # generate SIP code from the module and its objects
     self.generateModule(module, stream)
     
     # Write the contents of the stream to the destination file
     if not destFile:
         destFile = os.path.join(phoenixRoot, 'sip/gen', module.name + '.sip')
     f = textfile_open(destFile, 'wt')
     f.write(stream.getvalue())
     f.close()
コード例 #7
0
ファイル: pi_generator.py プロジェクト: erhuabushuo/Phoenix
 def generate(self, module, destFile=None):
     stream = Utf8EncodingStream()
     
     # process the module object and its child objects
     self.generateModule(module, stream)
     
     # Write the contents of the stream to the destination file
     if not destFile:
         name = module.module + '.pi'
         if name.startswith('_'):
             name = name[1:]
         destFile = os.path.join(phoenixRoot, 'wx', name)
         
     if not os.path.exists(destFile):
         # create the file and write the header
         f = textfile_open(destFile, 'wt')
         f.write(header)
         f.close()
         
     self.writeSection(destFile, module.name, stream.getvalue())
コード例 #8
0
ファイル: pi_generator.py プロジェクト: wangdyna/wxPython
    def generate(self, module, destFile=None):
        stream = Utf8EncodingStream()

        # process the module object and its child objects
        self.generateModule(module, stream)

        # Write the contents of the stream to the destination file
        if not destFile:
            name = module.module + '.pi'
            if name.startswith('_'):
                name = name[1:]
            destFile = os.path.join(phoenixRoot, 'wx', name)

        if not os.path.exists(destFile):
            # create the file and write the header
            f = textfile_open(destFile, 'wt')
            f.write(header)
            f.close()

        self.writeSection(destFile, module.name, stream.getvalue())
コード例 #9
0
ファイル: pi_generator.py プロジェクト: mprosperi/Phoenix
 def _checkAndWriteHeader(destFile, header):
     if not os.path.exists(destFile):
         # create the file and write the header
         f = textfile_open(destFile, 'wt')
         f.write(header)
         f.close()