I'm tired of going through all the steps it takes (for me) to change the DocumentRoot in Apache. I'm trying to facilitate the process with the following Python script...
#!/usr/bin/python
import sys, re
if len(sys.argv) == 2:
f = open('/tmp/apachecdr', 'w')
f.write(open('/etc/apache2/httpd.conf').read())
f = open('/tmp/apachecdr', 'r')
r = re.sub('DocumentRoot "(.*?)"',
'DocumentRoot "' + sys.argv[1] + '"',
f.read())
f = open('/etc/apache2/httpd.conf', 'w')
f.write(r)
else:
print "Please supply the new DocumentRoot path."
I've saved this as /usr/bin/apachecdr so that I could simply open a shell and "sudo apachecdr /new/documentroot/path" and then restart with apachectl. My question is how would you write this?
It's my first time posting on Stack Overflow (and I'm new to Python) so please let me know if this is not specific enough of a question.