# HG changeset patch # User paulb # Date 1181692309 0 # Node ID 1343d239193c6221b583456cc11364c180c29974 # Parent 6f43112e81d672663e3a1e658e764577561ea576 [project @ 2007-06-12 23:51:49 by paulb] Changed the DirectoryRepository to manipulate directories instead of files. diff -r 6f43112e81d6 -r 1343d239193c WebStack/Repositories/Directory.py --- a/WebStack/Repositories/Directory.py Tue Jun 12 23:51:27 2007 +0000 +++ b/WebStack/Repositories/Directory.py Tue Jun 12 23:51:49 2007 +0000 @@ -3,7 +3,7 @@ """ Directory repositories for WebStack. -Copyright (C) 2005, 2006 Paul Boddie +Copyright (C) 2005, 2006, 2007 Paul Boddie This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -22,6 +22,7 @@ import os import time +import glob class DirectoryRepository: @@ -56,8 +57,7 @@ if not os.path.exists(path): os.mkdir(path) - f = open(self.full_path(self.new_filename), "wb") - f.close() + os.mkdir(self.full_path(self.new_filename)) # Guess the filesystem encoding. @@ -207,15 +207,15 @@ try: self.lock(self.new_filename) except KeyError: - f = open(self.edit_path(self.new_filename), "wb") - f.close() + os.mkdir(self.edit_path(self.new_filename)) try: + os.mkdir(edit_path) if opener is None: - f = open(edit_path, "wb") + f = open(os.path.join(edit_path, "data"), "wb") f.close() else: - f = opener(edit_path) + f = opener(os.path.join(edit_path, "data")) f.close() finally: self.unlock(self.new_filename) @@ -250,7 +250,9 @@ if os.path.exists(path) or os.path.exists(edit_path): while 1: try: - os.remove(path) + for filename in glob.glob(os.path.join(edit_path, "*")): + os.remove(filename) + os.rmdir(edit_path) except OSError: time.sleep(self.delay) else: @@ -264,7 +266,7 @@ edit_path = self.lock(key, create=0) try: - f = open(edit_path, "rb") + f = open(os.path.join(edit_path, "data"), "rb") s = "" try: s = f.read() @@ -284,7 +286,7 @@ edit_path = self.lock(key, create=1) try: - f = open(edit_path, "wb") + f = open(os.path.join(edit_path, "data"), "wb") try: f.write(value) finally: