Browse Source

simplified templates files; updated completion and generation; added bash completion for tests; TODO

tags/v2.1.0^0
Robin Thoni 8 years ago
parent
commit
fa2645ab10

+ 2
- 1
TODO View File

@@ -1 +1,2 @@
1
-site remove?
1
+site remove?
2
+add sitegen command to hooks' arguments ('./sitegen.py --config ./tests/sitegen.json')

+ 44
- 21
sitegen.py View File

@@ -133,7 +133,7 @@ class SiteGen:
133 133
                 domains.append(file[:-4])
134 134
         return domains
135 135
 
136
-    def get_all_site_templates(self):
136
+    def get_all_site_confs(self):
137 137
         files = os.listdir(self.get_site_template_dir())
138 138
         files.sort()
139 139
         templates = []
@@ -142,6 +142,15 @@ class SiteGen:
142 142
                 templates.append(file[:-5])
143 143
         return templates
144 144
 
145
+    def get_all_site_incs(self):
146
+        files = os.listdir(self.get_site_template_dir())
147
+        files.sort()
148
+        templates = []
149
+        for file in files:
150
+            if file.endswith(".include"):
151
+                templates.append(file[:-8])
152
+        return templates
153
+
145 154
     def get_all_sites(self):
146 155
         files = os.listdir(self.siteConfDir)
147 156
         files.sort()
@@ -165,10 +174,10 @@ class SiteGen:
165 174
             path.join(self.siteConfDir, domain + ".include")
166 175
         ]
167 176
 
168
-    def get_site_template_conf_files(self, template):
177
+    def get_site_template_conf_files(self, inc, conf):
169 178
         return [
170
-            path.join(self.get_site_template_dir(), template + ".conf"),
171
-            path.join(self.get_site_template_dir(), template + ".include")
179
+            path.join(self.get_site_template_dir(), conf + ".conf"),
180
+            path.join(self.get_site_template_dir(), inc + ".include")
172 181
         ]
173 182
 
174 183
     def get_site_dir(self, domain):
@@ -180,8 +189,8 @@ class SiteGen:
180 189
                 return True
181 190
         return False
182 191
 
183
-    def is_site_template_present(self, template):
184
-        for file in self.get_site_template_conf_files(template):
192
+    def is_site_template_present(self, inc, conf):
193
+        for file in self.get_site_template_conf_files(inc, conf):
185 194
             if path.isfile(file):
186 195
                 return True
187 196
         return False
@@ -249,14 +258,14 @@ class SiteGen:
249 258
         for domain in domains:
250 259
             self.cert_renew(domain)
251 260
 
252
-    def site_create(self, domain, template):
261
+    def site_create(self, domain, inc, conf):
253 262
         if self.is_site_present(domain):
254 263
             raise SiteGenException("Site is present", 1)
255
-        if not self.is_site_template_present(template):
264
+        if not self.is_site_template_present(inc, conf):
256 265
             raise SiteGenException("Template is not present", 1)
257 266
 
258 267
         args = [domain, self.get_site_dir(domain)]
259
-        conf_files = self.get_site_template_conf_files(template)
268
+        conf_files = self.get_site_template_conf_files(inc, conf)
260 269
         site_files = self.get_site_conf_files(domain)
261 270
         for f in conf_files:
262 271
             args.append(f)
@@ -296,13 +305,18 @@ class SiteGen:
296 305
         os.remove(self.get_hook_file(hook_type, hook_name, True))
297 306
 
298 307
 
299
-def parse_domain(domain):
300
-    site_template = "default"
308
+def parse_domain(domain, default_inc="default", default_conf="https"):
309
+    inc = default_inc
310
+    conf = default_conf
301 311
     if ":" in domain:
302 312
         split = domain.split(":")
303 313
         domain = split[0]
304
-        site_template = split[1]
305
-    return domain, site_template
314
+        inc = split[1]
315
+        if "." in inc:
316
+            split = inc.split(".")
317
+            inc = split[0]
318
+            conf = split[1]
319
+    return domain, inc, conf
306 320
 
307 321
 
308 322
 def parse_hook(hook):
@@ -328,16 +342,25 @@ def domain_completer(prefix, **kwargs):
328 342
     return site_gen.get_all_domains()
329 343
 
330 344
 
331
-def site_template_completer(prefix, **kwargs):
345
+def site_conf_completer(prefix, **kwargs):
332 346
     site_gen = get_site_gen(prefix, **kwargs)
333
-    return site_gen.get_all_site_templates()
347
+    return site_gen.get_all_site_confs()
348
+
349
+
350
+def site_inc_completer(prefix, **kwargs):
351
+    site_gen = get_site_gen(prefix, **kwargs)
352
+    return site_gen.get_all_site_incs()
334 353
 
335 354
 
336 355
 def site_create_completer(prefix, **kwargs):
337
-    if ":" in prefix:
338
-        domain, template = parse_domain(prefix)
339
-        templates = site_template_completer(prefix, **kwargs)
340
-        return [domain + ":" + elt for elt in templates]
356
+    domain, inc, conf = parse_domain(prefix, None, None)
357
+    if inc is not None:
358
+        if conf is not None:
359
+            templates = site_conf_completer(prefix, **kwargs)
360
+            return [domain + ":" + inc + "." + elt for elt in templates]
361
+        else:
362
+            templates = site_inc_completer(prefix, **kwargs)
363
+            return [domain + ":" + elt for elt in templates]
341 364
 
342 365
     return domain_completer(prefix, **kwargs)
343 366
 
@@ -404,8 +427,8 @@ def main():
404 427
                 site_gen.cert_enddate(args.cert_enddate)
405 428
 
406 429
         elif args.site_create is not None:
407
-            domain, site_template = parse_domain(args.site_create)
408
-            site_gen.site_create(domain, site_template)
430
+            domain, inc, conf = parse_domain(args.site_create)
431
+            site_gen.site_create(domain, inc, conf)
409 432
 
410 433
         elif args.hook_enable is not None:
411 434
             hook_type, hook_name = parse_hook(args.hook_enable)

+ 0
- 1
sitegen/templates/default.conf View File

@@ -1 +0,0 @@
1
-https.conf

+ 0
- 1
sitegen/templates/default.include View File

@@ -1 +0,0 @@
1
-https.include

+ 3
- 0
sitegen/templates/default.include View File

@@ -0,0 +1,3 @@
1
+ServerName %%HOST%%
2
+DocumentRoot %%ROOT%%
3
+ServerAlias %%HOST%%

+ 0
- 1
sitegen/templates/docker.http.conf View File

@@ -1 +0,0 @@
1
-http.conf

+ 0
- 1
sitegen/templates/docker.http.include View File

@@ -1 +0,0 @@
1
-docker.https.include

+ 0
- 1
sitegen/templates/docker.https.conf View File

@@ -1 +0,0 @@
1
-https.conf

sitegen/templates/docker.https.include → sitegen/templates/docker.include View File


+ 0
- 1
sitegen/templates/http.include View File

@@ -1 +0,0 @@
1
-https.include

+ 0
- 3
sitegen/templates/https.include View File

@@ -1,3 +0,0 @@
1
-ServerName %%HOST%%
2
-DocumentRoot %%ROOT%%
3
-ServerAlias %%HOST%%

+ 0
- 1
sitegen/templates/laravel.http.conf View File

@@ -1 +0,0 @@
1
-http.conf

+ 0
- 1
sitegen/templates/laravel.https.conf View File

@@ -1 +0,0 @@
1
-https.conf

+ 0
- 1
sitegen/templates/laravel.https.include View File

@@ -1 +0,0 @@
1
-laravel.http.include

sitegen/templates/laravel.http.include → sitegen/templates/laravel.include View File


+ 0
- 1
sitegen/templates/reverse.http.conf View File

@@ -1 +0,0 @@
1
-http.conf

+ 0
- 1
sitegen/templates/reverse.https.conf View File

@@ -1 +0,0 @@
1
-https.conf

sitegen/templates/reverse.http.include → sitegen/templates/reverse.include View File


+ 3
- 0
sitegen/templates/rhttp.conf View File

@@ -0,0 +1,3 @@
1
+<VirtualHost %%HOST%%:80>
2
+    Include sites-available/%%HOST%%.include
3
+</VirtualHost>

+ 19
- 0
sitegen/templates/rhttps.conf View File

@@ -0,0 +1,19 @@
1
+<IfModule mod_ssl.c>
2
+    <VirtualHost %%HOST%%:80>
3
+        ServerName %%HOST%%
4
+        Redirect permanent / https://%%HOST%%/
5
+    </VirtualHost>
6
+    <VirtualHost %%HOST%%:443>
7
+        Include sites-available/%%HOST%%.include
8
+
9
+        SSLEngine on
10
+        SSLCertificateFile /etc/ssl/private/%%HOST%%.crt
11
+        SSLCertificateKeyFile /etc/ssl/private/%%HOST%%.key
12
+        SSLCertificateChainFile /etc/ssl/private/%%HOST%%-chain.crt
13
+    </VirtualHost>
14
+</IfModule>
15
+<IfModule !mod_ssl.c>
16
+    <VirtualHost %%HOST%%:80>
17
+        Include sites-available/%%HOST%%.include
18
+    </VirtualHost>
19
+</IfModule>

sitegen/templates/reverse.https.include → sitegen/templates/sreverse.include View File


+ 3
- 0
tests/sitegen.completion View File

@@ -0,0 +1,3 @@
1
+#!/usr/bin/env bash
2
+
3
+eval "$(register-python-argcomplete ./sitegen.py)"

Loading…
Cancel
Save