Permalink
Browse files

Updates

  • Loading branch information...
1 parent 0c4ef75 commit 9e6665ed7aa293bc0c1d18d363a1785cd55305c7 @dagwieers committed Feb 14, 2006
Showing with 51 additions and 29 deletions.
  1. +26 −19 sarahdb.py
  2. +25 −10 sarahlib.py
View
@@ -18,7 +18,8 @@
reader = Sax2.Reader()
filelist = glob.glob('advisories/RH?A-*.xml')
-#filelist = glob.glob('advisories/RHSA-2005-839.xml')
+#filelist = glob.glob('advisories/RHSA-*.xml')
+#filelist = ['advisories/RHSA-2005-791.xml', ]
filelist.sort()
for file in filelist:
@@ -65,28 +66,34 @@
next = walker.nextNode()
while walker.currentNode.tagName == 'reference':
refrec = advrec.copy()
- refrec['reftype'] = walker.currentNode.getAttribute('type')
- if refrec['reftype'] == 'self':
+
+ if walker.currentNode.hasAttribute('type'):
+ refrec['reftype'] = walker.currentNode.getAttribute('type')
+
+ if walker.currentNode.hasAttribute('href'):
refrec['reference'] = walker.currentNode.getAttribute('href')
+
+ next = walker.nextNode()
+ while walker.currentNode.tagName in ('advisory', 'bugzilla', 'cve', 'summary'):
+ if walker.currentNode.tagName in ('advisory', 'bugzilla', 'cve'):
+ refrec['id'] = walker.currentNode.firstChild.data
+ elif walker.currentNode.tagName == 'summary':
+ refrec['summary'] = walker.currentNode.firstChild.data
+ else:
+ raise 'Unknown tag in reference node'
+ next = walker.nextNode()
+
+ if refrec['reftype'] == 'self':
refrec['id'] = advrec['advid']
+
+ if not refrec.has_key('summary'):
refrec['summary'] = None
- elif refrec['reftype'] == 'cve':
- refrec['reference'] = walker.currentNode.getAttribute('href')
- refrec['id'] = walker.currentNode.firstChild.firstChild.data
- refrec['summary'] = None
- elif refrec['reftype'] == 'bugzilla':
- refrec['reference'] = walker.currentNode.getAttribute('href')
- refrec['id'] = walker.currentNode.firstChild.firstChild.data
- ### FIXME: capture the summary as well, when available
-# <reference type="bugzilla" href="http://bugzilla.redhat.com/179171"><bugzilla>179171</bugzilla><summary>CVE-2005-4134 Very long topic history.dat DoS</summary></reference>
- refrec['summary'] = None
- else:
- refrec['reference'] = None
+
+ if not refrec.has_key('id'):
refrec['id'] = None
- refrec['summary'] = None
+
sarahlib.insertrec(cur, 'ref', refrec)
- con.commit()
- next = walker.nextNode()
+ con.commit()
continue
elif walker.currentNode.tagName == 'topic':
@@ -108,7 +115,7 @@
except: pass
next = walker.nextNode()
while walker.currentNode.tagName == 'file':
- rpmrec = advrec
+ rpmrec = advrec.copy()
rpmrec['arch'] = walker.currentNode.getAttribute('arch')
rpmrec['prodshort'] = prorec['prodshort']
rpmrec['channel'] = []
View
@@ -17,6 +17,15 @@
'pro': { 'prodshort': 'unique primary key', },
}
+
+### Build insert strings for each database
+insertstr = { }
+for name in headers.keys():
+ insertstr[name] = 'insert into %s ( ' % name
+ for key in headers[name]: insertstr[name] += '%s, ' % key
+ insertstr[name] = insertstr[name].rstrip(', ') + ' ) values ( ' + '%s, ' * len(headers[name])
+ insertstr[name] = insertstr[name].rstrip(', ') + ' )'
+
def sqlcreate(name):
'Return a database create SQL statement'
str = 'create table %s ( ' % name
@@ -27,13 +36,13 @@ def sqlcreate(name):
str += '%s varchar(10) %s,' % (key, ds)
return str.rstrip(', ') + ' )'
-def sqlinsert(name):
- 'Return a database insert SQL statement'
- str = 'insert into %s ( ' % name
- for key in headers[name]: str += '%s, ' % key
- str = str.rstrip(', ') + ' ) values ( '
- for key in headers[name]: str += '"%%(%s)s", ' % key
- return str.rstrip(', ') + ' )'
+#def sqlinsert(name):
+# 'Return a database insert SQL statement'
+# str = 'insert into %s ( ' % name
+# for key in headers[name]: str += '%s, ' % key
+# str = str.rstrip(', ') + ' ) values ( '
+# for key in headers[name]: str += '"%%(%s)s", ' % key
+# return str.rstrip(', ') + ' )'
def opendb():
'Open a database and return references'
@@ -48,8 +57,14 @@ def createtb(cur, name, create=False):
def insertrec(cur, name, rec):
'Insert a record in a database'
- ### Convert unicode to UTF-8
- for key in rec.keys():
+ global insertstr
+
+ values = []
+ for key in headers[name]:
+ ### Convert unicode to UTF-8
if isinstance(rec[key], types.UnicodeType):
rec[key] = rec[key].encode('utf-8')
- cur.execute(sqlinsert(name) % rec)
+ values.append(rec[key])
+# print insertstr[name]
+# print values
+ cur.execute(insertstr[name], values)

0 comments on commit 9e6665e

Please sign in to comment.