|
0 |
#!/usr/bin/env python3
|
|
1 |
|
|
2 |
import os
|
|
3 |
import sys
|
|
4 |
import configparser
|
|
5 |
|
|
6 |
try:
|
|
7 |
import DistUtilsExtra.auto
|
|
8 |
except ImportError:
|
|
9 |
print('To build lightdm-gtk-greeter-settings you need https://launchpad.net/python-distutils-extra')
|
|
10 |
sys.exit(1)
|
|
11 |
assert DistUtilsExtra.auto.__version__ >= '2.18', 'needs DistUtilsExtra.auto >= 2.18'
|
|
12 |
|
|
13 |
def write_config(libdir, values):
|
|
14 |
filename = os.path.join(libdir, 'lightdm_gtk_greeter_settings/installation_config.py')
|
|
15 |
try:
|
|
16 |
f = open(filename, 'w')
|
|
17 |
f.write('__all__ = [%s]\n' % ', '.join('"%s"' % k for k in values))
|
|
18 |
for k, v in values.items():
|
|
19 |
f.write('%s = %s\n' % (k, v))
|
|
20 |
except OSError as e:
|
|
21 |
print ("ERROR: Can't write installation_config: %s" % e)
|
|
22 |
sys.exit(1)
|
|
23 |
|
|
24 |
|
|
25 |
def move_desktop_file(root, target_data, prefix):
|
|
26 |
old_desktop_path = os.path.normpath(root + target_data +
|
|
27 |
'/share/applications')
|
|
28 |
old_desktop_file = old_desktop_path + '/lightdm-gtk-greeter-settings.desktop'
|
|
29 |
desktop_path = os.path.normpath(root + prefix + '/share/applications')
|
|
30 |
desktop_file = desktop_path + '/lightdm-gtk-greeter-settings.desktop'
|
|
31 |
|
|
32 |
if not os.path.exists(old_desktop_file):
|
|
33 |
print("ERROR: Can't find", old_desktop_file)
|
|
34 |
sys.exit(1)
|
|
35 |
elif target_data != prefix + '/':
|
|
36 |
# This is an /opt install, so rename desktop file to use extras-
|
|
37 |
desktop_file = desktop_path + '/extras-lightdm-gtk-greeter-settings.desktop'
|
|
38 |
try:
|
|
39 |
os.makedirs(desktop_path)
|
|
40 |
os.rename(old_desktop_file, desktop_file)
|
|
41 |
os.rmdir(old_desktop_path)
|
|
42 |
except OSError as e:
|
|
43 |
print ("ERROR: Can't rename", old_desktop_file, ":", e)
|
|
44 |
sys.exit(1)
|
|
45 |
|
|
46 |
return desktop_file
|
|
47 |
|
|
48 |
|
|
49 |
def update_desktop_file(filename, target_pkgdata, target_scripts):
|
|
50 |
|
|
51 |
config = configparser.RawConfigParser(strict=False, allow_no_value=True)
|
|
52 |
try:
|
|
53 |
config.read(filename)
|
|
54 |
except configparser.Error as e:
|
|
55 |
print("Cann't parse desktop file: %s" % e)
|
|
56 |
sys.exit(1)
|
|
57 |
|
|
58 |
if not config.has_section('Desktop Entry'):
|
|
59 |
config.add_section('Desktop Entry')
|
|
60 |
|
|
61 |
old_command = config.get('Desktop Entry', 'Exec', fallback='').split(None, 1)
|
|
62 |
new_command = target_scripts + 'lightdm-gtk-greeter-settings'
|
|
63 |
if len(old_command) > 1:
|
|
64 |
new_command += ' ' + new_command[1]
|
|
65 |
config.set('Desktop Entry', 'Exec', new_command)
|
|
66 |
|
|
67 |
with open(filename, 'w') as f:
|
|
68 |
config.write(f)
|
|
69 |
|
|
70 |
|
|
71 |
class InstallAndUpdateDataDirectory(DistUtilsExtra.auto.install_auto):
|
|
72 |
def run(self):
|
|
73 |
DistUtilsExtra.auto.install_auto.run(self)
|
|
74 |
|
|
75 |
target_data = '/' + os.path.relpath(self.install_data, self.root) + '/'
|
|
76 |
target_pkgdata = target_data + 'share/lightdm-gtk-greeter-settings/'
|
|
77 |
target_scripts = '/' + os.path.relpath(self.install_scripts, self.root) + '/'
|
|
78 |
|
|
79 |
values = {'__data_directory__': "'%s'" % (target_pkgdata),
|
|
80 |
'__version__': "%s" % self.distribution.get_version(),
|
|
81 |
'__config_path__': '"/etc/lightdm/lightdm-gtk-greeter.conf"'}
|
|
82 |
write_config(self.install_lib, values)
|
|
83 |
|
|
84 |
desktop_file = move_desktop_file(self.root, target_data, self.prefix)
|
|
85 |
update_desktop_file(desktop_file, target_pkgdata, target_scripts)
|
|
86 |
|
|
87 |
|
|
88 |
DistUtilsExtra.auto.setup(
|
|
89 |
name='lightdm-gtk-greeter-settings',
|
|
90 |
version='0.1',
|
|
91 |
license='GPL-3',
|
|
92 |
author='Andrew P.',
|
|
93 |
author_email='pan.pav.7c5@gmail.com',
|
|
94 |
description='Settings editor for LightDM GTK+ Greeter',
|
|
95 |
long_description='Settings editor for LightDM GTK+ Greeter',
|
|
96 |
url='https://launchpad.net/lightdm-gtk-greeter-settings',
|
|
97 |
cmdclass={'install': InstallAndUpdateDataDirectory}
|
|
98 |
)
|
|
99 |
|