Browse Source

added ee sync command

bugfixes
harshadyeola 10 years ago
parent
commit
7ad3db69ce
  1. 6
      config/ee.conf
  2. 80
      ee/cli/plugins/sync.py

6
config/ee.conf

@ -74,3 +74,9 @@ email =
### `ee.cli.plugins.example` or from the file path
### `/var/lib/ee/plugins/example.py`
enable_plugin = true
[sync]
### If enabled, load a plugin named `update` either from the Python module
### `ee.cli.plugins.example` or from the file path
### `/var/lib/ee/plugins/example.py`
enable_plugin = true

80
ee/cli/plugins/sync.py

@ -0,0 +1,80 @@
from cement.core.controller import CementBaseController, expose
from cement.core import handler, hook
from ee.core.fileutils import EEFileUtils
from ee.cli.plugins.sitedb import *
from ee.core.mysql import *
from ee.core.logging import Log
def ee_sync_hook(app):
# do something with the ``app`` object here.
pass
class EESyncController(CementBaseController):
class Meta:
label = 'sync'
stacked_on = 'base'
stacked_type = 'nested'
description = 'synchronize EasyEngine database'
@expose(hide=True)
def default(self):
self.sync()
@expose(hide=True)
def sync(self):
"""
1. reads database information from wp/ee-config.php
2. updates records into ee database accordingly.
"""
Log.info(self, "Synchronizing ee database, please wait ....")
sites = getAllsites(self)
if not sites:
pass
for site in sites:
if site.site_type in ['mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
ee_site_webroot = site.site_path
# Read config files
configfiles = glob.glob(ee_site_webroot + '/*-config.php')
if configfiles:
if EEFileUtils.isexist(self, configfiles[0]):
ee_db_name = (EEFileUtils.grep(self, configfiles[0],
'DB_NAME').split(',')[1]
.split(')')[0].strip().replace('\'', ''))
ee_db_user = (EEFileUtils.grep(self, configfiles[0],
'DB_USER').split(',')[1]
.split(')')[0].strip().replace('\'', ''))
ee_db_pass = (EEFileUtils.grep(self, configfiles[0],
'DB_PASSWORD').split(',')[1]
.split(')')[0].strip().replace('\'', ''))
ee_db_host = (EEFileUtils.grep(self, configfiles[0],
'DB_HOST').split(',')[1]
.split(')')[0].strip().replace('\'', ''))
# Check if database really exist
try:
if not EEMysql.check_db_exists(self, ee_db_name):
# Mark it as deleted if not exist
ee_db_name = 'deleted'
except StatementExcecutionError as e:
Log.debug(self, str(e))
except Exception as e:
Log.debug(self, str(e))
if site.db_name != ee_db_name:
# update records if any mismatch found
Log.debug(self, "Updating ee db record for {0}"
.format(site.sitename))
updateSiteInfo(self, site.sitename,
db_name=ee_db_name,
db_user=ee_db_user,
db_password=ee_db_pass,
db_host=ee_db_host)
def load(app):
# register the plugin class.. this only happens if the plugin is enabled
handler.register(EESyncController)
# register a hook (function) to run after arguments are parsed.
hook.register('post_argument_parsing', ee_sync_hook)
Loading…
Cancel
Save