1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# input-remapper - GUI for device specific keyboard mappings
# Copyright (C) 2025 sezanzeb <b8x45ygc9@mozmail.com>
#
# This file is part of input-remapper.
#
# input-remapper is free software: you can redistribute it and/or modify
# 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.
#
# input-remapper is distributed in the hope that it will be useful,
# 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
# along with input-remapper. If not, see <https://www.gnu.org/licenses/>.
import glob
import os
import re
import subprocess
from os.path import basename, splitext, join
from setuptools import setup
from setuptools.command.install import install
PO_FILES = "po/*.po"
class Install(install):
"""Add the commit hash and build .mo translations."""
def run(self):
# generate .mo files
make_lang()
install.run(self)
def get_packages(base="inputremapper"):
"""Return all modules used in input-remapper.
For example 'inputremapper.gui' or 'inputremapper.injection.mapping_handlers'
"""
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)):
continue
if name == "__pycache__":
continue
# find more python submodules in that directory
result += get_packages(os.path.join(base, name))
return result
def make_lang():
"""Build po files into mo/."""
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, "input-remapper.mo"), str(po_file)],
check=True,
)
lang_data = []
for po_file in glob.glob(PO_FILES):
lang = splitext(basename(po_file))[0]
lang_data.append(
(
f"/usr/share/input-remapper/lang/{lang}/LC_MESSAGES",
[f"mo/{lang}/input-remapper.mo"],
)
)
setup(
name="input-remapper",
version="2.1.1",
description="A tool to change the mapping of your input device buttons",
author="Sezanzeb",
author_email="proxima@sezanzeb.de",
url="https://github.com/sezanzeb/input-remapper",
license="GPL-3.0",
packages=get_packages(),
include_package_data=True,
data_files=[
# see development.md#files
*lang_data,
("/usr/share/input-remapper/", glob.glob("data/*")),
("/usr/share/applications/", ["data/input-remapper-gtk.desktop"]),
(
"/usr/share/metainfo/",
["data/io.github.sezanzeb.input_remapper.metainfo.xml"],
),
("/usr/share/icons/hicolor/scalable/apps/", ["data/input-remapper.svg"]),
("/usr/share/polkit-1/actions/", ["data/input-remapper.policy"]),
("/usr/share/dbus-1/system.d/", ["data/inputremapper.Control.conf"]),
("/etc/xdg/autostart/", ["data/input-remapper-autoload.desktop"]),
("/usr/bin/", ["bin/input-remapper-gtk"]),
("/usr/bin/", ["bin/input-remapper-service"]),
("/usr/bin/", ["bin/input-remapper-control"]),
("/usr/bin/", ["bin/input-remapper-reader-service"]),
],
install_requires=["setuptools", "evdev", "psutil", "pydbus", "pygobject", "pydantic"],
cmdclass={
"install": Install,
},
)
|