File indexing completed on 2024-10-06 03:43:24

0001 #!/usr/bin/python
0002 # -*- coding: utf-8 -*-
0003 #
0004 # Script to automatically update the "kdepackages.h" file
0005 # FIXME - This is a slow script. Rewrite me using a smart logic. Thanks!
0006 #
0007 import string
0008 import urllib
0009 import re
0010 
0011 def unescape(text):
0012     text = text.replace(" "," ")
0013     text = text.replace("‑","-")
0014     text = text.replace("&","&")
0015     return text
0016 
0017 
0018 print "Fetching products and components from bugs.kde.org..."
0019 
0020 pkg = open("src/kdepackages.h","w")
0021 pkg.write("// DO NOT EDIT - EDIT products in bugs.kde.org and run ./make_kdepackages_updated.py in kxmlgui to update\n")
0022 pkg.write("const char * const packages[] = {\n")
0023 
0024 data = urllib.urlopen('https://bugs.kde.org/describecomponents.cgi').read()
0025 
0026 for line in string.split(data,'\n'):
0027   print "====parsing:"
0028   #print line
0029   match = re.search('(describecomponents.cgi\?product=.*)">(.*)</a>', line)
0030   if match:
0031     product = match.group(2)
0032     link = match.group(1)
0033 
0034     link = 'https://bugs.kde.org/' + link
0035     data2 = urllib.urlopen(link).read()
0036 
0037     productname = unescape(product)
0038     print productname
0039     pkg.write("    \"" + productname + "\",\n")
0040     data2 = string.split(data2,'\n')
0041     iter = 0
0042     end = len(data2)
0043     print "link: " + link
0044     while( iter < end-1 ):
0045       iter = iter+1
0046       line = data2[iter]
0047       match = re.search('amp;resolution=---">(.*)</a>', line)
0048       if match:
0049         product = match.group(1)
0050         product = unescape(product)
0051         print "found component: " + product
0052         if product!="general":
0053           pkg.write("    \"" + productname + "/" + product + "\",\n")
0054           print productname + "/" + product
0055 
0056 pkg.write("0 };\n")
0057 pkg.close()