Further work on pluggable transports
This commit is contained in:
@@ -16,6 +16,9 @@ class BaseHandler(object):
|
||||
if handlers is None:
|
||||
self.transport_sync = SSHSyncTransport()
|
||||
self.transport_run = SSHRunTransport()
|
||||
else:
|
||||
self.transport_run = handlers['run']()
|
||||
self.transport_sync = handlers['sync']()
|
||||
self.transport_sync.bind_with(self.transport_run)
|
||||
self.transport_run.bind_with(self.transport_sync)
|
||||
|
||||
|
||||
@@ -20,8 +20,9 @@ class Executor(object):
|
||||
def valid(self, value):
|
||||
self._valid = value
|
||||
|
||||
def run(self):
|
||||
self._executor()
|
||||
def run(self, transport):
|
||||
if self.valid:
|
||||
self._executor(transport)
|
||||
|
||||
|
||||
class SyncTransport(object):
|
||||
@@ -40,23 +41,23 @@ class SyncTransport(object):
|
||||
def copy(self, resource, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def check(self, executor):
|
||||
def preprocess(self, executor):
|
||||
# we can check there if we need to run sync executor or not
|
||||
# ideally would be to do so on other side
|
||||
# it may set executor.valid to False then executor will be skipped
|
||||
pass
|
||||
|
||||
def _check_all(self):
|
||||
def preprocess_all(self):
|
||||
# we cat use there md5 for big files to check if we need to sync it
|
||||
# or if remote is still valid
|
||||
# we can run that in parallell also
|
||||
# can be also used to prepare files for further transfer
|
||||
for executor in self.executors:
|
||||
self.check(executor)
|
||||
self.preprocess(executor)
|
||||
|
||||
def _run_all(self):
|
||||
def run_all(self):
|
||||
for executor in self.executors:
|
||||
if executor.valid:
|
||||
executor.run()
|
||||
executor.run(self)
|
||||
|
||||
def sync_all(self):
|
||||
"""
|
||||
@@ -64,8 +65,8 @@ class SyncTransport(object):
|
||||
then runs all sequentially.
|
||||
Could be someday changed to parallel thing.
|
||||
"""
|
||||
self._check_all()
|
||||
self._run_all()
|
||||
self.preprocess_all()
|
||||
self.run_all()
|
||||
self.executors = [] # clear after all
|
||||
|
||||
|
||||
@@ -77,6 +78,11 @@ class RunTransport(object):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
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
|
||||
|
||||
|
||||
@@ -62,11 +62,11 @@ class SSHSyncTransport(SyncTransport, _SSHTransport):
|
||||
params=(_from, _to, use_sudo))
|
||||
self.executors.append(executor)
|
||||
|
||||
def sync_all(self):
|
||||
def run_all(self):
|
||||
for executor in self.executors:
|
||||
resource = executor.resource
|
||||
with fabric_api.settings(**self._fabric_settings(resource)):
|
||||
executor.run()
|
||||
executor.run(self)
|
||||
|
||||
|
||||
class SSHRunTransport(RunTransport, _SSHTransport):
|
||||
|
||||
Reference in New Issue
Block a user