IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Contribuez Python Discussion :

Installeur de modules


Sujet :

Contribuez Python

Mode arborescent

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2007
    Messages
    172
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 172
    Par défaut Installeur de modules
    Bonjour,

    j'ai crée un petit installeur de modules, si vous avez des retours ou améliorations à proposer j'suis preneur !

    Je ne le compile pas, il va vous falloir le module wx du coup

    Pour la musique soit vous pouvez prendre ici : La musique c'est ici

    soit vous renommez votre mp3 favori et le mettez dans le même dossier que le script "mods_installer.py"

    Voilà voilà

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    # coding: utf8
    import wx
    import time
    from time import gmtime, strftime
    import os
    from os.path import *
    from os import getcwd
    import subprocess
    import shlex
    import wx.lib.agw.hyperlink as hl
    import wx.media
     
    class MyFrame(wx.Frame):
        def __init__(self, parent, id, title):
            wx.Frame.__init__(self, None, id, u"PYTHON Modules Installer V0.1b par Fawn Le Sombre", wx.DefaultPosition, wx.Size(500, 750),style=wx.MINIMIZE_BOX|wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX|wx.STAY_ON_TOP)
     
            #Panel pour affichage
            self.panel = wx.Panel(self, -1)
     
            #On capture l'event de fermeture de l'app
            self.Bind(wx.EVT_CLOSE,self.on_close,self)
     
            #Deco
            ImgDir = (getcwd()+u"\\Fond_setup.jpg")
            fond = wx.Image(ImgDir, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
            fond1 = wx.StaticBitmap(self.panel, -1, fond)
     
            #Crée la barre d'état (en bas).
            self.CreerBarreEtat()
     
            #Musique Player
            self.player = wx.media.MediaCtrl(self.panel, szBackend=wx.media.MEDIABACKEND_WMP10)
            self.player.Load("zik.mp3")
            self.Bind(wx.media.EVT_MEDIA_LOADED,self.button_play,self.player)
     
            #Boutons
            self.PIP_install_verif = wx.Button(fond1,-1,u"Vérification Installation PIP")
            self.Bind(wx.EVT_BUTTON, self.PIPinstall_verif, self.PIP_install_verif)
     
            self.PIP_install = wx.Button(fond1,-1,u"Installer PIP")
            self.Bind(wx.EVT_BUTTON, self.PIPinstall, self.PIP_install)
            #On disable le bouton au cas ou il serait déjà installé
            self.PIP_install.Disable()
     
            self.MOD_uninstall = wx.Button(fond1,-1,u"Désinstaller ?")
            self.Bind(wx.EVT_BUTTON, self.MODuninstall, self.MOD_uninstall)
            self.MOD_uninstall.Disable()
     
            #Boutons musique
            self.buttonZik = wx.Button(fond1,-1,u"Play/Pause")
            self.Bind(wx.EVT_BUTTON, self.button_play, self.buttonZik)
     
            self.buttonZikStop = wx.Button(fond1
                                           ,-1,u"Stop")
            self.Bind(wx.EVT_BUTTON, self.button_stop, self.buttonZikStop)
     
            #widgets vides
            self.txtVideMemo = wx.StaticText(fond1,-1,"")
            self.txtVideMemo.SetFont(wx.Font(18, wx.DEFAULT , wx.NORMAL, wx.NORMAL,False, u"Impact" ))
            self.txtVideMemo.SetForegroundColour(u"RED")
     
            self.txtVidePIP = wx.StaticText(fond1,-1,"")
            self.txtVidePIP.SetFont(wx.Font(10, wx.DEFAULT , wx.NORMAL, wx.NORMAL,False, u"Impact" ))
     
            #widgets
            self.txtMod = wx.StaticText(fond1,-1,u"Module à installer :")
     
            self.txtBox = wx.TextCtrl(fond1,-1,size=(300,20),style=wx.TE_PROCESS_ENTER)
            self.txtBox.SetHint(u"Entrez le nom du MODULE ici...")
            self.txtBox.Disable()
            self.Bind(wx.EVT_TEXT_ENTER,self.Get_Mod,self.txtBox)
     
            self.AffichTxt=wx.TextCtrl(fond1,-1,size=(450,300),style=wx.TE_MULTILINE|wx.TE_READONLY)
            self.AffichTxt.SetBackgroundColour(u'BLACK')
            self.AffichTxt.SetFont(wx.Font(10, wx.DEFAULT , wx.NORMAL, wx.NORMAL,False ))
            self.AffichTxt.SetForegroundColour(u"FOREST GREEN")
     
            self.txtMajPip = wx.StaticText(fond1,-1,u'Lien MaJ fichier "get-pip.py" :')
     
            self.LienPip = hl.HyperLinkCtrl(fond1, wx.ID_ANY, u'Download "get-pip.py" ',URL="https://bootstrap.pypa.io/get-pip.py")
            self.LienPip.SetLinkCursor(wx.CURSOR_HAND)
            self.LienPip.SetUnderlines(False, False, True)
            self.LienPip.EnableRollover(True)
            self.LienPip.SetColours(u"BLUE", u"ORANGE", u"BLUE")
            self.LienPip.SetBold(True)
            self.LienPip.SetToolTip(wx.ToolTip(u'Lien pour télécharger ou mettre à jour "get-pip.py"'))
            self.LienPip.UpdateLink()
     
            #Sizer install
            gbox0 = wx.GridBagSizer(10,10)
            gbox0.SetEmptyCellSize((10,10))
            gbox0.Add(self.PIP_install_verif,(0,0))
            gbox0.Add(self.txtVidePIP,(0,1))
            gbox0.Add(self.PIP_install,(0,2))
            gbox0.Add(self.txtMajPip,(1,0))
            gbox0.Add(self.LienPip,(1,1))
     
            #Sizer gestion
            gbox1 = wx.GridBagSizer(10,10)
            gbox1.SetEmptyCellSize((2,2))
            gbox1.Add(self.txtMod,(0,0))
            gbox1.Add(self.txtBox,(0,1))
            gbox1.Add(self.txtVideMemo,(1,1))
            gbox1.Add(self.MOD_uninstall,(2,1))
     
            #Sizer affichage
            gbox2 = wx.GridBagSizer(10,10)
            gbox2.SetEmptyCellSize((10,10))
            gbox2.Add(self.AffichTxt,(0,0))
     
            #Sizer zik
            gbox3 = wx.GridBagSizer(10,10)
            gbox3.SetEmptyCellSize((10,10))
            gbox3.Add(self.buttonZik,(0,0))
            gbox3.Add(self.buttonZikStop,(0,1))
     
            #PIP
            box0 = wx.StaticBox(self.panel, -1, u"Installation PIP :")
            bsizer0 = wx.StaticBoxSizer(box0, wx.HORIZONTAL)
            sizerH0 = wx.BoxSizer(wx.VERTICAL)
            sizerH0.Add(gbox0, 0, wx.ALL|wx.CENTER, 10)
            bsizer0.Add(sizerH0, 1, wx.EXPAND, 0)
     
            #Modules
            box1 = wx.StaticBox(self.panel, -1, u"Gestion des modules :")
            bsizer1 = wx.StaticBoxSizer(box1, wx.HORIZONTAL)
            sizerH1 = wx.BoxSizer(wx.VERTICAL)
            sizerH1.Add(gbox1, 0, wx.ALL|wx.CENTER, 10)
            bsizer1.Add(sizerH1, 1, wx.EXPAND, 0)
     
            #Affichage
            box2 = wx.StaticBox(self.panel, -1, u"Affichage :")
            bsizer2 = wx.StaticBoxSizer(box2, wx.HORIZONTAL)
            sizerH2 = wx.BoxSizer(wx.VERTICAL)
            sizerH2.Add(gbox2, 0, wx.ALL|wx.CENTER, 10)
            bsizer2.Add(sizerH2, 1, wx.EXPAND, 0)
     
            #Zik
            box3 = wx.StaticBox(self.panel, -1, u"Musique :")
            bsizer3 = wx.StaticBoxSizer(box3, wx.HORIZONTAL)
            sizerH3 = wx.BoxSizer(wx.VERTICAL)
            sizerH3.Add(gbox3, 0, wx.ALL|wx.CENTER, 10)
            bsizer3.Add(sizerH3, 1, wx.EXPAND, 0)
     
            #--------Ajustement du sizer----------
            mainSizer = wx.BoxSizer(wx.VERTICAL)
            mainSizer.Add(bsizer0, 0,wx.ALL|wx.EXPAND, 10)
            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)
            self.SetSizer(mainSizer)
     
            #Préparation des dossiers et fichiers de configuration
            self.Check_up()
     
            #On check si PIP a été installé
            self.Check_pip()
     
            #couleur bouton zik
            self.buttonZik.SetBackgroundColour(wx.GREEN)
     
        def button_play(self,evt):
            colorpause=self.buttonZik.GetBackgroundColour()
            if colorpause==(wx.GREEN):
                self.player.Pause()
                self.buttonZik.SetBackgroundColour("")
            else:#sinon on play
                self.player.Play()
                self.buttonZikStop.SetBackgroundColour("")
                self.buttonZik.SetBackgroundColour(wx.GREEN)
            evt.Skip()
     
        def button_stop(self,evt):
            self.buttonZikStop.SetBackgroundColour(wx.RED)
            self.buttonZik.SetBackgroundColour("")
            self.player.Stop()
            evt.Skip()
     
        def Check_pip(self):
            global DirPip
            with open(DirPip,u"r") as check:
                data=check.read()
                if data=="0":
                    pass
                else:
                    with open(DirPip,"w") as pip_ok:
                        pip_ok.write("1")
                    self.PIP_install.Disable()
                    self.PIP_install_verif.Disable()
                    self.txtVidePIP.SetLabel(u'PIP est installé !')
                    self.txtVidePIP.SetForegroundColour(u"FOREST GREEN")
                    self.txtBox.Enable()
     
        def Check_up(self):
            global RepConf
            RepConf=getcwd()+u"\\config"
            #Vérification des répertoires 
            if exists(RepConf): #Verifie que le répertoire "config" existe.
                self.Check_files() 
            else : #Sinon
                os.mkdir(RepConf) #Crée le repertoire "batch" s'il n'existe pas.
                self.Check_files()
     
        def Check_files(self):
            global RepConf,DirPip,DirMemo
            DirMemo=RepConf+u"\\memo.txt"
            DirPip=RepConf+u"\\pip.txt"
            if exists(DirMemo):
                pass
            else:
                with open(DirMemo,u"w") as create_memo:
                    create_memo.close()
            if exists(DirPip):
                pass
            else:
                with open(DirPip,u"w") as create_pip:
                    create_pip.write(u"0")
     
     
        def PIPinstall(self,evt):
            out=0
            err=0
            self.AffichTxt.Clear()
            process = subprocess.Popen(shlex.split(u'python get-pip.py'), stdout=subprocess.PIPE,stderr=subprocess.PIPE)
            while True:
                output = process.stdout.readline()
                error= process.stderr.readline()
                if (output=='' and error=='') and process.poll() is not None:
                    if out==1:
                        self.PIP_install_out()
                    if err==1:
                        self.PIP_install_err()
                    break
                if output:
                    out_propre= output.strip()
                    out_propre=out_propre.decode(u'cp850',u'ignore')#On decode l'entrée envoyée par cmd.exe
                    self.AffichTxt.SetForegroundColour(u"FOREST GREEN")
                    self.AffichTxt.AppendText(out_propre + u"\n")
                    out=1
                    #print out_propre
                elif error:
                    error_propre= error.strip()
                    error_propre=error_propre.decode(u'cp850',u'ignore')#On decode l'entrée envoyée par cmd.exe
                    self.AffichTxt.SetForegroundColour(u"RED")
                    self.AffichTxt.AppendText(error_propre + u"\n")
                    err=1
     
                    #print error_propre
            evt.Skip()
     
        def PIP_install_out(self):
            global DirPip
            with open(DirPip,"w") as pip_ok:
                pip_ok.write("1")
            self.txtVidePIP.SetLabel(u'PIP est installé !')
            self.txtVidePIP.SetForegroundColour(u"FOREST GREEN")
            self.PIP_install.Disable()
            self.txtBox.Enable()
     
        def PIP_install_err(self):
            self.txtVidePIP.SetLabel(u'Erreur PIP install !')
            self.txtVidePIP.SetForegroundColour(u"RED")
     
        def PIPinstall_verif(self,evt):
            out=0
            err=0
            self.AffichTxt.Clear()
            process = subprocess.Popen(shlex.split(u'python -m pip -V'), stdout=subprocess.PIPE,stderr=subprocess.PIPE)
            while True:
                output = process.stdout.readline()
                error= process.stderr.readline()
                if (output=='' and error=='') and process.poll() is not None:
                    if out==1:
                        self.PIP_verif_out()
                    if err==1:
                        self.PIP_verif_err()
                    break
                if output:
                    out_propre= output.strip()
                    out_propre=out_propre.decode(u'cp850',u'ignore')#On decode l'entrée envoyée par cmd.exe
                    self.AffichTxt.SetForegroundColour(u"FOREST GREEN")
                    self.AffichTxt.AppendText(out_propre + u"\n")
                    out=1
                    #print out_propre
                elif error:
                    error_propre= error.strip()
                    error_propre=error_propre.decode(u'cp850',u'ignore')#On decode l'entrée envoyée par cmd.exe
                    self.AffichTxt.SetForegroundColour(u"RED")
                    self.AffichTxt.AppendText(error_propre + u"\n")
                    err=1
                    #print error_propre
            evt.Skip()
     
        def PIP_verif_err(self):
            self.txtVidePIP.SetLabel(u'PIP non installé !')
            self.txtVidePIP.SetForegroundColour(u"RED")
            self.PIP_install.Enable()
            self.PIP_install_verif.Disable()
     
        def PIP_verif_out(self):
            global RepConf,DirPip
            with open(DirPip,"w") as pip_ok:
                pip_ok.write("1")
            self.txtVidePIP.SetLabel(u'PIP est installé !')
            self.txtVidePIP.SetForegroundColour(u"FOREST GREEN")
            self.PIP_install_verif.Disable()
            self.txtBox.Enable()
     
        def Get_Mod(self,evt):
            global mod_to_install,exception
            out=0
            err=0
            exception=0
            self.AffichTxt.Clear()
            mod_to_install=self.txtBox.GetValue()
            process = subprocess.Popen(shlex.split(u'python -m pip install '+mod_to_install), stdout=subprocess.PIPE,stderr=subprocess.PIPE)
            while True:
                output = process.stdout.readline()
                error= process.stderr.readline()
                if (output=='' and error=='') and process.poll() is not None:
                    if out==1:
                        self.MOD_out()
                    if err==1:
                        self.MOD_err()
                    break
                if output:
                    out_propre= output.strip()
                    out_propre=out_propre.decode(u'cp850',u'ignore')#On decode l'entrée envoyée par cmd.exe
                    self.AffichTxt.SetForegroundColour(u"FOREST GREEN")
                    self.AffichTxt.AppendText(out_propre + u"\n")
                    txt_except=u"Requirement already satisfied: "+mod_to_install
                    if txt_except in out_propre:
                        exception=1    
                    out=1
                elif error:
                    error_propre= error.strip()
                    error_propre=error_propre.decode(u'cp850',u'ignore')#On decode l'entrée envoyée par cmd.exe
                    self.AffichTxt.SetForegroundColour(u"RED")
                    self.AffichTxt.AppendText(error_propre + u"\n")
                    err=1
            evt.Skip()
     
        def MOD_out(self):
            global DirMemo,mod_to_install,exception
            present=0
            self.txtVideMemo.SetLabel("")
            with open(DirMemo,u"r") as memo:
                lignes = memo.readlines()
                for ligne in lignes:
                    elem=ligne.rstrip(u'\n')
                    if mod_to_install in elem:
                        present=1
            if present==1 or exception==1:
                self.txtVideMemo.SetForegroundColour(u"RED")
                self.txtVideMemo.SetLabel(u"Module déjà installé !")
                self.MOD_uninstall.Enable()
                if present==0 and exception==1:
                    with open(DirMemo,u"a") as memo:
                        memo.write(mod_to_install+u"\n")
            else:
                with open(DirMemo,u"a") as memo:
                    memo.write(mod_to_install+u"\n")
                self.txtVideMemo.SetLabel(u"Le module a bien été installé !")
                self.txtVideMemo.SetForegroundColour(u"FOREST GREEN")
     
        def MOD_err(self):
            global DirMemo
            self.txtVideMemo.SetLabel("")
            self.AffichTxt.SetForegroundColour(u"RED")
            self.AffichTxt.SetLabel(u"Le module n'existe pas ! >o<")
            ###Hack pour mauvais nom de module#####
            with open(DirMemo,u"r") as memo:
                lines=memo.readlines()
                if len(lines) > 0:
                    del lines[-1]
                    file(DirMemo, 'w').writelines(lines)
     
        def MODuninstall(self,evt):
            global mod_to_uninstall
            out=0
            err=0
            self.AffichTxt.Clear()
            mod_to_uninstall=self.txtBox.GetValue()
            process = subprocess.Popen(shlex.split(u'python -m pip uninstall -y '+mod_to_uninstall), stdout=subprocess.PIPE)
            while True:
                output = process.stdout.readline()
                if output=='' and process.poll() is not None:
                    if out==1:
                        self.MOD_uninstall_out()
                    break
                if output:
                    out_propre= output.strip()
                    out_propre=out_propre.decode(u'cp850',u'ignore')#On decode l'entrée envoyée par cmd.exe
                    self.AffichTxt.SetForegroundColour(u"FOREST GREEN")
                    self.AffichTxt.AppendText(out_propre + u"\n")
                    out=1
            evt.Skip()
     
        def MOD_uninstall_out(self):
            global DirMemo,mod_to_uninstall
            self.txtVideMemo.SetLabel("")
            with open(DirMemo, u'r') as texte, open(u'nouveau_texte.txt', u'w') as nouveau_texte:
                for line in texte:
                    if mod_to_uninstall in line:
                        nouveau_texte.write(u'')
                    else:
                        nouveau_texte.write(line)
            os.remove(DirMemo)
            os.rename(u'nouveau_texte.txt', DirMemo)
            self.txtVideMemo.SetLabel(u"Le module a bien été désinstallé !")
            self.txtVideMemo.SetForegroundColour(u"FOREST GREEN")
            self.MOD_uninstall.Disable()
     
        def Chrono(self):#Chronometre (date )
            stemps = time.strftime(u"%A %d/%m/%Y") #Definit le format voulu
            self.SetStatusText(stemps,1) #Affiche a droite.
     
        def CreerBarreEtat(self):#Creation de la barre d'etat du bas avec l'affichage de la 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 on_close(self,evt):#On detruit tout :)
            try:
                self.player.Stop()
            except:
                pass
            finally:
                self.Destroy()
     
     
     
    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()
    Images attachées Images attachées  
    Fichiers attachés Fichiers attachés

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [OL-2010] Exporter un module vba - faire un "installeur"
    Par taspai dans le forum VBA Outlook
    Réponses: 2
    Dernier message: 28/10/2015, 17h42
  2. Réponses: 4
    Dernier message: 04/06/2007, 17h52
  3. msi ou comment réaliser un installeur?
    Par herzleid dans le forum Delphi
    Réponses: 11
    Dernier message: 09/04/2007, 20h27
  4. cherche module ou langage pour récupérer des données audio..
    Par Ry_Yo dans le forum Langages de programmation
    Réponses: 5
    Dernier message: 12/05/2003, 18h44
  5. PerlDoc sur une fonction d'un module
    Par lesouriciergris dans le forum Modules
    Réponses: 2
    Dernier message: 13/03/2003, 21h50

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo