Skip to content
Permalink
Browse files
enable pluginInstaller to run migrations
  • Loading branch information
myst3k committed Aug 20, 2020
1 parent fa076fa commit 956cbcc3c7d65ed139b94452360a7f34cbb39428
Showing 1 changed file with 42 additions and 0 deletions.
@@ -22,6 +22,11 @@ def stdOut(message):
print(("[" + time.strftime(
"%m.%d.%Y_%H-%M-%S") + "] #########################################################################\n"))

@staticmethod
def migrationsEnabled(pluginName: str) -> bool:
pluginHome = '/usr/local/CyberCP/' + pluginName
return os.path.exists(pluginHome + '/enable_migrations')

### Functions Related to plugin installation.

@staticmethod
@@ -103,6 +108,17 @@ def staticContent():

os.chdir(currentDir)

@staticmethod
def installMigrations(pluginName):
currentDir = os.getcwd()
os.chdir('/usr/local/CyberCP')
command = "/usr/local/CyberCP/bin/python manage.py makemigrations %s" % pluginName
subprocess.call(shlex.split(command))
command = "/usr/local/CyberCP/bin/python manage.py migrate %s" % pluginName
subprocess.call(shlex.split(command))
os.chdir(currentDir)


@staticmethod
def preInstallScript(pluginName):
pluginHome = '/usr/local/CyberCP/' + pluginName
@@ -184,6 +200,15 @@ def installPlugin(pluginName):

##

if pluginInstaller.migrationsEnabled(pluginName):
pluginInstaller.stdOut('Running Migrations..')
pluginInstaller.installMigrations(pluginName)
pluginInstaller.stdOut('Migrations Completed..')
else:
pluginInstaller.stdOut('Migrations not enabled, add file \'enable_migrations\' to plugin to enable')

##

pluginInstaller.restartGunicorn()

##
@@ -251,6 +276,14 @@ def removeInterfaceLink(pluginName):
writeToFile.writelines(items)
writeToFile.close()

@staticmethod
def removeMigrations(pluginName):
currentDir = os.getcwd()
os.chdir('/usr/local/CyberCP')
command = "/usr/local/CyberCP/bin/python manage.py migrate %s zero" % pluginName
subprocess.call(shlex.split(command))
os.chdir(currentDir)

@staticmethod
def removePlugin(pluginName):
try:
@@ -262,6 +295,15 @@ def removePlugin(pluginName):

##

if pluginInstaller.migrationsEnabled(pluginName):
pluginInstaller.stdOut('Removing migrations..')
pluginInstaller.removeMigrations(pluginName)
pluginInstaller.stdOut('Migrations removed..')
else:
pluginInstaller.stdOut('Migrations not enabled, add file \'enable_migrations\' to plugin to enable')

##

pluginInstaller.stdOut('Removing files..')
pluginInstaller.removeFiles(pluginName)
pluginInstaller.stdOut('Files removed..')

0 comments on commit 956cbcc

Please sign in to comment.