1#!/usr/bin/env python3 2# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- 3# LightDM GTK Greeter Settings 4# Copyright (C) 2014 Andrew P. <pan.pav.7c5@gmail.com> 5# 6# This program is free software: you can redistribute it and/or modify it 7# under the terms of the GNU General Public License version 3, as published 8# by the Free Software Foundation. 9# 10# This program is distributed in the hope that it will be useful, but 11# WITHOUT ANY WARRANTY; without even the implied warranties of 12# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 13# PURPOSE. See the GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License along 16# with this program. If not, see <http://www.gnu.org/licenses/>. 17 18import os 19import sys 20 21try: 22 import DistUtilsExtra.auto 23except ImportError: 24 print( 25 'To build lightdm-gtk-greeter-settings you need ' 26 'https://launchpad.net/python-distutils-extra') 27 sys.exit(1) 28assert DistUtilsExtra.auto.__version__ >= '2.18', \ 29 'needs DistUtilsExtra.auto >= 2.18' 30 31 32def write_config(libdir, values): 33 filename = os.path.join( 34 libdir, 'lightdm_gtk_greeter_settings/installation_config.py') 35 try: 36 f = open(filename, 'w') 37 f.write('__all__ = [%s]\n' % ', '.join('"%s"' % k for k in sorted(values))) 38 for k, v in sorted(values.items()): 39 f.write('%s = %s\n' % (k, v)) 40 except OSError as e: 41 print("ERROR: Can't write installation config: %s" % e) 42 sys.exit(1) 43 44 45class InstallAndUpdateDataDirectory(DistUtilsExtra.auto.install_auto): 46 47 user_options = DistUtilsExtra.auto.install_auto.user_options + \ 48 [('xfce-integration', None, 49 'adds application icon to Xfce settings manager'), 50 ('use-gtk-header', None, 51 'use GtkHeaderBar instead of default DE window header')] 52 53 def initialize_options(self): 54 super().initialize_options() 55 self.xfce_integration = None 56 self.use_gtk_header = None 57 58 def run(self): 59 DistUtilsExtra.auto.install_auto.run(self) 60 61 target_data = '/' + os.path.relpath(self.install_data, self.root) + '/' 62 target_pkgdata = target_data + 'share/lightdm-gtk-greeter-settings/' 63 64 values = {'__data_directory__': "'%s'" % (target_pkgdata), 65 '__version__': "'%s'" % self.distribution.get_version(), 66 '__config_path__': '"/usr/local/etc/lightdm/lightdm-gtk-greeter.conf"'} 67 write_config(self.install_lib, values) 68 69 desktop_file_path = os.path.join(self.install_data, 'share', 'applications', 70 'lightdm-gtk-greeter-settings.desktop') 71 72 if self.xfce_integration: 73 with open(desktop_file_path, 'a') as f: 74 f.write('X-XfcePluggable=true\n') 75 76 if self.use_gtk_header: 77 with open(desktop_file_path, 'r+') as f: 78 lines = f.readlines() 79 for i, line in enumerate(lines): 80 if line.startswith('Exec='): 81 lines[i] = line.strip() + ' --use-gtk-header\n' 82 break 83 f.seek(0) 84 f.truncate(0) 85 f.writelines(lines) 86 87 88DistUtilsExtra.auto.setup( 89 name='lightdm-gtk-greeter-settings', 90 version='1.2.2', 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