1.1 --- a/tools/make_freebusy.py Tue Sep 01 15:59:42 2015 +0200
1.2 +++ b/tools/make_freebusy.py Tue Sep 01 19:43:40 2015 +0200
1.3 @@ -29,12 +29,14 @@
1.4 from imip_store import FileStore, FilePublisher
1.5 import sys
1.6
1.7 -def make_freebusy(user, participant, store_and_publish, include_needs_action, reset_updated_list, verbose):
1.8 +def make_freebusy(store, publisher, preferences, user, participant,
1.9 + store_and_publish, include_needs_action, reset_updated_list, verbose):
1.10
1.11 """
1.12 - Make free/busy details for the records of the given 'user', generating
1.13 - details for 'participant' if not indicated as None; otherwise, generating
1.14 - free/busy details concerning the given user.
1.15 + Using the given 'store', 'publisher' and 'preferences', make free/busy
1.16 + details for the records of the given 'user', generating details for
1.17 + 'participant' if not indicated as None; otherwise, generating free/busy
1.18 + details concerning the given user.
1.19
1.20 If 'store_and_publish' is set, the stored details will be updated;
1.21 otherwise, the details will be written to standard output.
1.22 @@ -51,8 +53,6 @@
1.23 """
1.24
1.25 participant = participant or user
1.26 -
1.27 - preferences = Preferences(user)
1.28 tzid = preferences.get("TZID") or get_default_timezone()
1.29
1.30 # Get the size of the free/busy window.
1.31 @@ -63,9 +63,6 @@
1.32 window_size = 100
1.33 window_end = get_window_end(tzid, window_size)
1.34
1.35 - store = FileStore()
1.36 - publisher = FilePublisher()
1.37 -
1.38 # Get identifiers for uncancelled events either from a list of events
1.39 # providing free/busy periods at the end of the given time window, or from
1.40 # a list of all events.
1.41 @@ -132,15 +129,33 @@
1.42
1.43 # Interpret the command line arguments.
1.44
1.45 + participants = []
1.46 + args = []
1.47 + store_dir = []
1.48 + publishing_dir = []
1.49 + preferences_dir = []
1.50 + ignored = []
1.51 +
1.52 + # Collect user details first, switching to other arguments when encountering
1.53 + # switches.
1.54 +
1.55 + l = participants
1.56 +
1.57 + for arg in sys.argv[1:]:
1.58 + if arg in ("-n", "-s", "-v", "-r"):
1.59 + args.append(arg)
1.60 + l = ignored
1.61 + elif arg == "-S":
1.62 + l = store_dir
1.63 + elif arg == "-P":
1.64 + l = publishing_dir
1.65 + elif arg == "-p":
1.66 + l = preferences_dir
1.67 + else:
1.68 + l.append(arg)
1.69 +
1.70 try:
1.71 - user = sys.argv[1]
1.72 - args = sys.argv[2:]
1.73 - participant = args and args[0] not in ("-n", "-s", "-v", "-r") and args[0] or None
1.74 - store_and_publish = "-s" in args
1.75 - include_needs_action = "-n" in args
1.76 - reset_updated_list = "-r" in args
1.77 - verbose = "-v" in args
1.78 -
1.79 + user = participants[0]
1.80 except IndexError:
1.81 print >>sys.stderr, """\
1.82 Need a user and an optional participant (if different from the user),
1.83 @@ -151,14 +166,39 @@
1.84 """
1.85 sys.exit(1)
1.86
1.87 + # Define any other participant of interest plus options.
1.88 +
1.89 + participant = participants[1:] and participants[1] or None
1.90 + store_and_publish = "-s" in args
1.91 + include_needs_action = "-n" in args
1.92 + reset_updated_list = "-r" in args
1.93 + verbose = "-v" in args
1.94 +
1.95 + # Override defaults if indicated.
1.96 +
1.97 + store_dir = store_dir and store_dir[0] or None
1.98 + publishing_dir = publishing_dir and publishing_dir[0] or None
1.99 + preferences_dir = preferences_dir and preferences_dir[0] or None
1.100 +
1.101 + # Obtain store-related objects.
1.102 +
1.103 + store = FileStore(store_dir)
1.104 + publisher = FilePublisher(publishing_dir)
1.105 + preferences = Preferences(user, preferences_dir)
1.106 +
1.107 + # Obtain a list of users for processing.
1.108 +
1.109 if user in ("*", "all"):
1.110 - users = FileStore().get_users()
1.111 + users = store.get_users()
1.112 else:
1.113 users = [user]
1.114
1.115 + # Process the given users.
1.116 +
1.117 for user in users:
1.118 if verbose:
1.119 print >>sys.stderr, user
1.120 - make_freebusy(user, participant, store_and_publish, include_needs_action, reset_updated_list, verbose)
1.121 + make_freebusy(store, publisher, preferences, user, participant,
1.122 + store_and_publish, include_needs_action, reset_updated_list, verbose)
1.123
1.124 # vim: tabstop=4 expandtab shiftwidth=4