Blob Blame History Raw
%if 0%{?fedora} || 0%{?rhel} >= 8
%bcond_without python3
%else  # 0#{?fedora} || 0#{?rhel} >= 8
%bcond_with python3
%endif # 0#{?fedora} || 0#{?rhel} >= 8

%global pypi_name evic

# %%{_udevrulesdir} is not defined during srpm-build.  :/
%{!?_udevrulesdir:%global _udevrulesdir %{_usr}/lib/udev/rules.d}

# No tagged releases.  :/
%global commit 176cf0b076db331cf79dcab4232abd1158b183fa
%{?commit:%global shortcommit %(c="%{commit}"; /bin/echo ${c:0:7})}
%{?commit:%global git_date 20161101}
%{?commit:%global git_rel .git%{git_date}.%{shortcommit}}
%{?commit:%global git_ver -git%{git_date}-%{shortcommit}}


Name:		python-%{pypi_name}
Version:	0.1
Release:	0.12%{?git_rel}%{?dist}
Summary:	USB programmer for devices based on the Joyetech Evic VTC Mini

License:	GPLv3+
URL:		https://github.com/Ban3/python-%{pypi_name}
Source0:	%{url}/archive/%{commit}.tar.gz#/%{name}-%{version}%{?git_ver}.tar.gz

# Patches from upstream.
Patch0:		%{url}/pull/38.patch#/%{name}-0.1-all_PRs.patch

BuildArch:	noarch

BuildRequires:	help2man
BuildRequires:	systemd

%description
%{summary}.

%package -n python2-%{pypi_name}
Summary:	%{summary}

BuildRequires:	python2-click
BuildRequires:	python2-binstruct
BuildRequires:	python2-bitarray
BuildRequires:	python2-bitstruct
BuildRequires:	python2-devel
BuildRequires:	python2-hidapi
BuildRequires:	python2-pillow
BuildRequires:	python2-setuptools
BuildRequires:	python2-pytest
BuildRequires:	python2-pytest-runner

Requires:	%{_udevrulesdir}
Requires:	python2-click
Requires:	python2-binstruct
Requires:	python2-bitarray
Requires:	python2-bitstruct
Requires:	python2-hidapi
Requires:	python2-pillow

%{?python_provide:%python_provide python2-%{pypi_name}}

%description -n python2-%{pypi_name}
%{summary}.


%if %{with python3}
%package -n python3-%{pypi_name}
Summary:	%{summary}

BuildRequires:	python3-binstruct
BuildRequires:	python3-bitarray
BuildRequires:	python3-bitstruct
BuildRequires:	python3-click
BuildRequires:	python3-devel
BuildRequires:	python3-hidapi
BuildRequires:	python3-pillow
BuildRequires:	python3-setuptools
BuildRequires:	python3-pytest
BuildRequires:	python3-pytest-runner

Requires:	%{_udevrulesdir}
Requires:	python3-binstruct
Requires:	python3-bitarray
Requires:	python3-bitstruct
Requires:	python3-click
Requires:	python3-hidapi
Requires:	python3-pillow

%{?systemd_requires}

%{?python_provide:%python_provide python3-%{pypi_name}}

%description -n python3-%{pypi_name}
%{summary}.
%endif # with python3


%prep
%if "0%{?commit}" == "0"
%autosetup -p 1
%else  # "0#{?commit}" == "0"
%autosetup -p 1 -n %{name}-%{commit}
%endif # "0#{?commit}" == "0"


%build
%py2_build
%if %{with python3}
%py3_build
%endif # with python3


%install
%py2_install

# Rename files installed in %%{_bindir}.
files=""
for f in %{buildroot}%{_bindir}/* ; do
	/bin/ln ${f} ${f}-%{python2_version}
	files="${files##' '} ${f}"
done

%if %{with python3}
# Remove left-overs from %%py2_install.
%{__rm} -fr ${files}

%py3_install

# Rename files installed in %%{_bindir}.
for f in %{buildroot}%{_bindir}/* ; do
	/bin/ln ${f} ${f}-%{python3_version}
done

# Remove clutter in %%{_bindir}.
%{__rm} -f %{buildroot}%{_bindir}/*-%{python2_version}-%{python3_version}

# Needed for help2man.
PYTHONPATH="%{buildroot}/%{python3_sitelib}:${PYTHONPATH}"
%endif # with python3

# Needed for help2man.
PYTHONPATH="%{buildroot}/%{python2_sitelib}:${PYTHONPATH}"
export PYTHONPATH="${PYTHONPATH%%':'}"

# Generate man-pages.
%{__mkdir} -p %{buildroot}%{_mandir}/man1				\
	%{buildroot}%{_udevrulesdir} %{buildroot}%{_unitdir}

for f in %{buildroot}%{_bindir}/* ; do
	file="$(%{_bindir}/basename ${f})"
	LC_ALL=C.utf8.utf-8 LANG=en_US.utf-8 %{_bindir}/help2man		\
		-o "%{buildroot}%{_mandir}/man1/${file}.1" -s 1 -N	\
		--version-string="%{version}" --no-discard-stderr ${f}
done

# Install udev-rules.
%{__mv} %{buildroot}%{_usr}/udev/* %{buildroot}%{_udevrulesdir}
%{__rm} -fr %{buildroot}%{_usr}/udev

# Install systemd unit.
%{__install} -pm0644 scripts/*.service %{buildroot}%{_unitdir}

%if %{with python3}
# Remove clutter from man-page generation.
%{__rm} -fv %{buildroot}%{python3_sitelib}/%{pypi_name}/*.py{c,o}
%{_bindir}/find %{buildroot}%{python2_sitelib}/%{pypi_name}		\
	-name '__pycache__' -print0 | %{_bindir}/xargs -0 %{__rm} -rfv
%endif # with python3


%check
%{__python2} setup.py test
%if %{with python3}
LC_ALL=C.utf8.utf-8 LANG=en_US.utf-8 %{__python3} setup.py test
%endif


%post -n python3-%{pypi_name}
%systemd_post evic-usb-rtc-sync.service


%preun -n python3-%{pypi_name}
%systemd_preun evic-usb-rtc-sync.service


%postun -n python3-%{pypi_name}
%systemd_postun_with_restart evic-usb-rtc-sync.service


%files -n python2-%{pypi_name}
%license LICENSE
%doc README.rst
%if %{with python3}
%{_bindir}/*-%{python2_version}
%{_mandir}/man1/*-%{python2_version}.1.*
%else  # with python3
%{_bindir}/*
%{_mandir}/man1/*.1.*
%endif # with python3
%{_udevrulesdir}/*.rules
%{python2_sitelib}/%{pypi_name}
%{python2_sitelib}/%{pypi_name}-%{version}-py%{python2_version}.egg-info


%if %{with python3}
%files -n python3-%{pypi_name}
%license LICENSE
%doc README.rst
%exclude %{_bindir}/*-%{python2_version}
%exclude %{_mandir}/man1/*-%{python2_version}.1.*
%{_bindir}/*
%{_mandir}/man1/*.1.*
%{_udevrulesdir}/*.rules
%{_unitdir}/*.service
%{python3_sitelib}/%{pypi_name}
%{python3_sitelib}/%{pypi_name}-%{version}-py%{python3_version}.egg-info
%endif # with python3


%changelog
* Sat Jul 14 2018 Fedora Release Engineering <releng@fedoraproject.org> - 0.1-0.12.git20161101.176cf0b
- Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild

* Tue Jun 19 2018 Miro Hrončok <mhroncok@redhat.com> - 0.1-0.11.git20161101.176cf0b
- Rebuilt for Python 3.7

* Mon Feb 12 2018 Iryna Shcherbina <ishcherb@redhat.com> - 0.1-0.10.git20161101.176cf0b
- Update Python 2 dependency declarations to new packaging standards
  (See https://fedoraproject.org/wiki/FinalizingFedoraSwitchtoPython3)

* Fri Feb 09 2018 Fedora Release Engineering <releng@fedoraproject.org> - 0.1-0.9.git20161101.176cf0b
- Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild

* Sat Jan 06 2018 Björn Esser <besser82@fedoraproject.org> - 0.1-0.8.git20161101.176cf0b
- Updated snapshot

* Thu Jul 27 2017 Fedora Release Engineering <releng@fedoraproject.org> - 0.1-0.7.git20160814.f916017
- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Mass_Rebuild

* Sat Feb 11 2017 Fedora Release Engineering <releng@fedoraproject.org> - 0.1-0.6.git20160814.f916017
- Rebuilt for https://fedoraproject.org/wiki/Fedora_26_Mass_Rebuild

* Mon Dec 19 2016 Miro Hrončok <mhroncok@redhat.com> - 0.1-0.5.git20160814.f916017
- Rebuild for Python 3.6

* Mon Oct 24 2016 Björn Esser <fedora@besser82.io> - 0.1-0.4.git20160814.f916017
- %%{_udevrulesdir} is not defined during srpm-build
- Fix invocation of %%autosetup

* Mon Oct 24 2016 Björn Esser <fedora@besser82.io> - 0.1-0.3.git20160814.f916017
- Initial import (rhbz 1387834)

* Mon Oct 24 2016 Björn Esser <fedora@besser82.io> - 0.1-0.2.git20160814.f916017
- Changes suggested during review (rhbz 1387834)
- Add BuildRequires: systemd
- Use %%{_udevrulesdir}
- Don't mark udev-rules as %%config(noreplace)

* Fri Oct 21 2016 Björn Esser <fedora@besser82.io> - 0.1-0.1.git20160814.f916017
- Initial package (rhbz 1387834)