1.1 --- a/MoinMessage.py Fri Jan 18 00:36:13 2013 +0100
1.2 +++ b/MoinMessage.py Sat Jan 19 21:18:36 2013 +0100
1.3 @@ -14,7 +14,6 @@
1.4 from subprocess import Popen, PIPE
1.5 from tempfile import mkstemp
1.6 from urlparse import urlsplit
1.7 -from MoinMoin.util import lock
1.8 import httplib
1.9 import os
1.10
1.11 @@ -131,83 +130,6 @@
1.12
1.13 return mailbox
1.14
1.15 -class MessageStore:
1.16 -
1.17 - "A page-specific message store."
1.18 -
1.19 - def __init__(self, page):
1.20 -
1.21 - "Initialise a message store for the given 'page'."
1.22 -
1.23 - self.path = page.getPagePath("messages")
1.24 - self.next_path = os.path.join(self.path, "next")
1.25 - lock_dir = page.getPagePath("message-locks")
1.26 - self.lock = lock.WriteLock(lock_dir)
1.27 -
1.28 - def get_next(self):
1.29 -
1.30 - "Return the next message number."
1.31 -
1.32 - next = self.read_next()
1.33 - if not next:
1.34 - next = self.deduce_next()
1.35 - self.write_next(next)
1.36 - return next
1.37 -
1.38 - def deduce_next(self):
1.39 -
1.40 - "Deduce the next message number from the existing message files."
1.41 -
1.42 - return max([int(filename) for filename in os.listdir(self.path) if filename.isdigit()] or [0]) + 1
1.43 -
1.44 - def read_next(self):
1.45 -
1.46 - "Read the next message number from a special file."
1.47 -
1.48 - if not os.path.exists(self.next_path):
1.49 - return 0
1.50 -
1.51 - f = open(self.next_path)
1.52 - try:
1.53 - try:
1.54 - return int(f.read())
1.55 - except ValueError:
1.56 - return 0
1.57 - finally:
1.58 - f.close()
1.59 -
1.60 - def write_next(self, next):
1.61 -
1.62 - "Write the 'next' message number to a special file."
1.63 -
1.64 - f = open(self.next_path, "w")
1.65 - try:
1.66 - f.write(str(next))
1.67 - finally:
1.68 - f.close()
1.69 -
1.70 - def write_message(self, message, next):
1.71 -
1.72 - "Write the given 'message' to a file with the given 'next' message number."
1.73 -
1.74 - f = open(os.path.join(self.path, str(next)), "w")
1.75 - try:
1.76 - f.write(message.as_string())
1.77 - finally:
1.78 - f.close()
1.79 -
1.80 - def append(self, message):
1.81 -
1.82 - "Append the given 'message' to the store."
1.83 -
1.84 - self.lock.acquire()
1.85 - try:
1.86 - next = self.get_next()
1.87 - self.write_message(message, next)
1.88 - self.write_next(next + 1)
1.89 - finally:
1.90 - self.lock.release()
1.91 -
1.92 class MoinMessageError(Exception):
1.93 pass
1.94