Generalized and improved python script for dependency copying