# HG changeset patch # User Thierry Florac # Date 1341246713 -7200 # Node ID 3d92cfb6801b1881c97883cb884f22a327381336 # Parent 576f6b3c913ac7c49bfc37c78d34bb34eea2251b Added "container" utility module diff -r 576f6b3c913a -r 3d92cfb6801b src/ztfy/utils/container.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ztfy/utils/container.py Mon Jul 02 18:31:53 2012 +0200 @@ -0,0 +1,40 @@ +### -*- coding: utf-8 -*- #################################################### +############################################################################## +# +# Copyright (c) 2012 Thierry Florac +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# +############################################################################## + + +# import standard packages + +# import Zope3 interfaces + +# import local interfaces + +# import Zope3 packages + +# import local packages + + +def getContentName(container, base_name): + """Get a real name for a given base name and a container + + Target name will be suffixed with an index if base name already exists + """ + if base_name not in container: + return base_name + index = 2 + name = '%s-%02d' % (base_name, index) + while name in container: + index += 1 + name = '%s-%02d' % (base_name, index) + return name