# HG changeset patch # User Paul Boddie # Date 1491154941 -7200 # Node ID 9ad1212a636dd867c01157283fb45f4e8ca49960 # Parent 91015b5e0edd6bb77519469d0d4c1123d6600b60 Made use of free/busy collections when transferring data between stores. This should ensure that the stored representations remain appropriate in the copied data. Made journal details optional for the store copying tool. diff -r 91015b5e0edd -r 9ad1212a636d tools/copy_store.py --- a/tools/copy_store.py Sun Apr 02 18:36:21 2017 +0200 +++ b/tools/copy_store.py Sun Apr 02 19:42:21 2017 +0200 @@ -83,46 +83,56 @@ freebusy = from_store.get_freebusy(user) if freebusy: - to_store.set_freebusy(user, freebusy) + to_freebusy = to_store.get_freebusy_for_update(user) + for period in freebusy: + to_freebusy.insert_period(period) + to_store.set_freebusy(user, to_freebusy) # Copy free/busy information for other users. for other in from_store.get_freebusy_others(user): freebusy = from_store.get_freebusy_for_other(user, other) if freebusy: - to_store.set_freebusy_for_other(user, freebusy, other) + to_freebusy = to_store.get_freebusy_for_other_for_update(user, other) + for period in freebusy: + to_freebusy.insert_period(period) + to_store.set_freebusy_for_other(user, to_freebusy, other) # Copy free/busy offers. offers = from_store.get_freebusy_offers(user) if offers: - to_store.set_freebusy_offers(user, offers) + to_offers = to_store.get_freebusy_offers_for_update(user) + for period in offers: + to_offers.insert_period(period) + to_store.set_freebusy_offers(user, to_offers) # For each quota group... - for quota in from_journal.get_quotas(): + if from_journal and to_journal: + for quota in from_journal.get_quotas(): - # Copy quota limits. - - to_journal.set_limits(quota, from_journal.get_limits(quota)) + # Copy quota limits. - # Copy group mappings. + to_journal.set_limits(quota, from_journal.get_limits(quota)) - to_journal.set_groups(quota, from_journal.get_groups(quota)) + # Copy group mappings. - # Copy delegates. + to_journal.set_groups(quota, from_journal.get_groups(quota)) - to_journal.set_delegates(quota, from_journal.get_delegates(quota)) + # Copy delegates. - # Copy journal details. + to_journal.set_delegates(quota, from_journal.get_delegates(quota)) + + # Copy journal details. - for group in from_journal.get_quota_users(quota): - to_journal.set_entries(quota, group, from_journal.get_entries(quota, group)) + for group in from_journal.get_quota_users(quota): + to_journal.set_entries(quota, group, from_journal.get_entries(quota, group)) - # Copy individual free/busy details. + # Copy individual free/busy details. - for other in from_journal.get_freebusy_others(quota): - to_journal.set_freebusy_for_other(quota, other, from_journal.get_freebusy_for_other(quota, other)) + for other in from_journal.get_freebusy_others(quota): + to_journal.set_freebusy_for_other(quota, other, from_journal.get_freebusy_for_other(quota, other)) # Main program. @@ -142,11 +152,11 @@ else: l.append(arg) - if len(from_store_args) not in (0, 3) or len(to_store_args) != 3: + if len(from_store_args) not in (0, 2, 3) or len(to_store_args) not in (2, 3): print >>sys.stderr, """\ Usage: %s \\ - [ ( -f | --from ) ] \\ - ( -t | --to ) + [ ( -f | --from ) [ ] ] \\ + ( -t | --to ) [ ] Need details of a destination store indicated by the -t or --to option. In addition, details of a source store may be indicated by the -f or --from @@ -156,21 +166,23 @@ # Override defaults if indicated. - getvalue = lambda value, pos=0, default=None: value and value[pos] or default + getvalue = lambda value, pos=0, default=None: value and len(value) > pos and value[pos] or default from_store_type = getvalue(from_store_args, 0, settings["STORE_TYPE"]) from_store_dir = getvalue(from_store_args, 1) from_journal_dir = getvalue(from_store_args, 2) - to_store_type, to_store_dir, to_journal_dir = to_store_args + to_store_type = getvalue(to_store_args, 0) + to_store_dir = getvalue(to_store_args, 1) + to_journal_dir = getvalue(to_store_args, 2) # Obtain store-related objects. from_store = get_store(from_store_type, from_store_dir) - from_journal = get_journal(from_store_type, from_journal_dir) + from_journal = from_journal_dir and get_journal(from_store_type, from_journal_dir) to_store = get_store(to_store_type, to_store_dir) - to_journal = get_journal(to_store_type, to_journal_dir) + to_journal = to_journal_dir and get_journal(to_store_type, to_journal_dir) # Process the store.