1 |
On Sunday 31 December 2006 00:00, Kevin O'Gorman wrote: |
2 |
> Hey, Jerry, wanna make a project team? I woulda done Python if I had |
3 |
> thought it was gonna get big. It now seems like that would be a good idea. |
4 |
> Care to: |
5 |
> 1) share your code? |
6 |
> 2) start a sourceforge project? |
7 |
> 3) just tantalize us with your results? |
8 |
> |
9 |
|
10 |
|
11 |
It's far, far from being finished or polished... here it is: |
12 |
|
13 |
#!/usr/bin/python |
14 |
# |
15 |
try: |
16 |
import psyco |
17 |
psyco.full() |
18 |
except ImportError: |
19 |
print "Non-Fatal error importing PSYCO" |
20 |
pass |
21 |
# |
22 |
try: |
23 |
import readline |
24 |
except ImportError: |
25 |
print "Fatal Error importing readline" |
26 |
sys.exit(1) |
27 |
# |
28 |
try: |
29 |
import struct |
30 |
except ImportError: |
31 |
print "Fatal Error importing struct" |
32 |
sys.exit(1) |
33 |
# |
34 |
try: |
35 |
import string |
36 |
except ImportError: |
37 |
print "Fatal Error importing string" |
38 |
sys.exit(1) |
39 |
# |
40 |
try: |
41 |
import sys |
42 |
except ImportError: |
43 |
print "Fatal Error imporing sys" |
44 |
sys.exit(1) |
45 |
# |
46 |
try: |
47 |
import os |
48 |
except ImportError: |
49 |
print "Fatal Error imporing os" |
50 |
sys.exit(1) |
51 |
|
52 |
al="array.list" |
53 |
il="index.list" |
54 |
ni="/var/www/localhost/htdocs/index2.html" |
55 |
z=0 |
56 |
rightNow="today!" |
57 |
version="1.0" |
58 |
|
59 |
print "Every Damn Index - version ",version |
60 |
print "" |
61 |
|
62 |
print 'Scanning hard drive and creating list of all discovered files.' |
63 |
print "" |
64 |
|
65 |
os.system('tree -fixn --noreport -o '+il+' /') |
66 |
|
67 |
print 'Construction of index list completed!' |
68 |
print "" |
69 |
|
70 |
print"Reading text from: ", il |
71 |
print "" |
72 |
|
73 |
# |
74 |
# read index.list and create new array list |
75 |
# |
76 |
input=open(il,'r') |
77 |
output=open(al,'w') |
78 |
|
79 |
for line in input.readlines(): |
80 |
|
81 |
# strip off leading and trailing spaces |
82 |
line = string.strip(line, " ") |
83 |
|
84 |
# stip off CR's |
85 |
line = string.rstrip(line,chr(10)) |
86 |
|
87 |
words=string.split(line,"/") |
88 |
steps=len(words) |
89 |
|
90 |
if words[steps-1]=="index.html": |
91 |
output.writelines(line+chr(10)) |
92 |
|
93 |
words=string.split(line,".") |
94 |
steps=len(words) |
95 |
|
96 |
if words[steps-1]=="pdf": |
97 |
output.writelines(line+chr(10)) |
98 |
|
99 |
words=string.split(line,".") |
100 |
steps=len(words) |
101 |
|
102 |
if words[steps-1]=="chm": |
103 |
output.writelines(line+chr(10)) |
104 |
|
105 |
z=z+1 |
106 |
|
107 |
if z > 2000: |
108 |
print ".", |
109 |
z=0 |
110 |
|
111 |
print"" |
112 |
|
113 |
print "Successfully processed ",il |
114 |
print"" |
115 |
|
116 |
input.close() |
117 |
output.close() |
118 |
|
119 |
print"Reading text from: "+al+" and building new "+ni |
120 |
print"" |
121 |
|
122 |
input=open(al,'r') |
123 |
output=open(ni,'w') |
124 |
|
125 |
output.writelines('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 |
126 |
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'+chr(10)) |
127 |
output.writelines("<html>"+chr(10)) |
128 |
output.writelines("<head>"+chr(10)) |
129 |
output.writelines("<title>Evey Damn Index "+version+"- copyright Jerome D. |
130 |
McBride - 2006</title>"+chr(10)) |
131 |
output.writelines('<meta name="GENERATOR" content="NONE">'+chr(10)) |
132 |
output.writelines('<meta http-equiv="Content-Type" content="text/html; |
133 |
charset=iso-8859-1">'+chr(10)) |
134 |
#output.writelines('<img id= "logo" |
135 |
src="http://www.expertsrt.com/images/xrt.png" alt="ERT Logo" |
136 |
style="vertical-align:top"/>'+chr(10)) |
137 |
output.writelines("</head>"+chr(10)) |
138 |
output.writelines("<body>"+chr(10)) |
139 |
output.writelines("<hr>"+chr(10)) |
140 |
output.writelines("<strong> Every Damn Index - Version "+version+" |
141 |
</strong>"+chr(10)) |
142 |
output.writelines("<hr>"+chr(10)) |
143 |
output.writelines("This page conatins a list of all available html |
144 |
indexes, .pdf and .chm files"+chr(10)) |
145 |
output.writelines("created "+rightNow+chr(10)) |
146 |
output.writelines("<hr>"+chr(10)) |
147 |
output.writelines("<br>"+chr(10)) |
148 |
|
149 |
z=0 |
150 |
|
151 |
for line in input.readlines(): |
152 |
|
153 |
# strip off leading and trailing spaces |
154 |
line = string.strip(line, " ") |
155 |
|
156 |
# strip off leading and trailing slashes |
157 |
line = string.strip(line, "/") |
158 |
|
159 |
# stip off CR's |
160 |
line = string.rstrip(line,chr(10)) |
161 |
|
162 |
print 'Looking for package info for:', line |
163 |
#clean up previous info.dat file |
164 |
os.system("rm info.dat 2>/dev/null 1>/dev/null") |
165 |
os.system('/usr/bin/equery belongs '+line+' >info.dat') |
166 |
|
167 |
inputData=open('info.dat','r') |
168 |
infoText=inputData.read() |
169 |
inputData.close() |
170 |
|
171 |
if len(infoText)==0: |
172 |
infoText="PNA/PNA" |
173 |
|
174 |
words=string.split(infoText,"/") |
175 |
steps=len(words) |
176 |
|
177 |
groupName=words[0] |
178 |
packageName=words[1] |
179 |
|
180 |
output.writelines('<br>--'+packageName+'-- <a |
181 |
href="'+line+'">documentation</a> found at '+line+'</br>'+chr(10)) |
182 |
|
183 |
output.writelines("<hr>"+chr(10)) |
184 |
output.writelines("The end..."+chr(10)) |
185 |
output.writelines("<br>"+chr(10)) |
186 |
output.writelines("</body>"+chr(10)) |
187 |
output.writelines("</html>"+chr(10)) |
188 |
|
189 |
print "New index2.html written to ",ni,"." |
190 |
print "" |
191 |
|
192 |
print "Program successfully shutdown." |
193 |
print "" |
194 |
|
195 |
input.close() |
196 |
output.close() |
197 |
|
198 |
os.system("rm "+al+" 2>/dev/null 1>/dev/null") |
199 |
os.system("rm "+il+" 2>/dev/null 1>/dev/null") |
200 |
os.system("rm info.dat 2>/dev/null 1>/dev/null") |
201 |
|
202 |
sys.exit(0) |
203 |
|
204 |
As for manning a project... time hasn't allowed me the pleasure of a decent |
205 |
day off from work. I would, however, contribute as I can. |
206 |
|
207 |
Cheers all and enjoy |
208 |
|
209 |
-- |
210 |
|
211 |
Jerry McBride |
212 |
-- |
213 |
gentoo-user@g.o mailing list |