X-Git-Url: http://git.inspyration.org/?a=blobdiff_plain;f=oestarter%2Fmanager.py;fp=oestarter%2Fmanager.py;h=faea1d59ea0f151a27bdc164d27f91800ec5bf08;hb=2ae328d4235951cdbdf561a2b797148311a57e5c;hp=be7a7469ebfed0c4593bfb841c08a3e358d262f2;hpb=a18a61f4979435d34357c8dd7a8164aee7274291;p=oegtk%2Feasy_starter.git diff --git a/oestarter/manager.py b/oestarter/manager.py index be7a746..faea1d5 100644 --- a/oestarter/manager.py +++ b/oestarter/manager.py @@ -1,14 +1,46 @@ #!/usr/bin/python3 #-*- coding: utf-8 -*- +import subprocess -def test_action_on_start_button(action, modules, bases, scripts): - print("""Éléments récupérés : -modules : -%s -bases -%s -scripts -%s -action -%s""" % (modules, bases, scripts, action)) +class OEManager: + def __init__(self, path_server, path_addons): + self.path_server = path_server + self.path_addons = path_addons + + def action(self, action, modules, bases, scripts): + option, base = '', bases[0] + + if action == 'Réinstaller': + # Supprimer et recréer la base + self.new_database(base) + # Passer les scripts + self.call_scripts(scripts) + # Gérer l'option de réinstallation + option = '-i' + elif action == 'Mettre à jour': + # Gérer l'option de mise à jour + option = '-u' + + # Paramétrer correctement l'option -i ou -u + if option: + option += ' ' + ','.join(modules) + ' ' + + self.start_openerp(option, base) + + def new_database(self, base): + subprocess.getstatusoutput("dropdb %s" % base) + subprocess.getstatusoutput("createdb %s" % base) + + def call_scripts(self, scripts): + for script in scripts: + subprocess.getstatusoutput(script) + + def start_openerp(self, option, base): + commande = '%s --addons-path=%s %s-d %s' % ( + self.path_server, + self.path_addons, + option, + base + ) + subprocess.getstatusoutput(commande)