Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Adds structure location support in the xmlfile directory implementation

  • Loading branch information
m0rgen committed Dec 13, 2013
1 parent 907f7c7 commit eedc07735e80c97172cb4f3af592f0a04886445f
@@ -32,7 +32,9 @@
principalForPrincipalID, proxySubprincipal, addProxy, removeProxy,
ProxyError, ProxyWarning, autoDisableMemcached
)
from calendarserver.tools.principals import getProxies, setProxies, updateRecord
from calendarserver.tools.principals import (
getProxies, setProxies, updateRecord, attrMap
)
from calendarserver.tools.purge import WorkerService, PurgeOldEventsService, DEFAULT_BATCH_SIZE, DEFAULT_RETAIN_DAYS
from calendarserver.tools.cmdline import utilityMain

@@ -140,26 +142,6 @@ def main():
utilityMain(configFileName, RunnerService, verbose=debug)


attrMap = {
'GeneratedUID' : { 'attr' : 'guid', },
'RealName' : { 'attr' : 'fullName', },
'RecordName' : { 'attr' : 'shortNames', },
'Comment' : { 'extras' : True, 'attr' : 'comment', },
'Description' : { 'extras' : True, 'attr' : 'description', },
'Type' : { 'extras' : True, 'attr' : 'type', },
'Capacity' : { 'extras' : True, 'attr' : 'capacity', },
'Building' : { 'extras' : True, 'attr' : 'building', },
'Floor' : { 'extras' : True, 'attr' : 'floor', },
'Street' : { 'extras' : True, 'attr' : 'street', },
'City' : { 'extras' : True, 'attr' : 'city', },
'State' : { 'extras' : True, 'attr' : 'state', },
'ZIP' : { 'extras' : True, 'attr' : 'zip', },
'Country' : { 'extras' : True, 'attr' : 'country', },
'Phone' : { 'extras' : True, 'attr' : 'phone', },
'Geo' : { 'extras' : True, 'attr' : 'geo', },
'AutoSchedule' : { 'attr' : 'autoSchedule', },
'AutoAcceptGroup' : { 'attr' : 'autoAcceptGroup', },
}

class Runner(object):

@@ -218,8 +200,8 @@ def run(self):
self.respondWithError("Command failed: '%s'" % (str(e),))
raise

# Locations

# Locations

def command_getLocationList(self, command):
self.respondWithRecordsOfTypes(self.dir, command, ["locations"])
@@ -266,6 +248,7 @@ def command_getLocationAttributes(self, command):

command_getResourceAttributes = command_getLocationAttributes


@inlineCallbacks
def command_setLocationAttributes(self, command):

@@ -306,8 +289,8 @@ def command_deleteLocation(self, command):
return
self.respondWithRecordsOfTypes(self.dir, command, ["locations"])

# Resources

# Resources

def command_getResourceList(self, command):
self.respondWithRecordsOfTypes(self.dir, command, ["resources"])
@@ -379,6 +362,67 @@ def command_getLocationAndResourceList(self, command):
self.respondWithRecordsOfTypes(self.dir, command, ["locations", "resources"])


# Addresses

def command_getAddressList(self, command):
self.respondWithRecordsOfTypes(self.dir, command, ["addresses"])


@inlineCallbacks
def command_createAddress(self, command):
kwargs = {}
for key, info in attrMap.iteritems():
if key in command:
kwargs[info['attr']] = command[key]

try:
yield updateRecord(True, self.dir, "addresses", **kwargs)
except DirectoryError, e:
self.respondWithError(str(e))
return

self.respondWithRecordsOfTypes(self.dir, command, ["addresses"])


def command_getAddressAttributes(self, command):
guid = command['GeneratedUID']
record = self.dir.recordWithGUID(guid)
if record is None:
self.respondWithError("Principal not found: %s" % (guid,))
return
recordDict = recordToDict(record)
self.respond(command, recordDict)
return succeed(None)


@inlineCallbacks
def command_setAddressAttributes(self, command):
kwargs = {}
for key, info in attrMap.iteritems():
if key in command:
kwargs[info['attr']] = command[key]
try:
yield updateRecord(False, self.dir, "addresses", **kwargs)
except DirectoryError, e:
self.respondWithError(str(e))
return

yield self.command_getAddressAttributes(command)


def command_deleteAddress(self, command):
kwargs = {}
for key, info in attrMap.iteritems():
if key in command:
kwargs[info['attr']] = command[key]
try:
self.dir.destroyRecord("addresses", **kwargs)
except DirectoryError, e:
self.respondWithError(str(e))
return
self.respondWithRecordsOfTypes(self.dir, command, ["addresses"])


# Config

def command_readConfig(self, command):
@@ -87,8 +87,14 @@ def usage(e=None):
print(" --get-auto-schedule-mode: read auto-schedule mode")
print(" --set-auto-accept-group=principal: set auto-accept-group")
print(" --get-auto-accept-group: read auto-accept-group")
print(" --add {locations|resources} 'full name' [record name] [GUID]: add a principal")
print(" --add {locations|resources|addresses} 'full name' [record name] [GUID]: add a principal")
print(" --remove: remove a principal")
print(" --set-geo=url: set the geo: url for an address (e.g. geo:37.331741,-122.030333)")
print(" --get-geo: get the geo: url for an address")
print(" --set-street-address=streetaddress: set the street address string for an address")
print(" --get-street-address: get the street address string for an address")
print(" --set-address=guid: associate principal with an address (by guid)")
print(" --get-address: get the associated address's guid")

if e:
sys.exit(64)
@@ -116,6 +122,27 @@ def doWork(self):
directory = rootResource.getDirectory()
yield self.function(rootResource, directory, self.store, *self.params)

attrMap = {
'GeneratedUID' : { 'attr' : 'guid', },
'RealName' : { 'attr' : 'fullName', },
'RecordName' : { 'attr' : 'shortNames', },
'AutoSchedule' : { 'attr' : 'autoSchedule', },
'AutoAcceptGroup' : { 'attr' : 'autoAcceptGroup', },

'Comment' : { 'extras' : True, 'attr' : 'comment', },
'Description' : { 'extras' : True, 'attr' : 'description', },
'Type' : { 'extras' : True, 'attr' : 'type', },

# For "Locations", i.e. scheduled spaces
'Capacity' : { 'extras' : True, 'attr' : 'capacity', },
'Floor' : { 'extras' : True, 'attr' : 'floor', },
'AssociatedAddress' : { 'extras' : True, 'attr' : 'associatedAddress', },

# For "Addresses", i.e. nonscheduled areas containing Locations
'AbbreviatedName' : { 'extras' : True, 'attr' : 'abbreviatedName', },
'StreetAddress' : { 'extras' : True, 'attr' : 'streetAddress', },
'Geo' : { 'extras' : True, 'attr' : 'geo', },
}


def main():
@@ -142,6 +169,12 @@ def main():
"get-auto-schedule-mode",
"set-auto-accept-group=",
"get-auto-accept-group",
"set-geo=",
"get-geo",
"set-address=",
"get-address",
"set-street-address=",
"get-street-address",
"verbose",
],
)
@@ -258,6 +291,24 @@ def main():
elif opt in ("", "--get-auto-accept-group"):
principalActions.append((action_getAutoAcceptGroup,))

elif opt in ("", "--set-geo"):
principalActions.append((action_setValue, "Geo", arg))

elif opt in ("", "--get-geo"):
principalActions.append((action_getValue, "Geo"))

elif opt in ("", "--set-street-address"):
principalActions.append((action_setValue, "StreetAddress", arg))

elif opt in ("", "--get-street-address"):
principalActions.append((action_getValue, "StreetAddress"))

elif opt in ("", "--set-address"):
principalActions.append((action_setValue, "AssociatedAddress", arg))

elif opt in ("", "--get-address"):
principalActions.append((action_getValue, "AssociatedAddress"))

else:
raise NotImplementedError(opt)

@@ -274,7 +325,7 @@ def main():
elif addType:

try:
addType = matchStrings(addType, ["locations", "resources"])
addType = matchStrings(addType, ["locations", "resources", "addresses"])
except ValueError, e:
print(e)
return
@@ -296,7 +347,7 @@ def main():
elif listPrincipals:
try:
listPrincipals = matchStrings(listPrincipals, ["users", "groups",
"locations", "resources"])
"locations", "resources", "addresses"])
except ValueError, e:
print(e)
return
@@ -393,6 +444,7 @@ def runSearch(service, rootResource, directory, store, searchTerm):
"groups" : "Group",
"locations" : "Place",
"resources" : "Resource",
"addresses" : "Address",
}.get(record.recordType),
))
print(" GUID: %s" % (record.guid,))
@@ -667,6 +719,29 @@ def action_getAutoAcceptGroup(rootResource, directory, store, principal):
print("No auto-accept-group assigned to %s" % (prettyPrincipal(principal),))


@inlineCallbacks
def action_setValue(rootResource, directory, store, principal, name, value):
print("Setting %s to %s for %s" % (
name, value, prettyPrincipal(principal),
))

principal.record.extras[attrMap[name]["attr"]] = value
(yield updateRecord(False, directory,
principal.record.recordType,
guid=principal.record.guid,
shortNames=principal.record.shortNames,
fullName=principal.record.fullName,
**principal.record.extras
))


def action_getValue(rootResource, directory, store, principal, name):
print("%s for %s is %s" % (
name,
prettyPrincipal(principal),
principal.record.extras[attrMap[name]["attr"]]
))


def abort(msg, status=1):
sys.stdout.write("%s\n" % (msg,))
@@ -176,6 +176,7 @@
<array>
<string>resources</string>
<string>locations</string>
<string>addresses</string>
</array>
</dict>
</dict>

0 comments on commit eedc077

Please sign in to comment.
You can’t perform that action at this time.