Changeset 5:573fdae8b1f6 in mailjam for postman/daemon.py
- Timestamp:
- May 16, 2012, 11:41:47 AM (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
postman/daemon.py
r2 r5 42 42 for m in self.mailings.keys(): 43 43 self.mailings[m].save() 44 return True 45 return False 44 46 45 47 def load(self): … … 59 61 mailing.load() 60 62 self.mailings[address] = mailing 61 63 return True 64 return False 62 65 63 def add_mailing_list(self, list_info={}): 66 def clear(self): 67 """ 68 Delete all stored data from disk (useful for testing). 69 DANGER: Calling this method will remove all data from disk, leaving the 70 postman instance with no persistence data, if the postman process die, 71 before another .save() call is made, all data will be lost. 72 """ 73 if self.dbs['mailings'].exists(): 74 # We do not delete each mailing list file, but only the file 75 # containing the list of existing mailing lists 76 self.dbs['mailings'].delete() 77 return True 78 return False 79 80 def add_mailing_list(self, info={}): 64 81 """ 65 82 Add a new mailing list to this postman instance. expects one parameter, 66 list_info, which is a dictionary that should contain, at least, the83 info, which is a dictionary that should contain, at least, the 67 84 following keys: 68 85 … … 72 89 73 90 """ 74 if not isinstance( list_info, dict):75 raise TypeError( list_info, ' is not a valid dictionary')91 if not isinstance(info, dict): 92 raise TypeError(info, ' is not a valid dictionary') 76 93 77 if 'name' not in list_info.keys() or \ 78 'address' not in list_info.keys() or \ 79 'members' not in list_info.keys(): 80 raise ValueError(list_info, ' does not seem to be a valid configuration') 94 if 'name' not in info.keys() or \ 95 'address' not in info.keys() or \ 96 'members' not in info.keys() or \ 97 'config' not in info.keys(): 98 raise ValueError(info, ' does not seem to be a valid configuration') 81 99 82 if list_info['address'] in self.mailings_addresses:83 raise IndexError( list_info['address'],100 if info['address'] in self.mailings_addresses: 101 raise IndexError(info['address'], 84 102 ' has been already added to postman') 85 103 86 mailing = MailingList( list_info['name'], list_info['address'],87 list_info['members'])104 mailing = MailingList(info['name'], info['address'], 105 info['members'], info['config']) 88 106 self.mailings[mailing.address] = mailing 89 107 self.mailings_addresses.append(mailing.address) 90 108 # After adding new mailings, save them to disk 91 109 self.save() 110 return True 92 111 93 112 def add_mailing_member(self, member_addr=None, list_addr=None): … … 109 128 raise IndexError(list_addr, ' is not a valid mailing list') 110 129 111 member = Member(member_addr) 112 130 added = self.mailings[list_addr].add_member_by_address(member_addr) 131 if added: 132 self.save() 133 return added 113 134 114 135
Note:
See TracChangeset
for help on using the changeset viewer.