| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
import os, sys, stat |
| 24 |
from os.path import join, expanduser, isdir |
| 25 |
from .scriptlib import command, cd, cp |
| 26 |
|
| 27 |
_module_path = os.path.split(os.path.realpath(sys._getframe().f_code.co_filename))[0] |
| 28 |
|
| 29 |
print('Repertoire courant : ' + _module_path) |
| 30 |
|
| 31 |
paths = { |
| 32 |
'root': '/usr/local', |
| 33 |
'local': expanduser('~/.local'), |
| 34 |
} |
| 35 |
|
| 36 |
locations = { |
| 37 |
'desktop_path': 'applications', |
| 38 |
'mime_root_path': 'mime', |
| 39 |
'mime_path': 'mime/packages', |
| 40 |
'svg_icon_path': 'icons/hicolor/scalable/apps', |
| 41 |
'png_icon_path': 'icons/hicolor/48x48/apps', |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
while True: |
| 47 |
choice = input('Installer pour tous les utilisateurs (o/N) ?') |
| 48 |
if choice in ('n', 'N', ''): |
| 49 |
choice = 'local' |
| 50 |
break |
| 51 |
elif choice in ('o', 'O'): |
| 52 |
if not os.access(paths['root'], os.W_OK): |
| 53 |
print("\n\033[1;31m*** ERREUR ***\033[0m") |
| 54 |
print("Vous n'avez pas la permission d'installer pour " |
| 55 |
"tous les utilisateurs.") |
| 56 |
print("Tapez '\033[0;32msudo python tools/linux-install.py\033[0m' pour une " |
| 57 |
"installation multi-utilisateurs.") |
| 58 |
sys.exit(1) |
| 59 |
choice = 'root' |
| 60 |
break |
| 61 |
else: |
| 62 |
print("Réponse incorrecte (tapez 'o' ou 'N').") |
| 63 |
|
| 64 |
|
| 65 |
for loc in locations: |
| 66 |
locations[loc] = join(paths[choice], 'share', locations[loc]) |
| 67 |
if not isdir(locations[loc]): |
| 68 |
os.makedirs(locations[loc]) |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
cd(join(_module_path, 'resources')) |
| 73 |
|
| 74 |
cp('geophar.desktop', locations['desktop_path']) |
| 75 |
cp('geophar.svg', locations['svg_icon_path']) |
| 76 |
cp('geophar.png', locations['png_icon_path']) |
| 77 |
cp('x-geophar.xml', locations['mime_path']) |
| 78 |
|
| 79 |
cd('../..') |
| 80 |
|
| 81 |
. |
| 82 |
if choice == 'root': |
| 83 |
exec_path = '/usr/local/bin' |
| 84 |
else: |
| 85 |
exec_path = expanduser('~/bin') |
| 86 |
if not isdir(exec_path): |
| 87 |
os.mkdir(exec_path) |
| 88 |
|
| 89 |
script_name = join(exec_path, 'geophar') |
| 90 |
|
| 91 |
with open(script_name, 'w') as f: |
| 92 |
f.write('#!/bin/sh\n') |
| 93 |
f.write('exec %s/geophar.pyw $*' % os.getcwd()) |
| 94 |
|
| 95 |
if choice == 'root': |
| 96 |
os.chmod(script_name, stat.S_IRWXU|stat.S_IXOTH) |
| 97 |
else: |
| 98 |
os.chmod(script_name, stat.S_IRWXU) |
| 99 |
|
| 100 |
s. |
| 101 |
|
| 102 |
update_desktop = 'update-desktop-database %s' % locations['desktop_path'] |
| 103 |
update_mime = 'update-mime-database %s' % locations['mime_root_path'] |
| 104 |
command(update_desktop) |
| 105 |
command(update_mime) |
| 106 |
|
| 107 |
n. |
| 108 |
|
| 109 |
cd(_module_path) |
| 110 |
|
| 111 |
with open('linux-uninstall.py', 'w') as f: |
| 112 |
f.write('#!/usr/bin/env python3\n') |
| 113 |
f.write('# -*- coding: utf-8 -*-\n') |
| 114 |
f.write('from scriptlib import *\n') |
| 115 |
f.write('rm(%s)\n' % repr(join(locations['desktop_path'], 'geophar.desktop'))) |
| 116 |
f.write('rm(%s)\n' % repr(join(locations['mime_path'], 'x-geophar.xml'))) |
| 117 |
f.write('rm(%s)\n' % repr(join(locations['svg_icon_path'], 'geophar.svg'))) |
| 118 |
f.write('rm(%s)\n' % repr(join(locations['png_icon_path'], 'geophar.png'))) |
| 119 |
f.write('rm(%s)\n' % repr(script_name)) |
| 120 |
f.write('command(%s)\n' % repr(update_desktop)) |
| 121 |
f.write('command(%s)\n' % repr(update_mime)) |
| 122 |
f.write('print("=== Desinstallation terminee. ===")') |
| 123 |
|
| 124 |
os.chmod('linux-uninstall.py', stat.S_IRWXU) |
| 125 |
|
| 126 |
print("=== L'installation est terminée. ===") |
| 127 |
print("Un fichier linux-uninstall.py a été généré.") |