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