Browse Source

update apply_template scripts

- check for existence of file
- use OVERWRITE boolean
- throw an exception sometimes
Charles Reid 1 month ago
parent
commit
6e414d0d1c
2 changed files with 12 additions and 4 deletions
  1. 6
    2
      apache/apply_templates.py
  2. 6
    2
      mediawiki/apply_templates.py

+ 6
- 2
apache/apply_templates.py View File

@@ -28,6 +28,7 @@ OVERWRITE = True
28 28
 env = Environment(loader=FileSystemLoader('.'))
29 29
 
30 30
 tfile = 'charlesreid1.wiki.conf.j2'
31
+rfile = 'charlesreid1.wiki.conf'
31 32
 
32 33
 content = env.get_template(tfile).render({
33 34
     "server_name_default" : "charlesreid1.com",
@@ -35,6 +36,9 @@ content = env.get_template(tfile).render({
35 36
 })
36 37
 
37 38
 # Write to file
38
-with open('charlesreid1.wiki.conf','w') as f:
39
-    f.write(content)
39
+if os.path.exists(rfile) and not OVERWRITE:
40
+    raise Exception("Error: file %s already exists!"%(rfile))
41
+else:
42
+    with open(rfile,'w') as f:
43
+        f.write(content)
40 44
 

+ 6
- 2
mediawiki/apply_templates.py View File

@@ -28,12 +28,16 @@ OVERWRITE = True
28 28
 env = Environment(loader=FileSystemLoader('.'))
29 29
 
30 30
 tfile = 'LocalSettings.php.j2'
31
+rfile = 'LocalSettings.php'
31 32
 
32 33
 content = env.get_template(tfile).render({
33 34
     "server_name_default" : "charlesreid1.com"
34 35
 })
35 36
 
36 37
 # Write to file
37
-with open('LocalSettings.php','w') as f:
38
-    f.write(content)
38
+if os.path.exists(rfile) and not OVERWRITE:
39
+    raise Exception("Error: file %s already exists!"%(rfile))
40
+else:
41
+    with open(rfile,'w') as f:
42
+        f.write(content)
39 43