imip-agent

Changeset

808:edb600931518
2015-10-05 Paul Boddie raw files shortlog changelog graph Preserve counter-proposals when dequeuing requests: counter-proposal removal should be done explicitly. Changed exists usage to isdir and isfile.
imip_store.py (file)
     1.1 --- a/imip_store.py	Mon Oct 05 20:10:38 2015 +0200
     1.2 +++ b/imip_store.py	Mon Oct 05 23:53:38 2015 +0200
     1.3 @@ -25,7 +25,7 @@
     1.4  from imiptools.dates import format_datetime, get_datetime, to_timezone
     1.5  from imiptools.filesys import fix_permissions, FileBase
     1.6  from imiptools.period import FreeBusyPeriod
     1.7 -from os.path import exists, isfile, join
     1.8 +from os.path import isdir, isfile, join
     1.9  from os import listdir, remove, rmdir
    1.10  from time import sleep
    1.11  import codecs
    1.12 @@ -213,7 +213,7 @@
    1.13          "Return a list of event identifiers."
    1.14  
    1.15          filename = self.get_object_in_store(user, "objects")
    1.16 -        if not filename or not exists(filename):
    1.17 +        if not filename or not isdir(filename):
    1.18              return None
    1.19  
    1.20          return [name for name in listdir(filename) if isfile(join(filename, name))]
    1.21 @@ -258,7 +258,7 @@
    1.22          """
    1.23  
    1.24          filename = self.get_event_filename(user, uid, recurrenceid)
    1.25 -        if not filename or not exists(filename):
    1.26 +        if not filename or not isfile(filename):
    1.27              return None
    1.28  
    1.29          return filename and self._get_object(user, filename)
    1.30 @@ -283,7 +283,7 @@
    1.31          "Get the event for the given 'user' with the given 'uid'."
    1.32  
    1.33          filename = self.get_complete_event_filename(user, uid)
    1.34 -        if not filename or not exists(filename):
    1.35 +        if not filename or not isfile(filename):
    1.36              return None
    1.37  
    1.38          return filename and self._get_object(user, filename)
    1.39 @@ -355,7 +355,7 @@
    1.40          """
    1.41  
    1.42          filename = self.get_object_in_store(user, "recurrences", uid)
    1.43 -        if not filename or not exists(filename):
    1.44 +        if not filename or not isdir(filename):
    1.45              return []
    1.46  
    1.47          return [name for name in listdir(filename) if isfile(join(filename, name))]
    1.48 @@ -368,7 +368,7 @@
    1.49          """
    1.50  
    1.51          filename = self.get_object_in_store(user, "cancellations", "recurrences", uid)
    1.52 -        if not filename or not exists(filename):
    1.53 +        if not filename or not isdir(filename):
    1.54              return []
    1.55  
    1.56          return [name for name in listdir(filename) if isfile(join(filename, name))]
    1.57 @@ -396,7 +396,7 @@
    1.58          """
    1.59  
    1.60          filename = self.get_recurrence_filename(user, uid, recurrenceid)
    1.61 -        if not filename or not exists(filename):
    1.62 +        if not filename or not isfile(filename):
    1.63              return None
    1.64  
    1.65          return filename and self._get_object(user, filename)
    1.66 @@ -452,7 +452,7 @@
    1.67          """
    1.68  
    1.69          filename = self.get_object_in_store(user, "freebusy-providers")
    1.70 -        if not filename or not exists(filename):
    1.71 +        if not filename or not isfile(filename):
    1.72              return None
    1.73  
    1.74          # Attempt to read providers, with a declaration of the datetime
    1.75 @@ -560,7 +560,7 @@
    1.76          "Get free/busy details for the given 'user'."
    1.77  
    1.78          filename = self.get_object_in_store(user, name or "freebusy")
    1.79 -        if not filename or not exists(filename):
    1.80 +        if not filename or not isfile(filename):
    1.81              return []
    1.82          else:
    1.83              return map(lambda t: FreeBusyPeriod(*t),
    1.84 @@ -571,7 +571,7 @@
    1.85          "For the given 'user', get free/busy details for the 'other' user."
    1.86  
    1.87          filename = self.get_object_in_store(user, "freebusy-other", other)
    1.88 -        if not filename or not exists(filename):
    1.89 +        if not filename or not isfile(filename):
    1.90              return []
    1.91          else:
    1.92              return map(lambda t: FreeBusyPeriod(*t),
    1.93 @@ -642,7 +642,7 @@
    1.94          "Get requests for the given 'user' from the given 'queue'."
    1.95  
    1.96          filename = self.get_object_in_store(user, queue)
    1.97 -        if not filename or not exists(filename):
    1.98 +        if not filename or not isfile(filename):
    1.99              return None
   1.100  
   1.101          return self._get_table_atomic(user, filename, [(1, None), (2, None)])
   1.102 @@ -733,15 +733,7 @@
   1.103          result = []
   1.104  
   1.105          for request in requests:
   1.106 -            if request[:2] == (uid, recurrenceid):
   1.107 -
   1.108 -                # Remove associated objects.
   1.109 -
   1.110 -                type = request[2]
   1.111 -                if type == "COUNTER":
   1.112 -                    self.remove_counters(user, uid, recurrenceid)
   1.113 -
   1.114 -            else:
   1.115 +            if request[:2] != (uid, recurrenceid):
   1.116                  result.append(request)
   1.117  
   1.118          self.set_requests(user, result)
   1.119 @@ -774,7 +766,7 @@
   1.120          """
   1.121  
   1.122          filename = self.get_event_filename(user, uid, recurrenceid, "counters")
   1.123 -        if not filename or not exists(filename):
   1.124 +        if not filename or not isdir(filename):
   1.125              return False
   1.126  
   1.127          return [name for name in listdir(filename) if isfile(join(filename, name))]
   1.128 @@ -814,7 +806,7 @@
   1.129          """
   1.130  
   1.131          filename = self.get_event_filename(user, uid, recurrenceid, "counters")
   1.132 -        if not filename:
   1.133 +        if not filename or not isdir(filename):
   1.134              return False
   1.135  
   1.136          removed = False
   1.137 @@ -833,7 +825,7 @@
   1.138          """
   1.139  
   1.140          filename = self.get_event_filename(user, uid, recurrenceid, "counters", other)
   1.141 -        if not filename:
   1.142 +        if not filename or not isfile(filename):
   1.143              return False
   1.144  
   1.145          return self._remove_object(filename)
   1.146 @@ -851,7 +843,7 @@
   1.147          filename = self.get_event_filename(user, uid, recurrenceid)
   1.148          cancelled_filename = self.get_event_filename(user, uid, recurrenceid, "cancellations")
   1.149  
   1.150 -        if filename and cancelled_filename and exists(filename):
   1.151 +        if filename and cancelled_filename and isfile(filename):
   1.152              return self.move_object(filename, cancelled_filename)
   1.153  
   1.154          return False
   1.155 @@ -885,7 +877,7 @@
   1.156  
   1.157          filename = self.get_event_filename(user, uid, recurrenceid, "cancellations")
   1.158  
   1.159 -        if filename and exists(filename):
   1.160 +        if filename and isfile(filename):
   1.161              return self._remove_object(filename)
   1.162  
   1.163          return False