[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/applicationcontrol/
ZopeVersion utility now use xml.dom.minidom to parse .svn/entries
Dmitry Vasiliev
dima at hlabs.spb.ru
Thu Jan 26 09:57:19 EST 2006
Log message for revision 41452:
ZopeVersion utility now use xml.dom.minidom to parse .svn/entries
Changed:
U Zope3/trunk/src/zope/app/applicationcontrol/tests/test_zopeversion.py
U Zope3/trunk/src/zope/app/applicationcontrol/zopeversion.py
-=-
Modified: Zope3/trunk/src/zope/app/applicationcontrol/tests/test_zopeversion.py
===================================================================
--- Zope3/trunk/src/zope/app/applicationcontrol/tests/test_zopeversion.py 2006-01-26 11:47:52 UTC (rev 41451)
+++ Zope3/trunk/src/zope/app/applicationcontrol/tests/test_zopeversion.py 2006-01-26 14:57:18 UTC (rev 41452)
@@ -19,11 +19,13 @@
import shutil
import tempfile
import unittest
+from xml.sax.saxutils import quoteattr
from zope.interface.verify import verifyObject
from zope.app.applicationcontrol.interfaces import IZopeVersion
from zope.app.applicationcontrol.zopeversion import ZopeVersion
+
class Test(unittest.TestCase):
def setUp(self):
@@ -32,19 +34,27 @@
def tearDown(self):
shutil.rmtree(self.tmpdir)
- def prepare(self, version, tag):
+ def prepare(self, version, fields):
if version:
f = open(os.path.join(self.tmpdir, "version.txt"), "w")
f.write(version)
if not version.endswith("\n"):
f.write("\n")
f.close()
- if tag:
+ if fields:
os.mkdir(os.path.join(self.tmpdir, ".svn"))
f = open(os.path.join(self.tmpdir, ".svn", "entries"), "w")
- f.write(tag)
- if not tag.endswith("\n"):
- f.write("\n")
+ fields = ["%s=%s" % (key, quoteattr(val))
+ for key, val in fields.items()]
+ text = ('<?xml version="1.0" encoding="utf-8"?>\n'
+ '<wc-entries\n'
+ ' xmlns="svn:">\n'
+ '<entry\n'
+ ' name=""\n'
+ ' kind="dir"\n'
+ ' %s/>\n'
+ '</wc-entries>\n' % "\n ".join(fields))
+ f.write(text)
f.close()
def _Test__new(self):
@@ -63,34 +73,34 @@
self.assertEqual(zope_version.getZopeVersion(), "Development/Unknown")
def test_ZopeVersion_svntrunk(self):
- self.prepare(None, """
- url="svn+ssh://svn.zope.org/repos/main/Zope3/trunk/src/zope"
- revision="10000"
- """)
+ self.prepare(None, {
+ "url": "svn+ssh://svn.zope.org/repos/main/Zope3/trunk/src/zope",
+ "revision": "10000"
+ })
zope_version = self._Test__new()
self.assertEqual(zope_version.getZopeVersion(),
"Development/Revision: 10000")
def test_ZopeVersion_svnbranch(self):
- self.prepare(None, """
- url="svn+ssh://svn.zope.org/repos/main/Zope3/branches/Zope3-1.0/src/zope"
- revision="10000"
- """)
+ self.prepare(None, {
+ "url": "svn+ssh://svn.zope.org/repos/main/Zope3/branches/Zope3-1.0/src/zope",
+ "revision": "10000"
+ })
zope_version = self._Test__new()
self.assertEqual(zope_version.getZopeVersion(),
"Development/Revision: 10000/Branch: Zope3-1.0")
def test_ZopeVersion_svntag(self):
- self.prepare(None, """
- url="svn+ssh://svn.zope.org/repos/main/Zope3/tags/Zope3-1.0/src/zope"
- revision="10000"
- """)
+ self.prepare(None, {
+ "url": "svn+ssh://svn.zope.org/repos/main/Zope3/tags/Zope3-1.0/src/zope",
+ "revision": "10000"
+ })
zope_version = self._Test__new()
self.assertEqual(zope_version.getZopeVersion(),
"Development/Revision: 10000/Tag: Zope3-1.0")
def test_ZopeVersion_svn_unknown(self):
- self.prepare(None, "")
+ self.prepare(None, {"uuid": ""})
zope_version = self._Test__new()
self.assertEqual(zope_version.getZopeVersion(), "Development/Unknown")
@@ -108,10 +118,10 @@
def test_ZopeVersion_release_svntrunk(self):
# demonstrate that the version.txt data is discarded if
# there's revision-control metadata:
- self.prepare("Zope 3 1.0.0", """
- url="svn+ssh://svn.zope.org/repos/main/Zope3/trunk/src/zope"
- revision="10000"
- """)
+ self.prepare("Zope 3 1.0.0", {
+ "url": "svn+ssh://svn.zope.org/repos/main/Zope3/trunk/src/zope",
+ "revision": "10000"
+ })
zope_version = self._Test__new()
self.assertEqual(zope_version.getZopeVersion(),
"Development/Revision: 10000")
Modified: Zope3/trunk/src/zope/app/applicationcontrol/zopeversion.py
===================================================================
--- Zope3/trunk/src/zope/app/applicationcontrol/zopeversion.py 2006-01-26 11:47:52 UTC (rev 41451)
+++ Zope3/trunk/src/zope/app/applicationcontrol/zopeversion.py 2006-01-26 14:57:18 UTC (rev 41452)
@@ -19,15 +19,17 @@
import os
import re
+from xml.dom.minidom import parse
import zope.app
from zope.app.applicationcontrol.interfaces import IZopeVersion
from zope.interface import implements
+
class ZopeVersion(object):
+
implements(IZopeVersion)
- __entries = re.compile(r'(url|revision)\s*=\s*"([^"]+)"')
__tags = re.compile(r'/(tags|branches)/([^/]+)/')
def __init__(self, path=None):
@@ -52,8 +54,10 @@
versionfile = os.path.join(self.path, "version.txt")
if os.path.isfile(versionfile):
f = file(versionfile)
- self.result = f.readline().strip() or self.result
- f.close()
+ try:
+ self.result = f.readline().strip() or self.result
+ finally:
+ f.close()
return self.result
def __setSVNVersion(self, svndir):
@@ -61,30 +65,23 @@
# get the version information
if os.path.isfile(entriesfile):
- f = file(entriesfile)
- url, revision = "", ""
- for line in f:
- match = self.__entries.search(line)
- if match is not None:
- name, value = match.group(1, 2)
- if name == "url":
- url = value
- elif name == "revision":
- revision = value
- if url and revision:
- break
- f.close()
+ doc = parse(entriesfile)
+ here = doc.getElementsByTagNameNS("svn:", "entry").item(0)
+ if here:
+ url = here.getAttribute("url")
+ revision = here.getAttribute("revision")
- if revision and url:
- match = self.__tags.search(url)
- tag = ""
- if match is not None:
- type, value = match.group(1, 2)
- if type == "tags":
- tag = "/Tag: %s" % value
- elif type == "branches":
- tag = "/Branch: %s" % value
- self.result = "Development/Revision: %s%s" \
- % (revision, tag)
+ if revision and url:
+ match = self.__tags.search(url)
+ if match is None:
+ tag = ""
+ else:
+ type, value = match.groups()
+ if type == "tags":
+ tag = "/Tag: %s" % value
+ elif type == "branches":
+ tag = "/Branch: %s" % value
+ self.result = ("Development/Revision: %s%s"
+ % (revision, tag))
ZopeVersionUtility = ZopeVersion()
More information about the Zope3-Checkins
mailing list