2024-10-29 08:23:45 +00:00
|
|
|
#!/usr/bin/env python3
|
2020-10-26 22:45:22 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2022-01-01 12:00:49 +00:00
|
|
|
# input-remapper - GUI for device specific keyboard mappings
|
2024-10-16 19:15:11 +00:00
|
|
|
# Copyright (C) 2024 sezanzeb <b8x45ygc9@mozmail.com>
|
2020-10-26 22:45:22 +00:00
|
|
|
#
|
2022-01-01 12:00:49 +00:00
|
|
|
# This file is part of input-remapper.
|
2020-10-26 22:45:22 +00:00
|
|
|
#
|
2022-01-01 12:00:49 +00:00
|
|
|
# input-remapper 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.
|
|
|
|
#
|
2022-01-01 12:00:49 +00:00
|
|
|
# input-remapper 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
|
2022-01-01 12:00:49 +00:00
|
|
|
# along with input-remapper. 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-11-07 09:38:06 +00:00
|
|
|
PO_FILES = "po/*.po"
|
2021-06-28 19:24:30 +00:00
|
|
|
|
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-11-07 09:38:06 +00:00
|
|
|
|
2021-01-31 14:09:47 +00:00
|
|
|
def run(self):
|
2021-09-29 18:41:55 +00:00
|
|
|
try:
|
2021-11-07 09:38:06 +00:00
|
|
|
commit = os.popen("git rev-parse HEAD").read().strip()
|
|
|
|
if re.match(r"^([a-z]|[0-9])+$", commit):
|
2021-09-29 18:41:55 +00:00
|
|
|
# for whatever reason different systems have different paths here
|
2021-11-07 09:38:06 +00:00
|
|
|
build_dir = ""
|
2022-01-01 12:00:49 +00:00
|
|
|
if os.path.exists("build/lib/inputremapper"):
|
2021-11-07 09:38:06 +00:00
|
|
|
build_dir = "build/lib/"
|
2022-01-01 12:00:49 +00:00
|
|
|
with open(f"{build_dir}inputremapper/commit_hash.py", "w+") as f:
|
2021-09-29 18:41:55 +00:00
|
|
|
f.write(f"COMMIT_HASH = '{commit}'\n")
|
|
|
|
except Exception as e:
|
2021-11-07 09:38:06 +00:00
|
|
|
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
|
|
|
|
2022-01-01 12:00:49 +00:00
|
|
|
def get_packages(base="inputremapper"):
|
|
|
|
"""Return all modules used in input-remapper.
|
2021-03-21 18:15:20 +00:00
|
|
|
|
2022-04-17 10:19:23 +00:00
|
|
|
For example 'inputremapper.gui' or 'inputremapper.injection.mapping_handlers'
|
2021-03-21 18:15:20 +00:00
|
|
|
"""
|
2021-11-07 09:38:06 +00:00
|
|
|
if not os.path.exists(os.path.join(base, "__init__.py")):
|
2021-09-29 18:17:45 +00:00
|
|
|
# only python modules
|
|
|
|
return []
|
|
|
|
|
2021-11-07 09:38:06 +00:00
|
|
|
result = [base.replace("/", ".")]
|
2021-09-29 18:17:45 +00:00
|
|
|
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
|
|
|
|
|
2021-11-07 09:38:06 +00:00
|
|
|
if name == "__pycache__":
|
2021-03-21 18:15:20 +00:00
|
|
|
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-11-07 09:38:06 +00:00
|
|
|
os.makedirs("mo", exist_ok=True)
|
2021-06-28 19:24:30 +00:00
|
|
|
for po_file in glob.glob(PO_FILES):
|
|
|
|
lang = splitext(basename(po_file))[0]
|
2021-11-07 09:38:06 +00:00
|
|
|
os.makedirs(join("mo", lang), exist_ok=True)
|
|
|
|
print(f"generating translation for {lang}")
|
|
|
|
subprocess.run(
|
2022-01-01 12:00:49 +00:00
|
|
|
["msgfmt", "-o", join("mo", lang, "input-remapper.mo"), str(po_file)],
|
2021-11-07 09:38:06 +00:00
|
|
|
check=True,
|
|
|
|
)
|
2021-06-28 19:24:30 +00:00
|
|
|
|
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]
|
2021-11-07 09:38:06 +00:00
|
|
|
lang_data.append(
|
2022-01-10 19:37:22 +00:00
|
|
|
(
|
|
|
|
f"/usr/share/input-remapper/lang/{lang}/LC_MESSAGES",
|
|
|
|
[f"mo/{lang}/input-remapper.mo"],
|
|
|
|
)
|
2021-11-07 09:38:06 +00:00
|
|
|
)
|
2021-06-28 19:24:30 +00:00
|
|
|
|
2021-07-03 13:49:23 +00:00
|
|
|
|
2020-11-29 09:42:20 +00:00
|
|
|
setup(
|
2022-01-01 12:00:49 +00:00
|
|
|
name="input-remapper",
|
2023-09-18 21:42:29 +00:00
|
|
|
version="2.0.1",
|
2021-11-07 09:38:06 +00:00
|
|
|
description="A tool to change the mapping of your input device buttons",
|
|
|
|
author="Sezanzeb",
|
|
|
|
author_email="proxima@sezanzeb.de",
|
2022-01-01 12:00:49 +00:00
|
|
|
url="https://github.com/sezanzeb/input-remapper",
|
2021-11-07 09:38:06 +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,
|
2022-01-01 12:00:49 +00:00
|
|
|
("/usr/share/input-remapper/", glob.glob("data/*")),
|
2023-02-12 08:56:33 +00:00
|
|
|
("/usr/share/applications/", ["data/input-remapper-gtk.desktop"]),
|
2023-02-27 17:49:13 +00:00
|
|
|
(
|
|
|
|
"/usr/share/metainfo/",
|
|
|
|
["data/io.github.sezanzeb.input_remapper.metainfo.xml"],
|
|
|
|
),
|
2024-01-27 10:59:18 +00:00
|
|
|
("/usr/share/icons/hicolor/scalable/apps/", ["data/input-remapper.svg"]),
|
2022-01-01 12:00:49 +00:00
|
|
|
("/usr/share/polkit-1/actions/", ["data/input-remapper.policy"]),
|
|
|
|
("/usr/lib/systemd/system", ["data/input-remapper.service"]),
|
|
|
|
("/etc/dbus-1/system.d/", ["data/inputremapper.Control.conf"]),
|
|
|
|
("/etc/xdg/autostart/", ["data/input-remapper-autoload.desktop"]),
|
|
|
|
("/usr/lib/udev/rules.d", ["data/99-input-remapper.rules"]),
|
|
|
|
("/usr/bin/", ["bin/input-remapper-gtk"]),
|
|
|
|
("/usr/bin/", ["bin/input-remapper-service"]),
|
|
|
|
("/usr/bin/", ["bin/input-remapper-control"]),
|
2022-11-11 23:48:59 +00:00
|
|
|
("/usr/bin/", ["bin/input-remapper-reader-service"]),
|
2020-11-29 09:42:20 +00:00
|
|
|
],
|
2022-02-07 16:52:41 +00:00
|
|
|
install_requires=["setuptools", "evdev", "pydbus", "pygobject", "pydantic"],
|
2021-01-31 14:09:47 +00:00
|
|
|
cmdclass={
|
2021-11-07 09:38:06 +00:00
|
|
|
"install": Install,
|
2021-01-31 14:09:47 +00:00
|
|
|
},
|
2020-10-26 22:45:22 +00:00
|
|
|
)
|