PIM: sync.py --sync-flags

Arbitrary sync flags can be passed to SyncPeerWithFlags() with the
new --sync-flags command line parameter. The value of that parameter
must be a JSON formatted hash.

The advantage of this approach over explicit command line parameters
(like --progress-frequency) is that we do not need to add further code
when adding new flags. We can also pass intentionally broken flags
to check the PIM Managers error handling.

The downside is that it is a bit less user-friendly.

With this change, progress frequency and PBAP sync can be set in two
ways, either as part of --sync-flags or with the individual command
line parameters.  The latter override --sync-flags.
This commit is contained in:
Patrick Ohly 2014-07-17 15:38:22 +02:00
parent 1a9e55bfe6
commit bc392b99f5
1 changed files with 5 additions and 1 deletions

View File

@ -36,6 +36,7 @@ import functools
import sys
import traceback
import itertools
import json
import time
from optparse import OptionParser
@ -66,6 +67,9 @@ parser.add_option("", "--poll-progress",
parser.add_option("-m", "--mode",
action="store", default='',
help="Override default PBAP sync mode. One of 'all', 'text', 'incremental' (default).")
parser.add_option("", "--sync-flags",
action="store", default='',
help="Additionall SyncPeerWithFlags() flags in JSON notation. For example: { 'pbap-chunk-transfer-time': 20, 'pbap-chunk-time-lambda': 0.5, 'pbap-chunk-max-count-photo': 100 }")
parser.add_option("-f", "--progress-frequency",
action="store", type="float", default=0.0,
help="Override default progress event frequency.")
@ -237,7 +241,7 @@ if not error and options.sync:
pull_progress()
print 'syncing peer %s' % peername
flags = {}
flags = json.loads(options.sync_flags)
if options.progress_frequency != 0.0:
flags['progress-frequency'] = options.progress_frequency
if options.mode: