-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathautomat.py
More file actions
executable file
·65 lines (51 loc) · 1.54 KB
/
automat.py
File metadata and controls
executable file
·65 lines (51 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
import os
import subprocess
def get_immediate_subdirectories(dir):
return [name for name in os.listdir(dir)
if os.path.isdir(os.path.join(dir, name))]
def main():
path = '/home/user/webdev/'
mod = False
for subdirname in get_immediate_subdirectories(path):
if (not os.path.exists("/etc/apache2/sites-available/" + subdirname+ ".conf") ):
sitefile = open("/etc/apache2/sites-available/" + subdirname+ ".conf", "w")
if os.path.isfile(os.path.join(path, subdirname, 'yii')):
docrootdir = subdirname + '/web'
else:
docrootdir = subdirname
sitefile.write("""<VirtualHost *:80>
ServerName """ + subdirname + """
ServerAlias www.""" + subdirname + """
DocumentRoot """ + os.path.join(path, docrootdir) + """
<Location />
Require all granted
</Location>
<Directory />
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>""")
sitefile.close()
print("Creating file /etc/apache2/sites-available/" + subdirname + ".conf");
print('Writing to hosts file');
hosts = open("/etc/hosts", "a")
hosts.write("\n 127.0.0.1 " + subdirname)
hosts.close()
print('enabling site');
os.system('a2ensite ' + subdirname)
mod = True
else:
print subdirname + ' - Ok'
print('Restarting apache');
os.system('/etc/init.d/apache2 reload')
return 0
if __name__ == '__main__':
if os.getuid() == 0:
main();
else:
print 'Need sudo'
os.system('sudo ' + os.path.abspath( __file__ ))