#!/bin/env python

import os
import re
from shutil import copy2

destination_root = os.environ.get("POTOO_API")

roots = {
	"output" : [
		"bin/WinVs2013Debug32", "bin/WinVs2013Debug64", "bin/WinVs2013Release32", "bin/WinVs2013Release64",
		"lib/WinVs2013Debug32", "lib/WinVs2013Debug64", "lib/WinVs2013Release32", "lib/WinVs2013Release64",
		],
	"source/cut" : [ "include", ],
}

root_files = (
	"cut-import.props",
)

# A list of patterns to check if a file should be installed or not.
# The absolute file names will be checked against these patterns.
# Note: On Windows, the file names will have backslashes, not forward slashes
ignored_files = (
	r"\.ilk",
	r"\.exp",
	r"\.gitkeep",
	r"cut-samples",
	r"cut-detail/",
	r"stdafx\.h",
)

def is_ignored(f):
	for pattern in ignored_files:
		if re.search(pattern, f):
			return True
	return False

def create_dirs(d):
	if os.path.exists(d):
		return
	os.makedirs(d)

def do_copy(s, t):
	print("{0} => {1}".format(s, t))
	copy2(s, t)

def main():
	print("Destination root: {0}".format(destination_root))
	if destination_root is None:
		print("Invalid destination_root")
		exit(-1)

	buf = []

	working_dir = os.getcwd()
	for root in roots.keys():
		os.chdir(os.path.join(working_dir, root))
		for subdir in roots[root]:
			for currentDir, dirs, files in os.walk(subdir):
				for f in files:
					source = os.path.normpath(os.path.join(working_dir, root, currentDir, f))
					if is_ignored(source):
						continue
					targetDir = os.path.normpath(os.path.join(destination_root, currentDir))
					create_dirs(targetDir)

					target = os.path.normpath(os.path.join(targetDir, f))
					do_copy(source, target)
	for f in root_files:
		if is_ignored(f):
			continue
		source = os.path.join(working_dir, f)
		target = os.path.join(destination_root, f)
		do_copy(source, target)

if __name__ == '__main__':
	main()

@@ -27,19 +27,17 @@
 t os
-%0D%0Aimport re
+, re, sys
 %0D%0Afr
@@ -62,16 +62,23 @@
 opy2%0D%0A%0D%0A
+try:%0D%0A%09
 destinat
@@ -115,16 +115,211 @@
 OO_API%22)
+ or sys.argv%5B1%5D%0D%0Aexcept:%0D%0A%09print(%22Error: You must supply a destination_root by either using the POTOO_API environment variable or supplying the path as first argument to this script.%22)%0D%0A%09exit(-1)
 %0D%0A%0D%0Aroot
@@ -1232,24 +1232,105 @@
 ef main():%0D%0A
+%09global destination_root%0D%0A%09destination_root = os.path.abspath(destination_root)%0D%0A
 %09print(%22Dest
@@ -1439,16 +1439,17 @@
 ion_root
+.
 %22)%0D%0A%09%09ex
@@ -1462,21 +1462,8 @@
 %0D%0A%0D%0A
-%09buf = %5B%5D%0D%0A%0D%0A
 %09wor
@@ -1486,16 +1486,18 @@
 tcwd()%0D%0A
+%0D%0A
 %09for roo

Install script now also accepts an install dir from the commandline