import os.path
import os
import sys
import config
from config import Config
cfg = Config()
import MySQLdb
import MySQLdb.cursors
import codecs
import shutil
import re
from configuration import GetPassword
#########################
#########################
def doitupgradesql(row, httpdocs):
sqlfile = '/mnt/data/joomlabase/%s-%s/libraries/versioning/upgrade.sql' % ('expert', '1.1.2')
if sqlfile and os.path.exists(sqlfile):
uconn = MySQLdb.connect(
host = 'db',
user = row['username'],
passwd = GetPassword(row['domain']),
db = row['username'],
cursorclass=MySQLdb.cursors.DictCursor)
ucursor = uconn.cursor()
f = codecs.open(sqlfile, 'r', 'latin-1')
for line in f:
line = line.replace('#_', row['dbPrefix'])[:-1]
if len(line):
try:
print line
print ucursor.execute(line)
except MySQLdb.OperationalError, e:
print e
except MySQLdb.IntegrityError, e:
print e
def doit(row, httpdocs):
cmd = []
os.chdir(os.path.join("/mnt/data/vhosts", row['domain']))
cmd.append("chmod 755 " + os.path.join(httpdocs, "skel-post.sh"))
cmd.append("httpdocs/skel-post.sh")
if 1:
for c in cmd:
print c
os.system(c)
else:
print cmd
def doit666(row, htdocs):
handler = re.compile(r'var\s+\$cache_handler\s*=\s*\'(.+)\';', re.MULTILINE)
settings = re.compile(r'var\s+\$memcache_settings\s*=.+;', re.MULTILINE)
caching = re.compile(r'var\s+\$caching\s*=\s*\'(.+)\';', re.MULTILINE)
cpath = os.path.join(htdocs, 'configuration.php')
if os.path.exists(cpath):
f = open(cpath)
cphp = f.read()
f.close()
cphp = handler.sub('var $cache_handler = \'memcache\';', cphp)
cphp = settings.sub('var $memcache_settings = array("persistent" => "0", "compression" => "0", "servers" => array("0" => array("host" => "mem", "port" => "11211")));', cphp)
cphp = caching.sub('var $caching = \'1\';', cphp)
f = open(cpath, 'w')
f.write(cphp)
f.close()
else:
print '%s: config does not exist' % row['domain']
#########################
#########################
os.chdir(cfg.cfg['vhostsDir'])
conn = MySQLdb.connect( host = 'db',
user = config.dbUser,
passwd = config.dbPass,
db = 'grid',
cursorclass=MySQLdb.cursors.DictCursor)
cursor = conn.cursor()
cursor.execute('SELECT * FROM domains WHERE `plan`=\'managed\' AND `product`=\'expert\'')
all = cursor.fetchall()
for row in all:
try:
# print row['domain'] + " ..."
doit(row, os.path.join(cfg.cfg['vhostsDir'], row['domain'], 'httpdocs'))
except Exception, e:
print str(e)
print row['domain'] + ' failed'
continue