beremiz_postinst.py
changeset 434 092060fd8afb
parent 433 ca07a88ee68a
child 435 75fe73597273
equal deleted inserted replaced
433:ca07a88ee68a 434:092060fd8afb
     1 #!/usr/bin/env python
       
     2 # -*- coding: utf-8 -*-
       
     3 
       
     4 # La première ligne doit commencer par #! et contenir python.
       
     5 # Elle sera adaptée au système de destination automatiquement
       
     6 
       
     7 """ This is a part of Beremiz project.
       
     8 
       
     9     Post installation script for win32 system
       
    10     
       
    11     This script creat a shortcut for Beremiz.py in the desktop and the
       
    12     start menu, and remove them at the uninstallation
       
    13     
       
    14 """
       
    15 
       
    16 import os
       
    17 import sys
       
    18 
       
    19 # Ce script sera aussi lancé lors de la désinstallation.
       
    20 # Pour n'exécuter du code que lors de l'installation :
       
    21 if sys.argv[1] == '-install':
       
    22     # On récupère le dossier où mes fichiers seront installés (dossier où python est aussi installé sous windows)
       
    23     python_path = sys.prefix
       
    24     # On récupère le chemin de pythonw.exe (l'exécutable python qui n'affiche pas de console).
       
    25     # Si vous voulez une console, remplacez pythonw.exe par python.exe
       
    26     pyw_path = os.path.abspath(os.path.join(python_path, 'pythonw.exe'))
       
    27     # On récupère le dossier coincoin
       
    28     Beremiz_dir = os.path.abspath(os.path.join(python_path, 'LOLITech', 'Beremiz'))
       
    29     
       
    30     # On récupère les chemins de coincoin.py, et de coincoin.ico
       
    31     # (Ben oui, l'icone est au format ico, oubliez le svg, ici on en est encore à la préhistoire.
       
    32     # Heureusement que the GIMP sait faire la conversion !)
       
    33     ico_path = os.path.join(Beremiz_dir, 'Beremiz.ico')
       
    34     script_path = os.path.join(Beremiz_dir, 'Beremiz.py')
       
    35     
       
    36     # Création des raccourcis
       
    37     # Pour chaque raccourci, on essaye de le faire pour tous les utilisateurs (Windows NT/2000/XP),
       
    38     # sinon on le fait pour l'utilisateur courant (Windows 95/98/ME)
       
    39     
       
    40     # Raccourcis du bureau
       
    41     # On essaye de trouver un bureau
       
    42     try:
       
    43         desktop_path = get_special_folder_path("CSIDL_COMMON_DESKTOPDIRECTORY")
       
    44     except OSError:
       
    45         desktop_path = get_special_folder_path("CSIDL_DESKTOPDIRECTORY")
       
    46     
       
    47     # On créé le raccourcis
       
    48     create_shortcut(pyw_path, # programme à lancer
       
    49                     "Can Node Editor", # Description
       
    50                     os.path.join(desktop_path, 'Beremiz.lnk'),  # fichier du raccourcis (gardez le .lnk)
       
    51                     script_path, # Argument (script python)
       
    52                     Beremiz_dir, # Dossier courant
       
    53                     ico_path # Fichier de l'icone
       
    54                     )
       
    55     # On va cafter au programme de désinstallation qu'on a fait un fichier, pour qu'il soit supprimé
       
    56     # lors de la désinstallation
       
    57     file_created(os.path.join(desktop_path, 'Beremiz.lnk'))
       
    58     
       
    59     # Raccourcis dans le menu démarrer (idem qu'avant)
       
    60     try:
       
    61         start_path = get_special_folder_path("CSIDL_COMMON_PROGRAMS")
       
    62     except OSError:
       
    63         start_path = get_special_folder_path("CSIDL_PROGRAMS")
       
    64     
       
    65     
       
    66 
       
    67     # Création du dossier dans le menu programme
       
    68     programs_path = os.path.join(start_path, "Beremiz project")
       
    69     try :
       
    70         os.mkdir(programs_path)
       
    71 
       
    72     except OSError:
       
    73 
       
    74         pass
       
    75     directory_created(programs_path)
       
    76     
       
    77     create_shortcut(pyw_path, # Cible
       
    78                     "Can Node Editor", #Description
       
    79                     os.path.join(programs_path, 'Beremiz.lnk'),  # Fichier
       
    80                     script_path, # Argument
       
    81                     Beremiz_dir, # Dossier de travail
       
    82                     ico_path # Icone
       
    83                     )
       
    84     file_created(os.path.join(programs_path, 'Beremiz.lnk'))
       
    85     
       
    86     # End (youpi-message)
       
    87     # Ce message sera affiché (très) furtivement dans l'installateur.
       
    88     # Vous pouvez vous en servir comme moyen de communication secret, c'est très in.
       
    89     sys.stdout.write("Shortcuts created.")
       
    90     # Fin du bidule
       
    91     sys.exit()