[Collab-qa-commits] r1032 - udd/src/udd

neronus-guest at alioth.debian.org neronus-guest at alioth.debian.org
Sat Aug 9 14:01:48 UTC 2008


Author: neronus-guest
Date: 2008-08-09 14:01:47 +0000 (Sat, 09 Aug 2008)
New Revision: 1032

Modified:
   udd/src/udd/aux.py
   udd/src/udd/packages_gatherer.py
   udd/src/udd/sources_gatherer.py
Log:
Switched quoting to the db-api for packages and sources gatherers
fixed quoting function in aux.py (which hopefully won't be used any longer)


Modified: udd/src/udd/aux.py
===================================================================
--- udd/src/udd/aux.py	2008-08-09 13:06:53 UTC (rev 1031)
+++ udd/src/udd/aux.py	2008-08-09 14:01:47 UTC (rev 1032)
@@ -9,7 +9,7 @@
 
 def quote(s):
   "Quote a string for SQL"
-  return "'" + s.replace("'", "\\'") + "'"
+  return "'" + s.replace("\\", "\\\\").replace("'", "\\'") + "'"
 
 def null_or_quote(dict, key):
   "If key is an element of dict, return it quoted. Return NULL otherwise"

Modified: udd/src/udd/packages_gatherer.py
===================================================================
--- udd/src/udd/packages_gatherer.py	2008-08-09 13:06:53 UTC (rev 1031)
+++ udd/src/udd/packages_gatherer.py	2008-08-09 14:01:47 UTC (rev 1032)
@@ -1,5 +1,5 @@
 # /usr/bin/env python
-# Last-Modified: <Fri Aug  8 12:42:28 2008>
+# Last-Modified: <Sat Aug  9 12:45:57 2008>
 # This file is a part of the Ultimate Debian Database project
 
 import debian_bundle.deb822
@@ -53,11 +53,14 @@
     for k in packages_gatherer.mandatory:
       if k not in control:
 	raise "Mandatory field %s not specified" % k
-      d[k] = "'" + control[k].replace("\\", "\\\\").replace("'", "\\'") + "'"
+      d[k] = control[k]
     for k in packages_gatherer.non_mandatory:
-      d[k] = aux.null_or_quote(control, k)
+      if k not in control:
+	d[k] = None
+      else:
+	d[k] = control[k]
     for k in control.keys():
-      if k not in packages_gatherer.mandatory and k not in packages_gatherer.non_mandatory and k not in packages_gatherer.ignorable:
+      if k not in packages_gatherer.non_mandatory and k not in packages_gatherer.mandatory and k not in packages_gatherer.ignorable:
 	if k not in packages_gatherer.warned_about:
 	  packages_gatherer.warned_about[k] = 1
 	else:
@@ -84,22 +87,17 @@
 
       d = self.build_dict(control)
 
-      # These are integer values - we don't need quotes for them
-      if d['Installed-Size'] != 'NULL':
-	d['Installed-Size'] = d['Installed-Size'].strip("'")
-      if d['Size'] != 'NULL':
-	d['Size'] = d['Size'].strip("'")
-
       # We just use the first line of the description
-      if d['Description'] != "NULL":
+      if 'Description' in d:
 	d['Description'] = d['Description'].split("\n",1)[0]
-	# If the description was a one-liner only, we don't need to add
-	# a quote
-	if d['Description'][-1] != "'" or d['Description'][-2] == '\\':
-	  d['Description'] += "'"
+
+      # Convert numbers to numbers
+      for f in ['Installed-Size', 'Size']:
+	if d[f] is not None:
+	  d[f] = int(d[f])
       
       # Source is non-mandatory, but we don't want it to be NULL
-      if d['Source'] == "NULL":
+      if d['Source'] is None:
 	d['Source'] = d['Package']
 	d['Source_Version'] = d['Version']
       else:
@@ -118,9 +116,9 @@
 	  %(Build-Essential)s, %(Origin)s, %(SHA1)s,
 	  %(Replaces)s, %(Section)s, %(MD5sum)s, %(Bugs)s, %(Priority)s,
 	  %(Tag)s, %(Task)s, %(Python-Version)s, %(Provides)s,
-	  %(Conflicts)s, %(SHA256)s, %(Original-Maintainer)s)""" % d
+	  %(Conflicts)s, %(SHA256)s, %(Original-Maintainer)s)"""
       try:
-	cur.execute(query)
+	cur.execute(query, d)
       except psycopg2.ProgrammingError:
 	print query
 	raise

Modified: udd/src/udd/sources_gatherer.py
===================================================================
--- udd/src/udd/sources_gatherer.py	2008-08-09 13:06:53 UTC (rev 1031)
+++ udd/src/udd/sources_gatherer.py	2008-08-09 14:01:47 UTC (rev 1032)
@@ -1,5 +1,5 @@
 #/usr/bin/env python
-# Last-Modified: <Fri Aug  8 12:45:43 2008>
+# Last-Modified: <Sat Aug  9 12:05:42 2008>
 # This file is a part of the Ultimate Debian Database project
 
 import debian_bundle.deb822
@@ -43,27 +43,30 @@
     for k in sources_gatherer.mandatory:
       if k not in control:
 	raise "Mandatory field %s not specified" % k
-      d[k] = "'" + control[k].replace("\\", "\\\\").replace("'", "\\'") + "'"
+      d[k] = control[k]
     for k in sources_gatherer.non_mandatory:
-      d[k] = null_or_quote(control, k)
+      if k in control:
+	d[k] = control[k]
+      else:
+	d[k] = None
     
-    d['Vcs-Type'] = 'NULL'
-    d['Vcs-Url'] = 'NULL'
+    d['Vcs-Type'] = None
+    d['Vcs-Url'] = None
     for vcs in sources_gatherer.vcs:
       if control.has_key("Vcs-"+vcs):  
-        d['Vcs-Type'] = quote(vcs)
-	d['Vcs-Url'] = quote(control["Vcs-"+vcs])
+        d['Vcs-Type'] = vcs
+	d['Vcs-Url'] = control["Vcs-"+vcs]
 	break
       elif control.has_key("X-Vcs-"+vcs):  
-        d['Vcs-Type'] = quote(vcs)
-	d['Vcs-Url'] = quote(control["X-Vcs-"+vcs])
+        d['Vcs-Type'] = vcs
+	d['Vcs-Url'] = control["X-Vcs-"+vcs]
 	break
     if control.has_key("Vcs-Browser"):  
-        d['Vcs-Browser'] = quote(control["Vcs-Browser"])
+        d['Vcs-Browser'] = control["Vcs-Browser"]
     elif control.has_key("X-Vcs-Browser"):  
-        d['Vcs-Browser'] = quote(control["X-Vcs-Browser"])
+        d['Vcs-Browser'] = control["X-Vcs-Browser"]
     else:
-        d['Vcs-Browser'] = 'NULL'
+        d['Vcs-Browser'] = None
     
     for k in control.keys():
       if k not in sources_gatherer.mandatory and k not in sources_gatherer.non_mandatory and k not in sources_gatherer.ignorable:
@@ -90,8 +93,8 @@
 	  %(Section)s, %(Vcs-Type)s, %(Vcs-Url)s, %(Vcs-Browser)s,
 	  %(Python-Version)s, %(Checksums-Sha1)s, %(Checksums-Sha256)s,
 	  %(Original-Maintainer)s, %(Dm-Upload-Allowed)s)
-	  """  % d
-      cur.execute(query)
+	  """ 
+      cur.execute(query, d)
 
   def run(self, source):
     if not source in self.config:




More information about the Collab-qa-commits mailing list