[cedar-backup-svn] SF.net SVN: cedar-backup:[1003] cedar-backup2/trunk
Brought to you by:
pronovic
|
From: <pro...@us...> - 2010-07-07 20:48:52
|
Revision: 1003
http://cedar-backup.svn.sourceforge.net/cedar-backup/?rev=1003&view=rev
Author: pronovic
Date: 2010-07-07 20:48:46 +0000 (Wed, 07 Jul 2010)
Log Message:
-----------
Refactor checkUnique() and parseCommaSeparatedString() from config to util.
Modified Paths:
--------------
cedar-backup2/trunk/CedarBackup2/config.py
cedar-backup2/trunk/CedarBackup2/util.py
cedar-backup2/trunk/Changelog
cedar-backup2/trunk/TODO
Modified: cedar-backup2/trunk/CedarBackup2/config.py
===================================================================
--- cedar-backup2/trunk/CedarBackup2/config.py 2010-07-07 20:23:00 UTC (rev 1002)
+++ cedar-backup2/trunk/CedarBackup2/config.py 2010-07-07 20:48:46 UTC (rev 1003)
@@ -244,8 +244,8 @@
# Cedar Backup modules
from CedarBackup2.writers.util import validateScsiId, validateDriveSpeed
-from CedarBackup2.util import UnorderedList, AbsolutePathList, ObjectTypeList
-from CedarBackup2.util import RegexMatchList, RegexList, encodePath
+from CedarBackup2.util import UnorderedList, AbsolutePathList, ObjectTypeList, parseCommaSeparatedString
+from CedarBackup2.util import RegexMatchList, RegexList, encodePath, checkUnique
from CedarBackup2.util import convertSize, UNIT_BYTES, UNIT_KBYTES, UNIT_MBYTES, UNIT_GBYTES
from CedarBackup2.xmlutil import isElement, readChildren, readFirstChild
from CedarBackup2.xmlutil import readStringList, readString, readInteger, readBoolean
@@ -4414,7 +4414,7 @@
options.overrides = Config._parseOverrides(sectionNode)
options.hooks = Config._parseHooks(sectionNode)
managedActions = readString(sectionNode, "managed_actions")
- options.managedActions = Config._parseCommaSeparatedString(managedActions)
+ options.managedActions = parseCommaSeparatedString(managedActions)
return options
@staticmethod
@@ -4872,7 +4872,7 @@
remotePeer.ignoreFailureMode = readString(entry, "ignore_failures")
remotePeer.managed = readBoolean(entry, "managed")
managedActions = readString(entry, "managed_actions")
- remotePeer.managedActions = Config._parseCommaSeparatedString(managedActions)
+ remotePeer.managedActions = parseCommaSeparatedString(managedActions)
remotePeers.append(remotePeer)
if localPeers == []:
localPeers = None
@@ -4909,34 +4909,11 @@
else:
runBefore = readString(sectionNode, "run_before")
runAfter = readString(sectionNode, "run_after")
- beforeList = Config._parseCommaSeparatedString(runBefore)
- afterList = Config._parseCommaSeparatedString(runAfter)
+ beforeList = parseCommaSeparatedString(runBefore)
+ afterList = parseCommaSeparatedString(runAfter)
return ActionDependencies(beforeList, afterList)
@staticmethod
- def _parseCommaSeparatedString(commaString):
- """
- Parses a list of values out of a comma-separated string.
-
- The items in the list are split by comma, and then have whitespace
- stripped. As a special case, if C{commaString} is C{None}, then C{None}
- will be returned.
-
- @param commaString: List of values in comma-separated string format.
- @return: Values from commaString split into a list, or C{None}.
- """
- if commaString is None:
- return None
- else:
- pass1 = commaString.split(",")
- pass2 = []
- for item in pass1:
- item = item.strip()
- if len(item) > 0:
- pass2.append(item)
- return pass2
-
- @staticmethod
def _parseBlankBehavior(parentNode):
"""
Reads a single C{BlankBehavior} object from immediately beneath the parent.
@@ -5680,7 +5657,7 @@
elif self.extensions.orderMode == "dependency":
if action.dependencies is None:
raise ValueError("Each extended action must set dependency information, based on order mode.")
- Config._checkUnique("Duplicate extension names exist:", names)
+ checkUnique("Duplicate extension names exist:", names)
def _validateOptions(self):
"""
@@ -5893,36 +5870,9 @@
if ((self.options is None or self.options.managedActions is None or len(self.options.managedActions) < 1)
and (remotePeer.managedActions is None or len(remotePeer.managedActions) < 1)):
raise ValueError("Managed actions list must be set in options section or individual remote peer.")
- Config._checkUnique("Duplicate peer names exist:", names)
+ checkUnique("Duplicate peer names exist:", names)
- ##############################################
- # Utility methods used for validating content
- ##############################################
-
- @staticmethod
- def _checkUnique(prefix, values):
- """
- Checks that all values are unique.
-
- The values list is checked for duplicate values. If there are
- duplicates, an exception is thrown. All duplicate values are listed in
- the exception.
-
- @param prefix: Prefix to use in the thrown exception
- @param values: List of values to check
-
- @raise ValueError: If there are duplicates in the list
- """
- values.sort()
- duplicates = []
- for i in range(1, len(values)):
- if values[i-1] == values[i]:
- duplicates.append(values[i])
- if duplicates:
- raise ValueError("%s %s" % (prefix, duplicates))
-
-
########################################################################
# General utility functions
########################################################################
Modified: cedar-backup2/trunk/CedarBackup2/util.py
===================================================================
--- cedar-backup2/trunk/CedarBackup2/util.py 2010-07-07 20:23:00 UTC (rev 1002)
+++ cedar-backup2/trunk/CedarBackup2/util.py 2010-07-07 20:48:46 UTC (rev 1003)
@@ -1936,3 +1936,56 @@
return result
return path
+
+#########################
+# checkUnique() function
+#########################
+
+def checkUnique(prefix, values):
+ """
+ Checks that all values are unique.
+
+ The values list is checked for duplicate values. If there are
+ duplicates, an exception is thrown. All duplicate values are listed in
+ the exception.
+
+ @param prefix: Prefix to use in the thrown exception
+ @param values: List of values to check
+
+ @raise ValueError: If there are duplicates in the list
+ """
+ values.sort()
+ duplicates = []
+ for i in range(1, len(values)):
+ if values[i-1] == values[i]:
+ duplicates.append(values[i])
+ if duplicates:
+ raise ValueError("%s %s" % (prefix, duplicates))
+
+
+#######################################
+# parseCommaSeparatedString() function
+#######################################
+
+def parseCommaSeparatedString(commaString):
+ """
+ Parses a list of values out of a comma-separated string.
+
+ The items in the list are split by comma, and then have whitespace
+ stripped. As a special case, if C{commaString} is C{None}, then C{None}
+ will be returned.
+
+ @param commaString: List of values in comma-separated string format.
+ @return: Values from commaString split into a list, or C{None}.
+ """
+ if commaString is None:
+ return None
+ else:
+ pass1 = commaString.split(",")
+ pass2 = []
+ for item in pass1:
+ item = item.strip()
+ if len(item) > 0:
+ pass2.append(item)
+ return pass2
+
Modified: cedar-backup2/trunk/Changelog
===================================================================
--- cedar-backup2/trunk/Changelog 2010-07-07 20:23:00 UTC (rev 1002)
+++ cedar-backup2/trunk/Changelog 2010-07-07 20:48:46 UTC (rev 1003)
@@ -1,5 +1,6 @@
Version 2.20.0 unreleased
+ * This is a cleanup release with no functional changes.
* Switch to minimum Python version of 2.5 (everyone should have it now).
- Make cback script more robust in the case of a bad interpreter version
- Change file headers, comments, manual, etc. to reference Python 2.5
@@ -11,7 +12,8 @@
- Move unit tests into testcase folder to avoid test.py naming conflict
* Remove "Translate [x:y] into [a:b]" debug message for uid/gid translation.
* Refactor out util.isRunningAsRoot() to replace scattered os.getuid() calls.
- * Remove configuration boilerplate "As with all of the ... are optional..."
+ * Remove boilerplate comments "As with all of the ... " in config code.
+ * Refactor checkUnique() and parseCommaSeparatedString() from config to util.
Version 2.19.6 22 May 2010
Modified: cedar-backup2/trunk/TODO
===================================================================
--- cedar-backup2/trunk/TODO 2010-07-07 20:23:00 UTC (rev 1002)
+++ cedar-backup2/trunk/TODO 2010-07-07 20:48:46 UTC (rev 1003)
@@ -78,9 +78,6 @@
If each extension really has its own Config object (?) pull out common parsing code
Config code is generally readable, might not be worth abstracting it
- Not sure that comments are worth it -- they're longer than the method body
-Pull out general utilities from config parsing
- - Comma-separated string
- - Check unique
FilesystemList
- excludePaths should become excludedPaths (to differentiate from flags)
- same goes for other lists and maybe ignoreFile (ignoreFileName?)
@@ -90,7 +87,6 @@
- In fact, maybe the knapsack algorithms could operate on a filesystem list instead of the the other way around?
- or, a knapsack algorithm is some sort of predicate or "filter" on a list ???
remove image.py
-maybe get rid of epydoc @type declarations -- they clutter things up and aren't that useful (?)
should common test methods be put into a test case superclass?
- here, I'm thinking of the tar stuff, the "raise on assign failure" etc.
- maybe looking up resources is something a test class always does?
@@ -104,7 +100,7 @@
Get rid of specialized Subversion repository configuration (BDBRepository, FSFSRepository, etc.)
Come up with standard parsing for config items lots of code uses -- exclusions, for example
Spread out the functionality for the validate action
-Standardize on a way to "merge" several levels of configuration for a parmeters that exist on more than one level
+Standardize on a way to "merge" several levels of configuration for a parameters that exist on more than one level
get rid of store.writeImage() -- or rather, rename writeImageBlankSafe to be writeImage
Come up with a way to better share store and rebuild functionality
- Can one extension class provide more than one command, maybe with two named methods?
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|