[Collab-qa-commits] r2258 - udd/udd

Andreas Tille tille at alioth.debian.org
Sat May 5 07:03:24 UTC 2012


Author: tille
Date: 2012-05-05 07:03:24 +0000 (Sat, 05 May 2012)
New Revision: 2258

Modified:
   udd/udd/bibref_gatherer.py
Log:
Revert the manual (and thus unsorted and unreproducible) creation of the bibtex file and rather create it via a database query in the end


Modified: udd/udd/bibref_gatherer.py
===================================================================
--- udd/udd/bibref_gatherer.py	2012-05-05 06:30:30 UTC (rev 2257)
+++ udd/udd/bibref_gatherer.py	2012-05-05 07:03:24 UTC (rev 2258)
@@ -13,7 +13,6 @@
 import re
 import logging
 import logging.handlers
-from aux import to_unicode
 
 debug=0
 
@@ -43,7 +42,7 @@
 
     self.bibrefs = []
     self.bibrefsinglelist = []
-    
+
     self.bibtexfile = open('debian.bib', 'w')
 
   def setref(self, references, source, package, rank):
@@ -70,31 +69,7 @@
                        'volume'    : 0,
                        'year'      : 0,
                      }
-    # Create unique BibTeX key
-    ## first calculate year in case we might need it for unique bibtex key
     for r in references.keys():
-      if r.lower() == 'year':
-        year = str(references[r])
-        break
-    bibtexkey = source
-    if bibtexkey in self.bibrefsinglelist and year != '':
-      bibtexkey = source+year
-    if bibtexkey in self.bibrefsinglelist:
-      # if there are more than one reference per source package and even in
-      # the same year append the rank as letter
-      bibtexkey += 'abcdefghijklmnopqrstuvwxyz'[rank]
-    ref={}
-    ref['rank']    = rank
-    ref['source']  = source
-    ref['key']     = 'bibtex'
-    ref['value']   = bibtexkey
-    ref['package'] = package
-    self.bibrefsinglelist.append(bibtexkey)
-    self.bibrefs.append(ref)
-    print >>self.bibtexfile, "@Article{%s," % bibtexkey
-
-    # Now parse remaining references
-    for r in references.keys():
       # print r
       key = r.lower()
       if key == 'debian-package':
@@ -119,12 +94,24 @@
       else:
         ref['value']   = references[r].strip()
       self.bibrefs.append(ref)
-      if key not in ('package', 'refid'):
-        try:
-          print >>self.bibtexfile, '  %s = "{%s}",' % (ref['key'], ref['value'].encode("utf-8"))
-        except UnicodeEncodeError, err:
-          self.log.error("Problem printing value %s of source %s (%s)" % (ref['key'], source, str(err)))
-    print >>self.bibtexfile, "}\n"
+      if r.lower() == 'year':
+        year = ref['value']
+    # Create unique BibTeX key
+    bibtexkey = source
+    if bibtexkey in self.bibrefsinglelist and year != '':
+      bibtexkey = source+year
+    if bibtexkey in self.bibrefsinglelist:
+      # if there are more than one reference per source package and even in
+      # the same year append the rank as letter
+      bibtexkey += 'abcdefghijklmnopqrstuvwxyz'[rank]
+    ref={}
+    ref['rank']    = rank
+    ref['source']  = source
+    ref['key']     = 'bibtex'
+    ref['value']   = bibtexkey
+    ref['package'] = package
+    self.bibrefsinglelist.append(bibtexkey)
+    self.bibrefs.append(ref)
     return ref
 
   def run(self):
@@ -270,6 +257,10 @@
     cur.execute("DEALLOCATE bibref_insert")
     cur.execute("ANALYZE %s" % my_config['table'])
 
+    cur.execute("SELECT * FROM bibtex()")
+    for row in cur.fetchall():
+	print >>self.bibtexfile, row[0]
+
 if __name__ == '__main__':
   main()
 




More information about the Collab-qa-commits mailing list