def test_pssh_copy_remote_file(self): """Test parallel copy file to local host""" test_file_data = 'test' local_test_path = 'directory_test_local_remote_copied' remote_test_path = 'directory_test_remote_copy' local_copied_dir = '_'.join([local_test_path, self.host]) new_local_copied_dir = '.'.join([local_test_path, self.host]) for path in [local_test_path, remote_test_path, local_copied_dir, new_local_copied_dir]: try: shutil.rmtree(path) except OSError: try: os.unlink(path) except Exception: pass pass os.mkdir(remote_test_path) local_file_paths = [] for i in range(0, 10): remote_file_path_dir = os.path.join(remote_test_path, 'dir_foo' + str(i)) os.mkdir(remote_file_path_dir) remote_file_path = os.path.join(remote_file_path_dir, 'foo' + str(i)) local_file_path = os.path.join(local_copied_dir, 'dir_foo' + str(i), 'foo' + str(i)) local_file_paths.append(local_file_path) test_file = open(remote_file_path, 'w') test_file.write(test_file_data) test_file.close() client = ParallelSSHClient([self.host], port=self.listen_port, pkey=self.user_key) cmds = client.copy_remote_file(remote_test_path, local_test_path) for cmd in cmds: self.assertRaises(ValueError, cmd.get) cmds = client.copy_remote_file(remote_test_path, local_test_path, recurse=True) for cmd in cmds: cmd.get() try: self.assertTrue(os.path.isdir(local_copied_dir)) for path in local_file_paths: self.assertTrue(os.path.isfile(path)) except Exception: shutil.rmtree(remote_test_path) finally: shutil.rmtree(local_copied_dir) cmds = client.copy_remote_file(remote_test_path, local_test_path, suffix_separator='.', recurse=True) for cmd in cmds: cmd.get() new_local_copied_dir = '.'.join([local_test_path, self.host]) try: for path in local_file_paths: path = path.replace(local_copied_dir, new_local_copied_dir) self.assertTrue(os.path.isfile(path)) finally: shutil.rmtree(new_local_copied_dir) shutil.rmtree(remote_test_path)
command += " -sa " + saturation command += " -ev " + ev command += " -w " + width command += " -h " + height command += " -o " + "/home/pi/" + name # create a folder to store current set images set_dir = "/var/www/html/img/" + name os.mkdir(set_dir) # run commands to take images output = parallel_client.run_command(command) parallel_client.join(output) # transfer all images to web server greenlets = parallel_client.copy_remote_file(name, set_dir + "/" + name) joinall(greenlets, raise_error=True) # delete all images on slave Pis output = parallel_client.run_command("rm /home/pi/" + name) parallel_client.join(output) # add .jpg extension to all images in folder image_files = os.listdir(set_dir) for image in image_files: os.rename(os.path.join(set_dir, image), os.path.join(set_dir, image + ".jpg")) image_files = os.listdir(set_dir) # get updated image files # zip image set folder to be downloaded shutil.make_archive(set_dir, "zip", set_dir)