/[gentoo]/src/gwn/get_glsas.py
Gentoo

Contents of /src/gwn/get_glsas.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations) (download) (as text)
Mon Sep 1 21:20:49 2014 UTC (3 years, 11 months ago) by hwoarang
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +30 -10 lines
File MIME type: text/x-python
get_glsas.py: Multiple fixes

- Add command line arguments for start-stop date
- Escape ',' in description since it conflicts with the wordpress pluging for
tables
- Take care of GLSAs for multiple packages
- improve code to construct the GLSA id hyperlink

1 #!/usr/bin/python
2
3 import urllib2
4 from bs4 import BeautifulSoup
5 import sys, re, os, time
6
7 foundone = 0
8 glsa_list = []
9 package_list = []
10 description_list = []
11 bug_list = []
12
13 def getglsas(table):
14 global foundone, glsa_list, package_list, description_list, bug_list
15 rows = table.findAll('tr')
16 for tr in rows:
17 cols = tr.findAll('td')
18 passt = 0
19 glsanum = ''
20 package = ''
21 description = ''
22 bugnum = ''
23 for td in cols:
24 if passt == 0:
25 if td.a:
26 # Fetch GLSA id and reconstruct the href
27 glsanum = str(td.a).split()
28 if any(str(date_from) in date for date in glsanum):
29 foundone = 1
30 glsanum = glsanum[0] + " " + glsanum[1] + glsanum[2] + glsanum[3]
31 glsa_list.append(glsanum)
32 else:
33 break
34 passt += 1
35 else:
36 # Ignore table headers
37 passt = 0
38
39 elif passt == 1:
40 # Ignore severity
41 passt += 1
42
43 elif passt == 2:
44 # Fetch package name and construct href
45 if td.a:
46 # This is usually for GLSAs for
47 # multiple packages.
48 # FIXME: There has to be a better way
49 # to do that...
50 package = td.find_next(text=True).strip().split()[0]
51 extra_pkg = \
52 td.find_next(text=True).strip() + " more)"
53 package = \
54 "<a href=\"http://packages.gentoo.org/package/%s\">%s</a>" \
55 % (package, extra_pkg)
56 else:
57 package = str(td.string).strip()
58 package = "<a href=\"http://packages.gentoo.org/package/%s\">%s</a>" % (package, package)
59 package_list.append(package)
60 passt += 1
61
62 elif passt == 3:
63 # Fetch description
64 description = str(td.string).strip().replace(',','\,')
65 description_list.append(description)
66 passt += 1
67
68 elif passt == 4:
69 # Fetch Bug number and recontruct the href
70 if td.a:
71 bugnum = str(td.a).split()
72 bugnum = bugnum[0] + " " + \
73 bugnum[1] + bugnum[2] + bugnum[3]
74 bug_list.append(bugnum)
75 passt = 0
76 if __name__ == '__main__':
77 # get dates from command line, else use now (time.time())
78 starttime = time.gmtime(time.time() - (60 * 60 * 24 * 1))
79 endtime = time.gmtime(time.time() + (60 * 60 * 24 * 31))
80 if len(sys.argv) >=1:
81 if len(sys.argv) >= 2:
82 starttime = time.strptime(str(int(sys.argv[1])), "%Y%m%d")
83 endtime = time.strptime(str(int(sys.argv[2])), "%Y%m%d")
84 else:
85 print "Usage: " + os.path.basename(sys.argv[0]) + " [start-date] [end-date]"
86 print "dates must be passed in 'yyyymmdd' format"
87 print "if no dates are specified then it defaults to a date range of the last 31 days"
88
89 # Format the string to what we expect
90 date_to = time.strftime("%Y%m", endtime)
91 date_from = time.strftime("%Y%m", starttime)
92 glsas = urllib2.urlopen("http://www.gentoo.org/security/en/glsa/index.xml?passthrough=1").read()
93 soup = BeautifulSoup(glsas)
94 table = soup.findAll('table')
95 # There is probably a better way to fetch the table with the GLSAs
96 table = table[2]
97 print "Looking for GLSAs from %s to %s\n\n" % (date_from, date_to)
98 getglsas(table)
99
100 if foundone:
101 print "\n\nFound %s GLSAs\n" % len(glsa_list)
102
103 print "Copy and paste the following text to the GMN Security section\n\n"
104
105 print "<h1>Security</h1>"
106 if not foundone:
107 print "No GLSAs have been released this month! You are safe :)"
108 else:
109 print "The following <a title=\"GLSAs\" " + \
110 "href=\"http://www.gentoo.org/security/en/glsa/index.xml\">GLSAs</a> " + \
111 "have been released by the <a title=\"Security Team\" " + \
112 "href=\"http://wiki.gentoo.org/wiki/Project:Security\">Security Team" + \
113 "</a>"
114 print "[table tablesorter=\"1\" id=\"glsas\"]"
115 print "GLSA, Package, Description, Bug"
116 for x in range(0,len(glsa_list)):
117 print glsa_list[x] + ", " + package_list[x] + \
118 ", " + description_list[x] + ", " + bug_list[x]
119 print "[/table]"
120 sys.exit(0)

  ViewVC Help
Powered by ViewVC 1.1.20