Projects
Kolab:Winterfell
pykolab-python3
Log In
Username
Password
We truncated the diff of some files because they were too big. If you want to see the full diff for every file,
click here
.
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 2
View file
pykolab-0.9.0.tar.gz/pykolab/itip/__init__.py
Changed
@@ -173,112 +173,105 @@ return itip_objects -def check_event_conflict(kolab_event, itip_event): +def check_event_conflict_impl(kolab_event, itip_event): """ Determine whether the given kolab event conflicts with the given itip event """ conflict = False # don't consider conflict with myself - if kolab_event.uid == itip_event'uid': - return conflict + if kolab_event.uid == itip_event.uid: + return False # don't consider conflict if event has TRANSP:TRANSPARENT - if _is_transparent(kolab_event): - return conflict - - if _is_transparent(itip_event'xml'): - return conflict + if _is_transparent(kolab_event) or _is_transparent(itip_event): + return False _es = to_dt(kolab_event.get_start()) # use iCal style end date: next day for all-day events _ee = to_dt(kolab_event.get_ical_dtend()) - _is = to_dt(itip_event'start') - _ie = to_dt(itip_event'end') + _is = to_dt(itip_event.get_start()) + _ie = to_dt(itip_event.get_ical_dtend()) # Escape looping through anything if neither of the events is recurring. - if not itip_event'xml'.is_recurring() and not kolab_event.is_recurring(): + if not itip_event.is_recurring() and not kolab_event.is_recurring(): return check_date_conflict(_es, _ee, _is, _ie) - loop = 0 + if _ee < _is: + earlierEvent = kolab_event + laterEvent = itip_event + else: + earlierEvent = itip_event + laterEvent = kolab_event - done = False + # We can't move forward, so no conflict + if not earlierEvent.is_recurring(): + return False + + targetStart = to_dt(laterEvent.get_start()) + targetEnd = to_dt(laterEvent.get_ical_dtend()) + + eventStart = to_dt(earlierEvent.get_start()) + eventEnd = to_dt(earlierEvent.get_ical_dtend()) + + loop = 0 # naive loops to check for collisions in (recurring) events # TODO: compare recurrence rules directly (e.g. matching time slot or weekday or monthday) - while not conflict and not done: + while not conflict: loop += 1 + # Safeguard + if loop > 100: + log.warning("Breaking conflict detection loop after %d iterations." % (loop)) + return False + + # Scroll forward the earlier event recurrence until we're at the target date. + while eventEnd < targetStart and eventStart is not None: + log.debug( + "Attempt to move forward kolab event recurrence from {} closer to {}".format( + eventStart, + targetStart + ), + level=8 + ) - # Scroll forward the kolab event recurrence until we're in the prime - # spot. We choose to start with the Kolab event because that is likely - # the older one. - if _ee < _is: - while _ee < _is and _es is not None and kolab_event.is_recurring(): - log.debug( - "Attempt to move forward kolab event recurrence from {} closer to {}".format( - _ee, - _is - ), - level=8 - ) - - __es = to_dt(kolab_event.get_next_occurence(_es)) - - if __es is not None and not __es == _es: - _es = __es - _ee = to_dt(kolab_event.get_occurence_end_date(_es)) - else: - done = True - break - - # Scroll forward the itip event recurrence until we're in the - # prime spot, this time with the iTip event. - if _ie < _es: - while _ie < _es and _is is not None and itip_event'xml'.is_recurring(): - log.debug( - "Attempt to move forward itip event recurrence from {} closer to {}".format( - _ie, - _es - ), - level=8 - ) - - __is = to_dt(itip_event'xml'.get_next_occurence(_is)) - - if __is is not None and not _is == __is: - _is = __is - _ie = to_dt(itip_event'xml'.get_occurence_end_date(_is)) - else: - done = True - break + nextEventStart = to_dt(earlierEvent.get_next_occurence(eventStart)) + + if nextEventStart is not None and nextEventStart != eventStart: + eventStart = nextEventStart + eventEnd = to_dt(earlierEvent.get_occurence_end_date(eventStart)) + else: + # We can't move forward, break and compare + return check_date_conflict(eventStart, eventEnd, targetStart, targetEnd) # Now that we have some events somewhere in the same neighborhood... - conflict = check_date_conflict(_es, _ee, _is, _ie) + conflict = check_date_conflict(eventStart, eventEnd, targetStart, targetEnd) log.debug( - "* Comparing itip at %s/%s with kolab at %s/%s: conflict - %r (occurence - %d)" % ( - _is, _ie, _es, _ee, conflict, loop + "* Comparing earlier at %s/%s with later at %s/%s: conflict - %r (occurence - %d)" % ( + eventStart, eventEnd, targetStart, targetEnd, conflict, loop ), level=8 ) if not conflict: - if kolab_event.is_recurring() and itip_event'xml'.is_recurring(): - if not kolab_event.has_exceptions() and not itip_event'xml'.has_exceptions(): - log.debug("No conflict, both recurring, but neither with exceptions", level=8) - done = True - break - - _is = to_dt(itip_event'xml'.get_next_occurence(_is)) - - if _is is not None: - _ie = to_dt(itip_event'xml'.get_occurence_end_date(_is)) + # Move the later event one forward, and try again + targetStart = to_dt(laterEvent.get_next_occurence(targetStart)) + if targetStart is not None: + targetEnd = to_dt(itip_event.get_occurence_end_date(targetStart)) else: - done = True + return False return conflict +def check_event_conflict(kolab_event, itip_event): + """ + Determine whether the given kolab event conflicts with the given itip event + """ + return check_event_conflict_impl(kolab_event, itip_event'xml') + + def _is_transparent(event): return event.get_transparency() or event.get_status() == kolabformat.StatusCancelled
View file
pykolab-0.9.0.tar.gz/pykolab/wap_client/__init__.py
Changed
@@ -30,7 +30,7 @@ kolab_wap_url = conf.get('kolab_wap', 'api_url') -if not kolab_wap_url == None: +if kolab_wap_url is not None: result = urlparse(kolab_wap_url) else: result = None @@ -52,15 +52,16 @@ conn = None + def authenticate(username=None, password=None, domain=None): global session_id - if username == None: + if username is None: username = conf.get('ldap', 'bind_dn') - if password == None: + if password is None: password = conf.get('ldap', 'bind_pw') - if domain == None: + if domain is None: domain = conf.get('kolab', 'primary_domain') post = json.dumps( @@ -80,10 +81,11 @@ session_id = response'session_token' return True + def connect(uri=None): global conn, API_SSL, API_PORT, API_HOSTNAME, API_BASE - if not uri == None: + if uri is not None: result = urlparse(uri) if hasattr(result, 'scheme') and result.scheme == 'https': @@ -99,7 +101,7 @@ if hasattr(result, 'path'): API_BASE = result.path - if conn == None: + if conn is None: if API_SSL: conn = httplib.HTTPSConnection(API_HOSTNAME, API_PORT) else: @@ -109,6 +111,7 @@ return conn + def disconnect(quit=False): global conn, session_id @@ -120,15 +123,17 @@ conn.close() conn = None + def domain_add(domain, aliases=): dna = conf.get('ldap', 'domain_name_attribute') post = json.dumps({ - dna: domain + aliases + dna: domain + aliases }) return request('POST', 'domain.add', post=post) + def domain_delete(domain, force=False): domain_id, domain_attrs = domain_find(domain).popitem() @@ -141,34 +146,41 @@ return request('POST', 'domain.delete', post=post) + def domain_find(domain): dna = conf.get('ldap', 'domain_name_attribute') - get = { dna: domain } + get = {dna: domain} return request('GET', 'domain.find', get=get) + def domain_info(domain): domain_id, domain_attrs = domain_find(domain) - get = { 'id': domain_id } + get = {'id': domain_id} return request('GET', 'domain.info', get=get) + def domains_capabilities(): return request('GET', 'domains.capabilities') + def domains_list(): return request('GET', 'domains.list') + def form_value_generate(params): post = json.dumps(params) return request('POST', 'form_value.generate', post=post) + def form_value_generate_password(*args, **kw): return request('GET', 'form_value.generate_password') + def form_value_list_options(object_type, object_type_id, attribute): post = json.dumps( { @@ -180,24 +192,26 @@ return request('POST', 'form_value.list_options', post=post) + def form_value_select_options(object_type, object_type_id, attribute): post = json.dumps( { 'object_type': object_type, 'type_id': object_type_id, - 'attributes': attribute + 'attributes': attribute } ) return request('POST', 'form_value.select_options', post=post) + def get_group_input(): group_types = group_types_list() if len(group_types) > 1: for key in group_types: if not key == "status": - print("%s) %s" % (key,group_typeskey'name')) + print("%s) %s" % (key, group_typeskey'name')) group_type_id = utils.ask_question("Please select the group type") @@ -223,11 +237,12 @@ paramsattribute = utils.ask_question(attribute) for attribute in group_type_info'auto_form_fields': - retval = eval("group_form_value_generate_%s(params)" % (attribute)) + retval = eval("group_form_value_generate_%s(params)" % attribute) paramsattribute = retvalattribute return params + def get_user_input(): user_types = user_types_list() @@ -235,7 +250,7 @@ print("") for key in user_types'list': if not key == "status": - print("%s) %s" % (key,user_types'list'key'name')) + print("%s) %s" % (key, user_types'list'key'name')) print("") user_type_id = utils.ask_question("Please select the user type") @@ -264,7 +279,8 @@ for attribute in user_type_info'form_fields': if isinstance(user_type_info'form_fields'attribute, dict): - if 'optional' in user_type_info'form_fields'attribute and user_type_info'form_fields'attribute'optional': + if ('optional' in user_type_info'form_fields'attribute) and \ + user_type_info'form_fields'attribute'optional': may_attrs.append(attribute) else: must_attrs.append(attribute) @@ -284,7 +300,7 @@ default = attribute_valuesattribute'default' paramsattribute = utils.ask_menu( - "Choose the %s value" % (attribute), + "Choose the %s value" % attribute, attribute_valuesattribute'list', default=default ) @@ -295,7 +311,7 @@ default = user_type_info'form_fields'attribute'default' paramsattribute = utils.ask_menu( - "Choose the %s value" % (attribute), + "Choose the %s value" % attribute, user_type_info'form_fields'attribute'values',
View file
pykolab-0.9.0.tar.gz/tests/unit/test-011-itip.py
Changed
@@ -457,6 +457,7 @@ itip_event = itip.events_from_message(message_from_string(itip_recurring))0 self.assertTrue(itip.check_event_conflict(event3, itip_event), "Conflict in two recurring events") + self.assertTrue(itip.check_event_conflict_impl(itip_event'xml', event3), "Conflict in two recurring events reverse") event4 = Event() event4.set_recurrence(rrule) @@ -530,6 +531,23 @@ self.assertFalse(itip.check_event_conflict(event, itip_event), "Conflicting dates (exception)") + def test_002_check_event_conflict_forever_recurring(self): + # This test is here to make sure performance issue is fixed (T1988) + # make the event recurring forever + itip_recurring_forever = itip_recurring.replace("RRULE:FREQ=DAILY;INTERVAL=1;COUNT=5", "RRULE:FREQ=WEEKLY;BYDAY=MO") + itip_event = itip.events_from_message(message_from_string(itip_recurring_forever))0 + + rrule = kolabformat.RecurrenceRule() + rrule.setFrequency(kolabformat.RecurrenceRule.Weekly) + + event = Event() + event.set_recurrence(rrule) + event.set_start(datetime.datetime(2012, 6, 29, 9, 30, 0, tzinfo=pytz.utc)) + event.set_end(datetime.datetime(2012, 6, 29, 10, 30, 0, tzinfo=pytz.utc)) + + self.assertFalse(itip.check_event_conflict_impl(event, itip_event'xml'), "No conflict") + self.assertFalse(itip.check_event_conflict_impl(itip_event'xml', event), "No conflict, reverse") + def test_003_send_reply(self): itip_events = itip.events_from_message(message_from_string(itip_non_multipart)) itip.send_reply("resource-collection-car@example.org", itip_events, "SUMMARY=%(summary)s; STATUS=%(status)s; NAME=%(name)s;")
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.