Browse Source

Added plugins db structure

feature/plugin
gau1991 10 years ago
parent
commit
e931d9f0cc
  1. 32
      ee/cli/plugins/models.py
  2. 126
      ee/cli/plugins/pluginsdb.py

32
ee/cli/plugins/models.py

@ -55,3 +55,35 @@ class SiteDB(Base):
#
# def getType(self):
# return '%r>' % (self.site_type)
class PluginDB(Base):
"""
Databse model for site table
"""
__tablename__ = 'plugins'
__table_args__ = {'extend_existing': True}
id = Column(Integer, primary_key=True)
pluginname = Column(String, unique=True)
plugin_type = Column(String)
plugin_version = Column(String)
# Use default=func.now() to set the default created time
# of a site to be the current time when a
# Site record was created
installed_on = Column(DateTime, default=func.now())
is_enabled = Column(Boolean, unique=False, default=True, nullable=False)
def __init__(self, pluginname, plugin_type=None, plugin_version=None,
plugin_enabled=True):
self.pluginname = pluginname
self.plugin_type = plugin_type
self.plugin_version = plugin_version
self.is_enabled = plugin_enabled
# def __repr__(self):
# return '<Site %r>' % (self.site_type)
#
# def getType(self):
# return '%r>' % (self.site_type)

126
ee/cli/plugins/pluginsdb.py

@ -0,0 +1,126 @@
from sqlalchemy import Column, DateTime, String, Integer, Boolean
from sqlalchemy import ForeignKey, func
from sqlalchemy.orm import relationship, backref
from sqlalchemy.ext.declarative import declarative_base
from ee.core.logging import Log
from ee.core.database import db_session
from ee.cli.plugins.models import PluginDB
import sys
import glob
def addNewPlugin(self, site, stype, cache, path,
enabled=True, ssl=False, fs='ext4', db='mysql',
db_name=None, db_user=None, db_password=None,
db_host='localhost', hhvm=0, pagespeed=0):
"""
Add New Site record information into ee database.
"""
try:
newRec = PluginDB(site, stype, cache, path, enabled, ssl, fs, db,
db_name, db_user, db_password, db_host, hhvm,
pagespeed)
db_session.add(newRec)
db_session.commit()
except Exception as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to add site to database")
def getPluginInfo(self, site):
"""
Retrieves site record from ee databse
"""
try:
q = PluginDB.query.filter(PluginDB.sitename == site).first()
return q
except Exception as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to query database for site info")
def updatePluginInfo(self, site, stype='', cache='', webroot='',
enabled=True, ssl=False, fs='', db='', db_name=None,
db_user=None, db_password=None, db_host=None, hhvm=None,
pagespeed=None):
"""updates site record in database"""
try:
q = PluginDB.query.filter(PluginDB.sitename == site).first()
except Exception as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to query database for site info")
if not q:
Log.error(self, "{0} does not exist in database".format(site))
# Check if new record matches old if not then only update database
if stype and q.site_type != stype:
q.site_type = stype
if cache and q.cache_type != cache:
q.cache_type = cache
if q.is_enabled != enabled:
q.is_enabled = enabled
if ssl and q.is_ssl != ssl:
q.is_ssl = ssl
if db_name and q.db_name != db_name:
q.db_name = db_name
if db_user and q.db_user != db_user:
q.db_user = db_user
if db_user and q.db_password != db_password:
q.db_password = db_password
if db_host and q.db_host != db_host:
q.db_host = db_host
if webroot and q.site_path != webroot:
q.site_path = webroot
if (hhvm is not None) and (q.is_hhvm is not hhvm):
q.is_hhvm = hhvm
if (pagespeed is not None) and (q.is_pagespeed is not pagespeed):
q.is_pagespeed = pagespeed
try:
q.created_on = func.now()
db_session.commit()
except Exception as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to update site info in application database.")
def deletePluginInfo(self, site):
"""Delete site record in database"""
try:
q = PluginDB.query.filter(PluginDB.sitename == site).first()
except Exception as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to query database")
if not q:
Log.error(self, "{0} does not exist in database".format(site))
try:
db_session.delete(q)
db_session.commit()
except Exception as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to delete site from application database.")
def getAllplugins(self):
"""
1. returns all records from ee database
"""
try:
q = PluginDB.query.all()
return q
except Exception as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to query database")
Loading…
Cancel
Save