Changeset 5:573fdae8b1f6 in mailjam for postman/models.py


Ignore:
Timestamp:
May 16, 2012, 11:41:47 AM (12 years ago)
Author:
Francisco de Borja Lopez Rio <borja@…>
Branch:
default
Phase:
public
Message:

Added tests for postman.daemon.Postman

Added a method to postman.daemon.Postman to "clear" all the storage associated
to a given postman instance (removing all the files from disk)

Fixed some bugs, mostly caused by typos through the sources, detected while
writing more tests

Removed the storage and archive attributes from postman.models.MailingList,
now they are methods "marked" as properties using the @property decorator.
This keeps the storage objects from being serialized into json objects by
the storage backend (de-serializing them caused some trouble and it is not
necessary at all)

Added create() and delete() methods to postman.storage.JsonStorage. the first
one ensures the path to the storage file exists (creating all subdirs if
necessary) and the second one deletes the storage file from disk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • postman/models.py

    r4 r5  
    3333    """
    3434
    35     def __init__(self, name, address, members={}, config={}, storage=None):
     35    def __init__(self, name, address, members={}, config={}):
    3636        self.name = name
    3737        self.address = address
     
    3939        self.config = config
    4040        self._validate_config() # validate the config parameters
    41         self.storage = Storage(os.path.join(self.config['storage'],
    42                                             self.address))
    43         self.archive = Storage(os.path.join(self.config['archive'],
    44                                             self.address))       
    4541       
    4642    def __repr__(self):
     
    7268            raise ValueError(address, ' is not a valid email address')
    7369        return address in self.members_addresses()
    74        
     70
     71    @property
     72    def storage(self):
     73        return Storage(os.path.join(self.config['storage'], self.address))
     74
     75    @property
     76    def archive(self):
     77        return Storage(os.path.join(self.config['archive'], self.address))
     78   
    7579    def members_addresses(self):
    7680        return self.members.keys()
     
    97101        return True
    98102
     103    def info(self):
     104        """
     105        Returns a dict we can use to add this mailing list to a postman
     106        instance
     107        """
     108        # FIXME: This code could be replaced with something that
     109        # automagically generates the dict from the instance attributes
     110        return {'name': self.name, 'address': self.address,
     111                'members': self.members, 'config': self.config}
     112
    99113    def load(self):
    100114        if self.storage.exists():
Note: See TracChangeset for help on using the changeset viewer.