83
def _parseSVNEntries(self, entriesFile):
85
Given a readable file object which represents a .svn/entries
86
file, return the revision as a string. If the file cannot be
87
parsed, return the string "Unknown".
90
from xml.dom.minidom import parse
91
doc = parse(entriesFile).documentElement
92
for node in doc.childNodes:
93
if hasattr(node, 'getAttribute'):
94
rev = node.getAttribute('revision')
96
return rev.encode('ascii')
82
101
def _getSVNVersion(self):
103
Figure out the SVN revision number based on the existance of
104
twisted/.svn/entries, and its contents. This requires parsing the
105
entries file and reading the first XML tag in the xml document that has
106
a revision="" attribute.
108
@return: None or string containing SVN Revision number.
83
110
mod = sys.modules.get(self.package)
85
112
ent = os.path.join(os.path.dirname(mod.__file__),
88
115
if os.path.exists(ent):
89
from xml.dom.minidom import parse
90
doc = parse(file(ent)).documentElement
91
for node in doc.childNodes:
92
if hasattr(node, 'getAttribute'):
93
rev = node.getAttribute('revision')
95
return rev.encode('ascii')
116
return self._parseSVNEntries(open(ent))
97
119
def _formatSVNVersion(self):
98
120
ver = self._getSVNVersion()