<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[15034] CalendarServer/trunk/calendarserver/tools</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/15034">15034</a></dd>
<dt>Author</dt> <dd>sagen@apple.com</dd>
<dt>Date</dt> <dd>2015-08-06 14:04:52 -0700 (Thu, 06 Aug 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>calendarserver_config now has --logging and --accounting options</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunkcalendarservertoolsconfigpy">CalendarServer/trunk/calendarserver/tools/config.py</a></li>
<li><a href="#CalendarServertrunkcalendarservertoolstesttest_configpy">CalendarServer/trunk/calendarserver/tools/test/test_config.py</a></li>
<li><a href="#CalendarServertrunkcalendarservertoolstesttest_gatewaypy">CalendarServer/trunk/calendarserver/tools/test/test_gateway.py</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunkcalendarservertoolsconfigpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tools/config.py (15033 => 15034)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/tools/config.py        2015-08-05 22:37:53 UTC (rev 15033)
+++ CalendarServer/trunk/calendarserver/tools/config.py        2015-08-06 21:04:52 UTC (rev 15034)
</span><span class="lines">@@ -43,6 +43,7 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> WRITABLE_CONFIG_KEYS = [
</span><ins>+ "AccountingCategories",
</ins><span class="cx"> "Authentication.Basic.AllowedOverWireUnencrypted",
</span><span class="cx"> "Authentication.Basic.Enabled",
</span><span class="cx"> "Authentication.Digest.AllowedOverWireUnencrypted",
</span><span class="lines">@@ -83,8 +84,21 @@
</span><span class="cx"> "ServerRoot",
</span><span class="cx"> ]
</span><span class="cx">
</span><ins>+ACCOUNTING_CATEGORIES = {
+ "http": ("HTTP",),
+ "itip": ("iTIP", "iTIP-VFREEBUSY",),
+ "implicit": ("Implicit Errors",),
+ "autoscheduling": ("AutoScheduling",),
+ "ischedule": ("iSchedule",),
+ "migration": ("migration",),
+}
</ins><span class="cx">
</span><ins>+LOGGING_CATEGORIES = {
+ "directory": ("twext^who", "txdav^who",),
+ "imip": ("txdav^caldav^datastore^scheduling^imip",),
+}
</ins><span class="cx">
</span><ins>+
</ins><span class="cx"> def usage(e=None):
</span><span class="cx"> if e:
</span><span class="cx"> print(e)
</span><span class="lines">@@ -95,8 +109,10 @@
</span><span class="cx"> print("")
</span><span class="cx"> print("Print the value of the given config key.")
</span><span class="cx"> print("options:")
</span><ins>+ print(" -a --accounting: Specify accounting categories (combinations of http, itip, implicit, autoscheduling, ischedule, migration, or off)")
</ins><span class="cx"> print(" -h --help: print this help and exit")
</span><span class="cx"> print(" -f --config: Specify caldavd.plist configuration path")
</span><ins>+ print(" -l --logging: Specify logging categories (combinations of directory, imip, or default)")
</ins><span class="cx"> print(" -r --restart: Restart the calendar service")
</span><span class="cx"> print(" --start: Start the calendar service and agent")
</span><span class="cx"> print(" --stop: Stop the calendar service and agent")
</span><span class="lines">@@ -125,13 +141,15 @@
</span><span class="cx">
</span><span class="cx"> try:
</span><span class="cx"> (optargs, args) = getopt(
</span><del>- sys.argv[1:], "hf:rw:", [
</del><ins>+ sys.argv[1:], "hf:rw:a:l:", [
</ins><span class="cx"> "help",
</span><span class="cx"> "config=",
</span><span class="cx"> "writeconfig=",
</span><span class="cx"> "restart",
</span><span class="cx"> "start",
</span><span class="cx"> "stop",
</span><ins>+ "accounting=",
+ "logging=",
</ins><span class="cx"> ],
</span><span class="cx"> )
</span><span class="cx"> except GetoptError, e:
</span><span class="lines">@@ -139,6 +157,8 @@
</span><span class="cx">
</span><span class="cx"> configFileName = DEFAULT_CONFIG_FILE
</span><span class="cx"> writeConfigFileName = ""
</span><ins>+ accountingCategories = None
+ loggingCategories = None
</ins><span class="cx"> doStop = False
</span><span class="cx"> doStart = False
</span><span class="cx"> doRestart = False
</span><span class="lines">@@ -153,6 +173,12 @@
</span><span class="cx"> elif opt in ("-w", "--writeconfig"):
</span><span class="cx"> writeConfigFileName = arg
</span><span class="cx">
</span><ins>+ elif opt in ("-a", "--accounting"):
+ accountingCategories = arg.split(",")
+
+ elif opt in ("-l", "--logging"):
+ loggingCategories = arg.split(",")
+
</ins><span class="cx"> if opt == "--stop":
</span><span class="cx"> doStop = True
</span><span class="cx">
</span><span class="lines">@@ -198,6 +224,24 @@
</span><span class="cx"> writable = WritableConfig(config, writeConfigFileName)
</span><span class="cx"> writable.read()
</span><span class="cx">
</span><ins>+ # Convert logging categories to actual config key changes
+ if loggingCategories is not None:
+ args = ["LogLevels="]
+ if loggingCategories != ["default"]:
+ for cat in loggingCategories:
+ if cat in LOGGING_CATEGORIES:
+ for moduleName in LOGGING_CATEGORIES[cat]:
+ args.append("LogLevels.{}=debug".format(moduleName))
+
+ # Convert accounting categories to actual config key changes
+ if accountingCategories is not None:
+ args = ["AccountingCategories="]
+ if accountingCategories != ["off"]:
+ for cat in accountingCategories:
+ if cat in ACCOUNTING_CATEGORIES:
+ for key in ACCOUNTING_CATEGORIES[cat]:
+ args.append("AccountingCategories.{}=True".format(key))
+
</ins><span class="cx"> processArgs(writable, args)
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -265,8 +309,12 @@
</span><span class="cx"> if "=" in configKey:
</span><span class="cx"> # This is an assignment
</span><span class="cx"> configKey, stringValue = configKey.split("=")
</span><del>- value = writable.convertToValue(stringValue)
- writable.set({configKey: value})
</del><ins>+ if stringValue:
+ value = writable.convertToValue(stringValue)
+ valueDict = setKeyPath({}, configKey, value)
+ writable.set(valueDict)
+ else:
+ writable.delete(configKey)
</ins><span class="cx"> else:
</span><span class="cx"> # This is a read
</span><span class="cx"> c = config
</span><span class="lines">@@ -416,7 +464,14 @@
</span><span class="cx"> @return: parent
</span><span class="cx"> """
</span><span class="cx"> original = parent
</span><del>- parts = keyPath.split(".")
</del><ins>+
+ # Embedded ^ should be replaced by .
+ # That way, we can still use . as key path separator even though sometimes
+ # a key part wants to have a . in it (such as a LogLevels module).
+ # For example: LogLevels.twext^who, will get converted to a "LogLevels"
+ # dict containing a the key "twext.who"
+ parts = [p.replace("^", ".") for p in keyPath.split(".")]
+
</ins><span class="cx"> for part in parts[:-1]:
</span><span class="cx"> child = parent.get(part, None)
</span><span class="cx"> if child is None:
</span><span class="lines">@@ -531,6 +586,20 @@
</span><span class="cx"> self.dirty = True
</span><span class="cx">
</span><span class="cx">
</span><ins>+ def delete(self, key):
+ """
+ Deletes the specified key
+
+ @param key: the key to delete
+ @type key: C{str}
+ """
+ try:
+ del self.currentConfigSubset[key]
+ self.dirty = True
+ except:
+ pass
+
+
</ins><span class="cx"> def read(self):
</span><span class="cx"> """
</span><span class="cx"> Reads in the data contained in the writable plist file.
</span><span class="lines">@@ -568,7 +637,7 @@
</span><span class="cx"> def convertToValue(cls, string):
</span><span class="cx"> """
</span><span class="cx"> Inspect string and convert the value into an appropriate Python data type
</span><del>- TODO: change this to look at actual types definied within stdconfig
</del><ins>+ TODO: change this to look at actual types defined within stdconfig
</ins><span class="cx"> """
</span><span class="cx"> if "." in string:
</span><span class="cx"> try:
</span></span></pre></div>
<a id="CalendarServertrunkcalendarservertoolstesttest_configpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tools/test/test_config.py (15033 => 15034)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/tools/test/test_config.py        2015-08-05 22:37:53 UTC (rev 15033)
+++ CalendarServer/trunk/calendarserver/tools/test/test_config.py        2015-08-06 21:04:52 UTC (rev 15034)
</span><span class="lines">@@ -171,6 +171,247 @@
</span><span class="cx"> self.assertEquals(results["error"], "Unknown command 'bogus'")
</span><span class="cx">
</span><span class="cx">
</span><ins>+ @inlineCallbacks
+ def test_commandLineArgs(self):
+ """
+ Verify commandline assignments works
+ """
+
+ # Check current values
+
+ results = yield self.runCommand(
+ command_readConfig,
+ script="calendarserver_config")
+
+ self.assertEquals(results["result"]["DefaultLogLevel"], "warn")
+ self.assertEquals(results["result"]["Scheduling"]["iMIP"]["Enabled"], False)
+
+ # Set a single-level key and a multi-level key
+
+ results = yield self.runCommand(
+ None,
+ script="calendarserver_config",
+ additionalArgs=["DefaultLogLevel=debug", "Scheduling.iMIP.Enabled=True"],
+ parseOutput=False
+ )
+
+ results = yield self.runCommand(
+ command_readConfig,
+ script="calendarserver_config")
+
+ self.assertEquals(results["result"]["DefaultLogLevel"], "debug")
+ self.assertEquals(results["result"]["Scheduling"]["iMIP"]["Enabled"], True)
+ self.assertEquals(results["result"]["LogLevels"], {})
+
+ # Directly set some LogLevels sub-keys
+
+ results = yield self.runCommand(
+ None,
+ script="calendarserver_config",
+ additionalArgs=["LogLevels.testing=debug", "LogLevels.testing2=warn"],
+ parseOutput=False
+ )
+
+ results = yield self.runCommand(
+ command_readConfig,
+ script="calendarserver_config")
+
+ self.assertEquals(
+ results["result"]["LogLevels"],
+ {"testing": "debug", "testing2" : "warn"}
+ )
+
+ # Test that setting additional sub-keys retains previous sub-keys
+
+ results = yield self.runCommand(
+ None,
+ script="calendarserver_config",
+ additionalArgs=["LogLevels.testing3=info", "LogLevels.testing4=warn"],
+ parseOutput=False
+ )
+
+ results = yield self.runCommand(
+ command_readConfig,
+ script="calendarserver_config")
+
+ self.assertEquals(
+ results["result"]["LogLevels"],
+ {"testing": "debug", "testing2" : "warn", "testing3": "info", "testing4" : "warn"}
+ )
+
+ # Test that an empty value deletes the key
+
+ results = yield self.runCommand(
+ None,
+ script="calendarserver_config",
+ additionalArgs=["LogLevels="],
+ parseOutput=False
+ )
+
+ results = yield self.runCommand(
+ command_readConfig,
+ script="calendarserver_config")
+
+ self.assertEquals(
+ results["result"]["LogLevels"], # now an empty dict
+ {}
+ )
+
+
+ @inlineCallbacks
+ def test_loggingCategories(self):
+ """
+ Verify logging categories get mapped to the correct python module names
+ """
+
+
+ # Check existing values
+
+ results = yield self.runCommand(
+ command_readConfig,
+ script="calendarserver_config")
+
+ self.assertEquals(results["result"]["LogLevels"], {})
+
+ # Set to directory and imip
+
+ results = yield self.runCommand(
+ None,
+ script="calendarserver_config",
+ additionalArgs=["--logging=directory,imip"],
+ parseOutput=False
+ )
+
+ results = yield self.runCommand(
+ command_readConfig,
+ script="calendarserver_config")
+
+ self.assertEquals(
+ results["result"]["LogLevels"],
+ {
+ "twext.who": "debug",
+ "txdav.who": "debug",
+ "txdav.caldav.datastore.scheduling.imip": "debug",
+ }
+ )
+
+ # Set up to imip, and the directory modules should go away
+
+ results = yield self.runCommand(
+ None,
+ script="calendarserver_config",
+ additionalArgs=["--logging=imip"],
+ parseOutput=False
+ )
+
+ results = yield self.runCommand(
+ command_readConfig,
+ script="calendarserver_config")
+
+ self.assertEquals(
+ results["result"]["LogLevels"],
+ {
+ "txdav.caldav.datastore.scheduling.imip": "debug",
+ }
+ )
+
+ # Set to default, and all modules should go away
+
+ results = yield self.runCommand(
+ None,
+ script="calendarserver_config",
+ additionalArgs=["--logging=default"],
+ parseOutput=False
+ )
+
+ results = yield self.runCommand(
+ command_readConfig,
+ script="calendarserver_config")
+
+ self.assertEquals(
+ results["result"]["LogLevels"], {}
+ )
+
+
+ @inlineCallbacks
+ def test_accountingCategories(self):
+ """
+ Verify accounting categories get mapped to the correct keys
+ """
+ # Check existing values
+
+ results = yield self.runCommand(
+ command_readConfig,
+ script="calendarserver_config")
+
+ self.assertEquals(
+ results["result"]["AccountingCategories"],
+ {
+ 'AutoScheduling': False,
+ 'HTTP': False,
+ 'Implicit Errors': False,
+ 'iSchedule': False,
+ 'iTIP': False,
+ 'iTIP-VFREEBUSY': False,
+ 'migration': False,
+ }
+ )
+
+ # Set to http and itip
+
+ results = yield self.runCommand(
+ None,
+ script="calendarserver_config",
+ additionalArgs=["--accounting=http,itip"],
+ parseOutput=False
+ )
+
+ results = yield self.runCommand(
+ command_readConfig,
+ script="calendarserver_config")
+
+ self.assertEquals(
+ results["result"]["AccountingCategories"],
+ {
+ 'AutoScheduling': False,
+ 'HTTP': True,
+ 'Implicit Errors': False,
+ 'iSchedule': False,
+ 'iTIP': True,
+ 'iTIP-VFREEBUSY': True,
+ 'migration': False,
+ }
+ )
+
+ # Set to off, so all are off
+
+ results = yield self.runCommand(
+ None,
+ script="calendarserver_config",
+ additionalArgs=["--accounting=off"],
+ parseOutput=False
+ )
+
+ results = yield self.runCommand(
+ command_readConfig,
+ script="calendarserver_config")
+
+ self.assertEquals(
+ results["result"]["AccountingCategories"],
+ {
+ 'AutoScheduling': False,
+ 'HTTP': False,
+ 'Implicit Errors': False,
+ 'iSchedule': False,
+ 'iTIP': False,
+ 'iTIP-VFREEBUSY': False,
+ 'migration': False,
+ }
+ )
+
+
+
+
</ins><span class="cx"> def test_keyPath(self):
</span><span class="cx"> d = ConfigDict()
</span><span class="cx"> setKeyPath(d, "one", "A")
</span></span></pre></div>
<a id="CalendarServertrunkcalendarservertoolstesttest_gatewaypy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tools/test/test_gateway.py (15033 => 15034)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/tools/test/test_gateway.py        2015-08-05 22:37:53 UTC (rev 15033)
+++ CalendarServer/trunk/calendarserver/tools/test/test_gateway.py        2015-08-06 21:04:52 UTC (rev 15034)
</span><span class="lines">@@ -144,7 +144,8 @@
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def runCommand(
</span><del>- self, command, error=False, script="calendarserver_command_gateway"
</del><ins>+ self, command, error=False, script="calendarserver_command_gateway",
+ additionalArgs=None, parseOutput=True
</ins><span class="cx"> ):
</span><span class="cx"> """
</span><span class="cx"> Run the given command by feeding it as standard input to
</span><span class="lines">@@ -163,18 +164,24 @@
</span><span class="cx"> if error:
</span><span class="cx"> args.append("--error")
</span><span class="cx">
</span><ins>+ if additionalArgs:
+ args.extend(additionalArgs)
+
</ins><span class="cx"> cwd = sourceRoot
</span><span class="cx">
</span><span class="cx"> deferred = Deferred()
</span><span class="cx"> reactor.spawnProcess(CapturingProcessProtocol(deferred, command), cmd, args, env=os.environ, path=cwd)
</span><span class="cx"> output = yield deferred
</span><del>- try:
- plist = readPlistFromString(output)
- except xml.parsers.expat.ExpatError, e:
- print("Error (%s) parsing (%s)" % (e, output))
- raise
</del><ins>+ if parseOutput:
+ try:
+ plist = readPlistFromString(output)
+ returnValue(plist)
+ except xml.parsers.expat.ExpatError, e:
+ print("Error (%s) parsing (%s)" % (e, output))
+ raise
+ else:
+ returnValue(output)
</ins><span class="cx">
</span><del>- returnValue(plist)
</del><span class="cx">
</span><span class="cx">
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>