Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Test
/
templar-min
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
7ee3f73d
authored
2017-02-07 11:05:22 -0600
by
Marcos Cano
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
recursive functionality added
1 parent
ea43f423
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
4 deletions
src/templar.min.py
src/templar.min.py
View file @
7ee3f73
#!/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
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
)
...
...
Please
register
or
sign in
to post a comment