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
|
2021-02-22 18:48:20 +00:00
|
|
|
# Copyright (C) 2021 sezanzeb <proxima@sezanzeb.de>
|
2020-10-26 22:45:22 +00:00
|
|
|
#
|
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-29 09:42:20 +00:00
|
|
|
import glob
|
2021-01-31 14:09:47 +00:00
|
|
|
import os
|
|
|
|
import re
|
2021-06-28 19:24:30 +00:00
|
|
|
import subprocess
|
|
|
|
from os.path import basename, splitext, join
|
2020-11-29 09:42:20 +00:00
|
|
|
from setuptools import setup
|
2021-01-31 14:09:47 +00:00
|
|
|
from setuptools.command.install import install
|
|
|
|
|
|
|
|
|
2021-06-28 19:24:30 +00:00
|
|
|
PO_FILES = 'po/*.po'
|
|
|
|
|
2021-07-03 13:49:23 +00:00
|
|
|
|
2021-01-31 14:09:47 +00:00
|
|
|
class Install(install):
|
2021-07-03 13:49:23 +00:00
|
|
|
"""Add the commit hash and build .mo translations."""
|
2021-01-31 14:09:47 +00:00
|
|
|
def run(self):
|
2021-09-29 18:41:55 +00:00
|
|
|
try:
|
|
|
|
commit = os.popen('git rev-parse HEAD').read().strip()
|
|
|
|
if re.match(r'^([a-z]|[0-9])+$', commit):
|
|
|
|
# for whatever reason different systems have different paths here
|
|
|
|
build_dir = ''
|
|
|
|
if os.path.exists('build/lib/keymapper'):
|
|
|
|
build_dir = 'build/lib/'
|
|
|
|
with open(f'{build_dir}keymapper/commit_hash.py', 'w+') as f:
|
|
|
|
f.write(f"COMMIT_HASH = '{commit}'\n")
|
|
|
|
except Exception as e:
|
|
|
|
print('Failed to save the commit hash:', e)
|
2021-07-03 13:49:23 +00:00
|
|
|
|
2021-06-28 19:24:30 +00:00
|
|
|
# generate .mo files
|
|
|
|
make_lang()
|
2021-01-31 14:09:47 +00:00
|
|
|
|
|
|
|
install.run(self)
|
2020-10-26 22:45:22 +00:00
|
|
|
|
2020-12-24 00:26:34 +00:00
|
|
|
|
2021-09-29 18:17:45 +00:00
|
|
|
def get_packages(base='keymapper'):
|
2021-03-21 18:15:20 +00:00
|
|
|
"""Return all modules used in key-mapper.
|
|
|
|
|
2021-09-29 18:17:45 +00:00
|
|
|
For example 'keymapper.gui' or 'keymapper.injection.consumers'
|
2021-03-21 18:15:20 +00:00
|
|
|
"""
|
2021-09-29 18:17:45 +00:00
|
|
|
if not os.path.exists(os.path.join(base, '__init__.py')):
|
|
|
|
# only python modules
|
|
|
|
return []
|
|
|
|
|
|
|
|
result = [base.replace('/', '.')]
|
|
|
|
for name in os.listdir(base):
|
|
|
|
if not os.path.isdir(os.path.join(base, name)):
|
2021-03-21 18:15:20 +00:00
|
|
|
continue
|
|
|
|
|
|
|
|
if name == '__pycache__':
|
|
|
|
continue
|
|
|
|
|
2021-09-29 18:17:45 +00:00
|
|
|
# find more python submodules in that directory
|
|
|
|
result += get_packages(os.path.join(base, name))
|
2021-03-21 18:15:20 +00:00
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
2021-06-28 19:24:30 +00:00
|
|
|
def make_lang():
|
2021-07-03 13:49:23 +00:00
|
|
|
"""Build po files into mo/."""
|
2021-06-28 19:24:30 +00:00
|
|
|
os.makedirs('mo', exist_ok=True)
|
|
|
|
for po_file in glob.glob(PO_FILES):
|
|
|
|
lang = splitext(basename(po_file))[0]
|
|
|
|
os.makedirs(join('mo', lang), exist_ok=True)
|
|
|
|
print(f'generating translation for {lang}')
|
|
|
|
subprocess.run(['msgfmt', '-o', join('mo', lang, 'key-mapper.mo'), str(po_file)], check=True)
|
|
|
|
|
2021-07-03 13:49:23 +00:00
|
|
|
|
2021-06-28 19:24:30 +00:00
|
|
|
lang_data = []
|
|
|
|
for po_file in glob.glob(PO_FILES):
|
|
|
|
lang = splitext(basename(po_file))[0]
|
|
|
|
lang_data.append((
|
|
|
|
f'/usr/share/key-mapper/lang/{lang}/LC_MESSAGES',
|
|
|
|
[f'mo/{lang}/key-mapper.mo']
|
|
|
|
))
|
|
|
|
|
2021-07-03 13:49:23 +00:00
|
|
|
|
2020-11-29 09:42:20 +00:00
|
|
|
setup(
|
2020-10-31 13:43:09 +00:00
|
|
|
name='key-mapper',
|
2021-09-29 17:56:08 +00:00
|
|
|
version='1.1.0',
|
2020-11-29 09:42:20 +00:00
|
|
|
description='A tool to change the mapping of your input device buttons',
|
|
|
|
author='Sezanzeb',
|
2021-02-22 18:48:20 +00:00
|
|
|
author_email='proxima@sezanzeb.de',
|
2020-11-29 09:42:20 +00:00
|
|
|
url='https://github.com/sezanzeb/key-mapper',
|
2020-10-26 22:45:22 +00:00
|
|
|
license='GPL-3.0',
|
2021-03-21 18:15:20 +00:00
|
|
|
packages=get_packages(),
|
2021-07-03 13:49:23 +00:00
|
|
|
include_package_data=True,
|
2020-10-26 22:45:22 +00:00
|
|
|
data_files=[
|
2020-12-25 14:39:04 +00:00
|
|
|
# see development.md#files
|
2021-06-28 19:24:30 +00:00
|
|
|
*lang_data,
|
2020-11-29 12:30:16 +00:00
|
|
|
('/usr/share/key-mapper/', glob.glob('data/*')),
|
|
|
|
('/usr/share/applications/', ['data/key-mapper.desktop']),
|
2020-12-24 00:26:34 +00:00
|
|
|
('/usr/share/polkit-1/actions/', ['data/key-mapper.policy']),
|
|
|
|
('/usr/lib/systemd/system', ['data/key-mapper.service']),
|
|
|
|
('/etc/dbus-1/system.d/', ['data/keymapper.Control.conf']),
|
|
|
|
('/etc/xdg/autostart/', ['data/key-mapper-autoload.desktop']),
|
2021-04-16 12:33:50 +00:00
|
|
|
('/usr/lib/udev/rules.d', ['data/key-mapper.rules']),
|
2020-11-29 12:30:16 +00:00
|
|
|
('/usr/bin/', ['bin/key-mapper-gtk']),
|
|
|
|
('/usr/bin/', ['bin/key-mapper-service']),
|
2020-12-24 00:26:34 +00:00
|
|
|
('/usr/bin/', ['bin/key-mapper-control']),
|
2021-03-21 18:15:20 +00:00
|
|
|
('/usr/bin/', ['bin/key-mapper-helper']),
|
2020-11-29 09:42:20 +00:00
|
|
|
],
|
2020-11-29 13:19:32 +00:00
|
|
|
install_requires=[
|
|
|
|
'setuptools',
|
|
|
|
'evdev',
|
2021-04-27 09:55:13 +00:00
|
|
|
'pydbus',
|
|
|
|
'pygobject',
|
2020-12-24 00:26:34 +00:00
|
|
|
],
|
2021-01-31 14:09:47 +00:00
|
|
|
cmdclass={
|
|
|
|
'install': Install,
|
|
|
|
},
|
2020-10-26 22:45:22 +00:00
|
|
|
)
|