Skip to content

Commit

Permalink
Merge pull request #96 from zopefoundation/maurits/pretty-print-last-…
Browse files Browse the repository at this point in the history
…version-for-profile

When logging an upgrade, print the version tuple joined by dots
  • Loading branch information
mauritsvanrees committed Sep 28, 2020
2 parents 87d65a2 + c6d1d74 commit 959d3cc
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changelog
2.0.3 (unreleased)
------------------

- When logging an upgrade, print the version tuple joined by dots.

- Renamed ``xml`` dir to ``xml_templates``.
This avoids an import warning on Python 2.7.

Expand Down
10 changes: 10 additions & 0 deletions Products/GenericSetup/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,16 @@ class Doh:
doh = Doh()
self.assertRaises(ValueError, _getDottedName, doh)

def test__version_for_print(self):
from ..utils import _version_for_print as vfp

self.assertEqual(vfp('1000'), '1000')
self.assertEqual(vfp(('1000',)), '1000')
self.assertEqual(vfp(('1', '2', '3')), '1.2.3')
self.assertEqual(vfp((42)), '42')
self.assertEqual(vfp(('unknown')), 'unknown')
self.assertEqual(vfp((None)), 'None')


class PropertyManagerHelpersTests(unittest.TestCase):

Expand Down
15 changes: 10 additions & 5 deletions Products/GenericSetup/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
from .utils import _computeTopologicalSort
from .utils import _getProductPath
from .utils import _resolveDottedName
from .utils import _version_for_print
from .utils import _wwwdir


Expand Down Expand Up @@ -1129,7 +1130,8 @@ def upgradeProfile(self, profile_id, dest=None):
dest = tuple(dest.split('.'))
if self.getLastVersionForProfile(profile_id) == dest:
generic_logger.warning('Profile %s is already at wanted '
'destination %r.', profile_id, dest)
'destination %r.', profile_id,
_version_for_print(dest))
return
upgrades = self.listUpgrades(profile_id)
# First get a list of single steps to apply. This may be
Expand All @@ -1153,8 +1155,9 @@ def upgradeProfile(self, profile_id, dest=None):
if dest is not None and not dest_found:
generic_logger.warning(
'No route found to destination version %r for profile %s. '
'Profile stays at current version, %r', dest, profile_id,
self.getLastVersionForProfile(profile_id))
'Profile stays at current version, %r',
_version_for_print(dest), profile_id,
_version_for_print(self.getLastVersionForProfile(profile_id)))
return
if to_apply:
for step in to_apply:
Expand All @@ -1165,12 +1168,14 @@ def upgradeProfile(self, profile_id, dest=None):
self.setLastVersionForProfile(profile_id, step.dest)
generic_logger.info(
'Profile %s upgraded to version %r.',
profile_id, self.getLastVersionForProfile(profile_id))
profile_id,
_version_for_print(
self.getLastVersionForProfile(profile_id)))
else:
generic_logger.info(
'No upgrades available for profile %s. '
'Profile stays at version %r.', profile_id,
self.getLastVersionForProfile(profile_id))
_version_for_print(self.getLastVersionForProfile(profile_id)))

#
# Helper methods
Expand Down
15 changes: 15 additions & 0 deletions Products/GenericSetup/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,21 @@ def _extractDocstring(func, default_title, default_description):
return title, description


def _version_for_print(version):
"""Return a version suitable for printing/logging.
Versions of profiles and destinations of upgrade steps
are likely tuples. We join them with dots.
Used internally when logging.
"""
if isinstance(version, six.string_types):
return version
if isinstance(version, tuple):
return ".".join(version)
return str(version)


##############################################################################
# WARNING: PLEASE DON'T USE THE CONFIGURATOR PATTERN. THE RELATED BASE CLASSES
# WILL BECOME DEPRECATED AS SOON AS GENERICSETUP ITSELF NO LONGER USES THEM.
Expand Down

0 comments on commit 959d3cc

Please sign in to comment.