Log message for revision 114757: Warn on App.ImageFile.ImageFile deprecated assumption of software_home. Forward ported 114749 from 2.12 branch
Changed: U Zope/trunk/doc/CHANGES.rst U Zope/trunk/src/App/ImageFile.py U Zope/trunk/src/App/config.py A Zope/trunk/src/App/tests/testImageFile.py -=- Modified: Zope/trunk/doc/CHANGES.rst =================================================================== --- Zope/trunk/doc/CHANGES.rst 2010-07-14 15:19:05 UTC (rev 114756) +++ Zope/trunk/doc/CHANGES.rst 2010-07-14 15:46:50 UTC (rev 114757) @@ -36,6 +36,11 @@ Features Added ++++++++++++++ +- Warn when App.ImageFile.ImageFile receives a relative path with no prefix, + and then has to assume the path to be relative to "software home". This + behaviour is deprecated as packages can be factored out to their own + distribution, making the "software home" relative path meaningless. + - Updated packages: - ZODB3 = 3.10.0b2 Modified: Zope/trunk/src/App/ImageFile.py =================================================================== --- Zope/trunk/src/App/ImageFile.py 2010-07-14 15:19:05 UTC (rev 114756) +++ Zope/trunk/src/App/ImageFile.py 2010-07-14 15:46:50 UTC (rev 114757) @@ -18,6 +18,7 @@ import os.path import stat import time +import warnings from AccessControl.class_init import InitializeClass from AccessControl.SecurityInfo import ClassSecurityInfo @@ -34,6 +35,13 @@ os.path.join(os.path.dirname(Zope2.__file__), os.path.pardir) ) +NON_PREFIX_WARNING = ('Assuming image location to be present in the Zope2 ' + 'distribution. This is deprecated and might lead to ' + 'broken code if the directory in question is moved ' + 'to another distribution. Please provide either an ' + 'absolute file system path or a prefix. Support for ' + 'relative filenames without a prefix might be ' + 'dropped in a future Zope2 release.') class ImageFile(Explicit): """Image objects stored in external files.""" @@ -43,9 +51,12 @@ def __init__(self, path, _prefix=None): import Globals # for data if _prefix is None: - _prefix=getattr(getConfiguration(), 'softwarehome', PREFIX) + _prefix=getattr(getConfiguration(), 'softwarehome', None) or PREFIX + if not os.path.isabs(path): + warnings.warn(NON_PREFIX_WARNING, UserWarning, 2 ) elif type(_prefix) is not type(''): _prefix=package_home(_prefix) + # _prefix is ignored if path is absolute path = os.path.join(_prefix, path) self.path=path if Globals.DevelopmentMode: Modified: Zope/trunk/src/App/config.py =================================================================== --- Zope/trunk/src/App/config.py 2010-07-14 15:19:05 UTC (rev 114756) +++ Zope/trunk/src/App/config.py 2010-07-14 15:46:50 UTC (rev 114757) @@ -36,7 +36,7 @@ def setConfiguration(cfg): """Set the global configuration object. - Legacy sources of common configuraiton values are updated to + Legacy sources of common configuration values are updated to reflect the new configuration; this may be removed in some future version. """ Copied: Zope/trunk/src/App/tests/testImageFile.py (from rev 114749, Zope/branches/2.12/src/App/tests/testImageFile.py) =================================================================== --- Zope/trunk/src/App/tests/testImageFile.py (rev 0) +++ Zope/trunk/src/App/tests/testImageFile.py 2010-07-14 15:46:50 UTC (rev 114757) @@ -0,0 +1,45 @@ +import unittest +import os.path +import App +from Testing.ZopeTestCase.warnhook import WarningsHook + + +class TestImageFile(unittest.TestCase): + + def setUp(self): + # ugly: need to save the old App.config configuration value since + # ImageFile might read it and trigger setting it to the default value + self.oldcfg = App.config._config + self.warningshook = WarningsHook() + self.warningshook.install() + + def tearDown(self): + self.warningshook.uninstall() + # ugly: need to restore configuration, or lack thereof + App.config._config = self.oldcfg + + def test_warn_on_software_home_default(self): + App.ImageFile.ImageFile('App/www/zopelogo.jpg') + self.assertEquals(self.warningshook.warnings.pop()[0], + App.ImageFile.NON_PREFIX_WARNING) + + def test_no_warn_on_absolute_path(self): + path = os.path.join(os.path.dirname(App.__file__), + 'www','zopelogo.jpg') + App.ImageFile.ImageFile(path) + self.failIf(self.warningshook.warnings) + + def test_no_warn_on_path_as_prefix(self): + prefix = os.path.dirname(App.__file__) + App.ImageFile.ImageFile('www/zopelogo.jpg', prefix) + self.failIf(self.warningshook.warnings) + + def test_no_warn_on_namespace_as_prefix(self): + prefix = App.__dict__ # same as calling globals() inside the App module + App.ImageFile.ImageFile('www/zopelogo.jpg', prefix) + self.failIf(self.warningshook.warnings) + +def test_suite(): + return unittest.TestSuite(( + unittest.makeSuite(TestImageFile), + )) _______________________________________________ Zope-Checkins maillist - Zope-Checkins@zope.org https://mail.zope.org/mailman/listinfo/zope-checkins