#!/usr/bin/python #-*- coding: iso-8859-15 -*- import pickle from time import gmtime, strftime import time from datetime import datetime import wx #importe le module graphique wx import os from os.path import * from os import getcwd #importe la fonction qui recupere le chemin du repertoire from wx.lib.intctrl import IntCtrl import thread import psutil #Vars Triggers Apache_on=0 CH_set=0 CM_set=0 CS_set=0 IH_set=0 IM_set=0 IS_set=0 MH_set=0 MM_set=0 MS_set=0 count_c=0 count_i=0 count_m=0 class MyFrame(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, None, id, u"MAGENTOOLS V1.0 par François GARBEZ", wx.DefaultPosition, wx.Size(900, 830),style=wx.MINIMIZE_BOX|wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX) chemin=getcwd()+"\\img" ico = wx.Icon(chemin+"\\icone32.ico", wx.BITMAP_TYPE_ICO) self.SetIcon(ico) #Panel pour affichage self.panel = wx.Panel(self, -1) #Crée la barre d'état (en bas). self.CreerBarreEtat() #Boutons self.buttonParcourir = wx.Button(self.panel,-1,u"PARCOURIR") self.Bind(wx.EVT_BUTTON, self.Parcourir, self.buttonParcourir) self.buttonCreateBatch = wx.Button(self.panel,-1,u"CREER BATCHS") self.Bind(wx.EVT_BUTTON, self.CreateBatch, self.buttonCreateBatch) self.buttonAllocMem= wx.Button(self.panel,-1,u"ALLOUER MEMOIRE") self.Bind(wx.EVT_BUTTON, self.AllocMem, self.buttonAllocMem) self.buttonCleanFlush = wx.Button(self.panel,-1,u"CACHE CLEAN/FLUSH") self.Bind(wx.EVT_BUTTON, self.CleanFlush, self.buttonCleanFlush) self.buttonOutilMem = wx.Button(self.panel,-1,u"OUTIL MEMOIRE") self.Bind(wx.EVT_BUTTON, self.OutilMem, self.buttonOutilMem) self.buttonOutilIndex = wx.Button(self.panel,-1,u"OUTIL REINDEX") self.Bind(wx.EVT_BUTTON, self.OutilIndex, self.buttonOutilIndex) self.buttonDesinstalle = wx.Button(self.panel,-1,u"DESINSTALLER MAGENTO") self.Bind(wx.EVT_BUTTON, self.Desinstalle, self.buttonDesinstalle) self.buttonApacheState = wx.Button(self.panel,-1,u"CHECK APACHE") self.Bind(wx.EVT_BUTTON, self.ApacheState, self.buttonApacheState) self.buttonCronClean= wx.Button(self.panel,-1,u"START !") self.Bind(wx.EVT_BUTTON, self.CronClean, self.buttonCronClean) self.buttonCronIndex= wx.Button(self.panel,-1,u"START !") self.Bind(wx.EVT_BUTTON, self.CronIndex, self.buttonCronIndex) self.buttonCronMem= wx.Button(self.panel,-1,u"START !") self.Bind(wx.EVT_BUTTON, self.CronMem, self.buttonCronMem) self.buttonStopCronClean= wx.Button(self.panel,-1,u"STOP !") self.Bind(wx.EVT_BUTTON, self.StopCronClean, self.buttonStopCronClean) self.buttonStopCronIndex= wx.Button(self.panel,-1,u"STOP !") self.Bind(wx.EVT_BUTTON, self.StopCronIndex, self.buttonStopCronIndex) self.buttonStopCronMem= wx.Button(self.panel,-1,u"STOP !") self.Bind(wx.EVT_BUTTON, self.StopCronMem, self.buttonStopCronMem) self.buttonResetCleanTimer= wx.Button(self.panel,-1,u"RESET TIMER CLEAN") self.Bind(wx.EVT_BUTTON, self.ResetCleanTimer, self.buttonResetCleanTimer) self.buttonResetIndexTimer= wx.Button(self.panel,-1,u"RESET TIMER INDEX") self.Bind(wx.EVT_BUTTON, self.ResetIndexTimer, self.buttonResetIndexTimer) self.buttonResetMemTimer= wx.Button(self.panel,-1,u"RESET TIMER MEMO") self.Bind(wx.EVT_BUTTON, self.ResetMemTimer, self.buttonResetMemTimer) #widgets vides self.txtVideParcourir = wx.StaticText(self.panel,-1,"",style=wx.TE_MULTILINE) self.txtVideCreateBatch = wx.StaticText(self.panel,-1,"") self.txtVideApacheState = wx.StaticText(self.panel,-1,"") self.txtVideCronClean= wx.StaticText(self.panel,-1,"") self.txtVideCronIndex= wx.StaticText(self.panel,-1,"") self.txtVideCronMem= wx.StaticText(self.panel,-1,"") #widgets self.ParcourirText=wx.StaticText(self.panel, -1, u"I-Définir le chemin d'installation de MAGENTO (fichier magento)\n-Exemple: C:\wamp64\www\magento2\\bin\magento \n-Cette étape est IMPERATIVE !") self.ParcourirText.SetFont(wx.Font(10, wx.DEFAULT , wx.NORMAL, wx.NORMAL,False, u"Arial" )); self.CurrentPathText=wx.StaticText(self.panel, -1, u"Chemin d'accès (PATH) actuellement sélectionné pour MAGENTO :") self.CurrentPathText.SetFont(wx.Font(10, wx.DEFAULT , wx.NORMAL, wx.NORMAL,False, u"Arial" )); self.CreateBatchText=wx.StaticText(self.panel, -1, u"II-Paramétrer et Créer les BATCHS") self.CreateBatchText.SetFont(wx.Font(10, wx.DEFAULT , wx.NORMAL, wx.NORMAL,False, u"Arial" )); #IntCtrl self.MemorySizeEntry=IntCtrl(self.panel,-1,value = 1,style=wx.TE_PROCESS_ENTER,min=1,max=1024,limited=True,size=(40,20)) self.CleanTimerEntryH=IntCtrl(self.panel,-1,value = 0,style=wx.TE_PROCESS_ENTER,min=0,max=23,limited=True,size=(25,20)) self.Bind(wx.EVT_TEXT_ENTER,self.SetCleanTimerH,self.CleanTimerEntryH) self.CleanTimerEntryM=IntCtrl(self.panel,-1,value = 0,style=wx.TE_PROCESS_ENTER,min=0,max=59,limited=True,size=(25,20)) self.Bind(wx.EVT_TEXT_ENTER,self.SetCleanTimerM,self.CleanTimerEntryM) self.CleanTimerEntryS=IntCtrl(self.panel,-1,value = 0,style=wx.TE_PROCESS_ENTER,min=0,max=59,limited=True,size=(25,20)) self.Bind(wx.EVT_TEXT_ENTER,self.SetCleanTimerS,self.CleanTimerEntryS) self.IndexTimerEntryH=IntCtrl(self.panel,-1,value = 0,style=wx.TE_PROCESS_ENTER,min=0,max=23,limited=True,size=(25,20)) self.Bind(wx.EVT_TEXT_ENTER,self.SetIndexTimerH,self.IndexTimerEntryH) self.IndexTimerEntryM=IntCtrl(self.panel,-1,value = 0,style=wx.TE_PROCESS_ENTER,min=0,max=59,limited=True,size=(25,20)) self.Bind(wx.EVT_TEXT_ENTER,self.SetIndexTimerM,self.IndexTimerEntryM) self.IndexTimerEntryS=IntCtrl(self.panel,-1,value = 0,style=wx.TE_PROCESS_ENTER,min=0,max=59,limited=True,size=(25,20)) self.Bind(wx.EVT_TEXT_ENTER,self.SetIndexTimerS,self.IndexTimerEntryS) self.MemTimerEntryH=IntCtrl(self.panel,-1,value = 0,style=wx.TE_PROCESS_ENTER,min=0,max=23,limited=True,size=(25,20)) self.Bind(wx.EVT_TEXT_ENTER,self.SetMemTimerH,self.MemTimerEntryH) self.MemTimerEntryM=IntCtrl(self.panel,-1,value = 0,style=wx.TE_PROCESS_ENTER,min=0,max=59,limited=True,size=(25,20)) self.Bind(wx.EVT_TEXT_ENTER,self.SetMemTimerM,self.MemTimerEntryM) self.MemTimerEntryS=IntCtrl(self.panel,-1,value = 0,style=wx.TE_PROCESS_ENTER,min=0,max=59,limited=True,size=(25,20)) self.Bind(wx.EVT_TEXT_ENTER,self.SetMemTimerS,self.MemTimerEntryS) #### self.MemorySizeText=wx.StaticText(self.panel, -1, u"Mémoire allouée à MAGENTO (max 1024 GB):") self.MemorySizeText.SetFont(wx.Font(10, wx.DEFAULT , wx.NORMAL, wx.NORMAL,False, u"Arial" )); self.MemorySizeText2=wx.StaticText(self.panel, -1, u"Validez en appuyant sur 'Entrée' !") self.MemorySizeText2.SetFont(wx.Font(10, wx.DEFAULT , wx.NORMAL, wx.NORMAL,False, u"Arial" )); self.UseBatchText=wx.StaticText(self.panel, -1, u"III-Utiliser les BATCHS et CRON") self.UseBatchText.SetFont(wx.Font(10, wx.DEFAULT , wx.NORMAL, wx.NORMAL,False, u"Arial" )); self.Unit_UseBatchText=wx.StaticText(self.panel, -1, u"Lancements unitaires :") self.Unit_UseBatchText.SetFont(wx.Font(10, wx.DEFAULT , wx.NORMAL, wx.NORMAL,False, u"Arial" )); self.ApacheStateText=wx.StaticText(self.panel, -1, u"Check serveur Apache :") self.ApacheStateText.SetFont(wx.Font(10, wx.DEFAULT , wx.NORMAL, wx.NORMAL,False, u"Arial" )); self.CronText=wx.StaticText(self.panel, -1, u"Tâches planifiées(CRON) :") self.CronText.SetFont(wx.Font(10, wx.DEFAULT , wx.NORMAL, wx.NORMAL,False, u"Arial" )); self.ChronoText=wx.StaticText(self.panel, -1, u"Affichage des Chronos :") self.ChronoText.SetFont(wx.Font(10, wx.DEFAULT , wx.NORMAL, wx.NORMAL,False, u"Arial" )); self.CleanTimerText=wx.StaticText(self.panel, -1, u"TIMER CLEAN :") self.CleanTimerText.SetFont(wx.Font(10, wx.DEFAULT , wx.NORMAL, wx.NORMAL,False, u"Arial" )); self.IndexTimerText=wx.StaticText(self.panel, -1, u"TIMER INDEX :") self.IndexTimerText.SetFont(wx.Font(10, wx.DEFAULT , wx.NORMAL, wx.NORMAL,False, u"Arial" )); self.MemTimerText=wx.StaticText(self.panel, -1, u"TIMER MEMO :") self.MemTimerText.SetFont(wx.Font(10, wx.DEFAULT , wx.NORMAL, wx.NORMAL,False, u"Arial" )); self.CleanTimerTextH=wx.StaticText(self.panel, -1, u"Heure(s)") self.CleanTimerTextH.SetFont(wx.Font(10, wx.DEFAULT , wx.NORMAL, wx.NORMAL,False, u"Arial" )); self.CleanTimerTextM=wx.StaticText(self.panel, -1, u"Minute(s)") self.CleanTimerTextM.SetFont(wx.Font(10, wx.DEFAULT , wx.NORMAL, wx.NORMAL,False, u"Arial" )); self.CleanTimerTextS=wx.StaticText(self.panel, -1, u"Seconde(s)") self.CleanTimerTextS.SetFont(wx.Font(10, wx.DEFAULT , wx.NORMAL, wx.NORMAL,False, u"Arial" )); self.IndexTimerTextH=wx.StaticText(self.panel, -1, u"Heure(s)") self.IndexTimerTextH.SetFont(wx.Font(10, wx.DEFAULT , wx.NORMAL, wx.NORMAL,False, u"Arial" )); self.IndexTimerTextM=wx.StaticText(self.panel, -1, u"Minute(s)") self.IndexTimerTextM.SetFont(wx.Font(10, wx.DEFAULT , wx.NORMAL, wx.NORMAL,False, u"Arial" )); self.IndexTimerTextS=wx.StaticText(self.panel, -1, u"Seconde(s)") self.IndexTimerTextS.SetFont(wx.Font(10, wx.DEFAULT , wx.NORMAL, wx.NORMAL,False, u"Arial" )); self.MemTimerTextH=wx.StaticText(self.panel, -1, u"Heure(s)") self.MemTimerTextH.SetFont(wx.Font(10, wx.DEFAULT , wx.NORMAL, wx.NORMAL,False, u"Arial" )); self.MemTimerTextM=wx.StaticText(self.panel, -1, u"Minute(s)") self.MemTimerTextM.SetFont(wx.Font(10, wx.DEFAULT , wx.NORMAL, wx.NORMAL,False, u"Arial" )); self.MemTimerTextS=wx.StaticText(self.panel, -1, u"Seconde(s)") self.MemTimerTextS.SetFont(wx.Font(10, wx.DEFAULT , wx.NORMAL, wx.NORMAL,False, u"Arial" )); #Checkbox self.CheckBoxClean=wx.CheckBox(self.panel,-1,"CRON Clean/Flush") self.CheckBoxIndex=wx.CheckBox(self.panel,-1,"CRON Reindex") self.CheckBoxMem=wx.CheckBox(self.panel,-1,"CRON Memory") #Sizers gbox1 = wx.GridBagSizer(10,10) gbox1.SetEmptyCellSize((10,10)) gbox1.Add(self.ParcourirText,(0,0)) gbox1.Add(self.CurrentPathText,(1,0)) gbox1.Add(self.buttonParcourir,(0,1)) gbox1.Add(self.txtVideParcourir,(1,1)) gbox2 = wx.GridBagSizer(10,10) gbox2.SetEmptyCellSize((10,10)) gbox2.Add(self.CreateBatchText,(0,0)) gbox2.Add(self.MemorySizeText,(1,0)) gbox2.Add(self.MemorySizeText2,(2,0)) gbox2.Add(self.MemorySizeEntry,(1,1)) gbox2.Add(self.buttonAllocMem,(2,1)) gbox2.Add(self.buttonCreateBatch,(2,2)) gbox2.Add(self.txtVideCreateBatch,(1,3)) gbox3 = wx.GridBagSizer(10,10) gbox3.SetEmptyCellSize((10,10)) gbox3.Add(self.CleanTimerText,(0,0)) gbox3.Add(self.IndexTimerText,(0,2)) gbox3.Add(self.MemTimerText,(0,4)) gbox3.Add(self.CleanTimerEntryH,(1,0),flag=wx.ALIGN_RIGHT) gbox3.Add(self.CleanTimerEntryM,(2,0),flag=wx.ALIGN_RIGHT) gbox3.Add(self.CleanTimerEntryS,(3,0),flag=wx.ALIGN_RIGHT) gbox3.Add(self.CleanTimerTextH,(1,1)) gbox3.Add(self.CleanTimerTextM,(2,1)) gbox3.Add(self.CleanTimerTextS,(3,1)) gbox3.Add(self.IndexTimerEntryH,(1,2),flag=wx.ALIGN_RIGHT) gbox3.Add(self.IndexTimerEntryM,(2,2),flag=wx.ALIGN_RIGHT) gbox3.Add(self.IndexTimerEntryS,(3,2),flag=wx.ALIGN_RIGHT) gbox3.Add(self.IndexTimerTextH,(1,3)) gbox3.Add(self.IndexTimerTextM,(2,3)) gbox3.Add(self.IndexTimerTextS,(3,3)) gbox3.Add(self.MemTimerEntryH,(1,4),flag=wx.ALIGN_RIGHT) gbox3.Add(self.MemTimerEntryM,(2,4),flag=wx.ALIGN_RIGHT) gbox3.Add(self.MemTimerEntryS,(3,4),flag=wx.ALIGN_RIGHT) gbox3.Add(self.MemTimerTextH,(1,5)) gbox3.Add(self.MemTimerTextM,(2,5)) gbox3.Add(self.MemTimerTextS,(3,5)) gbox3.Add(self.buttonResetCleanTimer,(1,10)) gbox3.Add(self.buttonResetIndexTimer,(2,10)) gbox3.Add(self.buttonResetMemTimer,(3,10)) gbox4 = wx.GridBagSizer(10,10) gbox4.SetEmptyCellSize((10,10)) gbox4.Add(self.UseBatchText,(0,0)) gbox4.Add(self.ApacheStateText,(1,0)) gbox4.Add(self.buttonApacheState,(2,0)) gbox4.Add(self.txtVideApacheState,(3,0)) gbox4.Add(self.Unit_UseBatchText,(1,1)) gbox4.Add(self.buttonCleanFlush,(2,1)) gbox4.Add(self.buttonOutilIndex,(3,1)) gbox4.Add(self.buttonOutilMem,(4,1)) gbox4.Add(self.CronText,(1,2)) gbox4.Add(self.CheckBoxClean,(2,2)) gbox4.Add(self.CheckBoxIndex,(3,2)) gbox4.Add(self.CheckBoxMem,(4,2)) gbox4.Add(self.ChronoText,(1,3)) gbox4.Add(self.txtVideCronClean,(2,3)) gbox4.Add(self.txtVideCronIndex,(3,3)) gbox4.Add(self.txtVideCronMem,(4,3)) gbox4.Add(self.buttonCronClean,(2,4)) gbox4.Add(self.buttonCronIndex,(3,4)) gbox4.Add(self.buttonCronMem,(4,4)) gbox4.Add(self.buttonStopCronClean,(2,5)) gbox4.Add(self.buttonStopCronIndex,(3,5)) gbox4.Add(self.buttonStopCronMem,(4,5)) gbox5 = wx.GridBagSizer(10,10) gbox5.SetEmptyCellSize((10,10)) gbox5.Add(self.buttonDesinstalle,(0,0)) #Définir chemin MAGENTO box1 = wx.StaticBox(self.panel, -1, u"Définition du PATH de MAGENTO :") bsizer1 = wx.StaticBoxSizer(box1, wx.HORIZONTAL) sizerH1 = wx.BoxSizer(wx.VERTICAL) sizerH1.Add(gbox1, 0, wx.ALL, 10) bsizer1.Add(sizerH1, 1, wx.EXPAND, 0) #Créer BATCHS box2 = wx.StaticBox(self.panel, -1, u"Création des BATCHS :") bsizer2 = wx.StaticBoxSizer(box2, wx.HORIZONTAL) sizerH2 = wx.BoxSizer(wx.VERTICAL) sizerH2.Add(gbox2, 0, wx.ALL, 10) bsizer2.Add(sizerH2, 1, wx.EXPAND, 0) #Définir les TIMERS box3= wx.StaticBox(self.panel, -1, u"Réglages des TIMERS :") bsizer3 = wx.StaticBoxSizer(box3, wx.HORIZONTAL) sizerH3 = wx.BoxSizer(wx.VERTICAL) sizerH3.Add(gbox3,0, wx.ALL, 10) bsizer3.Add(sizerH3, 1, wx.EXPAND, 0) #Lancer BATCHS box4 = wx.StaticBox(self.panel, -1, u"Lancements des BATCHS :") bsizer4 = wx.StaticBoxSizer(box4, wx.HORIZONTAL) sizerH4 = wx.BoxSizer(wx.VERTICAL) sizerH4.Add(gbox4,0, wx.ALL, 10) bsizer4.Add(sizerH4, 1, wx.EXPAND, 0) #Desinstallation box5 = wx.StaticBox(self.panel, -1, u"Désinstallation de MAGENTO :") bsizer5 = wx.StaticBoxSizer(box5, wx.HORIZONTAL) sizerH5 = wx.BoxSizer(wx.VERTICAL) sizerH5.Add(gbox5,0, wx.ALL|wx.CENTER, 10) bsizer5.Add(sizerH5, 1, wx.EXPAND, 0) #--------Ajustement des sizers---------- mainSizer = wx.BoxSizer(wx.VERTICAL) mainSizer.Add(bsizer1, 0,wx.ALL|wx.EXPAND, 10) mainSizer.Add(bsizer2, 0,wx.ALL|wx.EXPAND, 10) mainSizer.Add(bsizer3, 0,wx.ALL|wx.EXPAND, 10) mainSizer.Add(bsizer4, 0,wx.ALL|wx.EXPAND, 10) mainSizer.Add(bsizer5, 0,wx.ALL|wx.EXPAND, 10) self.SetSizer(mainSizer) #Init Repertoires self.VerifRep() #Init VARIABLES self.Init_vars() #Affiche PATH de MAGENTO self.AfficheChemin() #Fonctions def ResetCleanTimer(self,evt): global CH_set,CM_set,CS_set self.CleanTimerEntryH.Enable() self.CleanTimerEntryM.Enable() self.CleanTimerEntryS.Enable() self.CleanTimerEntryH.SetValue(0) self.CleanTimerEntryM.SetValue(0) self.CleanTimerEntryS.SetValue(0) self.buttonCronClean.Disable() CH_set=0 CM_set=0 CS_set=0 evt.Skip() def ResetIndexTimer(self,evt): global IH_set,IM_set,IS_set self.IndexTimerEntryH.Enable() self.IndexTimerEntryM.Enable() self.IndexTimerEntryS.Enable() self.IndexTimerEntryH.SetValue(0) self.IndexTimerEntryM.SetValue(0) self.IndexTimerEntryS.SetValue(0) self.buttonCronIndex.Disable() IH_set=0 IM_set=0 IS_set=0 evt.Skip() def ResetMemTimer(self,evt): global MH_set,MM_set,MS_set self.MemTimerEntryH.Enable() self.MemTimerEntryM.Enable() self.MemTimerEntryS.Enable() self.MemTimerEntryH.SetValue(0) self.MemTimerEntryM.SetValue(0) self.MemTimerEntryS.SetValue(0) self.buttonCronMem.Disable() MH_set=0 MM_set=0 MS_set=0 evt.Skip() def SetCleanTimerH(self,evt): global CleanH,CH_set,CM_set,CS_set CleanH=self.CleanTimerEntryH.GetValue() self.CleanTimerEntryH.Disable() CH_set=1 if (CH_set==1)and(CM_set==1)and(CS_set==1): self.buttonCronClean.Enable() evt.Skip() def SetCleanTimerM(self,evt): global CleanM,CM_set,CH_set,CS_set CleanM=self.CleanTimerEntryM.GetValue() self.CleanTimerEntryM.Disable() CM_set=1 if (CH_set==1)and(CM_set==1)and(CS_set==1): self.buttonCronClean.Enable() evt.Skip() def SetCleanTimerS(self,evt): global CleanS,CS_set,CM_set,CH_set CleanS=self.CleanTimerEntryS.GetValue() self.CleanTimerEntryS.Disable() CS_set=1 if (CH_set==1)and(CM_set==1)and(CS_set==1): self.buttonCronClean.Enable() evt.Skip() def SetIndexTimerH(self,evt): global IndexH,IH_set,IM_set,IS_set IndexH=self.IndexTimerEntryH.GetValue() self.IndexTimerEntryH.Disable() IH_set=1 if(IH_set==1)and(IM_set==1)and(IS_set==1): self.buttonCronIndex.Enable() evt.Skip() def SetIndexTimerM(self,evt): global IndexM,IM_set,IH_set,IS_set IndexM=self.IndexTimerEntryM.GetValue() self.IndexTimerEntryM.Disable() IM_set=1 if(IH_set==1)and(IM_set==1)and(IS_set==1): self.buttonCronIndex.Enable() evt.Skip() def SetIndexTimerS(self,evt): global IndexS,IS_set,IM_set,IH_set IndexS=self.IndexTimerEntryS.GetValue() self.IndexTimerEntryS.Disable() IS_set=1 if(IH_set==1)and(IM_set==1)and(IS_set==1): self.buttonCronIndex.Enable() evt.Skip() def SetMemTimerH(self,evt): global MemH,MH_set,MM_set,MS_set MemH=self.MemTimerEntryH.GetValue() self.MemTimerEntryH.Disable() MH_set=1 if(MH_set==1)and(MM_set==1)and(MS_set==1): self.buttonCronMem.Enable() evt.Skip() def SetMemTimerM(self,evt): global MemM,MM_set,MH_set,MS_set MemM=self.MemTimerEntryM.GetValue() self.MemTimerEntryM.Disable() MM_set=1 if(MH_set==1)and(MM_set==1)and(MS_set==1): self.buttonCronMem.Enable() evt.Skip() def SetMemTimerS(self,evt): global MemS,MS_set,MM_set,MH_et MemS=self.MemTimerEntryS.GetValue() self.MemTimerEntryS.Disable() MS_set=1 if(MH_set==1)and(MM_set==1)and(MS_set==1): self.buttonCronMem.Enable() evt.Skip() def StopCronClean(self,evt): try: self.timerClean.Stop() self.buttonResetCleanTimer.Enable() self.buttonCronClean.Enable() self.buttonStopCronClean.Disable() self.txtVideCronClean.SetLabel(u"0H 0Min 0sec") self.txtVideCronClean.Refresh() except: pass evt.Skip() def StopCronIndex(self,evt): try: self.timerIndex.Stop() self.buttonResetIndexTimer.Enable() self.buttonCronIndex.Enable() self.buttonStopCronIndex.Disable() self.txtVideCronIndex.SetLabel(u"0H 0Min 0sec") self.txtVideCronIndex.Refresh() except: pass evt.Skip() def StopCronMem(self,evt): try: self.timerMem.Stop() self.buttonResetMemTimer.Enable() self.buttonCronMem.Enable() self.buttonStopCronMem.Disable() self.txtVideCronMem.SetLabel(u"0H 0Min 0sec") self.txtVideCronMem.Refresh() except: pass evt.Skip() def CronClean(self,evt): global TzeroClean,CH_set,CM_set,CS_set if Apache_on==1: if (CH_set==1)and(CM_set==1)and(CS_set==1): self.timerClean=wx.Timer(self, -1) self.timerClean.Start(500) TzeroClean=time.time() self.Bind(wx.EVT_TIMER, self.ChronoClean, self.timerClean) self.buttonResetCleanTimer.Disable() self.buttonCronClean.Disable() self.buttonStopCronClean.Enable() else: self.ErrorTimer() else: self.ErrorApache() evt.Skip() def ChronoClean(self,evt): global TzeroClean,CleanH,CleanM,CleanS,count_c tempsP=time.time() diffTemps = tempsP-TzeroClean diffTup = time.gmtime(diffTemps) tempsF="%iH %iMin %isec" % ( diffTup.tm_hour, diffTup.tm_min, diffTup.tm_sec) self.txtVideCronClean.SetLabel(tempsF+u" Nb="+str(count_c)) self.txtVideCronClean.Refresh() if tempsF==str(CleanH)+u"H "+str(CleanM)+u"Min "+str(CleanS)+u"sec": self.timerClean.Stop() self.CleanFlush(evt) evt.Skip() def CronIndex(self,evt): global TzeroIndex,IH_set,IM_set,IS_set if Apache_on==1: if (IH_set==1)and(IM_set==1)and(IS_set==1): self.timerIndex=wx.Timer(self, -1) self.timerIndex.Start(500) TzeroIndex=time.time() self.Bind(wx.EVT_TIMER, self.ChronoIndex, self.timerIndex) self.buttonResetIndexTimer.Disable() self.buttonCronIndex.Disable() self.buttonStopCronIndex.Enable() else: self.ErrorTimer() else: self.ErrorApache() evt.Skip() def ChronoIndex(self,evt): global TzeroIndex,IndexH,IndexM,IndexS,count_i tempsP=time.time() diffTemps = tempsP-TzeroIndex diffTup = time.gmtime(diffTemps) tempsF="%iH %iMin %isec" % ( diffTup.tm_hour, diffTup.tm_min, diffTup.tm_sec) self.txtVideCronIndex.SetLabel(tempsF+u" Nb="+str(count_i)) self.txtVideCronIndex.Refresh() if tempsF==str(IndexH)+u"H "+str(IndexM)+u"Min "+str(IndexS)+u"sec": self.timerIndex.Stop() self.OutilIndex(evt) evt.Skip() def CronMem(self,evt): global TzeroMem,MH_set,MM_set,MS_set if Apache_on==1: if (MH_set==1)and(MM_set==1)and(MS_set==1): self.timerMem=wx.Timer(self, -1) self.timerMem.Start(500) TzeroMem=time.time() self.Bind(wx.EVT_TIMER, self.ChronoMem, self.timerMem) self.buttonResetMemTimer.Disable() self.buttonCronMem.Disable() self.buttonStopCronMem.Enable() else: self.ErrorTimer() else: self.ErrorApache() evt.Skip() def ChronoMem(self,evt): global TzeroMem,MemH,MemM,MemS,count_m tempsP=time.time() diffTemps = tempsP-TzeroMem diffTup = time.gmtime(diffTemps) tempsF="%iH %iMin %isec" % ( diffTup.tm_hour, diffTup.tm_min, diffTup.tm_sec) self.txtVideCronMem.SetLabel(tempsF+u" Nb="+str(count_m)) self.txtVideCronMem.Refresh() if tempsF==str(MemH)+u"H "+str(MemM)+u"Min "+str(MemS)+u"sec": self.timerMem.Stop() self.OutilMem(evt) evt.Skip() def ApacheState(self,evt): global Apache_on count=0 for p in psutil.process_iter(): pi = p.as_dict(attrs=['pid', 'name']) if pi['name'] == 'httpd.exe': count+=1 if count!=0: Apache_on=1 self.txtVideApacheState.SetFont(wx.Font(10, wx.DEFAULT , wx.NORMAL, wx.NORMAL,False, u"Arial" )) self.txtVideApacheState.SetForegroundColour(u"sea green")#On peut choisir la couleur(red,white,blue....) self.txtVideApacheState.SetLabel("Apache ON !") else: Apache_on=0 self.txtVideApacheState.SetFont(wx.Font(10, wx.DEFAULT , wx.NORMAL, wx.NORMAL,False, u"Arial" )) self.txtVideApacheState.SetForegroundColour(u"red")#On peut choisir la couleur(red,white,blue....) self.txtVideApacheState.SetLabel("Apache OFF !") evt.Skip() def ErrorTimer(self): dlg = wx.MessageDialog(self,u"Les TIMERS n'ont pas été crées !!!\nVous ne pouvez pas continuer !",u"Erreur de création de TIMERS !",\ style=wx.ICON_ERROR|wx.STAY_ON_TOP|wx.CENTER|wx.OK) #Definit les attributs de la fenetre de message. dlg.ShowModal() def ErrorBatch(self): dlg = wx.MessageDialog(self,u"Les BATCHS n'ont pas été crées !!!\nVous ne pouvez pas continuer !",u"Erreur de création de BATCHS !",\ style=wx.ICON_ERROR|wx.STAY_ON_TOP|wx.CENTER|wx.OK) #Definit les attributs de la fenetre de message. dlg.ShowModal() def ErrorApache(self): dlg = wx.MessageDialog(self,u"Le serveur APACHE n'est pas checké ou lancé !!!\nVous ne pouvez pas continuer !",u"Erreur connexion serveur !",\ style=wx.ICON_ERROR|wx.STAY_ON_TOP|wx.CENTER|wx.OK) #Definit les attributs de la fenetre de message. dlg.ShowModal() def CleanFlush(self,evt): global rep_batchs,created_batchs,Apache_on,count_c if created_batchs==1: if Apache_on==1: OriginePath=os.getcwd() os.chdir(getcwd()+r"\batchs") thread.start_new_thread(os.system,("magento-cache-cleaner.bat",)) time.sleep(1) thread.start_new_thread(os.chdir,(OriginePath,)) count_c+=1 if self.CheckBoxClean.IsChecked()==True: self.CronClean(evt) else: self.timerClean.Stop() else: self.ErrorApache() else: self.ErrorBatch() evt.Skip() def OutilIndex(self,evt): global rep_batchs,created_batchs,Apache_on,count_i if created_batchs==1: if Apache_on==1: OriginePath=os.getcwd() os.chdir(getcwd()+r"\batchs") thread.start_new_thread(os.system,("magento-reindexer.bat",)) time.sleep(1) thread.start_new_thread(os.chdir,(OriginePath,)) count_i+=1 if self.CheckBoxIndex.IsChecked()==True: self.CronIndex(evt) else: self.timerIndex.Stop() else: self.ErrorApache() else: self.ErrorBatch() evt.Skip() def OutilMem(self,evt): global rep_batchs,created_batchs,Apache_on,count_m if created_batchs==1: if Apache_on==1: OriginePath=os.getcwd() os.chdir(getcwd()+r"\batchs") thread.start_new_thread(os.system,("magento-memory-size-definer.bat",)) time.sleep(1) thread.start_new_thread(os.chdir,(OriginePath,)) count_m+=1 if self.CheckBoxMem.IsChecked()==True: self.CronMem(evt) else: self.timerMem.Stop() else: self.ErrorApache() else: self.ErrorBatch() evt.Skip() def Desinstalle(self,evt): global rep_batchs,created_batchs,Apache_on if created_batchs==1: if Apache_on==1: OriginePath=os.getcwd() os.chdir(getcwd()+r"\batchs") thread.start_new_thread(os.system,("magento-uninstaller.bat",)) time.sleep(1) thread.start_new_thread(os.chdir,(OriginePath,)) else: self.ErrorApache() else: self.ErrorBatch() evt.Skip() def AllocMem(self,evt): global path_magento,allocated_mem,old_mem if(path_magento!=""): old_mem=self.MemorySizeEntry.GetValue() allocated_mem=1 self.MemorySizeEntry.Enable() self.MemorySizeEntry.SetFocus() self.MemorySizeEntry.SetSelection(-1,-1) self.Bind(wx.EVT_TEXT_ENTER,self.BloqueMem,self.MemorySizeEntry) else: dlg = wx.MessageDialog(self,u"PATH de MAGENTO NON défini !!!\nVous ne pouvez pas continuer !","Erreur de PATH de MAGENTO !",\ style=wx.ICON_ERROR|wx.STAY_ON_TOP|wx.CENTER|wx.OK) #Definit les attributs de la fenetre de message. dlg.ShowModal() evt.Skip() def BloqueMem(self,evt): global Val_mem,created_batchs Val_mem=self.MemorySizeEntry.GetValue() self.Pick_datas() self.MemorySizeEntry.Disable() if(created_batchs==1): self.UpdateBatchs() evt.Skip() def Pick_datas(self): global path_magento,path_defined,Val_mem,allocated_mem,created_batchs imp = file(str(rep_conf)+"\\magentools.conf",'w') pickle.dump((path_defined,path_magento,Val_mem,allocated_mem,created_batchs),imp) def CreateBatch(self,evt): global rep_batchs,path_magento,Val_mem,allocated_mem,created_batchs Val_mem=self.MemorySizeEntry.GetValue() if(path_magento!=""): if(allocated_mem==1): if not exists(rep_batchs+"\\magento-cache-cleaner.bat"): with open(rep_batchs+"\\magento-cache-cleaner.bat", "w") as batch: batch.write('@echo off\n') batch.write('chcp 1252\n') batch.write('echo ------Nettoie le cache de Magento 2------\n') batch.write('php '+path_magento+' cache:clean\n') batch.write('TIMEOUT /t 3 /nobreak\n') batch.write('echo ------ Flush le cache de Magento 2------\n') batch.write('echo Cache Nettoyé !\n') batch.write('echo Le programme se terminera dans 3 secondes...\n') batch.write('echo Appuyez sur une touche pour quitter tout de suite !\n') batch.write('TIMEOUT /t 3\n') batch.write('exit\n') else: pass if not exists(rep_batchs+"\\magento-memory-size-definer.bat"): with open(rep_batchs+"\\magento-memory-size-definer.bat", "w") as batch: batch.write('@echo off\n') batch.write('chcp 1252\n') batch.write('echo ------Outil de définition de mémoire Magento 2------\n') batch.write('php -dmemory_limit='+str(Val_mem)+'G '+path_magento+' setup:static-content:deploy\n') batch.write('echo Nouvelle allocation mémoire définie !\n') batch.write('echo Le programme se terminera dans 3 secondes...\n') batch.write('echo Appuyez sur une touche pour quitter tout de suite !\n') batch.write('TIMEOUT /t 3\n') batch.write('exit\n') else: pass if not exists(rep_batchs+"\\magento-reindexer.bat"): with open(rep_batchs+"\\magento-reindexer.bat", "w") as batch: batch.write('@echo off\n') batch.write('chcp 1252\n') batch.write('echo ------Outil de réindexation Magento 2------\n') batch.write('php '+path_magento+' indexer:reindex\n') batch.write('echo Réindexation éffectuée !\n') batch.write('echo Le programme se terminera dans 3 secondes...\n') batch.write('echo Appuyez sur une touche pour quitter tout de suite !\n') batch.write('TIMEOUT /t 3\n') batch.write('exit\n') else: pass if not exists(rep_batchs+"\\magento-uninstaller.bat"): with open(rep_batchs+"\\magento-uninstaller.bat", "w") as batch: batch.write('@echo off\n') batch.write('chcp 1252\n') batch.write('echo ------Outil de désinstallation de Magento 2------\n') batch.write('set choix=\n') batch.write('SET /P choix=Voulez-vous vraiment désinstaller Magento 2 ?(y/n)\n') batch.write('if /I "%choix%"=="y" goto choix1\n') batch.write('if /I "%choix%"=="n" goto choix2\n') batch.write(':choix1\n') batch.write('php '+path_magento+' setup:uninstall -n\n') batch.write('echo Désinstallation éffectuée ! \n') batch.write('echo Le programme se terminera dans 3 secondes...\n') batch.write('echo Appuyez sur une touche pour quitter tout de suite !\n') batch.write('TIMEOUT /t 3\n') batch.write('exit\n') batch.write(':choix2\n') batch.write('echo Désinstallation interrompue !\n') batch.write('echo Le programme se terminera dans 3 secondes...\n') batch.write('echo Appuyez sur une touche pour quitter tout de suite !\n') batch.write('TIMEOUT /t 3\n') batch.write('exit\n') created_batchs=1 self.Pick_datas() else: pass if(created_batchs==1): self.txtVideCreateBatch.SetFont(wx.Font(10, wx.DEFAULT , wx.NORMAL, wx.NORMAL,False, u"Arial" )) self.txtVideCreateBatch.SetForegroundColour(u"sea green")#On peut choisir la couleur(red,white,blue....) self.txtVideCreateBatch.SetLabel(u"Batchs crées avec succès !") self.buttonCreateBatch.Disable() else: self.txtVideCreateBatch.SetFont(wx.Font(10, wx.DEFAULT , wx.NORMAL, wx.NORMAL,False, u"Arial" )) self.txtVideCreateBatch.SetForegroundColour(u"red")#On peut choisir la couleur(red,white,blue....) self.txtVideCreateBatch.SetLabel(u"Erreur lors de la création des BATCHS !") else: dlg = wx.MessageDialog(self,u"ALLOCATION mémoire NON définie !!!\nVous ne pouvez pas continuer !",u"Erreur d'allocation mémoire !",\ style=wx.ICON_ERROR|wx.STAY_ON_TOP|wx.CENTER|wx.OK) #Definit les attributs de la fenetre de message. dlg.ShowModal() else: dlg = wx.MessageDialog(self,u"PATH de MAGENTO NON défini !!!\nVous ne pouvez pas continuer !",u"Erreur de PATH de MAGENTO !",\ style=wx.ICON_ERROR|wx.STAY_ON_TOP|wx.CENTER|wx.OK) #Definit les attributs de la fenetre de message. dlg.ShowModal() evt.Skip() def UpdateBatchs(self): global path_magento,Val_mem,old_mem,rep_batchs,old_path #Cache Cleaner Update with open(rep_batchs+"\\magento-cache-cleaner.bat", "r") as batch: data = batch.readlines() data[3]=data[3].replace(str(old_path),str(path_magento),1) with open(rep_batchs+"\\magento-cache-cleaner.bat", "w") as batch: batch.writelines(data) #Memory Sizer Update with open(rep_batchs+"\\magento-memory-size-definer.bat", "r") as batch: data = batch.readlines() data[3]=data[3].replace(str(old_mem),str(Val_mem),1) data[3]=data[3].replace(str(old_path),str(path_magento),1) with open(rep_batchs+"\\magento-memory-size-definer.bat", "w") as batch: batch.writelines(data) #Reindexer Update with open(rep_batchs+"\\magento-reindexer.bat", "r") as batch: data = batch.readlines() data[3]=data[3].replace(str(old_path),str(path_magento),1) with open(rep_batchs+"\\magento-reindexer.bat", "w") as batch: batch.writelines(data) #Uninstaller Update with open(rep_batchs+"\\magento-uninstaller.bat", "r") as batch: data = batch.readlines() data[8]=data[8].replace(str(old_mem),str(Val_mem),1) with open(rep_batchs+"\\magento-uninstaller.bat", "w") as batch: batch.writelines(data) date = time.strftime("%A %d/%m/%Y\n%H:%M:%S") self.txtVideCreateBatch.SetFont(wx.Font(10, wx.DEFAULT , wx.NORMAL, wx.NORMAL,False, u"Arial" )) self.txtVideCreateBatch.SetForegroundColour(u"sea green")#On peut choisir la couleur(red,white,blue....) self.txtVideCreateBatch.SetLabel(u"BATCHS mis à jour !\n"+str(date)) def VerifRep(self): global rep_batchs,rep_conf rep_batchs = (getcwd()+"\\batchs") rep_conf=(getcwd()+"\\config") #Vérification des répertoires if exists(rep_batchs): #Verifie que le répertoire "batchs" existe. pass #Si oui il ne fait rien et continue else : #Sinon os.mkdir(rep_batchs) #Crée le repertoire "batchs" s'il n'existe pas. if exists(rep_conf): #Verifie que le répertoire "config" existe. pass #Si oui il ne fait rien et continue else : #Sinon os.mkdir(rep_conf) #Crée le repertoire "config" s'il n'existe pas. def Init_vars(self): global rep_batchs,rep_conf,path_defined,path_magento,Val_mem,allocated_mem,created_batchs,old_mem,old_path,Apache_on if exists(rep_conf+"\\magentools.conf"): dep=file(str(rep_conf)+"\\magentools.conf",'r') #Ouvre le fichier "magentools.conf" en lecture path_defined,path_magento,Val_mem,allocated_mem,created_batchs=pickle.load(dep) self.MemorySizeEntry.SetValue(int(Val_mem)) self.MemorySizeEntry.Disable() if(created_batchs==1): old_mem=Val_mem old_path=path_magento self.buttonCreateBatch.Disable() self.txtVideCreateBatch.SetFont(wx.Font(10, wx.DEFAULT , wx.NORMAL, wx.NORMAL,False, u"Arial" )) self.txtVideCreateBatch.SetForegroundColour(u"red")#On peut choisir la couleur(red,white,blue....) self.txtVideCreateBatch.SetLabel(u"BATCHS déjà crées !") else: self.MemorySizeEntry.Disable() created_batchs=0 path_defined=0 allocated_mem=0 path_magento="" Val_mem=1 imp = file(str(rep_conf)+"\\magentools.conf",'w') pickle.dump((path_defined,path_magento,Val_mem,allocated_mem,created_batchs),imp) def AfficheChemin(self): global path_defined,path_magento if path_defined==1: try: self.txtVideParcourir.SetFont(wx.Font(10, wx.DEFAULT , wx.NORMAL, wx.NORMAL,False, u"Arial" )) self.txtVideParcourir.SetForegroundColour(u"blue")#On peut choisir la couleur(red,white,blue....) self.txtVideParcourir.SetLabel(path_magento) self.txtVideParcourir.Wrap(300) except: self.txtVideParcourir.SetLabel("Erreur d'affichage...(Pas grave) ;)") def Chrono(self):#Chronometre (date et heure) stemps = time.strftime("%A %d/%m/%Y") #Definit le format voulu self.SetStatusText(stemps,1) #Affiche a chaque seconde. def CreerBarreEtat(self):#Creation de la barre d'etat du bas avec l'affichage de l'heure et date self.CreateStatusBar(2) #Cree une barre de statut (en bas) de deux parties. self.SetStatusWidths([-1,150]) #Definit la taille. self.Chrono()#Affiche. def Parcourir(self,evt): global path_defined,path_magento,created_batchs,old_path if path_defined==0: dlg =wx.FileDialog(self,u"Choisir un fichier",os.getcwd(),"magento",style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) if dlg.ShowModal() == wx.ID_OK: path_magento = dlg.GetPath() path_defined=1 #Le PATH de MAGENTO à été défini old_path=path_magento self.AfficheChemin() self.Pick_datas() else: dlg = wx.MessageDialog(self,u"PATH de MAGENTO déjà défini ! Voulez-vous changer le PATH de MAGENTO ?","Changement de PATH de MAGENTO !",\ style=wx.ICON_EXCLAMATION|wx.STAY_ON_TOP|wx.CENTER|wx.YES_NO|wx.CANCEL) #Definit les attributs de la fenetre de message. if dlg.ShowModal() == wx.ID_YES: dlg =wx.FileDialog(self,u"Choisir un fichier",os.getcwd(),"magento",style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) old_path=path_magento if dlg.ShowModal() == wx.ID_OK: path_magento = dlg.GetPath() self.AfficheChemin() self.Pick_datas() if(created_batchs==1): self.UpdateBatchs() evt.Skip() def on_close(evt):#Pour kill le timer wx.EVT_CLOSE(frame, on_close) self.timer.Stop() frame.Destroy() evt.Skip() class MyApp(wx.App): def OnInit(self): frame = MyFrame(None, -1, None) frame.Show(True) frame.Centre() return True if __name__=='__main__': app = MyApp(0) app.MainLoop()