Univention Bugzilla – Attachment 3896 Details for
Bug 24889
Unit-Test für logrotate-Konfigrations-Helper
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
Unit-Test
ucrLogrotate.py (text/plain), 4.40 KB, created by
Philipp Hahn
on 2011-11-25 10:49:31 CET
(
hide
)
Description:
Unit-Test
Filename:
MIME Type:
Creator:
Philipp Hahn
Created:
2011-11-25 10:49:31 CET
Size:
4.40 KB
patch
obsolete
>#!/usr/bin/python2.6 ># -*- coding: utf-8 -*- ># ># Univention Common Python Library ># ># Copyright 2010-2011 Univention GmbH ># ># http://www.univention.de/ ># ># All rights reserved. ># ># The source code of this program is made available ># under the terms of the GNU Affero General Public License version 3 ># (GNU AGPL V3) as published by the Free Software Foundation. ># ># Binary versions of this program provided by Univention to you as ># well as other copyrighted, protected or trademarked materials like ># Logos, graphics, fonts, specific documentations and configurations, ># cryptographic keys etc. are subject to a license agreement between ># you and Univention and not subject to the GNU AGPL V3. ># ># In the case you use this program under the terms of the GNU AGPL V3, ># the program is provided in the hope that it will be useful, ># but WITHOUT ANY WARRANTY; without even the implied warranty of ># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ># GNU Affero General Public License for more details. ># ># You should have received a copy of the GNU Affero General Public ># License with the Debian GNU/Linux or Univention distribution in file ># /usr/share/common-licenses/AGPL-3; if not, see ># <http://www.gnu.org/licenses/>. > >ALL = ['getLogrotateConfig'] > >def _getBoolDefault(varGlobal, varLocal, settings, configRegistry): > """ > Update dictionary 'settings'. > > 'varGlobal' and 'varLocal' name two boolean config-registry-entries from 'configRegistry'. > 'varGlobal' is used unless 'varLocal' overwrites the setting. > """ > configName = varGlobal.split("/")[-1] > if configRegistry.is_true(varGlobal, True): > settings[configName] = configName > if configRegistry.is_false(varLocal): > if settings.get(configName): del settings[configName] > if configRegistry.is_true(varLocal, False): > settings[configName] = configName > >def getLogrotateConfig(name, configRegistry): > """ > Return dictionary with logrotate settings. > > >>> from univention.config_registry import ConfigRegistry > >>> ucr = ConfigRegistry() > >>> ucr['logrotate/rotate'] = 'weekly' > >>> ucr['logrotate/rotate/count'] = '42' > >>> ucr['logrotate/size'] = '100k' > >>> ucr['logrotate/foo/size'] = '200k' > >>> ucr['logrotate/create'] = '0600 root root' > >>> ucr['logrotate/missingok'] = 'yes' > >>> ucr['logrotate/compress'] = 'yes' > >>> ucr['logrotate/notifempty'] = 'yes' > >>> ucr['logrotate/foo/notifempty'] = 'no' > >>> for l in sorted(getLogrotateConfig('foo', ucr).values()): print l > compress > create 0600 root root > missingok > rotate 42 > size 200k > weekly > """ > settings = {} > > for var in ["logrotate/", "logrotate/" + name + "/"]: > if configRegistry.get(var + "rotate"): > settings["rotate"] = configRegistry[var + "rotate"] > if configRegistry.get(var + "rotate/count"): > settings["rotate/count"] = "rotate " + configRegistry[var + "rotate/count"] > if configRegistry.get(var + "size"): > settings["size"] = "size " + configRegistry[var + "size"] > if configRegistry.get(var + "create"): > settings["create"] = "create " + configRegistry[var + "create"] > > _getBoolDefault("logrotate/missingok", "logrotate/" + name + "/missingok", settings, configRegistry) > _getBoolDefault("logrotate/compress", "logrotate/" + name + "/compress", settings, configRegistry) > _getBoolDefault("logrotate/notifempty", "logrotate/" + name + "/notifempty", settings, configRegistry) > > return settings > >def __test(s, varGlobal, varLocal): > """ > >>> __test({}, None, None) > {'a': 'a'} > >>> #__test({'a': 'x'}, None, None) # {'a': 'x'} > >>> __test({}, 0, None) > {} > >>> __test({}, 1, None) > {'a': 'a'} > >>> #__test({'a': 'x'}, 0, None) # {} > >>> __test({'a': 'x'}, 1, None) > {'a': 'a'} > >>> __test({}, None, 0, ) > {} > >>> __test({}, None, 1, ) > {'a': 'a'} > >>> __test({'a': 'x'}, None, 0, ) > {} > >>> __test({'a': 'x'}, None, 1, ) > {'a': 'a'} > >>> __test({}, 0, 0, ) > {} > >>> __test({}, 0, 1, ) > {'a': 'a'} > >>> __test({'a': 'x'}, 0, 0, ) > {} > >>> __test({'a': 'x'}, 0, 1, ) > {'a': 'a'} > >>> __test({}, 1, 0, ) > {} > >>> __test({}, 1, 1, ) > {'a': 'a'} > >>> __test({'a': 'x'}, 1, 0, ) > {} > >>> __test({'a': 'x'}, 1, 1, ) > {'a': 'a'} > """ > from univention.config_registry import ConfigRegistry > ucr = ConfigRegistry() > if varGlobal is not None: ucr['a'] = str(varGlobal) > if varLocal is not None: ucr['la'] = str(varLocal) > _getBoolDefault('a', 'la', s, ucr) > print s > >if __name__ == '__main__': > import doctest > doctest.testmod()
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 24889
: 3896