1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#!/usr/bin/python
import fileinput
import re
import commands
tempfile=open('workfile', 'w')
uref = "component"
value = "value"
text = "anything"
word_length = 0
for line in fileinput.input():
text = line
if re.search("uref=",text):
word_length = len(text) - 1 #remove newline
uref = text[5:word_length] #get component uref
if re.search("value=",text):
word_length = len(text) - 1 #remove newline
value = text[6:word_length] #get component value
#print uref,
#print "-------",
#print value
tempfile.write(uref)
tempfile.write(' ---------- ')
tempfile.write(value)
tempfile.write("\n")
tempfile.close()
print fileinput.filename()
x = open('workfile','r')
pp=fileinput.filename()
bom=open(pp +'.bom','w')
bom.write("Bill of Materials for "+ fileinput.filename() + '\n')
bom.write("\n")
bom.write("Component Value\n")
a = x.readlines()
a.sort()
for tuple in a:
bom.write(tuple)
bom.close()
x.close()
bom = open(pp + '.bom','r')
for line in bom.readlines():
print line,
commands.getoutput('rm workfile') #remove workfile
|