|
|
@ -83,6 +83,7 @@ class Networks(object): |
|
|
|
self._networks = {} |
|
|
|
self._networks = {} |
|
|
|
self._options = options |
|
|
|
self._options = options |
|
|
|
self._operations = 0 |
|
|
|
self._operations = 0 |
|
|
|
|
|
|
|
self._proxy_handler = None |
|
|
|
self.options() |
|
|
|
self.options() |
|
|
|
|
|
|
|
|
|
|
|
@property |
|
|
|
@property |
|
|
@ -130,6 +131,26 @@ class Networks(object): |
|
|
|
_log.debug('Config file saved') |
|
|
|
_log.debug('Config file saved') |
|
|
|
return |
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _proxy(self): |
|
|
|
|
|
|
|
"""Check and install the proxy.""" |
|
|
|
|
|
|
|
if not self._options['NetworkManager']['proxy']: |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self._proxy_handler: |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proxy = self._options['NetworkManager']['proxy'] |
|
|
|
|
|
|
|
if not '://' in proxy: |
|
|
|
|
|
|
|
proxy = 'http://' + proxy |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_log.debug('Installing proxy ' + proxy) |
|
|
|
|
|
|
|
self._proxy_handler = urllib2.ProxyHandler({ |
|
|
|
|
|
|
|
'http': proxy, |
|
|
|
|
|
|
|
'https': proxy}) |
|
|
|
|
|
|
|
opener = urllib2.build_opener(self._proxy_handler) |
|
|
|
|
|
|
|
urllib2.install_opener(opener) |
|
|
|
|
|
|
|
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 |
|
|
|
setup.""" |
|
|
|
setup.""" |
|
|
@ -162,6 +183,15 @@ class Networks(object): |
|
|
|
type='int', |
|
|
|
type='int', |
|
|
|
metavar='SECONDS', |
|
|
|
metavar='SECONDS', |
|
|
|
default=120) |
|
|
|
default=120) |
|
|
|
|
|
|
|
self._options.add_option( |
|
|
|
|
|
|
|
'--proxy', |
|
|
|
|
|
|
|
group='NetworkManager', |
|
|
|
|
|
|
|
option='proxy', |
|
|
|
|
|
|
|
help='Proxy server (Note: This is not needed on Windows " \ |
|
|
|
|
|
|
|
"and OS X systems as Mitter will use the system " \ |
|
|
|
|
|
|
|
"value.)', |
|
|
|
|
|
|
|
metavar='SERVER', |
|
|
|
|
|
|
|
default='') |
|
|
|
self._options.add_option( |
|
|
|
self._options.add_option( |
|
|
|
group='NetworkManager', |
|
|
|
group='NetworkManager', |
|
|
|
option='save_count', |
|
|
|
option='save_count', |
|
|
@ -187,6 +217,7 @@ class Networks(object): |
|
|
|
def messages(self, network=None): |
|
|
|
def messages(self, network=None): |
|
|
|
"""Return a list of NetworkData objects for the main "timeline" (the |
|
|
|
"""Return a list of NetworkData objects for the main "timeline" (the |
|
|
|
default list presented to the user.)""" |
|
|
|
default list presented to the user.)""" |
|
|
|
|
|
|
|
self._proxy() |
|
|
|
result = [] |
|
|
|
result = [] |
|
|
|
for shortcut in self._targets(network): |
|
|
|
for shortcut in self._targets(network): |
|
|
|
for message in self.networks[shortcut].messages(): |
|
|
|
for message in self.networks[shortcut].messages(): |
|
|
@ -201,6 +232,7 @@ class Networks(object): |
|
|
|
|
|
|
|
|
|
|
|
def update(self, status, reply_to=None, network=None): |
|
|
|
def update(self, status, reply_to=None, network=None): |
|
|
|
"""Update the user status. Must return the id for the new status.""" |
|
|
|
"""Update the user status. Must return the id for the new status.""" |
|
|
|
|
|
|
|
self._proxy() |
|
|
|
if reply_to and isinstance(reply_to, NetworkData): |
|
|
|
if reply_to and isinstance(reply_to, NetworkData): |
|
|
|
# If you pass a NetworkData object, we get the proper network |
|
|
|
# If you pass a NetworkData object, we get the proper network |
|
|
|
network = reply_to.network |
|
|
|
network = reply_to.network |
|
|
@ -215,12 +247,14 @@ class Networks(object): |
|
|
|
def reply_prefix(self, message): |
|
|
|
def reply_prefix(self, message): |
|
|
|
"""Return the prefix to be used in the reply for that message.""" |
|
|
|
"""Return the prefix to be used in the reply for that message.""" |
|
|
|
assert(isinstance(message, NetworkData)) |
|
|
|
assert(isinstance(message, NetworkData)) |
|
|
|
|
|
|
|
self._proxy() |
|
|
|
return self.networks[message.network].reply_prefix(message) |
|
|
|
return self.networks[message.network].reply_prefix(message) |
|
|
|
|
|
|
|
|
|
|
|
def repost(self, message): |
|
|
|
def repost(self, message): |
|
|
|
"""Repost a message in the user's timeline. The network used is |
|
|
|
"""Repost a message in the user's timeline. The network used is |
|
|
|
the same in the message.""" |
|
|
|
the same in the message.""" |
|
|
|
assert(isinstance(message, NetworkData)) |
|
|
|
assert(isinstance(message, NetworkData)) |
|
|
|
|
|
|
|
self._proxy() |
|
|
|
self.networks[message.network].repost(message) |
|
|
|
self.networks[message.network].repost(message) |
|
|
|
self._operations += 1 |
|
|
|
self._operations += 1 |
|
|
|
self._save() |
|
|
|
self._save() |
|
|
@ -229,6 +263,7 @@ class Networks(object): |
|
|
|
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._proxy() |
|
|
|
self.networks[message.network].favourite(message) |
|
|
|
self.networks[message.network].favourite(message) |
|
|
|
self._operations += 1 |
|
|
|
self._operations += 1 |
|
|
|
self._save() |
|
|
|
self._save() |
|
|
@ -241,6 +276,7 @@ class Networks(object): |
|
|
|
if isinstance(message, NetworkData): |
|
|
|
if isinstance(message, NetworkData): |
|
|
|
network = message.network |
|
|
|
network = message.network |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self._proxy() |
|
|
|
self.networks[network].delete_message(message) |
|
|
|
self.networks[network].delete_message(message) |
|
|
|
self._operations += 1 |
|
|
|
self._operations += 1 |
|
|
|
self._save() |
|
|
|
self._save() |
|
|
@ -253,6 +289,7 @@ class Networks(object): |
|
|
|
if not network in self.networks: |
|
|
|
if not network in self.networks: |
|
|
|
raise NetworksNoSuchNetworkError(network) |
|
|
|
raise NetworksNoSuchNetworkError(network) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self._proxy() |
|
|
|
data = self.networks[network].message(message_id) |
|
|
|
data = self.networks[network].message(message_id) |
|
|
|
data.network = network |
|
|
|
data.network = network |
|
|
|
self._operations += 1 |
|
|
|
self._operations += 1 |
|
|
@ -268,6 +305,7 @@ class Networks(object): |
|
|
|
"""Return a list of NetworkData objects for the replies for the user |
|
|
|
"""Return a list of NetworkData objects for the replies for the user |
|
|
|
messages.""" |
|
|
|
messages.""" |
|
|
|
result = [] |
|
|
|
result = [] |
|
|
|
|
|
|
|
self._proxy() |
|
|
|
for shortcut in self._targets(network): |
|
|
|
for shortcut in self._targets(network): |
|
|
|
for message in self.networks[shortcut].replies(): |
|
|
|
for message in self.networks[shortcut].replies(): |
|
|
|
message.network = shortcut |
|
|
|
message.network = shortcut |
|
|
|