|
| 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 | +importos# Load the library module |
| 12 | +importsys# Load the library module |
| 13 | +importdatetime# 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 | +iflen(sys.argv) <3: |
| 22 | +printtext |
| 23 | +sys.exit() |
| 24 | + |
| 25 | +if'-h'insys.argvor'--h'insys.argvor'-help'insys.argvor'--help'insys.argv: |
| 26 | +printtext |
| 27 | +sys.exit() |
| 28 | +else: |
| 29 | +if'-python'insys.argv[1]: |
| 30 | +config_file="python.cfg" |
| 31 | +extension=".py" |
| 32 | +elif'-bash'insys.argv[1]: |
| 33 | +config_file="bash.cfg" |
| 34 | +extension=".bash" |
| 35 | +elif'-ksh'insys.argv[1]: |
| 36 | +config_file="ksh.cfg" |
| 37 | +extension=".ksh" |
| 38 | +elif'-sql'insys.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 | +forlineininput: |
| 62 | +line=line.replace(old_text, new_text) |
| 63 | +line=line.replace(old_date, new_date) |
| 64 | +newscript.write(line) |
0 commit comments