~certify-web-dev/twisted/certify-trunk

« back to all changes in this revision

Viewing changes to twisted/python/versions.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-01-17 14:52:35 UTC
  • mfrom: (1.1.5 upstream) (2.1.2 etch)
  • Revision ID: james.westby@ubuntu.com-20070117145235-btmig6qfmqfen0om
Tags: 2.5.0-0ubuntu1
New upstream version, compatible with python2.5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
                    other.minor,
80
80
                    other.micro))
81
81
 
 
82
 
 
83
    def _parseSVNEntries(self, entriesFile):
 
84
        """
 
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".
 
88
        """
 
89
        try:
 
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')
 
95
                    if rev is not None:
 
96
                        return rev.encode('ascii')
 
97
        except:
 
98
            return "Unknown"
 
99
        
 
100
 
82
101
    def _getSVNVersion(self):
 
102
        """
 
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.
 
107
 
 
108
        @return: None or string containing SVN Revision number.
 
109
        """
83
110
        mod = sys.modules.get(self.package)
84
111
        if mod:
85
112
            ent = os.path.join(os.path.dirname(mod.__file__),
86
113
                               '.svn',
87
114
                               'entries')
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')
94
 
                        if rev is not None:
95
 
                            return rev.encode('ascii')
 
116
                return self._parseSVNEntries(open(ent))
 
117
 
96
118
 
97
119
    def _formatSVNVersion(self):
98
120
        ver = self._getSVNVersion()