Share Pastebin
Guest
Public paste!

mac

By: a guest | Feb 9th, 2010 | Syntax: Python | Size: 2.62 KB | Hits: 23 | Expires: Never
Copy text to clipboard
  1. import os.path
  2. import os
  3. import sys
  4. import config
  5. from config import Config
  6. cfg = Config()
  7. import MySQLdb
  8. import MySQLdb.cursors
  9. import codecs
  10. import shutil
  11. import re
  12. from configuration import GetPassword
  13.  
  14. #########################
  15. #########################
  16. def doitupgradesql(row, httpdocs):
  17.        
  18.         sqlfile = '/mnt/data/joomlabase/%s-%s/libraries/versioning/upgrade.sql' % ('expert', '1.1.2')
  19.         if sqlfile and os.path.exists(sqlfile):
  20.                 uconn = MySQLdb.connect(       
  21.                                         host = 'db',
  22.                                         user = row['username'],
  23.                                         passwd = GetPassword(row['domain']),
  24.                                         db = row['username'],
  25.                                         cursorclass=MySQLdb.cursors.DictCursor)
  26.  
  27.  
  28.                 ucursor = uconn.cursor()
  29.                 f = codecs.open(sqlfile, 'r', 'latin-1')
  30.                 for line in f:
  31.                         line = line.replace('#_', row['dbPrefix'])[:-1]
  32.                         if len(line):
  33.                                 try:
  34.                                         print line
  35.                                         print ucursor.execute(line)
  36.                                 except MySQLdb.OperationalError, e:
  37.                                         print e
  38.                                 except MySQLdb.IntegrityError, e:
  39.                                         print e
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46. def doit(row, httpdocs):
  47.         cmd = []
  48.        
  49.         os.chdir(os.path.join("/mnt/data/vhosts", row['domain']))
  50.         cmd.append("chmod 755 " + os.path.join(httpdocs, "skel-post.sh"))
  51.         cmd.append("httpdocs/skel-post.sh")
  52.        
  53.  
  54.  
  55.         if 1:
  56.                 for c in cmd:
  57.                         print c
  58.                         os.system(c)
  59.         else:
  60.                 print cmd
  61.  
  62. def doit666(row, htdocs):
  63.         handler = re.compile(r'var\s+\$cache_handler\s*=\s*\'(.+)\';', re.MULTILINE)
  64.         settings = re.compile(r'var\s+\$memcache_settings\s*=.+;', re.MULTILINE)
  65.         caching = re.compile(r'var\s+\$caching\s*=\s*\'(.+)\';', re.MULTILINE)
  66.  
  67.         cpath = os.path.join(htdocs, 'configuration.php')
  68.         if os.path.exists(cpath):
  69.                 f = open(cpath)
  70.                 cphp = f.read()
  71.                 f.close()
  72.                 cphp = handler.sub('var $cache_handler = \'memcache\';', cphp)
  73.                 cphp = settings.sub('var $memcache_settings = array("persistent" => "0", "compression" => "0", "servers" => array("0" => array("host" => "mem", "port" => "11211")));', cphp)
  74.                 cphp = caching.sub('var $caching = \'1\';', cphp)
  75.                 f = open(cpath, 'w')
  76.                 f.write(cphp)
  77.                 f.close()
  78.         else:
  79.                 print '%s: config does not exist' % row['domain']
  80.  
  81. #########################
  82. #########################
  83.  
  84. os.chdir(cfg.cfg['vhostsDir'])
  85.  
  86. conn = MySQLdb.connect( host = 'db',
  87.                         user = config.dbUser,
  88.                         passwd = config.dbPass,
  89.                         db = 'grid',
  90.                         cursorclass=MySQLdb.cursors.DictCursor)
  91. cursor = conn.cursor()
  92. cursor.execute('SELECT * FROM domains WHERE `plan`=\'managed\' AND `product`=\'expert\'')
  93. all = cursor.fetchall()
  94. for row in all:
  95.         try:
  96. #               print row['domain'] + " ..."
  97.                 doit(row, os.path.join(cfg.cfg['vhostsDir'], row['domain'], 'httpdocs'))
  98.         except Exception, e:
  99.                 print str(e)
  100.                 print row['domain'] + ' failed'
  101.                 continue