#!/usr/bin/python

import subprocess, os, sys
if len(sys.argv) is not 3:
	print "Usage: " + sys.argv[0] + " [file list to parse] [destination path]" 
	exit()

dest_path = sys.argv[2]
if dest_path[len(dest_path) - 1] is '/':
	dest_path = dest_path[0:len(dest_path) - 1]

try:
	fp = open(sys.argv[1],"r")
except:
	print "Error: Could not open file for reading!"
	
x = fp.readline().strip()
file_list = []
dir_list = []
while x:
	if os.path.isdir(x):
		dir_list.append(x)
	if os.path.isfile(x):
		file_list.append(x)
	x = fp.readline().strip()

for dir in dir_list:
	if not os.path.isdir(dest_path + dir):
		subprocess.call('mkdir -p ' + dest_path + dir,shell=True)

for file in file_list:
	file_components = file.split('/')
	containing_dir = '/'.join(file_components[0:len(file_components) - 1])
	if not os.path.isdir(dest_path + containing_dir):
		subprocess.call('mkdir -p ' + dest_path + containing_dir,shell=True)
	subprocess.call('cp ' + file + ' ' + dest_path + file,shell=True)
