From 7ee3f73df45ad064b8f432df19c6fa726418bba7 Mon Sep 17 00:00:00 2001
From: marcos <marcos@autoweb.com>
Date: Tue, 7 Feb 2017 11:05:22 -0600
Subject: [PATCH] recursive functionality added

---
 src/templar.min.py | 40 ++++++++++++++++++++++++++++++++++------
 1 file changed, 34 insertions(+), 6 deletions(-)

diff --git a/src/templar.min.py b/src/templar.min.py
index bf40ccf..7caeedd 100755
--- a/src/templar.min.py
+++ b/src/templar.min.py
@@ -1,13 +1,17 @@
 #!/usr/bin/python
 import string, re, sys
 import getopt,os.path, json
+from pprint import pprint
+
 
 
 debug = False
 ifile = ''
+folder = ''
 ofile = ifile
 printit = False
 vars=os.environ
+recursive = False
 
 
 class MyTemplate(string.Template):
@@ -69,17 +73,20 @@ def engine(ifile,ofile,vars):
 
 def main(argv):
 	try:
-		options, remainder = getopt.getopt(sys.argv[1:], 'o:f:i:v:dph', ['ofile=','o=', 
+		options, remainder = getopt.getopt(sys.argv[1:], 'o:f:i:v:r:dph', ['ofile=','o=', 
 															 'ifile=','i=',
 															 'vars=','v=',
 	                                                         'print','p', 
-	                                                         'help','h'	                                                        
+	                                                         'help','h',
+	                                                         'r='                                                        
 	                                                         ])
 	except getopt.GetoptError:
 		usage()
 		sys.exit(2)
 
-	global debug, vars, ifile, ofile,printit
+	global debug, vars, ifile, ofile,printit, recursive
+	print options
+
 
 	for opt, arg in options:
 		if opt in ('-v','--vars','--v'):
@@ -91,6 +98,14 @@ def main(argv):
 				print "using environment"
 				vars=os.environ
 
+		elif opt in ('-r','--r'):
+			if os.path.isdir(arg):
+				recursive= True
+				folder = arg
+			else:
+				print "folder provided [%s] does not exist" %arg
+				usage()
+
 		elif opt in ('-f','--ifile','--i','-i'):
 			if os.path.isfile(arg):
 				ifile=arg
@@ -110,7 +125,7 @@ def main(argv):
 
 	if debug:
 		print 'OPTIONS   :', options
-		print 'VARS    :', pprint(vars)
+		print 'VARS    :', pprint(str(vars))
 		print 'DEBUG   :', debug
 		print 'OUTPUT  :', ofile
 		print 'INPUT   :', ifile
@@ -118,8 +133,21 @@ def main(argv):
 		print 'REMAINING :', remainder
 
 
-	
-	engine(ifile, ofile, vars )
+	if recursive :
+		print folder
+		for  path, dirs, files in os.walk(folder):
+			for filename in files:
+				fullpath = os.path.join(path, filename)
+				if os.path.isfile(fullpath):
+					engine(fullpath, fullpath, vars)
+				else: 
+					print "file %s does not exists"%fullpath
+			
+	elif ifile != '': 
+		engine(ifile, ofile, vars )
+	else:
+		print "nothing provided"
+		sys.exit(1)
 
 
 
--
libgit2 0.24.0