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): def __init__(self, options):
self._networks = {} self._networks = {}
self._options = options self._options = options
self._operations = 0
self.options() self.options()
@property @property
@ -116,6 +117,16 @@ class Networks(object):
if not setup: if not setup:
raise NetworksNoNetworkSetupError 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): def settings(self):
"""Return a dictionary with the options that the interfaces need to """Return a dictionary with the options that the interfaces need to
@ -136,6 +147,17 @@ class Networks(object):
conn = self.networks[shortcut] conn = self.networks[shortcut]
conn.options(self._options) 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 return
def name(self, shortcut): def name(self, shortcut):
@ -157,6 +179,7 @@ class Networks(object):
for message in self.networks[shortcut].messages(): for message in self.networks[shortcut].messages():
message.network = shortcut message.network = shortcut
result.append(message) result.append(message)
self._operations += 1
return result return result
def update(self, status, reply_to=None, network=None): def update(self, status, reply_to=None, network=None):
@ -168,6 +191,7 @@ class Networks(object):
results = [] results = []
for shortcut in self._targets(network): for shortcut in self._targets(network):
results.append(self.networks[shortcut].update(status, reply_to)) results.append(self.networks[shortcut].update(status, reply_to))
self._operations += 1
return results return results
def reply_prefix(self, message): def reply_prefix(self, message):
@ -180,12 +204,14 @@ class Networks(object):
the same in the message.""" the same in the message."""
assert(isinstance(message, NetworkData)) assert(isinstance(message, NetworkData))
self.networks[message.network].repost(message) self.networks[message.network].repost(message)
self._operations += 1
return return
def favourite(self, message): def favourite(self, message):
"""Change the favourite status of the message.""" """Change the favourite status of the message."""
assert(isinstance(message, NetworkData)) assert(isinstance(message, NetworkData))
self.networks[message.network].favourite(message) self.networks[message.network].favourite(message)
self._operations += 1
return return
def delete_message(self, message, network=None): def delete_message(self, message, network=None):
@ -196,6 +222,7 @@ class Networks(object):
network = message.network network = message.network
self.networks[network].delete_message(message) self.networks[network].delete_message(message)
self._operations += 1
return return
def message(self, message_id, network): def message(self, message_id, network):
@ -207,6 +234,7 @@ class Networks(object):
data = self.networks[network].message(message_id) data = self.networks[network].message(message_id)
data.network = network data.network = network
self._operations += 1
return data return data
def link(self, message): def link(self, message):
@ -222,6 +250,7 @@ class Networks(object):
for message in self.networks[shortcut].replies(): for message in self.networks[shortcut].replies():
message.network = shortcut message.network = shortcut
result.append(message) result.append(message)
self._operations += 1
return result return result
def available_requests(self, network=None): def available_requests(self, network=None):

Loading…
Cancel
Save