bind_other works for Bat + Torrent
This commit is contained in:
parent
4bbc3f213d
commit
af02f05475
@ -83,16 +83,23 @@ class SolarTransport(object):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def get_transport_data(self, resource, name=None):
|
def get_transport_data(self, resource, name=None):
|
||||||
|
key = '_used_transport_%s' % self._mode
|
||||||
# TODO: naive object local cache
|
# TODO: naive object local cache
|
||||||
try:
|
try:
|
||||||
transport = resource._used_transport
|
transport = getattr(resource, key)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
if name is None:
|
if name is None:
|
||||||
name = self.preffered_transport_name
|
name = self.preffered_transport_name
|
||||||
transport = next(x for x in resource.transports() if x['name'] == name)
|
transport = next(x for x in resource.transports() if x['name'] == name)
|
||||||
setattr(resource, '_used_transport', transport)
|
setattr(resource, key, transport)
|
||||||
return transport
|
return transport
|
||||||
|
|
||||||
|
def other(self, resource):
|
||||||
|
return self._other
|
||||||
|
|
||||||
|
def bind_with(self, other):
|
||||||
|
self._other = other
|
||||||
|
|
||||||
|
|
||||||
class SyncTransport(SolarTransport):
|
class SyncTransport(SolarTransport):
|
||||||
"""
|
"""
|
||||||
@ -106,14 +113,6 @@ class SyncTransport(SolarTransport):
|
|||||||
super(SyncTransport, self).__init__()
|
super(SyncTransport, self).__init__()
|
||||||
self.executors = []
|
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):
|
def copy(self, resource, *args, **kwargs):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -160,11 +159,6 @@ class RunTransport(SolarTransport):
|
|||||||
def get_result(self, *args, **kwargs):
|
def get_result(self, *args, **kwargs):
|
||||||
raise NotImplementedError()
|
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):
|
def run(self, resource, *args, **kwargs):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -52,9 +52,10 @@ class BatTransport(SolarTransport):
|
|||||||
if not selected:
|
if not selected:
|
||||||
raise Exception("No valid transport found")
|
raise Exception("No valid transport found")
|
||||||
instance = self._bat_transports[selected['name']]()
|
instance = self._bat_transports[selected['name']]()
|
||||||
setattr(resource, '_used_transport', selected)
|
setattr(resource, '_used_transport_%s' % instance._mode, selected)
|
||||||
setattr(resource, key_name, instance)
|
setattr(resource, key_name, instance)
|
||||||
self._used_transports.append(instance)
|
self._used_transports.append(instance)
|
||||||
|
instance.bind_with(self._other_remember)
|
||||||
return instance
|
return instance
|
||||||
# return self._bat_transports[selected['name']]
|
# return self._bat_transports[selected['name']]
|
||||||
|
|
||||||
@ -62,6 +63,10 @@ class BatTransport(SolarTransport):
|
|||||||
self.select_valid_transport(resource)
|
self.select_valid_transport(resource)
|
||||||
return super(BatTransport, self).get_transport_data(resource, *args, **kwargs)
|
return super(BatTransport, self).get_transport_data(resource, *args, **kwargs)
|
||||||
|
|
||||||
|
def bind_with(self, other):
|
||||||
|
self._other_remember = other
|
||||||
|
|
||||||
|
|
||||||
class BatSyncTransport(SyncTransport, BatTransport):
|
class BatSyncTransport(SyncTransport, BatTransport):
|
||||||
|
|
||||||
preffered_transport_name = None
|
preffered_transport_name = None
|
||||||
|
@ -122,10 +122,6 @@ class TorrentSyncTransport(SyncTransport):
|
|||||||
'"%s"' % get_args]
|
'"%s"' % get_args]
|
||||||
self.other(resource).run(resource, *cmd, use_sudo=use_sudo)
|
self.other(resource).run(resource, *cmd, use_sudo=use_sudo)
|
||||||
|
|
||||||
def other(self, resource):
|
|
||||||
# TODO: implement it
|
|
||||||
pass
|
|
||||||
|
|
||||||
def preprocess(self, executor):
|
def preprocess(self, executor):
|
||||||
_from, _to, use_sudo = executor.params
|
_from, _to, use_sudo = executor.params
|
||||||
self._create_single_torrent(executor.resource, _from, _to, use_sudo)
|
self._create_single_torrent(executor.resource, _from, _to, use_sudo)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user