1#!/usr/bin/python 2# -*- coding: utf-8 -*- 3# 4# Script to automatically update the "kdepackages.h" file 5# FIXME - This is a slow script. Rewrite me using a smart logic. Thanks! 6# 7import string 8import urllib 9import re 10 11def unescape(text): 12 text = text.replace(" "," ") 13 text = text.replace("‑","-") 14 text = text.replace("&","&") 15 return text 16 17 18print "Fetching products and components from bugs.kde.org..." 19 20pkg = open("src/kdepackages.h","w") 21pkg.write("// DO NOT EDIT - EDIT products in bugs.kde.org and run ./make_kdepackages_updated.py in kxmlgui to update\n") 22pkg.write("const char * const packages[] = {\n") 23 24data = urllib.urlopen('https://bugs.kde.org/describecomponents.cgi').read() 25 26for line in string.split(data,'\n'): 27 print "====parsing:" 28 #print line 29 match = re.search('(describecomponents.cgi\?product=.*)">(.*)</a>', line) 30 if match: 31 product = match.group(2) 32 link = match.group(1) 33 34 link = 'https://bugs.kde.org/' + link 35 data2 = urllib.urlopen(link).read() 36 37 productname = unescape(product) 38 print productname 39 pkg.write(" \"" + productname + "\",\n") 40 data2 = string.split(data2,'\n') 41 iter = 0 42 end = len(data2) 43 print "link: " + link 44 while( iter < end-1 ): 45 iter = iter+1 46 line = data2[iter] 47 match = re.search('amp;resolution=---">(.*)</a>', line) 48 if match: 49 product = match.group(1) 50 product = unescape(product) 51 print "found component: " + product 52 if product!="general": 53 pkg.write(" \"" + productname + "/" + product + "\",\n") 54 print productname + "/" + product 55 56pkg.write("0 };\n") 57pkg.close() 58