Commit 3baea2f5 authored by Florian Fuchs's avatar Florian Fuchs

Added archival options.

parents bf3a8ae1 754b94dc
......@@ -7,7 +7,8 @@ NEWS for mailman.client
* Port to Python 3.4.
* Run test suite with `tox`.
* Use vcrpy for HTTP testing
* Use vcrpy for HTTP testing.
* Add list archiver access.
1.0.0a1 (2014-03-15)
......
......@@ -446,6 +446,14 @@ class _List:
entries.append(request)
return entries
@property
def archivers(self):
"""
Returns a _ListArchivers instance.
"""
url = 'lists/{0}/archivers'.format(self.list_id)
return _ListArchivers(self._connection, url, self)
def add_owner(self, address):
self.add_role('owner', address)
......@@ -551,6 +559,62 @@ class _List:
'lists/{0}'.format(self.fqdn_listname), None, 'DELETE')
class _ListArchivers:
"""
Represents the activation status for each site-wide available archiver
for a given list.
"""
def __init__(self, connection, url, list_obj):
"""
:param connection: An API connection object.
:type connection: _Connection.
:param url: The API url of the list's archiver endpoint.
:param url: str.
:param list_obj: The corresponding list object.
:type list_obj: _List.
"""
self._connection = connection
self._url = url
self._list_obj = list_obj
self._info = None
def __repr__(self):
self._get_info()
return '<Archivers on "{0}">'.format(self._list_obj.list_id)
def _get_info(self):
# Get data from API; only once per instance.
if self._info is None:
response, content = self._connection.call(self._url)
# Remove `http_etag` from dictionary, we only want
# the archiver info.
content.pop('http_etag')
self._info = content
def __iter__(self):
self._get_info()
for archiver in self._info:
yield self._info[archiver]
def __getitem__(self, key):
self._get_info()
# No precautions against KeyError, should behave like a dict.
return self._info[key]
def __setitem__(self, key, value):
self._get_info()
# No precautions against KeyError, should behave like a dict.
self._info[key] = value
# Update archiver status via the API.
self._connection.call(self._url, self._info, method='PUT')
def keys(self):
self._get_info()
for key in self._info:
yield key
class _Member:
def __init__(self, connection, url):
......
j==================
===================
Mailman REST client
===================
......@@ -687,3 +687,44 @@ Messages held for moderation can be listed on a per list basis.
>>> len(test_one.held)
0
Archivers
=========
Each list object has an ``archivers`` attribute.
>>> archivers = test_one.archivers
>>> print(archivers)
<Archivers on "test-one.example.com">
The activation status of each available archiver can be accessed like a
key in a dictionary.
>>> archivers = test_one.archivers
>>> for archiver in sorted(archivers.keys()):
... print('{0}: {1}'.format(archiver, archivers[archiver]))
mail-archive: True
mhonarc: True
prototype: False
>>> archivers['mail-archive']
True
>>> archivers['mhonarc']
True
They can also be set like items in dictionary.
>>> archivers['mail-archive'] = False
>>> archivers['mhonarc'] = False
So if we get a new ``archivers`` object from the API (by accessing the
list's archiver attribute again), we can see that the archiver stati
have now been set.
>>> archivers = test_one.archivers
>>> archivers['mail-archive']
False
>>> archivers['mhonarc']
False
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment