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()
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()
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)
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()
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())
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()
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())
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()