|
1 | 1 | # Script Name : new_script.py |
2 | 2 | # Author : Craig Richards |
3 | 3 | # Created : 20th November 2012 |
4 | | -# Last Modified : |
| 4 | +# Last Modified : |
5 | 5 | # Version : 1.0 |
6 | 6 |
|
7 | | -# Modifications : |
| 7 | +# Modifications : |
8 | 8 |
|
9 | 9 | # Description : This will create a new basic template for a new script |
10 | 10 |
|
|
19 | 19 | -sql : SQL Script''' |
20 | 20 |
|
21 | 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: |
| 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 | 29 | if '-python' in sys.argv[1]: |
30 | | - config_file="python.cfg" |
31 | | - extension=".py" |
| 30 | + config_file = "python.cfg" |
| 31 | + extension = ".py" |
32 | 32 | elif '-bash' in sys.argv[1]: |
33 | | - config_file="bash.cfg" |
34 | | - extension=".bash" |
| 33 | + config_file = "bash.cfg" |
| 34 | + extension = ".bash" |
35 | 35 | elif '-ksh' in sys.argv[1]: |
36 | | - config_file="ksh.cfg" |
37 | | - extension=".ksh" |
| 36 | + config_file = "ksh.cfg" |
| 37 | + extension = ".ksh" |
38 | 38 | elif '-sql' in sys.argv[1]: |
39 | | - config_file="sql.cfg" |
40 | | - extension=".sql" |
| 39 | + config_file = "sql.cfg" |
| 40 | + extension = ".sql" |
41 | 41 | else: |
42 | | - print 'Unknown option - ' + text |
| 42 | + print 'Unknown option - ' + text |
43 | 43 | sys.exit() |
44 | 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) |
| 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 | 55 | if not(os.path.exists(outputdir)): |
56 | 56 | os.mkdir(outputdir) |
57 | | -newscript = open(script, 'w') |
58 | | -input=open(input_file,'r') |
59 | | -today=datetime.date.today() |
60 | | -old_date= " Created :" |
61 | | -new_date= (" Created : "+today.strftime("%d %B %Y")) |
62 | | - |
63 | | -for line in input: |
| 57 | +newscript = open(script, 'w') |
| 58 | +input = open(input_file, 'r') |
| 59 | +today = datetime.date.today() |
| 60 | +old_date = " Created :" |
| 61 | +new_date = (" Created : " + today.strftime("%d %B %Y")) |
| 62 | + |
| 63 | +for line in input: |
64 | 64 | line = line.replace(old_text, new_text) |
65 | 65 | line = line.replace(old_date, new_date) |
66 | | - newscript.write(line) |
| 66 | + newscript.write(line) |
0 commit comments