Skip to content

Commit 765952e

Browse files
committed
Depending on the paramters I pass this will create a script empty script template
It reads the parameters I pass then reads my config files then creates me a new template
1 parent 6599c98 commit 765952e

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

new_script.py

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Script Name : new_script.py
2+
# Author : Craig Richards
3+
# Created : 20th November 2012
4+
# Last Modified :
5+
# Version : 1.0
6+
7+
# Modifications :
8+
9+
# Description : This will create a new basic template for a new script
10+
11+
import os # Load the library module
12+
import sys # Load the library module
13+
import datetime # Load the library module
14+
15+
text = '''You need to pass an argument for the new script you want to create, followed by the script name. You can use
16+
-python : Python Script
17+
-bash : Bash Script
18+
-ksh : Korn Shell Script
19+
-sql : SQL Script'''
20+
21+
if len(sys.argv) < 3:
22+
print text
23+
sys.exit()
24+
25+
if '-h' in sys.argv or '--h' in sys.argv or '-help' in sys.argv or '--help' in sys.argv:
26+
print text
27+
sys.exit()
28+
else:
29+
if '-python' in sys.argv[1]:
30+
config_file="python.cfg"
31+
extension=".py"
32+
elif '-bash' in sys.argv[1]:
33+
config_file="bash.cfg"
34+
extension=".bash"
35+
elif '-ksh' in sys.argv[1]:
36+
config_file="ksh.cfg"
37+
extension=".ksh"
38+
elif '-sql' in sys.argv[1]:
39+
config_file="sql.cfg"
40+
extension=".sql"
41+
else:
42+
print 'Unknown option - ' + text
43+
sys.exit()
44+
45+
confdir=os.getenv("my_config")
46+
scripts=os.getenv("scripts")
47+
dev_dir="Development"
48+
newfile=sys.argv[2]
49+
output_file=(newfile+extension)
50+
outputdir=os.path.join(scripts,dev_dir)
51+
script=os.path.join(outputdir, output_file)
52+
input_file=os.path.join(confdir,config_file)
53+
old_text=" Script Name : "
54+
new_text=(" Script Name : "+output_file)
55+
newscript = open(script, 'w')
56+
input=open(input_file,'r')
57+
today=datetime.date.today()
58+
old_date= " Created :"
59+
new_date= (" Created : "+today.strftime("%d %B %Y"))
60+
61+
for line in input:
62+
line = line.replace(old_text, new_text)
63+
line = line.replace(old_date, new_date)
64+
newscript.write(line)

0 commit comments

Comments
 (0)