Changeset View
Changeset View
Standalone View
Standalone View
wallace/module_resources.py
Show First 20 Lines • Show All 537 Lines • ▼ Show 20 Lines | for resource in resources.keys(): | ||||
# sets the 'conflicting' flag and adds a list of conflicting events found | # sets the 'conflicting' flag and adds a list of conflicting events found | ||||
try: | try: | ||||
num_messages += read_resource_calendar(resources[resource], itip_events) | num_messages += read_resource_calendar(resources[resource], itip_events) | ||||
except Exception, e: | except Exception, e: | ||||
log.error(_("Failed to read resource calendar for %r: %r") % (resource, e)) | log.error(_("Failed to read resource calendar for %r: %r") % (resource, e)) | ||||
end = time.time() | end = time.time() | ||||
log.debug(_("start: %r, end: %r, total: %r, messages: %d") % (start, end, (end-start), num_messages), level=8) | log.debug(_("start: %r, end: %r, total: %r, messages: %d") % (start, end, (end-start), num_messages), level=8) | ||||
Lint: PEP8 E226: missing whitespace around arithmetic operator | |||||
# For each resource (collections are first!) | # For each resource (collections are first!) | ||||
# check conflicts and either accept or decline the reservation request | # check conflicts and either accept or decline the reservation request | ||||
for resource in resource_dns: | for resource in resource_dns: | ||||
log.debug(_("Polling for resource %r") % (resource), level=8) | log.debug(_("Polling for resource %r") % (resource), level=8) | ||||
if not resources.has_key(resource): | if not resources.has_key(resource): | ||||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | for resource in resource_dns: | ||||
else: | else: | ||||
# This must have been a resource collection originally. | # This must have been a resource collection originally. | ||||
# We have inserted the reference to the original resource | # We have inserted the reference to the original resource | ||||
# record in 'memberof'. | # record in 'memberof'. | ||||
if resources[resource].has_key('memberof'): | if resources[resource].has_key('memberof'): | ||||
original_resource = resources[resources[resource]['memberof']] | original_resource = resources[resources[resource]['memberof']] | ||||
# Randomly select a target resource from the resource collection. | # Randomly select a target resource from the resource collection. | ||||
available_resource = resources[original_resource['uniquemember'][random.randint(0,(len(original_resource['uniquemember'])-1))]] | available_resource = resources[original_resource['uniquemember'][random.randint(0,(len(original_resource['uniquemember'])-1))]] | ||||
Lint: PEP8 E226 missing whitespace around arithmetic operator Lint: PEP8 E226: missing whitespace around arithmetic operator | |||||
done = True | done = True | ||||
if done: | if done: | ||||
break | break | ||||
# end for resource in resource_dns: | # end for resource in resource_dns: | ||||
return (available_resource, itip_event) | return (available_resource, itip_event) | ||||
▲ Show 20 Lines • Show All 617 Lines • ▼ Show 20 Lines | for itip_event in itip_events: | ||||
# TODO: look-up event organizer in LDAP and change localization to its preferredlanguage | # TODO: look-up event organizer in LDAP and change localization to its preferredlanguage | ||||
message_text = reservation_response_text(participant_status, owner) | message_text = reservation_response_text(participant_status, owner) | ||||
subject_template = _("Reservation Request for %(summary)s was %(status)s") | subject_template = _("Reservation Request for %(summary)s was %(status)s") | ||||
# Extra actions to take: send delegated reply | # Extra actions to take: send delegated reply | ||||
if participant_status == "DELEGATED": | if participant_status == "DELEGATED": | ||||
delegatee = [a for a in itip_event['xml'].get_attendees() if from_address in a.get_delegated_from(True)][0] | atts = itip_event['xml'].get_attendees() | ||||
delegatee = [ | |||||
a for a in atts if from_address in a.get_delegated_from(True) | |||||
][0] | |||||
delegated_message_text = _(""" | delegated_message_text = _(""" | ||||
*** This is an automated response, please do not reply! *** | *** This is an automated response, please do not reply! *** | ||||
Your reservation was delegated to "%s" which is available for the requested time. | Your reservation was delegated to "%s" which is available for the requested time. | ||||
""") % (delegatee.get_name()) | """) % (delegatee.get_name()) | ||||
pykolab.itip.send_reply(from_address, itip_event, delegated_message_text, | seed = random.randint(0, 6) | ||||
subject=subject_template) | alarm_after = (seed * 10) + 60 | ||||
log.debug(_("Set alarm to %s seconds") % (alarm_after), level=8) | |||||
signal.alarm(alarm_after) | |||||
pykolab.itip.send_reply( | |||||
from_address, | |||||
itip_event, | |||||
delegated_message_text, | |||||
subject=subject_template | |||||
) | |||||
signal.alarm(0) | |||||
# adjust some vars for the regular reply from the delegatee | # adjust some vars for the regular reply from the delegatee | ||||
message_text = reservation_response_text(delegatee.get_participant_status(True), owner) | message_text = reservation_response_text(delegatee.get_participant_status(True), owner) | ||||
from_address = delegatee.get_email() | from_address = delegatee.get_email() | ||||
time.sleep(2) | time.sleep(2) | ||||
pykolab.itip.send_reply(from_address, itip_event, message_text, | seed = random.randint(0, 6) | ||||
subject=subject_template) | alarm_after = (seed * 10) + 60 | ||||
log.debug(_("Set alarm to %s seconds") % (alarm_after), level=8) | |||||
signal.alarm(alarm_after) | |||||
pykolab.itip.send_reply( | |||||
from_address, | |||||
itip_event, | |||||
message_text, | |||||
subject=subject_template | |||||
) | |||||
signal.alarm(0) | |||||
def reservation_response_text(status, owner): | def reservation_response_text(status, owner): | ||||
message_text = _(""" | message_text = _(""" | ||||
*** This is an automated response, please do not reply! *** | *** This is an automated response, please do not reply! *** | ||||
We hereby inform you that your reservation was %s. | We hereby inform you that your reservation was %s. | ||||
""") % (participant_status_label(status)) | """) % (participant_status_label(status)) | ||||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | return message_text % { | ||||
'status': participant_status_label(status), | 'status': participant_status_label(status), | ||||
'orgname': organizer.name(), | 'orgname': organizer.name(), | ||||
'orgemail': organizer.email() | 'orgemail': organizer.email() | ||||
} | } | ||||
def send_owner_confirmation(resource, owner, itip_event): | def send_owner_confirmation(resource, owner, itip_event): | ||||
""" | """ | ||||
Send a reservation request to the resource owner for manual confirmation (ACCEPT or DECLINE) | Send a reservation request to the resource owner for manual confirmation (ACCEPT or | ||||
DECLINE) | |||||
This clones the given invtation with a new UID and setting the resource as organizer in order to | This clones the given invtation with a new UID and setting the resource as organizer in | ||||
receive the reply from the owner. | order to receive the reply from the owner. | ||||
""" | """ | ||||
uid = itip_event['uid'] | uid = itip_event['uid'] | ||||
event = itip_event['xml'] | event = itip_event['xml'] | ||||
organizer = event.get_organizer() | organizer = event.get_organizer() | ||||
event_attendees = [a.get_displayname() for a in event.get_attendees() if not a.get_cutype() == kolabformat.CutypeResource] | |||||
atts = event.get_attendees() | |||||
event_attendees = [ | |||||
a.get_displayname() for a in atts if not a.get_cutype() == kolabformat.CutypeResource | |||||
] | |||||
log.debug( | log.debug( | ||||
_("Clone invitation for owner confirmation: %r from %r") % ( | _("Clone invitation for owner confirmation: %r from %r") % ( | ||||
itip_event['uid'], event.get_organizer().email() | itip_event['uid'], event.get_organizer().email() | ||||
), | ), | ||||
level=8 | level=8 | ||||
) | ) | ||||
# generate new UID and set the resource as organizer | # generate new UID and set the resource as organizer | ||||
(mail, domain) = resource['mail'].split('@') | (mail, domain) = resource['mail'].split('@') | ||||
event.set_uid(str(uuid.uuid4())) | event.set_uid(str(uuid.uuid4())) | ||||
event.set_organizer(mail + '+' + base64.b64encode(uid, '-/') + '@' + domain, resource['cn']) | event.set_organizer(mail + '+' + base64.b64encode(uid, '-/') + '@' + domain, resource['cn']) | ||||
itip_event['uid'] = event.get_uid() | itip_event['uid'] = event.get_uid() | ||||
# add resource owner as (the sole) attendee | # add resource owner as (the sole) attendee | ||||
event._attendees = [] | event._attendees = [] | ||||
event.add_attendee(owner['mail'], owner['cn'], rsvp=True, role=kolabformat.Required, participant_status=kolabformat.PartNeedsAction) | event.add_attendee( | ||||
owner['mail'], | |||||
owner['cn'], | |||||
rsvp=True, | |||||
role=kolabformat.Required, | |||||
participant_status=kolabformat.PartNeedsAction | |||||
) | |||||
# flag this iTip message as confirmation type | # flag this iTip message as confirmation type | ||||
event.add_custom_property('X-Kolab-InvitationType', 'CONFIRMATION') | event.add_custom_property('X-Kolab-InvitationType', 'CONFIRMATION') | ||||
message_text = _(""" | message_text = _(""" | ||||
A reservation request for %(resource)s requires your approval! | A reservation request for %(resource)s requires your approval! | ||||
Please either accept or decline this invitation without saving it to your calendar. | Please either accept or decline this invitation without saving it to your calendar. | ||||
The reservation request was sent from %(orgname)s <%(orgemail)s>. | The reservation request was sent from %(orgname)s <%(orgemail)s>. | ||||
Subject: %(summary)s. | Subject: %(summary)s. | ||||
Date: %(date)s | Date: %(date)s | ||||
Participants: %(attendees)s | Participants: %(attendees)s | ||||
*** This is an automated message, please don't reply by email. *** | *** This is an automated message, please don't reply by email. *** | ||||
""")% { | """) % { | ||||
'resource': resource['cn'], | 'resource': resource['cn'], | ||||
'orgname': organizer.name(), | 'orgname': organizer.name(), | ||||
'orgemail': organizer.email(), | 'orgemail': organizer.email(), | ||||
'summary': event.get_summary(), | 'summary': event.get_summary(), | ||||
'date': event.get_date_text(), | 'date': event.get_date_text(), | ||||
'attendees': ",\n+ ".join(event_attendees) | 'attendees': ",\n+ ".join(event_attendees) | ||||
} | } | ||||
pykolab.itip.send_request(owner['mail'], itip_event, message_text, | seed = random.randint(0, 6) | ||||
alarm_after = (seed * 10) + 60 | |||||
log.debug(_("Set alarm to %s seconds") % (alarm_after), level=8) | |||||
signal.alarm(alarm_after) | |||||
pykolab.itip.send_request( | |||||
owner['mail'], | |||||
itip_event, | |||||
message_text, | |||||
subject=_('Booking request for %s requires confirmation') % (resource['cn']), | subject=_('Booking request for %s requires confirmation') % (resource['cn']), | ||||
direct=True) | direct=True | ||||
) | |||||
signal.alarm(0) | |||||
missing whitespace around arithmetic operator