/[qa]/trunk/pts/www/bin/excuses_to_xml.py
ViewVC logotype

Contents of /trunk/pts/www/bin/excuses_to_xml.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 450 - (hide annotations) (download) (as text)
Wed Dec 25 15:56:32 2002 UTC (10 years, 5 months ago) by hertzog
File MIME type: text/x-python
File size: 4522 byte(s)
* Fix an endless loop generated by line "insatisfiable dependencies" of
  kind `packagea (>= x) | packageb (<< y)' ... the > ... << confuses the
  simple html stripper.
1 hertzog 344 #!/usr/bin/python2.2
2    
3     # Make sure tabs expand to 8 spaces in vim
4     # vim: expandtab
5    
6 hertzog 351 # Copyright 2002 Raphaƫl Hertzog
7     # This file is distributed under the terms of the General Public License
8     # version 2 or (at your option) any later version.
9    
10 hertzog 357 import os.path, rfc822, sys, string, re, cPickle
11 hertzog 344 from xml.dom import implementation, ext
12    
13     from config import dir, odir
14    
15     def striphtml(input):
16     cleared = input.strip()
17 hertzog 450 # I have to clean it this way first because dependencies are copied raw
18     # in update_excuses.html ...
19     cleared = cleared.replace(">=", "&gt;=");
20     cleared = cleared.replace("<=", "&lt;=");
21     cleared = cleared.replace(">>", "&gt;&gt;");
22     cleared = cleared.replace("<<", "&lt;&lt;");
23 hertzog 344 while cleared.find("<") != -1 and cleared.find(">") != -1:
24     cleared = cleared[:cleared.find("<")] + cleared[cleared.find(">")+1:]
25     return cleared
26    
27 hertzog 357 # Load the list of excuses generated last time
28     old_done = {}
29     new_done = {}
30     if os.path.exists(odir + "/excuses_done"):
31     f = open(odir + "/excuses_done", "r")
32     old_done = cPickle.load(f)
33     f.close()
34 hertzog 344
35     f = open(dir + "/update_excuses.html", "r")
36     # Ignore everything until first list
37     while string.find(f.readline(), "<ul>") == -1:
38     pass
39    
40     top = 1
41 hertzog 357 package = ""
42     hash = ""
43     doc = None
44 hertzog 344 while 1:
45     line = f.readline()
46     if not line: break #eof
47     if line.find("</ul>") != -1:
48     top = 1
49 hertzog 357 if os.path.exists("%s/%s/%s" % (odir, hash, package)):
50     excf = open("%s/%s/%s/excuse.xml" % (odir, hash, package), "w")
51     ext.PrettyPrint(doc, excf, "iso-8859-1")
52     excf.close()
53     new_done[package] = 1
54 hertzog 344 continue
55     if line.find("<ul>") != -1:
56     top = 0
57     continue
58     # The rest depends of the state
59     if top:
60     words = re.split("[><() ]", line)
61 hertzog 357 package = words[6]
62     hash = package[0]
63     if package[0:3] == "lib":
64     hash = package[0:4]
65     # Create the XML Document
66     doc = implementation.createDocument(None, "excuse", None)
67     main_elt = doc.documentElement
68 hertzog 344 top = 0
69     else:
70     for subline in line.split("<li>"):
71     if not subline: continue
72     subline = subline.strip()
73     if subline.find("Maintainer:") != -1: continue
74     elif subline.find("Too young,") != -1:
75     words = subline.split()
76     main_elt.setAttribute("age", words[3])
77     main_elt.setAttribute("limit", words[5])
78     main_elt.setAttribute("progress", "%d" % (100.0 * string.atoi(words[3]) / string.atoi(words[5])))
79 hertzog 352 subline = striphtml(subline)
80     sub_elt = doc.createElement("item")
81     sub_elt.appendChild(doc.createTextNode(subline))
82     main_elt.appendChild(sub_elt)
83    
84 hertzog 344 elif subline.find("days old (needed") != -1:
85     words = subline.split()
86     main_elt.setAttribute("age", words[0])
87     main_elt.setAttribute("limit", words[4])
88     main_elt.setAttribute("problematic", "yes")
89     subline = striphtml(subline)
90     sub_elt = doc.createElement("item")
91     sub_elt.appendChild(doc.createTextNode(subline))
92     main_elt.appendChild(sub_elt)
93     else:
94     sub_elt = doc.createElement("item")
95     start = subline.find('href="http://')
96     if start != -1:
97     url = subline[start+6:subline.find('"',start+6)]
98     sub_elt.setAttribute("url", url)
99 hertzog 352 start = subline.find('href="#')
100     if start != -1:
101     url = subline[start+7:subline.find('"',start+7)]
102 hertzog 405 sub_elt.setAttribute("url", "http://packages.qa.debian.org/" + url)
103 hertzog 344 subline = striphtml(subline)
104     sub_elt.appendChild(doc.createTextNode(subline))
105     main_elt.appendChild(sub_elt)
106    
107     f.close()
108 hertzog 357
109     # Store the new list
110     f = open(odir + "/excuses_done", "w")
111     cPickle.dump(new_done, f, 0)
112 hertzog 344 f.close()
113    
114 hertzog 357 # Find excuses generated last time and not this time
115     # and remove them
116     for p in old_done.keys():
117     if not new_done.has_key(p):
118     hash = p[0]
119     if p[0:3] == "lib":
120     hash = p[0:4]
121     filename = "%s/%s/%s/excuse.xml" % (odir, hash, p)
122 hertzog 400 filenamerebuild = "%s/%s/%s/force-rebuild" % (odir, hash, p)
123 hertzog 357 if os.path.exists(filename):
124     os.unlink(filename)
125 hertzog 400 f = open(filenamerebuild, "w")
126     f.close()
127 hertzog 357
128     # We're done

Properties

Name Value
svn:eol-style native
svn:executable *
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.5