[Zope3-checkins] SVN: Zope3/branches/3.2/ Fixed issue 730:
Subversion 1.4 breaks mkzopeinstance.py
Dmitry Vasiliev
dima at hlabs.spb.ru
Thu Nov 9 07:18:09 EST 2006
Log message for revision 71100:
Fixed issue 730: Subversion 1.4 breaks mkzopeinstance.py
Merged revision 70397 from the trunk
Changed:
U Zope3/branches/3.2/doc/CHANGES.txt
U Zope3/branches/3.2/src/zope/app/applicationcontrol/tests/test_zopeversion.py
U Zope3/branches/3.2/src/zope/app/applicationcontrol/zopeversion.py
-=-
Modified: Zope3/branches/3.2/doc/CHANGES.txt
===================================================================
--- Zope3/branches/3.2/doc/CHANGES.txt 2006-11-09 11:39:48 UTC (rev 71099)
+++ Zope3/branches/3.2/doc/CHANGES.txt 2006-11-09 12:18:08 UTC (rev 71100)
@@ -10,6 +10,8 @@
Bug fixes
+ - Fixed issue 730: Subversion 1.4 breaks mkzopeinstance.py
+
- Fixed encoding of newlines, carriage returns, and tabs when
encoding attributes for widgets so we're consistent under all
Python 2.4.x versions (including 2.4.4, which failed tests before).
Modified: Zope3/branches/3.2/src/zope/app/applicationcontrol/tests/test_zopeversion.py
===================================================================
--- Zope3/branches/3.2/src/zope/app/applicationcontrol/tests/test_zopeversion.py 2006-11-09 11:39:48 UTC (rev 71099)
+++ Zope3/branches/3.2/src/zope/app/applicationcontrol/tests/test_zopeversion.py 2006-11-09 12:18:08 UTC (rev 71100)
@@ -24,97 +24,93 @@
from zope.app.applicationcontrol.interfaces import IZopeVersion
from zope.app.applicationcontrol.zopeversion import ZopeVersion
+
+class MockZopeVersion(ZopeVersion):
+
+ def setSVNInfoOutput(self, lines):
+ self.__lines = lines
+
+ def _getSVNInfoOutput(self):
+ return self.__lines
+
class Test(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp(prefix="test-zopeversion-")
+ self.zopeVersion = MockZopeVersion(self.tmpdir)
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:
+ try:
+ f.write(version)
+ if not version.endswith("\n"):
+ f.write("\n")
+ finally:
+ f.close()
+ 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")
- f.close()
+ self.zopeVersion.setSVNInfoOutput(fields)
- def _Test__new(self):
- return ZopeVersion(self.tmpdir)
-
def test_IVerify(self):
- verifyObject(IZopeVersion, self._Test__new())
+ verifyObject(IZopeVersion, self.zopeVersion)
- # In .svn/entries we check only two attributes:
- # 'url' - repository path
- # 'revision' - checked out revision number
-
def test_ZopeVersion(self):
self.prepare(None, None)
- zope_version = self._Test__new()
- self.assertEqual(zope_version.getZopeVersion(), "Development/Unknown")
+ self.assertEqual(self.zopeVersion.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"
- """)
- zope_version = self._Test__new()
- self.assertEqual(zope_version.getZopeVersion(),
- "Development/Revision: 10000")
+ self.prepare(None, [
+ "URL: svn+ssh://svn.zope.org/repos/main/Zope3/trunk/src/zope",
+ "Revision: 10000"
+ ])
+ self.assertEqual(self.zopeVersion.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"
- """)
- zope_version = self._Test__new()
- self.assertEqual(zope_version.getZopeVersion(),
- "Development/Revision: 10000/Branch: Zope3-1.0")
+ self.prepare(None, [
+ "URL: svn+ssh://svn.zope.org/repos/main/Zope3/branches/Zope3-1.0/src/zope",
+ "Revision: 10000"
+ ])
+ self.assertEqual(self.zopeVersion.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"
- """)
- zope_version = self._Test__new()
- self.assertEqual(zope_version.getZopeVersion(),
- "Development/Revision: 10000/Tag: Zope3-1.0")
+ self.prepare(None, [
+ "URL: svn+ssh://svn.zope.org/repos/main/Zope3/tags/Zope3-1.0/src/zope",
+ "Revision: 10000"
+ ])
+ self.assertEqual(self.zopeVersion.getZopeVersion(),
+ "Development/Revision: 10000/Tag: Zope3-1.0")
def test_ZopeVersion_svn_unknown(self):
- self.prepare(None, "")
- zope_version = self._Test__new()
- self.assertEqual(zope_version.getZopeVersion(), "Development/Unknown")
+ self.prepare(None, ["Nope: "])
+ self.assertEqual(self.zopeVersion.getZopeVersion(),
+ "Development/Unknown")
def test_ZopeVersion_release(self):
self.prepare("Zope 3 1.0.0", None)
- zope_version = self._Test__new()
- self.assertEqual(zope_version.getZopeVersion(),
- "Zope 3 1.0.0")
+ self.assertEqual(self.zopeVersion.getZopeVersion(),
+ "Zope 3 1.0.0")
def test_ZopeVersion_release_empty(self):
self.prepare(" ", None)
- zope_version = self._Test__new()
- self.assertEqual(zope_version.getZopeVersion(), "Development/Unknown")
+ self.assertEqual(self.zopeVersion.getZopeVersion(),
+ "Development/Unknown")
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"
- """)
- zope_version = self._Test__new()
- self.assertEqual(zope_version.getZopeVersion(),
- "Development/Revision: 10000")
+ self.prepare("Zope 3 1.0.0", [
+ "URL: svn+ssh://svn.zope.org/repos/main/Zope3/trunk/src/zope",
+ "Revision: 10000"
+ ])
+ self.assertEqual(self.zopeVersion.getZopeVersion(),
+ "Development/Revision: 10000")
def test_suite():
Modified: Zope3/branches/3.2/src/zope/app/applicationcontrol/zopeversion.py
===================================================================
--- Zope3/branches/3.2/src/zope/app/applicationcontrol/zopeversion.py 2006-11-09 11:39:48 UTC (rev 71099)
+++ Zope3/branches/3.2/src/zope/app/applicationcontrol/zopeversion.py 2006-11-09 12:18:08 UTC (rev 71100)
@@ -19,15 +19,17 @@
import os
import re
+import subprocess
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,39 +54,49 @@
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 _getSVNInfoOutput(self):
+ try:
+ proc = subprocess.Popen('svn info "%s"' % self.path,
+ shell=True, stdout=subprocess.PIPE)
+ except OSError:
+ pass
+ else:
+ if proc.wait() == 0:
+ return proc.stdout
+ return None
+
def __setSVNVersion(self, svndir):
- entriesfile = os.path.join(svndir, "entries")
+ output = self._getSVNInfoOutput()
+ if not output:
+ return
- # 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()
+ info = {}
+ for line in output:
+ parts = line.rstrip().split(": ", 1)
+ if len(parts) == 2:
+ key, value = parts
+ info[key] = value
- 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)
+ revision = info.get("Revision", "")
+ url = info.get("URL", "")
+ 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