[cedar-backup-svn] SF.net SVN: cedar-backup:[952] cedar-backup2/trunk
Brought to you by:
pronovic
|
From: <pro...@us...> - 2010-01-10 20:12:01
|
Revision: 952
http://cedar-backup.svn.sourceforge.net/cedar-backup/?rev=952&view=rev
Author: pronovic
Date: 2010-01-10 20:11:53 +0000 (Sun, 10 Jan 2010)
Log Message:
-----------
Add support for customization, so Debian can use wodim and genisoimage
Modified Paths:
--------------
cedar-backup2/trunk/CREDITS
cedar-backup2/trunk/CedarBackup2/cli.py
cedar-backup2/trunk/CedarBackup2/config.py
cedar-backup2/trunk/CedarBackup2/release.py
cedar-backup2/trunk/Changelog
cedar-backup2/trunk/test/configtests.py
cedar-backup2/trunk/util/test.py
Added Paths:
-----------
cedar-backup2/trunk/CedarBackup2/customize.py
cedar-backup2/trunk/test/customizetests.py
Modified: cedar-backup2/trunk/CREDITS
===================================================================
--- cedar-backup2/trunk/CREDITS 2009-08-16 20:37:19 UTC (rev 951)
+++ cedar-backup2/trunk/CREDITS 2010-01-10 20:11:53 UTC (rev 952)
@@ -23,7 +23,7 @@
software, as indicated in the source code itself.
Unless otherwise indicated, all Cedar Backup source code is Copyright
-(c) 2004-2009 Kenneth J. Pronovici and is released under the GNU General
+(c) 2004-2010 Kenneth J. Pronovici and is released under the GNU General
Public License. The contents of the GNU General Public License can be
found in the LICENSE file, or can be downloaded from http://www.gnu.org/.
Modified: cedar-backup2/trunk/CedarBackup2/cli.py
===================================================================
--- cedar-backup2/trunk/CedarBackup2/cli.py 2009-08-16 20:37:19 UTC (rev 951)
+++ cedar-backup2/trunk/CedarBackup2/cli.py 2010-01-10 20:11:53 UTC (rev 952)
@@ -8,7 +8,7 @@
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
-# Copyright (c) 2004-2007 Kenneth J. Pronovici.
+# Copyright (c) 2004-2007,2010 Kenneth J. Pronovici.
# All rights reserved.
#
# This program is free software; you can redistribute it and/or
@@ -87,6 +87,7 @@
# Cedar Backup modules
from CedarBackup2.release import AUTHOR, EMAIL, VERSION, DATE, COPYRIGHT
+from CedarBackup2.customize import customizeOverrides
from CedarBackup2.util import RestrictedContentList, DirectedGraph, PathResolverSingleton
from CedarBackup2.util import sortDict, splitCommandLine, executeCommand, getFunctionReference
from CedarBackup2.util import getUidGid, encodePath, Diagnostics
@@ -243,6 +244,7 @@
try:
logger.info("Configuration path is [%s]" % configPath)
config = Config(xmlPath=configPath)
+ customizeOverrides(config)
setupPathResolver(config)
actionSet = _ActionSet(options.actions, config.extensions, config.options,
config.peers, executeManaged, executeLocal)
Modified: cedar-backup2/trunk/CedarBackup2/config.py
===================================================================
--- cedar-backup2/trunk/CedarBackup2/config.py 2009-08-16 20:37:19 UTC (rev 951)
+++ cedar-backup2/trunk/CedarBackup2/config.py 2010-01-10 20:11:53 UTC (rev 952)
@@ -8,7 +8,7 @@
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
-# Copyright (c) 2004-2008 Kenneth J. Pronovici.
+# Copyright (c) 2004-2008,2010 Kenneth J. Pronovici.
# All rights reserved.
#
# This program is free software; you can redistribute it and/or
@@ -2622,6 +2622,35 @@
return 1
return 0
+ def addOverride(self, command, absolutePath):
+ """
+ If no override currently exists for the command, add one.
+ @param command: Name of command to be overridden.
+ @param absolutePath: Absolute path of the overrridden command.
+ """
+ exists = False
+ for object in self.overrides:
+ if object.command == command:
+ exists = True
+ break
+ if not exists:
+ self.overrides.append(CommandOverride(command, absolutePath))
+
+ def replaceOverride(self, command, absolutePath):
+ """
+ If override currently exists for the command, replace it; otherwise add it.
+ @param command: Name of command to be overridden.
+ @param absolutePath: Absolute path of the overrridden command.
+ """
+ exists = False
+ for object in self.overrides:
+ if object.command == command:
+ exists = True
+ object.absolutePath = absolutePath
+ break
+ if not exists:
+ self.overrides.append(CommandOverride(command, absolutePath))
+
def _setStartingDay(self, value):
"""
Property target used to set the starting day.
Added: cedar-backup2/trunk/CedarBackup2/customize.py
===================================================================
--- cedar-backup2/trunk/CedarBackup2/customize.py (rev 0)
+++ cedar-backup2/trunk/CedarBackup2/customize.py 2010-01-10 20:11:53 UTC (rev 952)
@@ -0,0 +1,97 @@
+# -*- coding: iso-8859-1 -*-
+# vim: set ft=python ts=3 sw=3 expandtab:
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+#
+# C E D A R
+# S O L U T I O N S "Software done right."
+# S O F T W A R E
+#
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+#
+# Copyright (c) 2010 Kenneth J. Pronovici.
+# All rights reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License,
+# Version 2, as published by the Free Software Foundation.
+#
+# This program is distributed 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.
+#
+# Copies of the GNU General Public License are available from
+# the Free Software Foundation website, http://www.gnu.org/.
+#
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+#
+# Author : Kenneth J. Pronovici <pro...@ie...>
+# Language : Python (>= 2.3)
+# Project : Cedar Backup, release 2
+# Revision : $Id$
+# Purpose : Implements customized behavior.
+#
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+
+########################################################################
+# Module documentation
+########################################################################
+
+"""
+Implements customized behavior.
+
+Some behaviors need to vary when packaged for certain platforms. For instance,
+while Cedar Backup generally uses cdrecord and mkisofs, Debian ships compatible
+utilities called wodim and genisoimage. I want there to be one single place
+where Cedar Backup is patched for Debian, rather than having to maintain a
+variety of patches in different places.
+
+@author: Kenneth J. Pronovici <pro...@ie...>
+"""
+
+########################################################################
+# Imported modules
+########################################################################
+
+# System modules
+import logging
+
+
+########################################################################
+# Module-wide constants and variables
+########################################################################
+
+logger = logging.getLogger("CedarBackup2.log.customize")
+
+PLATFORM = "standard"
+#PLATFORM = "debian"
+
+DEBIAN_CDRECORD = "/usr/bin/wodim"
+DEBIAN_MKISOFS = "/usr/bin/genisoimage"
+
+
+#######################################################################
+# Public functions
+#######################################################################
+
+################################
+# customizeOverrides() function
+################################
+
+def customizeOverrides(config, platform=PLATFORM):
+ """
+ Modify command overrides based on the configured platform.
+
+ On some platforms, we want to add command overrides to configuration. Each
+ override will only be added if the configuration does not already contain an
+ override with the same name. That way, the user still has a way to choose
+ their own version of the command if they want.
+
+ @param config: Configuration to modify
+ @param platform: Platform that is in use
+ """
+ if platform == "debian":
+ logger.info("Overriding cdrecord for Debian platform: %s" % DEBIAN_CDRECORD)
+ config.options.addOverride("cdrecord", DEBIAN_CDRECORD)
+ logger.info("Overriding mkisofs for Debian platform: %s" % DEBIAN_MKISOFS)
+ config.options.addOverride("mkisofs", DEBIAN_MKISOFS)
+
Property changes on: cedar-backup2/trunk/CedarBackup2/customize.py
___________________________________________________________________
Added: svn:keywords
+ Id
Modified: cedar-backup2/trunk/CedarBackup2/release.py
===================================================================
--- cedar-backup2/trunk/CedarBackup2/release.py 2009-08-16 20:37:19 UTC (rev 951)
+++ cedar-backup2/trunk/CedarBackup2/release.py 2010-01-10 20:11:53 UTC (rev 952)
@@ -33,8 +33,8 @@
AUTHOR = "Kenneth J. Pronovici"
EMAIL = "pro...@ie..."
-COPYRIGHT = "2004-2009"
-VERSION = "2.19.4"
-DATE = "16 Aug 2009"
+COPYRIGHT = "2004-2010"
+VERSION = "2.19.5"
+DATE = "unreleased"
URL = "http://cedar-backup.sourceforge.net/"
Modified: cedar-backup2/trunk/Changelog
===================================================================
--- cedar-backup2/trunk/Changelog 2009-08-16 20:37:19 UTC (rev 951)
+++ cedar-backup2/trunk/Changelog 2010-01-10 20:11:53 UTC (rev 952)
@@ -1,3 +1,7 @@
+Version 2.19.5 unreleased
+
+ * Add customization support, so Debian can use wodim and genisoimage.
+
Version 2.19.4 16 Aug 2009
* Add support for the Python 2.6 interpreter.
Modified: cedar-backup2/trunk/test/configtests.py
===================================================================
--- cedar-backup2/trunk/test/configtests.py 2009-08-16 20:37:19 UTC (rev 951)
+++ cedar-backup2/trunk/test/configtests.py 2010-01-10 20:11:53 UTC (rev 952)
@@ -9,7 +9,7 @@
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
-# Copyright (c) 2004-2008 Kenneth J. Pronovici.
+# Copyright (c) 2004-2008,2010 Kenneth J. Pronovici.
# All rights reserved.
#
# This program is free software; you can redistribute it and/or
@@ -6031,6 +6031,66 @@
self.failUnless(options1 != options2)
+ ####################################
+ # Test add and replace of overrides
+ ####################################
+
+ def testOverrides_001(self):
+ """
+ Test addOverride() with no existing overrides.
+ """
+ options = OptionsConfig();
+ options.overrides = []
+ options.addOverride("cdrecord", "/usr/bin/wodim")
+ self.failUnlessEqual([ CommandOverride("cdrecord", "/usr/bin/wodim"), ], options.overrides);
+
+ def testOverrides_002(self):
+ """
+ Test addOverride() with no existing override that matches.
+ """
+ options = OptionsConfig();
+ options.overrides = [ CommandOverride("one", "/one"), ]
+ options.addOverride("cdrecord", "/usr/bin/wodim")
+ self.failUnlessEqual([ CommandOverride("one", "/one"), CommandOverride("cdrecord", "/usr/bin/wodim"), ], options.overrides);
+
+ def testOverrides_003(self):
+ """
+ Test addOverride(), with existing override that matches.
+ """
+ options = OptionsConfig();
+ options.overrides = [ CommandOverride("cdrecord", "/one"), ]
+ options.addOverride("cdrecord", "/usr/bin/wodim")
+ self.failUnlessEqual([ CommandOverride("cdrecord", "/one"), ], options.overrides);
+
+ def testOverrides_004(self):
+ """
+ Test replaceOverride() with no existing overrides.
+ """
+ options = OptionsConfig();
+ options.overrides = []
+ options.replaceOverride("cdrecord", "/usr/bin/wodim")
+ self.failUnlessEqual([ CommandOverride("cdrecord", "/usr/bin/wodim"), ], options.overrides);
+
+ def testOverrides_005(self):
+ """
+ Test replaceOverride() with no existing override that matches.
+ """
+ options = OptionsConfig();
+ options.overrides = [ CommandOverride("one", "/one"), ]
+ options.replaceOverride("cdrecord", "/usr/bin/wodim")
+ self.failUnlessEqual([ CommandOverride("one", "/one"), CommandOverride("cdrecord", "/usr/bin/wodim"), ], options.overrides);
+
+ def testOverrides_006(self):
+ """
+ Test replaceOverride(), with existing override that matches.
+ """
+ options = OptionsConfig();
+ options.overrides = [ CommandOverride("cdrecord", "/one"), ]
+ options.replaceOverride("cdrecord", "/usr/bin/wodim")
+ self.failUnlessEqual([ CommandOverride("cdrecord", "/usr/bin/wodim"), ], options.overrides);
+
+
+
########################
# TestPeersConfig class
########################
Added: cedar-backup2/trunk/test/customizetests.py
===================================================================
--- cedar-backup2/trunk/test/customizetests.py (rev 0)
+++ cedar-backup2/trunk/test/customizetests.py 2010-01-10 20:11:53 UTC (rev 952)
@@ -0,0 +1,193 @@
+#!/usr/bin/env python
+# -*- coding: iso-8859-1 -*-
+# vim: set ft=python ts=3 sw=3 expandtab:
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+#
+# C E D A R
+# S O L U T I O N S "Software done right."
+# S O F T W A R E
+#
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+#
+# Copyright (c) 2010 Kenneth J. Pronovici.
+# All rights reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License,
+# Version 2, as published by the Free Software Foundation.
+#
+# This program is distributed 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.
+#
+# Copies of the GNU General Public License are available from
+# the Free Software Foundation website, http://www.gnu.org/.
+#
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+#
+# Author : Kenneth J. Pronovici <pro...@ie...>
+# Language : Python (>= 2.3)
+# Project : Cedar Backup, release 2
+# Revision : $Id$
+# Purpose : Tests customization functionality.
+#
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+
+########################################################################
+# Module documentation
+########################################################################
+
+"""
+Unit tests for CedarBackup2/customize.py.
+@author Kenneth J. Pronovici <pro...@ie...>
+"""
+
+
+########################################################################
+# Import modules and do runtime validations
+########################################################################
+
+import unittest
+
+from CedarBackup2.customize import customizeOverrides
+from CedarBackup2.config import Config, OptionsConfig, CommandOverride
+
+
+
+#######################################################################
+# Test Case Classes
+#######################################################################
+
+######################
+# TestFunctions class
+######################
+
+class TestFunctions(unittest.TestCase):
+
+ """Tests for the various public functions."""
+
+
+ ############################
+ # Test customizeOverrides()
+ ############################
+
+ def testCustomizeOverrides_001(self):
+ """
+ Test platform=standard, no existing overrides.
+ """
+ config = Config()
+ options = OptionsConfig();
+ options.overrides = []
+ config.options = options
+ customizeOverrides(config) # relies on default, which should be "standard"
+ self.failUnlessEqual([], options.overrides);
+ config.options = options
+ customizeOverrides(config, platform="standard")
+ self.failUnlessEqual([], options.overrides);
+
+ def testCustomizeOverrides_002(self):
+ """
+ Test platform=standard, existing override for cdrecord.
+ """
+ config = Config()
+ options = OptionsConfig();
+ options.overrides = [ CommandOverride("cdrecord", "/blech"), ]
+ config.options = options
+ customizeOverrides(config) # relies on default, which should be "standard"
+ self.failUnlessEqual([ CommandOverride("cdrecord", "/blech"), ], options.overrides);
+ config.options = options
+ customizeOverrides(config, platform="standard")
+ self.failUnlessEqual([ CommandOverride("cdrecord", "/blech"), ], options.overrides);
+
+ def testCustomizeOverrides_003(self):
+ """
+ Test platform=standard, existing override for mkisofs.
+ """
+ config = Config()
+ options = OptionsConfig();
+ options.overrides = [ CommandOverride("mkisofs", "/blech"), ]
+ config.options = options
+ customizeOverrides(config) # relies on default, which should be "standard"
+ self.failUnlessEqual([ CommandOverride("mkisofs", "/blech"), ], options.overrides);
+ config.options = options
+ customizeOverrides(config, platform="standard")
+ self.failUnlessEqual([ CommandOverride("mkisofs", "/blech"), ], options.overrides);
+
+ def testCustomizeOverrides_004(self):
+ """
+ Test platform=standard, existing override for cdrecord and mkisofs.
+ """
+ config = Config()
+ options = OptionsConfig();
+ options.overrides = [ CommandOverride("cdrecord", "/blech"), CommandOverride("mkisofs", "/blech2"), ]
+ config.options = options
+ customizeOverrides(config) # relies on default, which should be "standard"
+ self.failUnlessEqual([ CommandOverride("cdrecord", "/blech"), CommandOverride("mkisofs", "/blech2"), ], options.overrides);
+ config.options = options
+ customizeOverrides(config, platform="standard")
+ self.failUnlessEqual([ CommandOverride("cdrecord", "/blech"), CommandOverride("mkisofs", "/blech2"), ], options.overrides);
+
+ def testCustomizeOverrides_005(self):
+ """
+ Test platform=debian, no existing overrides.
+ """
+ config = Config()
+ options = OptionsConfig();
+ options.overrides = []
+ config.options = options
+ customizeOverrides(config, platform="debian")
+ self.failUnlessEqual([ CommandOverride("cdrecord", "/usr/bin/wodim"), CommandOverride("mkisofs", "/usr/bin/genisoimage"), ], options.overrides);
+
+ def testCustomizeOverrides_006(self):
+ """
+ Test platform=debian, existing override for cdrecord.
+ """
+ config = Config()
+ options = OptionsConfig();
+ options.overrides = [ CommandOverride("cdrecord", "/blech"), ]
+ config.options = options
+ customizeOverrides(config, platform="debian")
+ self.failUnlessEqual([ CommandOverride("cdrecord", "/blech"), CommandOverride("mkisofs", "/usr/bin/genisoimage"), ], options.overrides);
+
+ def testCustomizeOverrides_007(self):
+ """
+ Test platform=debian, existing override for mkisofs.
+ """
+ config = Config()
+ options = OptionsConfig();
+ options.overrides = [ CommandOverride("mkisofs", "/blech"), ]
+ config.options = options
+ customizeOverrides(config, platform="debian")
+ self.failUnlessEqual([ CommandOverride("cdrecord", "/usr/bin/wodim"), CommandOverride("mkisofs", "/blech"), ], options.overrides);
+
+ def testCustomizeOverrides_008(self):
+ """
+ Test platform=debian, existing override for cdrecord and mkisofs.
+ """
+ config = Config()
+ options = OptionsConfig();
+ options.overrides = [ CommandOverride("cdrecord", "/blech"), CommandOverride("mkisofs", "/blech2"), ]
+ config.options = options
+ customizeOverrides(config, platform="debian")
+ self.failUnlessEqual([ CommandOverride("cdrecord", "/blech"), CommandOverride("mkisofs", "/blech2"), ], options.overrides);
+
+
+#######################################################################
+# Suite definition
+#######################################################################
+
+def suite():
+ """Returns a suite containing all the test cases in this module."""
+ return unittest.TestSuite((
+ unittest.makeSuite(TestFunctions, 'test'),
+ ))
+
+
+########################################################################
+# Module entry point
+########################################################################
+
+# When this module is executed from the command-line, run its tests
+if __name__ == '__main__':
+ unittest.main()
+
Property changes on: cedar-backup2/trunk/test/customizetests.py
___________________________________________________________________
Added: svn:keywords
+ Id
Modified: cedar-backup2/trunk/util/test.py
===================================================================
--- cedar-backup2/trunk/util/test.py 2009-08-16 20:37:19 UTC (rev 951)
+++ cedar-backup2/trunk/util/test.py 2010-01-10 20:11:53 UTC (rev 952)
@@ -9,7 +9,7 @@
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
-# Copyright (c) 2004-2008 Kenneth J. Pronovici.
+# Copyright (c) 2004-2008,2010 Kenneth J. Pronovici.
# All rights reserved.
#
# This program is free software; you can redistribute it and/or
@@ -163,6 +163,7 @@
import test.splittests as splittests
import test.spantests as spantests
import test.capacitytests as capacitytests
+ import test.customizetests as customizetests
except ImportError, e:
print "Failed to import CedarBackup2 unit test module: %s" % e
print "You must either run the unit tests from the CedarBackup2 source"
@@ -220,6 +221,7 @@
if args == [] or "encrypt" in args: unittests["encrypt"] = encrypttests.suite()
if args == [] or "span" in args: unittests["span"] = spantests.suite()
if args == [] or "capacity" in args: unittests["capacity"] = capacitytests.suite()
+ if args == [] or "customize" in args: unittests["customize"] = customizetests.suite()
if args != []: print "*** Executing specific tests: %s" % unittests.keys()
# Print some diagnostic information
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|