def test_format_remote_path(self): self.assertEqual("[::1]:/foo/bar", utils.format_remote_path("::1", "/foo/bar")) self.assertEqual("127.0.0.1:/foo/bar", utils.format_remote_path("127.0.0.1", "/foo/bar")) self.assertEqual( "[::ffff:127.0.0.1]:/foo/bar", utils.format_remote_path("::ffff:127.0.0.1", "/foo/bar")) self.assertEqual("localhost:/foo/bar", utils.format_remote_path("localhost", "/foo/bar")) self.assertEqual("/foo/bar", utils.format_remote_path(None, "/foo/bar"))
def _synchronize_object(src, host, dst, on_execute, on_completion): """Creates a file or empty directory on a remote host. :param src: Empty directory used for rsync purposes :param host: Remote host :param dst: Destination path :param on_execute: Callback method to store pid of process in cache :param on_completion: Callback method to remove pid of process from cache """ # For creating path on the remote host rsync --relative path must # be used. With a modern rsync on the sending side (beginning with # 2.6.7), you can insert a dot and a slash into the source path, # like this: # rsync -avR /foo/./bar/baz.c remote:/tmp/ # That would create /tmp/bar/baz.c on the remote machine. # (Note that the dot must be followed by a slash, so "/foo/." # would not be abbreviated.) relative_tmp_file_path = os.path.join( src, './', os.path.normpath(dst).strip(os.path.sep)) # Do relative rsync local directory with remote root directory processutils.execute('rsync', '--archive', '--relative', '--no-implied-dirs', relative_tmp_file_path, utils.format_remote_path(host, os.path.sep), on_execute=on_execute, on_completion=on_completion)
def _synchronize_object(src, host, dst, on_execute, on_completion): """Creates a file or empty directory on a remote host. :param src: Empty directory used for rsync purposes :param host: Remote host :param dst: Destination path :param on_execute: Callback method to store pid of process in cache :param on_completion: Callback method to remove pid of process from cache """ # For creating path on the remote host rsync --relative path must # be used. With a modern rsync on the sending side (beginning with # 2.6.7), you can insert a dot and a slash into the source path, # like this: # rsync -avR /foo/./bar/baz.c remote:/tmp/ # That would create /tmp/bar/baz.c on the remote machine. # (Note that the dot must be followed by a slash, so "/foo/." # would not be abbreviated.) relative_tmp_file_path = os.path.join( src, './', os.path.normpath(dst).strip(os.path.sep)) # Do relative rsync local directory with remote root directory utils.execute('rsync', '--archive', '--relative', '--no-implied-dirs', relative_tmp_file_path, utils.format_remote_path(host, os.path.sep), on_execute=on_execute, on_completion=on_completion)
def remove_dir(self, host, dst, on_execute, on_completion, **kwargs): # Remove remote directory's content utils.execute('rsync', '--archive', '--delete-excluded', kwargs['tmp_dir_path'] + os.path.sep, utils.format_remote_path(host, dst), on_execute=on_execute, on_completion=on_completion) # Delete empty directory RsyncDriver._remove_object(kwargs['tmp_dir_path'], host, dst, on_execute=on_execute, on_completion=on_completion)
def remove_dir(self, host, dst, on_execute, on_completion): # Remove remote directory's content with utils.tempdir() as tempdir: utils.execute('rsync', '--archive', '--delete-excluded', tempdir + os.path.sep, utils.format_remote_path(host, dst), on_execute=on_execute, on_completion=on_completion) # Delete empty directory RsyncDriver._remove_object(tempdir, host, dst, on_execute=on_execute, on_completion=on_completion)
def remove_dir(self, host, dst, on_execute, on_completion): # Remove remote directory's content with utils.tempdir() as tempdir: processutils.execute('rsync', '--archive', '--delete-excluded', tempdir + os.path.sep, utils.format_remote_path(host, dst), on_execute=on_execute, on_completion=on_completion) # Delete empty directory RsyncDriver._remove_object(tempdir, host, dst, on_execute=on_execute, on_completion=on_completion)
def _remove_object(src, host, dst, on_execute, on_completion): """Removes a file or empty directory on a remote host. :param src: Empty directory used for rsync purposes :param host: Remote host :param dst: Destination path :param on_execute: Callback method to store pid of process in cache :param on_completion: Callback method to remove pid of process from cache """ utils.execute('rsync', '--archive', '--delete', '--include', os.path.basename(os.path.normpath(dst)), '--exclude', '*', os.path.normpath(src) + os.path.sep, utils.format_remote_path(host, os.path.dirname(os.path.normpath(dst))), on_execute=on_execute, on_completion=on_completion)
def _remove_object(src, host, dst, on_execute, on_completion): """Removes a file or empty directory on a remote host. :param src: Empty directory used for rsync purposes :param host: Remote host :param dst: Destination path :param on_execute: Callback method to store pid of process in cache :param on_completion: Callback method to remove pid of process from cache """ processutils.execute( 'rsync', '--archive', '--delete', '--include', os.path.basename(os.path.normpath(dst)), '--exclude', '*', os.path.normpath(src) + os.path.sep, utils.format_remote_path(host, os.path.dirname(os.path.normpath(dst))), on_execute=on_execute, on_completion=on_completion)
def test_format_remote_path(self): self.assertEqual("[::1]:/foo/bar", utils.format_remote_path("::1", "/foo/bar")) self.assertEqual("127.0.0.1:/foo/bar", utils.format_remote_path("127.0.0.1", "/foo/bar")) self.assertEqual("[::ffff:127.0.0.1]:/foo/bar", utils.format_remote_path("::ffff:127.0.0.1", "/foo/bar")) self.assertEqual("localhost:/foo/bar", utils.format_remote_path("localhost", "/foo/bar")) self.assertEqual("/foo/bar", utils.format_remote_path(None, "/foo/bar"))