chiark / gitweb /
Use a per-exchange-calendar cache file
authorMatthew Vernon <mv3@sanger.ac.uk>
Tue, 20 Nov 2018 17:54:23 +0000 (17:54 +0000)
committerMatthew Vernon <mv3@sanger.ac.uk>
Tue, 20 Nov 2018 17:54:23 +0000 (17:54 +0000)
We now use ~/.gooswapper to store our cache files (rather than CWD),
and also use one cache file per exchange calendar ID.

NOTES.org
gooswapper.py

index e565312..dc2c503 100644 (file)
--- a/NOTES.org
+++ b/NOTES.org
@@ -10,7 +10,7 @@
   appear as exchangelib.items.MeetingRequest AFAICT; report upstream?
 - [X] the is_recurring field is lies - use RecurringMaster type instead
 - [X] command-line arguments for accounts
-- [ ] support multiple cache files (e.g. 1 per exchange calendar)
+- [X] support multiple cache files (e.g. 1 per exchange calendar)
 - [ ] note which linked account corresponds with which cache file
 - [ ] configuration file?
 - [ ] bi-directional syncing...
index 3b5300c..24b7a2f 100644 (file)
@@ -20,6 +20,7 @@
 import sys
 import getpass
 import os
+import os.path
 import pickle
 import collections
 import argparse
@@ -58,10 +59,10 @@ flow = oauth2client.client.OAuth2WebServerFlow(gcal_client_id,
                                                gcal_client_secret,
                                                scope)
 
+gsdir = os.path.expanduser("~/.gooswapper")
+gcal_authpath = gsdir + "/.gooswap_gcal_creds.dat"
 
-gcal_authpath=".gooswap_gcal_creds.dat"
-
-cachepath=".gooswapcache"
+cachepath=None
 
 exchange_credential = None
 
@@ -437,9 +438,17 @@ def main():
     else:
         gcal_id = args.gcalid
 
+    #Make our config dir if it doesn't exist
+    if not os.path.exists(gsdir):
+        os.mkdir(gsdir,0o700)
+    #Cache file is specific to the Exchange calendar
+    global cachepath
+    cachepath = gsdir + "/.cache-%s" % \
+                (args.exchemail.replace('@','_').replace('/','_'))
+
     #log in to the accounts
     ex_account = ex_login(args.exchuser,args.exchemail,
-                          ".gooswapper_exch_conf.dat")
+                          gsdir+"/.gooswapper_exch_conf.dat")
     gcal_account = gcal_login(args)
     gcal_tz = get_gcal_timezone(gcal_account,gcal_id)