SVN: toys/cvsstats/email2sql.py

pawelz pawelz at pld-linux.org
Sun Feb 28 16:17:45 CET 2010


Author: pawelz
Date: Sun Feb 28 16:17:45 2010
New Revision: 11220

Modified:
   toys/cvsstats/email2sql.py
Log:
- dbg function
- debug no longer breaks SQL


Modified: toys/cvsstats/email2sql.py
==============================================================================
--- toys/cvsstats/email2sql.py	(original)
+++ toys/cvsstats/email2sql.py	Sun Feb 28 16:17:45 2010
@@ -11,13 +11,22 @@
 #  0 - no debug
 #  1 - print filenames
 #  2 - print some extra crap
-#  3 - print decoded message bodys (warning: it won't produce valid SQL
-#      script)
+#  3 - print decoded message bodys
 #
 # set it using -d flag. For example to set debug = 2 use:
 #  ./email2sql -d -d file
 debug = 0
 
+def dbg(level, msg):
+  """Prints debug messages.
+
+  Note, we don't want to use stderr, we want debug messages in generated SQL
+  code"""
+
+  if level <= debug:
+    for l in msg.splitlines():
+      print "-- %s" % l
+
 rmsg = re.compile(
   "^Author: (?P<author>\S+)\s+Date: (?P<date>.*)\n"
   "Module: (?P<module>\S+)\s+Tag: (?P<tag>.*)\n"
@@ -57,10 +66,7 @@
     if (not p):
       p = str(msg)
 
-    if (debug >= 3):
-      print "{{{"
-      print p
-      print "}}}"
+    dbg(3, "{{{\n" + p + "\n}}}")
 
     m = rmsg.search(p)
     if m:
@@ -152,8 +158,7 @@
     if f[0] == "-":
       continue
     try:
-      if debug >= 1:
-        print "-- %s" % f
+      dbg(1, f)
       c = commit(f)
       c.files_sql()
       c.commit_sql()


More information about the pld-cvs-commit mailing list