1.1 --- a/tools/copy_store.py Sun Apr 02 18:36:21 2017 +0200
1.2 +++ b/tools/copy_store.py Sun Apr 02 19:42:21 2017 +0200
1.3 @@ -83,46 +83,56 @@
1.4
1.5 freebusy = from_store.get_freebusy(user)
1.6 if freebusy:
1.7 - to_store.set_freebusy(user, freebusy)
1.8 + to_freebusy = to_store.get_freebusy_for_update(user)
1.9 + for period in freebusy:
1.10 + to_freebusy.insert_period(period)
1.11 + to_store.set_freebusy(user, to_freebusy)
1.12
1.13 # Copy free/busy information for other users.
1.14
1.15 for other in from_store.get_freebusy_others(user):
1.16 freebusy = from_store.get_freebusy_for_other(user, other)
1.17 if freebusy:
1.18 - to_store.set_freebusy_for_other(user, freebusy, other)
1.19 + to_freebusy = to_store.get_freebusy_for_other_for_update(user, other)
1.20 + for period in freebusy:
1.21 + to_freebusy.insert_period(period)
1.22 + to_store.set_freebusy_for_other(user, to_freebusy, other)
1.23
1.24 # Copy free/busy offers.
1.25
1.26 offers = from_store.get_freebusy_offers(user)
1.27 if offers:
1.28 - to_store.set_freebusy_offers(user, offers)
1.29 + to_offers = to_store.get_freebusy_offers_for_update(user)
1.30 + for period in offers:
1.31 + to_offers.insert_period(period)
1.32 + to_store.set_freebusy_offers(user, to_offers)
1.33
1.34 # For each quota group...
1.35
1.36 - for quota in from_journal.get_quotas():
1.37 + if from_journal and to_journal:
1.38 + for quota in from_journal.get_quotas():
1.39
1.40 - # Copy quota limits.
1.41 -
1.42 - to_journal.set_limits(quota, from_journal.get_limits(quota))
1.43 + # Copy quota limits.
1.44
1.45 - # Copy group mappings.
1.46 + to_journal.set_limits(quota, from_journal.get_limits(quota))
1.47
1.48 - to_journal.set_groups(quota, from_journal.get_groups(quota))
1.49 + # Copy group mappings.
1.50
1.51 - # Copy delegates.
1.52 + to_journal.set_groups(quota, from_journal.get_groups(quota))
1.53
1.54 - to_journal.set_delegates(quota, from_journal.get_delegates(quota))
1.55 + # Copy delegates.
1.56
1.57 - # Copy journal details.
1.58 + to_journal.set_delegates(quota, from_journal.get_delegates(quota))
1.59 +
1.60 + # Copy journal details.
1.61
1.62 - for group in from_journal.get_quota_users(quota):
1.63 - to_journal.set_entries(quota, group, from_journal.get_entries(quota, group))
1.64 + for group in from_journal.get_quota_users(quota):
1.65 + to_journal.set_entries(quota, group, from_journal.get_entries(quota, group))
1.66
1.67 - # Copy individual free/busy details.
1.68 + # Copy individual free/busy details.
1.69
1.70 - for other in from_journal.get_freebusy_others(quota):
1.71 - to_journal.set_freebusy_for_other(quota, other, from_journal.get_freebusy_for_other(quota, other))
1.72 + for other in from_journal.get_freebusy_others(quota):
1.73 + to_journal.set_freebusy_for_other(quota, other, from_journal.get_freebusy_for_other(quota, other))
1.74
1.75 # Main program.
1.76
1.77 @@ -142,11 +152,11 @@
1.78 else:
1.79 l.append(arg)
1.80
1.81 - if len(from_store_args) not in (0, 3) or len(to_store_args) != 3:
1.82 + if len(from_store_args) not in (0, 2, 3) or len(to_store_args) not in (2, 3):
1.83 print >>sys.stderr, """\
1.84 Usage: %s \\
1.85 - [ ( -f | --from ) <store type> <store directory> <journal directory> ] \\
1.86 - ( -t | --to ) <store type> <store directory> <journal directory>
1.87 + [ ( -f | --from ) <store type> <store directory> [ <journal directory> ] ] \\
1.88 + ( -t | --to ) <store type> <store directory> [ <journal directory> ]
1.89
1.90 Need details of a destination store indicated by the -t or --to option.
1.91 In addition, details of a source store may be indicated by the -f or --from
1.92 @@ -156,21 +166,23 @@
1.93
1.94 # Override defaults if indicated.
1.95
1.96 - getvalue = lambda value, pos=0, default=None: value and value[pos] or default
1.97 + getvalue = lambda value, pos=0, default=None: value and len(value) > pos and value[pos] or default
1.98
1.99 from_store_type = getvalue(from_store_args, 0, settings["STORE_TYPE"])
1.100 from_store_dir = getvalue(from_store_args, 1)
1.101 from_journal_dir = getvalue(from_store_args, 2)
1.102
1.103 - to_store_type, to_store_dir, to_journal_dir = to_store_args
1.104 + to_store_type = getvalue(to_store_args, 0)
1.105 + to_store_dir = getvalue(to_store_args, 1)
1.106 + to_journal_dir = getvalue(to_store_args, 2)
1.107
1.108 # Obtain store-related objects.
1.109
1.110 from_store = get_store(from_store_type, from_store_dir)
1.111 - from_journal = get_journal(from_store_type, from_journal_dir)
1.112 + from_journal = from_journal_dir and get_journal(from_store_type, from_journal_dir)
1.113
1.114 to_store = get_store(to_store_type, to_store_dir)
1.115 - to_journal = get_journal(to_store_type, to_journal_dir)
1.116 + to_journal = to_journal_dir and get_journal(to_store_type, to_journal_dir)
1.117
1.118 # Process the store.
1.119