class PythonStreamBinder {

	void runPlan(String[] args) throws Exception {
		if (args.length < 1) {
			System.out.println("Usage: prog <pathToScript> [parameter1]..[parameterX] - [<pathToPackage1> .. [<pathToPackageX]]");
			return;
		}

		int split = 0;
		for (int x = 0; x < args.length; x++) {
			if (args[x].equals("-")) {
				split = x;
				break;
			}
		}

		try {
			String planFile = args[0];
			String[] filesToCopy = Arrays.copyOfRange(args, 1, split == 0 ? args.length : split);
			String[] planArgumentsArray = Arrays.copyOfRange(args, split == 0 ? args.length : split + 1, args.length);

			// verify existence of files
			Path planPath = new Path(planFile);
			if (!FileSystem.getUnguardedFileSystem(planPath.toUri()).exists(planPath)) {
				throw new FileNotFoundException("Plan file " + planFile + " does not exist.");
			}
			for (String file : filesToCopy) {
				Path filePath = new Path(file);
				if (!FileSystem.getUnguardedFileSystem(filePath.toUri()).exists(filePath)) {
					throw new FileNotFoundException("Additional file " + file + " does not exist.");
				}
			}

			// setup temporary local directory for flink python library and user files
			Path targetDir = new Path(localTmpPath);
			deleteIfExists(targetDir);
			targetDir.getFileSystem().mkdirs(targetDir);

			// copy user files to temporary location
			copyFile(planPath, targetDir, planPath.getName());
			for (String file : filesToCopy) {
				Path source = new Path(file);
				copyFile(source, targetDir, source.getName());
			}

			String planNameWithExtension = planPath.getName();
			String planName = planNameWithExtension.substring(0, planNameWithExtension.indexOf(".py"));

			InterpreterUtils.initAndExecPythonScript(new PythonEnvironmentFactory(localTmpPath, planName), Paths.get(localTmpPath), planName, planArgumentsArray);
		} finally {
			try {
				// clean up created files
				FileSystem local = FileSystem.getLocalFileSystem();
				local.delete(new Path(localTmpPath), true);
			} catch (IOException ioe) {
				LOG.error("PythonAPI file cleanup failed. {}", ioe.getMessage());
			}
		}
	}

	  PythonStreamBinder(Configuration globalConfig);

}