예제 #1
0
	def writeFile(self):
		strOut = ''
		strOut += '\n\t' + self._renderNamespaceCode()
		strOut += '\n\t' + self.outConnection.getvalue()
		strOut += '\n\t' + script_create.readfile('./source/object_properties.cpp') #flags like Window.MAXIMIZE
		
		strTemplate = script_create.readfile(self.strFilename+'.cpp.template')
		strTemplate = strTemplate.replace('%%%INSERT_PROPERTY_CREATION_HERE%%%', strOut)
		if not alreadyExists('./gen/' + self.strFilename+'.cpp', strTemplate):
			fout = open('./gen/' + self.strFilename+'.cpp', 'w')
			fout.write(strTemplate)
			fout.close()
예제 #2
0
	def writeFile(self, dictCustomReplacements = None): 
		strTemplate = script_create.readfile(self.strFilename+'.cpp.template')
		
		if dictCustomReplacements:
			for key in dictCustomReplacements: strTemplate=strTemplate.replace(key, dictCustomReplacements[key])
		strTemplate = strTemplate.replace('%%%INSERT_FUNCTIONS_HERE%%%', self.outCode.getvalue())
		if not alreadyExists('./gen/' + self.strFilename+'.cpp', strTemplate):
			fout = open('./gen/' + self.strFilename+'.cpp', 'w')
			fout.write(strTemplate)
			fout.close()
		
		strTemplate = script_create.readfile(self.strFilename+'.h.template')
		strTemplate = strTemplate.replace('%%%INSERT_HEADERS_HERE%%%', self.outHeaders.getvalue())
		if not alreadyExists('./gen/' + self.strFilename+'.h', strTemplate):
			fout = open('./gen/' + self.strFilename+'.h', 'w')
			fout.write(strTemplate)
			fout.close()
예제 #3
0
def createDoc():
	txt = script_create.readfile('object_documentation.cpp')
	lines = txt.replace('\r\n','\n').split('\n')
	
	#first, create section objects. In the future we may have a place to independently specify these
	sections = {}
	for line in lines:
		if line.startswith('///Section:'):
			param, sectionname = script_create.parseParamEntry(line)
			#if we haven't seen this yet, create it.
			if sectionname not in sections:
				sections[sectionname] = Section_repr(sectionname)
				sections[sectionname].doc = '' 
				print sectionname
				#no general documentation for sections yet.
			
	#now, create namespace objects
	namespaces = {}
	currentNamespace = None
	for line in lines:
		if line.strip()=='' or (line.startswith('//') and not line.startswith('///')): continue
		if line.startswith('///'):
			param, data = script_create.parseParamEntry(line)
			if param=='Namespace':
				currentNamespace = Namespace_repr(data)
			elif param=='Section':
				currentNamespace.sectionname = data
			elif param=='Enddoc':
				#rejoin lines of doc
				currentNamespace.doc = '\n'.join(currentNamespace.doc)
				
				#place in dict
				namespaces[currentNamespace.name] = currentNamespace
				#assign to its section
				if currentNamespace.sectionname==None: raise Exception, 'Error: No section designated for namespace %s',currentNamespace.name
				if currentNamespace.sectionname not in sections:  raise Exception, 'Error: section %s not found, specified by namespace %s'%(currentNamespace.sectionname, currentNamespace.name)
				sections[currentNamespace.sectionname].namespaces.append(currentNamespace)
				currentNamespace = None
			elif param=='Doc':
				#starting documentation...
				currentNamespace.doc = []
		else:
			currentNamespace.doc.append(line)
	
	#now, add all of the functions
	aFunctions = script_create.processAllSource()
	for obj in aFunctions:
		ns = obj.namespace
		if ns not in namespaces: raise Exception, 'In function %s, namespace %s does not exist.'%(obj.functionname, obj.namespace)
		namespaces[ns].functions.append(obj)
	

	if len(sys.argv)>2:
		# Set the working directory to the second parameter passed to me
		d = sys.argv[2]
		os.chdir(d)
	
	#finally, write the xml
	fout = open(r'documentation.xml','w')
	fout.write('<?xml version="1.0" encoding="UTF-8"?>')
	fout.write('<?xml-stylesheet type="text/xsl" href="viewdoc.xsl"?>')
	fout.write('<launchorzdoc version="0.5">')
	
	i = 0
	#actually, don't sort the keys, so that "launchors" is before "language"
	for key in sections.keys():
		section = sections[key]
		fout.write('<section name="%s">'%xmlescape(section.name))
		if section.doc: fout.write('<section_doc>%s</section_doc>'%xmlescape(section.doc))
		for namespace in sorted(section.namespaces, key=operator.attrgetter('name')):
			fout.write('<namespace name="%s">'%xmlescape(namespace.name))
			if namespace.doc: fout.write('<namespace_doc>%s</namespace_doc>'%xmlescape(namespace.doc))
			for function in sorted(namespace.functions, key=operator.attrgetter('functionname')):
				i+=1
				if function.functionname.startswith('_'): continue #this is an undocumented function; don't include it.
				function.args = function.args.replace('INTDEFAULT','default')
				function.args = function.args.replace('string window','string strWindow')
				
				if function.instanceMethod==True: sInstanceParam = ' instance="true" '
				else: sInstanceParam = ''
				fout.write('<function name="%s" args="%s" returns="%s" impl="%s"%s>'%(xmlescape(function.functionname),xmlescape(function.args),xmlescape(function.returns),xmlescape(function.implementation),sInstanceParam))
				if function.doc: fout.write('<doc>%s</doc>'%xmlescape(function.doc))
				if function.example: fout.write('<example>%s</example>'%xmlescape(function.example))
				fout.write('</function>')
			fout.write('</namespace>')
		
		fout.write('</section>')
	
	fout.write('</launchorzdoc>')
	fout.close()
	print len(aFunctions), i
예제 #4
0
def alreadyExists(strFilename, strWholeFile):
	#if the exact same file already exists, don't write it. The main advantage is that the file isn't "touched" and gcc won't rebuild it.
	if not os.path.exists(strFilename): return False
	strWholeExistingFile = script_create.readfile(strFilename)
	return strWholeFile==strWholeExistingFile