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
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Script to automatically update the "kdepackages.h" file
# FIXME - This is a slow script. Rewrite me using a smart logic. Thanks!
#
import string
import urllib
import re
def unescape(text):
text = text.replace(" "," ")
text = text.replace("‑","-")
text = text.replace("&","&")
return text
print "Fetching products and components from bugs.kde.org..."
pkg = open("src/kdepackages.h","w")
pkg.write("// DO NOT EDIT - EDIT products in bugs.kde.org and run ./make_kdepackages_updated.py in kxmlgui to update\n")
pkg.write("const char * const packages[] = {\n")
data = urllib.urlopen('https://bugs.kde.org/describecomponents.cgi').read()
for line in string.split(data,'\n'):
print "====parsing:"
#print line
match = re.search('(describecomponents.cgi\?product=.*)">(.*)</a>', line)
if match:
product = match.group(2)
link = match.group(1)
link = 'https://bugs.kde.org/' + link
data2 = urllib.urlopen(link).read()
productname = unescape(product)
print productname
pkg.write(" \"" + productname + "\",\n")
data2 = string.split(data2,'\n')
iter = 0
end = len(data2)
print "link: " + link
while( iter < end-1 ):
iter = iter+1
line = data2[iter]
match = re.search('amp;resolution=---">(.*)</a>', line)
if match:
product = match.group(1)
product = unescape(product)
print "found component: " + product
if product!="general":
pkg.write(" \"" + productname + "/" + product + "\",\n")
print productname + "/" + product
pkg.write("0 };\n")
pkg.close()
|