Browse Source

Count the operations and save the config file if needed. fixes #198

master
Julio Biason 15 years ago
parent
commit
46dc141280
  1. 29
      mitterlib/network/__init__.py

29
mitterlib/network/__init__.py

@ -82,6 +82,7 @@ class Networks(object):
def __init__(self, options):
self._networks = {}
self._options = options
self._operations = 0
self.options()
@property
@ -116,6 +117,16 @@ class Networks(object):
if not setup:
raise NetworksNoNetworkSetupError
return
def _save(self):
"""Check the number of operations and, if it above the minimum value,
save the config file."""
max_count = self._options['Network_Manager']['save_count']
_log.debug('Operations %d, max %d', self._operations, max_count)
if self._operations > max_count:
self._options.save()
return
def settings(self):
"""Return a dictionary with the options that the interfaces need to
@ -136,6 +147,17 @@ class Networks(object):
conn = self.networks[shortcut]
conn.options(self._options)
# add Networks own options
self._options.add_group('Network_Manager', 'Network Manager')
self._options.add_option(
group='Network_Manager',
option='save_count',
help='Number of network operations till the config file ' \
'is saved',
type='int',
metavar='OPERATIONS',
default=5,
is_cmd_option=False)
return
def name(self, shortcut):
@ -157,6 +179,7 @@ class Networks(object):
for message in self.networks[shortcut].messages():
message.network = shortcut
result.append(message)
self._operations += 1
return result
def update(self, status, reply_to=None, network=None):
@ -168,6 +191,7 @@ class Networks(object):
results = []
for shortcut in self._targets(network):
results.append(self.networks[shortcut].update(status, reply_to))
self._operations += 1
return results
def reply_prefix(self, message):
@ -180,12 +204,14 @@ class Networks(object):
the same in the message."""
assert(isinstance(message, NetworkData))
self.networks[message.network].repost(message)
self._operations += 1
return
def favourite(self, message):
"""Change the favourite status of the message."""
assert(isinstance(message, NetworkData))
self.networks[message.network].favourite(message)
self._operations += 1
return
def delete_message(self, message, network=None):
@ -196,6 +222,7 @@ class Networks(object):
network = message.network
self.networks[network].delete_message(message)
self._operations += 1
return
def message(self, message_id, network):
@ -207,6 +234,7 @@ class Networks(object):
data = self.networks[network].message(message_id)
data.network = network
self._operations += 1
return data
def link(self, message):
@ -222,6 +250,7 @@ class Networks(object):
for message in self.networks[shortcut].replies():
message.network = shortcut
result.append(message)
self._operations += 1
return result
def available_requests(self, network=None):

Loading…
Cancel
Save