Commits

Henrique Romano committed eca5c0c

Implement a method get_revision

  • Participants
  • Parent commits 82eff3e

Comments (0)

Files changed (1)

File djangotriager/wc/subversion.py

         "missing" : "deleted",
     }
 
+    def __init__(self, dir):
+        super(Subversion, self).__init__(dir)
+        self._curr_rev = None
+
     def get_changes_from_xml(self, xml):
         result = {
             "modified" : [],
                 raise ValueError("File %s with unexpected status %s" % (path, status))
         return result
 
+    def get_revision_from_xml(self, xml):
+        doc = parseString(xml).documentElement
+        entries = doc.getElementsByTagName("entry")
+        if len(entries) == 1:
+            entry = entries[0]
+            if entry.attributes.has_key(u"revision"):
+                return entry.attributes[u'revision'].value
+
     def update(self):
         proc = Popen(["svn", "up"], cwd=self.dir, stdout=PIPE, stderr=PIPE)
         proc.communicate()
+        self._curr_rev = None
+
+    def get_revision(self):
+        if self._curr_rev is not None:
+            return self._curr_rev
+        proc = Popen(["svn", "info", "--xml"], cwd=self.dir, stdout=PIPE, stderr=PIPE)
+        stdout, stderr = proc.communicate()
+        if proc.returncode != 0:
+            raise ValueError("Status returned code %s" % proc.returncode)
+        self._curr_rev = self.get_revision_from_xml(stdout)
+        return self._curr_rev
 
     def get_changes(self):
         proc = Popen(["svn", "status", "--xml"], cwd=self.dir, stdout=PIPE, stderr=PIPE)