diff --git a/pluginInstaller/pluginInstaller.py b/pluginInstaller/pluginInstaller.py index 3093aa21c..65e7c64f2 100755 --- a/pluginInstaller/pluginInstaller.py +++ b/pluginInstaller/pluginInstaller.py @@ -22,6 +22,11 @@ class pluginInstaller: 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 @@ class pluginInstaller: 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 @@ class pluginInstaller: ## + 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 @@ class pluginInstaller: 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 @@ class pluginInstaller: ## + 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..')