Anonymous avatar Anonymous committed 5a4fb76

Add CSV output.

Comments (0)

Files changed (1)

 """
 Python interface to Ditz issue tracker (http://ditz.rubyforge.org).
 
+@todo: lazy reading of issues.
+
 @bug: write/read issue produces ditz error: Time/String comparison, due to
 Z being omitted from output.
 """
 
 import os
+import csv
 import yaml
 import glob
 
         path = os.path.join(self.issuedir, Project.filename)
         self.project = read_yaml(path)
 
+    def write_csv(self, path, *attrs):
+        """Write issues to CSV file."""
+
+        if not attrs:
+            attrs = Issue.attributes
+
+        fp = open(path, "w")
+        writer = csv.writer(fp)
+
+        writer.writerow([attr.capitalize() for attr in attrs])
+        for issue in sorted(self):
+            writer.writerow([getattr(issue, attr) for attr in attrs])
+
+        fp.close()
+
     def __iter__(self):
         """Iterate over all issues."""
 
 class Config(DitzObject):
     yaml_tag = DitzObject.ditz_tag + '/config'
     filename = ".ditz-config"
+    attributes = ["name", "email", "issue_dir"]
 
 class Project(DitzObject):
     yaml_tag = DitzObject.ditz_tag + '/project'
     filename = "project.yaml"
+    attributes = ["name", "version", "components", "releases"]
 
 class Component(DitzObject):
     yaml_tag = DitzObject.ditz_tag + '/component'
 
 class Release(DitzObject):
     yaml_tag = DitzObject.ditz_tag + '/release'
+    attributes = ["name", "status", "release_time", "log_events"]
+
+    def __str__(self):
+        return "%(name)s (%(release_time)s)" % self.__dict__
 
 class Issue(DitzObject):
     yaml_tag = DitzObject.ditz_tag + '/issue'
     template = "issue-%s.yaml"
+    attributes = ["title", "desc", "type", "component", "release",
+                  "status", "disposition"]
 
     @property
     def filename(self):
         return self.template % self.id
 
+    def __cmp__(self, other):
+        return (cmp(self.status, other.status) or
+                cmp(self.type, other.type) or
+                cmp(self.title, other.title) or
+                0)
+
+    def __str__(self):
+        return "%(title)s (%(type)s)" % self.__dict__
+
 def read_yaml(path):
     """Read YAML data from a file."""
     return yaml.safe_load(open(path))
     print
     print "Releases:"
     for release in ditz.project.releases:
-        date = release.release_time 
-        print "   %s [%s]" % (release.name, date if date else "unreleased")
+        print "   ", release
 
     print
     print "Issues:"
-    for issue in ditz:
-        print "   %s [%s]" % (issue.title, issue.type[1:])
+    for issue in sorted(ditz):
+        print "   ", issue
+
+    #ditz.write_csv("issues.csv", "title", "desc", "type", "release", "status")
     
-    issue.write(".")
-
 if __name__ == "__main__":
     _test()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.