Small clean up and refactor of the rsync target ipv6 observing formatter for synchronize action.

This commit is contained in:
Petr Mifek 2015-09-18 11:46:33 +02:00
parent 6f3f4dff7a
commit 27f779a7cc

View file

@ -44,16 +44,25 @@ class ActionModule(ActionBase):
return path
def _format_rsync_rsh_target(self, host, path, user):
''' formats rsync rsh target, escaping ipv6 addresses if needed '''
def _needs_ipv6_brackets(host):
return ':' in host
user_prefix = ''
if user:
user_prefix = '%s@' % (user, )
if _needs_ipv6_brackets(host):
return '[%s%s]:%s' % (user_prefix, host, path)
else:
return '%s%s:%s' % (user_prefix, host, path)
def _process_origin(self, host, path, user):
if host not in C.LOCALHOST:
userPart = ''
if user:
userPart = '%s@' % (user, )
if ":" in host:
return '[%s%s]:%s' % (userPart, host, path)
else:
return '%s%s:%s' % (userPart, host, path)
return self._format_rsync_rsh_target(host, path, user)
if ':' not in path and not path.startswith('/'):
path = self._get_absolute_path(path=path)
@ -62,13 +71,7 @@ class ActionModule(ActionBase):
def _process_remote(self, host, path, user):
transport = self._play_context.connection
if host not in C.LOCALHOST or transport != "local":
userPart = ''
if user:
userPart = '%s@' % (user, )
if ":" in host:
return '[%s%s]:%s' % (userPart, host, path)
else:
return '%s%s:%s' % (userPart, host, path)
return self._format_rsync_rsh_target(host, path, user)
if ':' not in path and not path.startswith('/'):
path = self._get_absolute_path(path=path)