## START: Set by rpmautospec
## (rpmautospec version 0.3.5)
## RPMAUTOSPEC: autorelease, autochangelog
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 4;
    base_release_number = tonumber(rpm.expand("%{?-b*}%{!?-b:1}"));
    print(release_number + base_release_number - 1);
}%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{!?-n:%{?dist}}
## END: Set by rpmautospec

Name:           input-remapper
Version:        2.0.0
Release:        %autorelease
Summary:        An easy to use tool to change the behaviour of your input devices

License:        GPL-3.0-or-later
URL:            https://github.com/sezanzeb/%{name}
Source0:        %{url}/archive/master/%{name}-%{version}.tar.gz
Source1:        README.Fedora
BuildArch:      noarch

BuildRequires:  desktop-file-utils
BuildRequires:  libappstream-glib
BuildRequires:  pyproject-rpm-macros
BuildRequires:  systemd-rpm-macros
BuildRequires:  python3-devel
BuildRequires:  python3-setuptools
BuildRequires:  python3-wheel
BuildRequires:  gettext
Requires:       gtksourceview4

%generate_buildrequires
%pyproject_buildrequires -r


%description
An easy to use tool to change the mapping of your input device buttons. 
Supports mice, keyboards, gamepads, X11, Wayland, combined buttons and 
programmable macros. Allows mapping non-keyboard events (click, joystick, 
wheel) to keys of keyboard devices.
The program works at the evdev interface level, by filtering and redirecting 
the output of physical devices to that of virtual ones.


%prep
%autosetup -p1 -n %{name}-%{version}
cp %{SOURCE1} ./
#Fix rpmlint errors
#find inputremapper/ -iname "*.py" -type f -print0 | xargs -0 sed -i -e 's+\s*#\s*!/usr/bin/python3++'


%build
%pyproject_wheel


%install
%pyproject_install
%pyproject_save_files inputremapper
mv %{buildroot}%{python3_sitelib}/etc %{buildroot}/etc
mv %{buildroot}%{python3_sitelib}/usr/bin %{buildroot}/usr/bin
mv %{buildroot}%{python3_sitelib}/usr/lib/systemd %{buildroot}/usr/lib/systemd
mv %{buildroot}%{python3_sitelib}/usr/lib/udev %{buildroot}/usr/lib/udev
mv %{buildroot}%{python3_sitelib}/usr/share %{buildroot}/usr/share
mkdir -p %{buildroot}/usr/share/dbus-1/system.d/
mv %{buildroot}/etc/dbus-1/system.d/inputremapper.Control.conf %{buildroot}/usr/share/dbus-1/system.d/

# clean up duplicate files
rm %{buildroot}%{_datadir}/%{name}/inputremapper.Control.conf
rm %{buildroot}%{_datadir}/%{name}/io.github.sezanzeb.input_remapper.metainfo.xml
rm %{buildroot}%{_datadir}/%{name}/%{name}-gtk.desktop
rm %{buildroot}%{_datadir}/%{name}/%{name}.policy


%post -n %{name}
%systemd_post %{name}.service


%preun -n %{name}
%systemd_preun %{name}.service


%postun -n %{name}
%systemd_postun_with_restart %{name}.service


%check
desktop-file-validate %{buildroot}/%{_datadir}/applications/%{name}-gtk.desktop
appstream-util validate-relax --nonet %{buildroot}%{_metainfodir}/*.metainfo.xml


%files -f %{pyproject_files}
%doc README.md README.Fedora
%license LICENSE
%{_datadir}/dbus-1/system.d/inputremapper.Control.conf
%{_sysconfdir}/xdg/autostart/%{name}-autoload.desktop
%{_bindir}/%{name}*
%{_unitdir}/%{name}.service
%{_udevrulesdir}/99-%{name}.rules
%{_datadir}/%{name}

# deal with non-standard location of localization files
%exclude %dir %{_datadir}/%{name}/lang
%lang(fr) %{_datadir}/%{name}/lang/fr
%lang(fr) %{_datadir}/%{name}/lang/fr_FR
%lang(it) %{_datadir}/%{name}/lang/it
%lang(it) %{_datadir}/%{name}/lang/it_IT
%lang(ru) %{_datadir}/%{name}/lang/ru
%lang(ru) %{_datadir}/%{name}/lang/ru_RU
%lang(sk) %{_datadir}/%{name}/lang/sk
%lang(sk) %{_datadir}/%{name}/lang/sk_SK
%lang(uk) %{_datadir}/%{name}/lang/uk
%lang(uk) %{_datadir}/%{name}/lang/uk_UA
%lang(zh) %{_datadir}/%{name}/lang/zh
%lang(zh) %{_datadir}/%{name}/lang/zh_CN

%{_datadir}/applications/%{name}-gtk.desktop
%{_datadir}/polkit-1/actions/%{name}.policy
%{_metainfodir}/*.metainfo.xml


%changelog
* Thu Jul 20 2023 Fedora Release Engineering <releng@fedoraproject.org> - 2.0.0-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild

* Thu Jun 15 2023 Python Maint <python-maint@redhat.com> - 2.0.0-3
- Rebuilt for Python 3.12

* Mon May 29 2023 Alexander Ploumistos <alexpl@fedoraproject.org> - 2.0.0-5
- Work around non-standard location of localization files

* Tue May 23 2023 Alexander Ploumistos <alexpl@fedoraproject.org> - 2.0.0-4
- Import into Fedora proper (fedora#2180418)

* Tue May 23 2023 Alexander Ploumistos <alexpl@fedoraproject.org> - 2.0.0-3
- Remove duplicate files
- Add README.Fedora
- Drop direct systemctl calls

* Sun May 21 2023 Alexander Ploumistos <alexpl@fedoraproject.org> - 2.0.0-2
- Rename package to input-remapper
- Switch to autorelease and autochangelog
- Use find_lang macro
- Remove explicit python runtime dependencies

* Mon Mar 20 2023 Alexander Ploumistos <alexpl@fedoraproject.org> - 2.0.0-1
- Update to 2.0.0

* Thu Nov 17 2022 Alexander Ploumistos <alexpl@fedoraproject.org> - 1.5.0-2
- Rework files stanza

* Wed Nov 16 2022 Alexander Ploumistos <alexpl@fedoraproject.org> - 1.5.0-1
- Version 1.5.0
- Spec file based on Paweł Marciniak's <sunwire+repo@gmail.com> work
- Fix license