2020-10-26 22:45:22 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
# -*- coding: utf-8 -*-
|
2020-10-31 13:43:09 +00:00
|
|
|
# key-mapper - GUI for device specific keyboard mappings
|
2020-10-26 22:45:22 +00:00
|
|
|
# Copyright (C) 2020 sezanzeb <proxima@hip70890b.de>
|
|
|
|
#
|
2020-10-31 13:02:59 +00:00
|
|
|
# This file is part of key-mapper.
|
2020-10-26 22:45:22 +00:00
|
|
|
#
|
2020-10-31 13:02:59 +00:00
|
|
|
# key-mapper is free software: you can redistribute it and/or modify
|
2020-10-26 22:45:22 +00:00
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
2020-10-31 13:02:59 +00:00
|
|
|
# key-mapper is distributed in the hope that it will be useful,
|
2020-10-26 22:45:22 +00:00
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2020-10-31 13:02:59 +00:00
|
|
|
# along with key-mapper. If not, see <https://www.gnu.org/licenses/>.
|
2020-10-26 22:45:22 +00:00
|
|
|
|
|
|
|
|
2020-11-21 15:36:20 +00:00
|
|
|
import os
|
|
|
|
|
2020-10-26 22:45:22 +00:00
|
|
|
import DistUtilsExtra.auto
|
|
|
|
|
|
|
|
|
2020-11-21 15:36:20 +00:00
|
|
|
class Install(DistUtilsExtra.auto.install_auto):
|
|
|
|
def run(self):
|
|
|
|
DistUtilsExtra.auto.install_auto.run(self)
|
|
|
|
self.ensure_polkit_prefix()
|
|
|
|
|
|
|
|
def ensure_polkit_prefix(self):
|
|
|
|
"""Make sure the policy file uses the right prefix."""
|
|
|
|
executable = os.path.join(self.install_data, 'bin/key-mapper-gtk')
|
|
|
|
assert os.path.exists(executable)
|
|
|
|
|
2020-11-25 20:55:04 +00:00
|
|
|
policy_path = '/usr/share/polkit-1/actions/key-mapper.policy'
|
2020-11-21 15:36:20 +00:00
|
|
|
|
2020-11-22 20:41:29 +00:00
|
|
|
with open(policy_path, 'r') as file:
|
|
|
|
contents = file.read()
|
2020-11-21 15:36:20 +00:00
|
|
|
if '{executable}' not in contents:
|
|
|
|
# already done previously
|
|
|
|
return
|
|
|
|
|
2020-11-22 20:41:29 +00:00
|
|
|
with open(policy_path, 'w') as file:
|
2020-11-21 15:36:20 +00:00
|
|
|
print(
|
|
|
|
f'Inserting the correct path "{executable}" into '
|
2020-11-25 20:55:04 +00:00
|
|
|
'keymapper.policy'
|
2020-11-21 15:36:20 +00:00
|
|
|
)
|
2020-11-22 20:41:29 +00:00
|
|
|
file.write(contents.format(
|
2020-11-21 15:36:20 +00:00
|
|
|
executable=executable
|
|
|
|
))
|
|
|
|
|
|
|
|
|
2020-10-26 22:45:22 +00:00
|
|
|
DistUtilsExtra.auto.setup(
|
2020-10-31 13:43:09 +00:00
|
|
|
name='key-mapper',
|
2020-10-26 22:45:22 +00:00
|
|
|
version='0.1.0',
|
2020-10-31 13:43:09 +00:00
|
|
|
description='GUI for device specific keyboard mappings',
|
2020-10-26 22:45:22 +00:00
|
|
|
license='GPL-3.0',
|
|
|
|
data_files=[
|
2020-10-31 13:43:09 +00:00
|
|
|
('share/applications/', ['data/key-mapper.desktop']),
|
2020-11-25 20:55:04 +00:00
|
|
|
('/usr/share/polkit-1/actions/', ['data/key-mapper.policy']),
|
|
|
|
('/usr/lib/systemd/system', ['data/key-mapper.service']),
|
|
|
|
('/etc/xdg/autostart/', ['data/key-mapper-autoload']),
|
2020-10-26 22:45:22 +00:00
|
|
|
],
|
2020-11-21 15:36:20 +00:00
|
|
|
cmdclass={
|
|
|
|
'install': Install
|
|
|
|
}
|
2020-10-26 22:45:22 +00:00
|
|
|
)
|