Changeset 5:573fdae8b1f6 in mailjam for postman/storage.py
- Timestamp:
- May 16, 2012, 11:41:47 AM (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
postman/storage.py
r4 r5 1 1 # -*- coding: utf-8 -*- 2 2 3 import os, json 3 import os, errno, json 4 4 5 5 6 class JsonStorage(): … … 17 18 return os.path.exists(self.path) 18 19 20 def create(self): 21 """ 22 Ensure all the subdirectories in the path to the storage file 23 exist 24 """ 25 try: 26 os.makedirs(os.path.dirname(self.path)) 27 except OSError, e: 28 # If the dir already exists do not complain, if it is 29 # any other error, raise the exception 30 if e.errno != errno.EEXIST: 31 raise 32 19 33 def jsonize(self, obj): 20 34 """ … … 45 59 46 60 def write(self, data): 61 if not self.exists(): 62 # ensure the path to the storage file exists 63 self.create() 47 64 with open(self.path, 'w') as storage: 48 65 json.dump(data, storage, sort_keys=True, indent=4, … … 64 81 return data 65 82 83 def delete(self): 84 """ 85 Remove the storage file 86 """ 87 if self.exists(): 88 os.remove(self.path) 89 return True 90 return False
Note:
See TracChangeset
for help on using the changeset viewer.