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

Andreas Tille tille at alioth.debian.org
Sat Apr 21 20:01:10 UTC 2012


Author: tille
Date: 2012-04-21 20:01:10 +0000 (Sat, 21 Apr 2012)
New Revision: 2234

Modified:
   udd/udd/bibref_gatherer.py
Log:
Try to export a BibTeX file from upstream citation data


Modified: udd/udd/bibref_gatherer.py
===================================================================
--- udd/udd/bibref_gatherer.py	2012-04-21 01:56:41 UTC (rev 2233)
+++ udd/udd/bibref_gatherer.py	2012-04-21 20:01:10 UTC (rev 2234)
@@ -13,6 +13,7 @@
 import re
 import logging
 import logging.handlers
+from aux import to_unicode
 
 debug=0
 
@@ -42,6 +43,8 @@
 
     self.bibrefs = []
     self.bibrefsinglelist = []
+    
+    self.bibtexfile = open('debian.bib', 'w')
 
   def setref(self, references, source, package, rank):
     year=''
@@ -67,7 +70,31 @@
                        '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':
@@ -92,24 +119,12 @@
       else:
         ref['value']   = references[r].strip()
       self.bibrefs.append(ref)
-      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)
+      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"
     return ref
 
   def run(self):




More information about the Collab-qa-commits mailing list