]> xenbits.xensource.com Git - people/larsk/xenproject-org-gitdm.git/commitdiff
Use csv package instead of manual CSV handling
authorGermán Póo-Caamaño <gpoo@gnome.org>
Thu, 23 Jun 2011 00:23:40 +0000 (17:23 -0700)
committerGermán Póo-Caamaño <gpoo@gnome.org>
Thu, 23 Jun 2011 02:27:19 +0000 (19:27 -0700)
Python provides a module to handle csv files which is named
csv.  Therefore, it is necessary to rename the csv.py to
avoid name conflicts when the module csv is used.

Signed-off-by: Germán Póo-Caamaño <gpoo@gnome.org>
csv.py [deleted file]
csvdump.py [new file with mode: 0644]
gitdm

diff --git a/csv.py b/csv.py
deleted file mode 100644 (file)
index cec1f06..0000000
--- a/csv.py
+++ /dev/null
@@ -1,40 +0,0 @@
-#
-# aggregate per-month statistics for people
-#
-import sys, datetime
-
-class CSVStat:
-    def __init__ (self, name, employer, date):
-        self.name = name
-        self.employer = employer
-        self.added = self.removed = 0
-        self.date = date
-    def accumulate (self, p):
-        self.added = self.added + p.added
-        self.removed = self.removed + p.removed
-
-PeriodCommitHash = { }
-
-def AccumulatePatch (p, Aggregate):
-    date = "%.2d-%.2d-01"%(p.date.year, p.date.month)
-    if (Aggregate == 'week'):
-        date = "%.2d-%.2d"%(p.date.isocalendar()[0], p.date.isocalendar()[1])
-    authdatekey = "%s-%s"%(p.author.name, date)
-    if authdatekey not in PeriodCommitHash:
-        empl = p.author.emailemployer (p.email, p.date)
-        stat = CSVStat (p.author.name, empl, date)
-        PeriodCommitHash[authdatekey] = stat
-    else:
-        stat = PeriodCommitHash[authdatekey]
-    stat.accumulate (p)
-
-def OutputCSV (file):
-    if file is None:
-        return
-    file.write ("Name\tAffliation\tDate\tAdded\tRemoved\n")
-    for date, stat in PeriodCommitHash.items():
-        # sanitise names " is common and \" sometimes too
-        empl_name = stat.employer.name.replace ("\"", ".").replace ("\\", ".")
-        author_name = stat.name.replace ("\"", ".").replace ("\\", ".")
-        file.write ("\"%s\"\t\"%s\"\t%s\t%d\t%d\n"%(author_name, empl_name, stat.date, \
-                                                    stat.added, stat.removed))
diff --git a/csvdump.py b/csvdump.py
new file mode 100644 (file)
index 0000000..4e81954
--- /dev/null
@@ -0,0 +1,46 @@
+#
+# aggregate per-month statistics for people
+#
+import sys, datetime
+import csv
+
+class CSVStat:
+    def __init__ (self, name, email, employer, date):
+        self.name = name
+        self.email = email
+        self.employer = employer
+        self.added = self.removed = 0
+        self.date = date
+    def accumulate (self, p):
+        self.added = self.added + p.added
+        self.removed = self.removed + p.removed
+
+PeriodCommitHash = { }
+
+def AccumulatePatch (p, Aggregate):
+    date = "%.2d-%.2d-01"%(p.date.year, p.date.month)
+    if (Aggregate == 'week'):
+        date = "%.2d-%.2d"%(p.date.isocalendar()[0], p.date.isocalendar()[1])
+    authdatekey = "%s-%s"%(p.author.name, date)
+    if authdatekey not in PeriodCommitHash:
+        empl = p.author.emailemployer (p.email, p.date)
+        stat = CSVStat (p.author.name, p.email, empl, date)
+        PeriodCommitHash[authdatekey] = stat
+    else:
+        stat = PeriodCommitHash[authdatekey]
+    stat.accumulate (p)
+
+def OutputCSV (file):
+    if file is None:
+        return
+    writer = csv.writer (file, quoting=csv.QUOTE_NONNUMERIC)
+    writer.writerow (['Name', 'Email', 'Affliation', 'Date',
+                      'Added', 'Removed'])
+    for date, stat in PeriodCommitHash.items():
+        # sanitise names " is common and \" sometimes too
+        empl_name = stat.employer.name.replace ('"', '.').replace ('\\', '.')
+        author_name = stat.name.replace ('"', '.').replace ('\\', '.')
+        writer.writerow ([author_name, stat.email, empl_name, stat.date,
+                          stat.added, stat.removed])
+
+__all__ = [ 'OutputCSV' ]
diff --git a/gitdm b/gitdm
index 8133c2286ec18e50256de11223cc9759cd2cbe74..84b4f5b1cf226e89e23b9d2f2b370c5ac60d4fd8 100755 (executable)
--- a/gitdm
+++ b/gitdm
@@ -11,7 +11,7 @@
 # Public License, version 2.
 
 
-import database, csv, ConfigFile, reports
+import database, csvdump, ConfigFile, reports
 import getopt, datetime
 import os, re, sys, rfc822, string
 from patterns import *
@@ -374,7 +374,7 @@ while (1):
         for hacker in p.reports:
             hacker.addreport (p)
     CSCount += 1
-    csv.AccumulatePatch (p, Aggregate)
+    csvdump.AccumulatePatch (p, Aggregate)
 print >> sys.stderr, 'Grabbing changesets...done       '
 
 if DumpDB:
@@ -403,9 +403,9 @@ if TotalChanged == 0:
 if DateStats:
     PrintDateStats ()
 
-csv.OutputCSV (CSVFile)
+csvdump.OutputCSV (CSVFile)
 if CSVFile is not None:
-        CSVFile.close ()
+    CSVFile.close ()
 
 if DevReports:
     reports.DevReports (hlist, TotalChanged, CSCount, TotalRemoved)