bind_other works for Bat + Torrent

This commit is contained in:
Jedrzej Nowak 2015-10-12 10:38:53 +02:00
parent 4bbc3f213d
commit af02f05475
3 changed files with 15 additions and 20 deletions

View File

@ -83,16 +83,23 @@ class SolarTransport(object):
pass
def get_transport_data(self, resource, name=None):
key = '_used_transport_%s' % self._mode
# TODO: naive object local cache
try:
transport = resource._used_transport
transport = getattr(resource, key)
except AttributeError:
if name is None:
name = self.preffered_transport_name
transport = next(x for x in resource.transports() if x['name'] == name)
setattr(resource, '_used_transport', transport)
setattr(resource, key, transport)
return transport
def other(self, resource):
return self._other
def bind_with(self, other):
self._other = other
class SyncTransport(SolarTransport):
"""
@ -106,14 +113,6 @@ class SyncTransport(SolarTransport):
super(SyncTransport, self).__init__()
self.executors = []
def bind_with(self, other):
# we migth add there something later
# like compat checking etc
self._other = other
def other(self, resource):
return self._other
def copy(self, resource, *args, **kwargs):
pass
@ -160,11 +159,6 @@ class RunTransport(SolarTransport):
def get_result(self, *args, **kwargs):
raise NotImplementedError()
def bind_with(self, other):
# we migth add there something later
# like compat checking etc
self.other = other
def run(self, resource, *args, **kwargs):
pass

View File

@ -52,9 +52,10 @@ class BatTransport(SolarTransport):
if not selected:
raise Exception("No valid transport found")
instance = self._bat_transports[selected['name']]()
setattr(resource, '_used_transport', selected)
setattr(resource, '_used_transport_%s' % instance._mode, selected)
setattr(resource, key_name, instance)
self._used_transports.append(instance)
instance.bind_with(self._other_remember)
return instance
# return self._bat_transports[selected['name']]
@ -62,6 +63,10 @@ class BatTransport(SolarTransport):
self.select_valid_transport(resource)
return super(BatTransport, self).get_transport_data(resource, *args, **kwargs)
def bind_with(self, other):
self._other_remember = other
class BatSyncTransport(SyncTransport, BatTransport):
preffered_transport_name = None

View File

@ -122,10 +122,6 @@ class TorrentSyncTransport(SyncTransport):
'"%s"' % get_args]
self.other(resource).run(resource, *cmd, use_sudo=use_sudo)
def other(self, resource):
# TODO: implement it
pass
def preprocess(self, executor):
_from, _to, use_sudo = executor.params
self._create_single_torrent(executor.resource, _from, _to, use_sudo)