コード例 #1
0
ファイル: eplusdata.py プロジェクト: JasonGlazer/eppy
 def initdict(self,fname):
     #create a blank dictionary
     if isinstance(fname,idd):
         self.dt,self.dtls=fname.dt,fname.dtls
         return self.dt,self.dtls
     
     st=mylib2.readfile(fname)
     nocom=removecomment(st,'!')
     idfst=nocom
     nocom=removecomment(idfst,'\\')
     idfst=nocom
     ls=string.split(idfst,';')
     lss=[]
     for el in ls:
         lst=string.split(el,',')
         lss.append(lst)
     
     for i in range(0,len(lss)):
         for j in range(0,len(lss[i])):
             lss[i][j]=lss[i][j].strip()
     
     dt={}
     dtls=[]
     for el in lss:
         if el[0]=='':continue
         dt[el[0].upper()]=[]
         dtls.append(el[0].upper())
     
     self.dt,self.dtls=dt,dtls
     return dt,dtls
コード例 #2
0
ファイル: eplusdata.py プロジェクト: cmiller8/eppy
 def initdict(self,fname):
     st=mylib2.readfile(fname)
     nocom=removecomment(st,'!')
     idfst=nocom
     ls=string.split(idfst,';')
     lss=[]
     for el in ls:
         lst=string.split(el,',')
         lss.append(lst)
         
     for i in range(0,len(lss)):
         for j in range(0,len(lss[i])):
             lss[i][j]=lss[i][j].strip()
         
     dt={}
     dtls=[]
     for el in lss:
         if el[0]=='':continue
         dt[el[0].upper()]=[]
         dtls.append(el[0].upper())
         
     return dt,dtls
コード例 #3
0
	def makedict(self,dictfile,fname):
		#stuff file data into the blank dictionary
		#fname='./exapmlefiles/5ZoneDD.idf'
		#fname='./1ZoneUncontrolled.idf'
		if isinstance(dictfile,idd):
			localidd=copy.deepcopy(dictfile)
			dt,dtls=localidd.dt,localidd.dtls
		else:
			dt,dtls=self.initdict(dictfile)
		st=mylib2.readfile(fname)
		nocom=removecomment(st,'!')
		idfst=nocom
		nocom=removecomment(idfst,'\\')
		idfst=nocom
		ls=string.split(idfst,';')
		lss=[]
		for el in ls:
			lst=string.split(el,',')
			lss.append(lst)
		
		for i in range(0,len(lss)):
			for j in range(0,len(lss[i])):
				lss[i][j]=lss[i][j].strip()
		
		for el in lss:
			node=el[0].upper()
			if dt.has_key(node):
				#stuff data in this key
				dt[node.upper()].append(el)
			else:
				#scream
				if node=='':continue
				print 'this node -%s-is not present in base dictionary'%(node)
			
		self.dt,self.dtls=dt,dtls
		return dt,dtls
コード例 #4
0
import mylib1,mylib2
コード例 #5
0
def extractidddata(fname,debug=False):
	"""
	extracts all the needed information out of the idd file
	if debug is True, it generates a series of text files.
	Each text file is incrementally different. You can do a diff 
	see what the change is
	"""
	st=mylib2.readfile(fname)
	(nocom,nocom1,blocklst)=get_nocom_vars(st)
	
	
	st=nocom
	st1=removeblanklines(st)
	if debug:
		mylib1.writeStr2File('nocom2.txt',st1)
	
	
	#find the groups and the start object of the group
	#find all the group strings
	groupls=[]
	ls=st1.splitlines()
	for el in ls:
		lss=el.split()
		if lss[0].upper()=='\\group'.upper():
			groupls.append(el)
	
	
	#find the var just after each item in groupls
	groupstart=[]
	for i in range(len(groupls)):
		ii=ls.index(groupls[i])
		groupstart.append([ls[ii],ls[ii+1]])
	
	#remove the group commentline
	for el in groupls:
		ls.remove(el)
	
	if debug:
		st1='\n'.join(ls)
		mylib1.writeStr2File('nocom3.txt',st1)
	
	#strip each line
	for i in range(len(ls)):
		ls[i]=ls[i].strip()
	
	if debug:
		st1='\n'.join(ls)
		mylib1.writeStr2File('nocom4.txt',st1)
	
	#ensure that each line is a comment or variable
	#find lines that don't start with a comment
	#if this line has a comment in it
	#	then move the comment to a new line below
	lss=[]
	for i in range(len(ls)):
		#find lines that don't start with a comment
		if ls[i][0]!='\\':
			#if this line has a comment in it
			pt=ls[i].find('\\')
			if pt!=-1:
				#then move the comment to a new line below
				lss.append(ls[i][:pt].strip())
				lss.append(ls[i][pt:].strip())
			else:
				lss.append(ls[i])
		else:
			lss.append(ls[i])
	
	
	ls=lss[:]
	if debug:
		st1='\n'.join(ls)
		mylib1.writeStr2File('nocom5.txt',st1)
	
	#need to make sure that each line has only one variable - as in WindowGlassSpectralData,
	lss=[]
	for el in ls:
		# if the line is not a comment
		if el[0]!='\\':
			#test for more than one var
			ll=el.split(',')
			if ll[-1]=='':
				tmp=ll.pop()
			for elm in ll:
				if elm[-1]==';':
					lss.append(elm.strip())
				else:
					lss.append((elm+',').strip())
		else:
			lss.append(el)
	
	ls_debug=ls[:] # needed for the next debug - 'nocom7.txt'
	ls=lss[:]
	if debug:
		st1='\n'.join(ls)
		mylib1.writeStr2File('nocom6.txt',st1)
	
	if debug:
		#need to make sure that each line has only one variable - as in WindowGlassSpectralData,
		#this is same as above.
		# but the variables are put in without the ';' and ','
		#so we can do a diff between 'nocom7.txt' and 'nocom8.txt'. Should be identical
		lss_debug=[]
		for el in ls_debug:
			# if the line is not a comment
			if el[0]!='\\':
				#test for more than one var
				ll=el.split(',')
				if ll[-1]=='':
					tmp=ll.pop()
				for elm in ll:
					if elm[-1]==';':
						lss_debug.append(elm[:-1].strip())
					else:
						lss_debug.append((elm).strip())
			else:
				lss_debug.append(el)
		
		ls_debug=lss_debug[:]
		st1='\n'.join(ls_debug)
		mylib1.writeStr2File('nocom7.txt',st1)
	
	
	#replace each var with '=====var======'
	#join into a string,
	#split using '=====var====='
	for i in range(len(lss)):
		#if the line is not a comment
		if lss[i][0]!='\\':
			lss[i]='=====var====='
	
	st2='\n'.join(lss)
	lss=st2.split('=====var=====\n')
	lss.pop(0) # the above split generates an extra item at start
	
	if debug:
		fname='nocom8.txt'
		f=open(fname,'wb')
		k=0
		for i in range(len(blocklst)):
			for j in range(len(blocklst[i])):
				f.write(blocklst[i][j]+'\n')
				f.write(lss[k])
				k=k+1
		
		f.close()
	
	#map the structure of the comments -(this is 'lss' now) to 
	#the structure of blocklst - blocklst is a nested list
	#make lss a similar nested list
	k=0
	lst=[]
	for i in range(len(blocklst)):
		lst.append([])
		for j in range(len(blocklst[i])):
			lst[i].append(lss[k])
			k=k+1
	
	
	if debug:
		fname='nocom9.txt'
		f=open(fname,'wb')
		k=0
		for i in range(len(blocklst)):
			for j in range(len(blocklst[i])):
				f.write(blocklst[i][j]+'\n')
				f.write(lst[i][j])
				k=k+1
		
		f.close()
			
	
	
	#break up multiple line comment so that it is a list
	for i in range(len(lst)):
		for j in range(len(lst[i])):
			lst[i][j]=lst[i][j].splitlines()
			# remove the '\'
			for k in range(len(lst[i][j])):
				lst[i][j][k]=lst[i][j][k][1:]
	commlst=lst
	
	
	#copied with minor modifications from readidd2_2.py -- which has been erased ha !
	c=lst
	lss=[]
	for i in range(0,len(c)):
		ls=[]
		for j in range(0,len(c[i])):
			it=c[i][j]
			dt={}
			for el in it:
				if len(el.split())==0:
					break
				dt[el.split()[0]]=[]
			
			for el in it:
				if len(el.split())==0:
					break
				dt[el.split()[0]].append(string.join(el.split()[1:]))
				                
			
			ls.append(dt)
		
		lss.append(ls)
	commdct=lss
	
	return blocklst,commlst,commdct