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.8%{?git_rel}%{?dist}
Summary:	USB programmer for devices based on the Joyetech Evic VTC Mini

License:	GPLv3+
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


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

BuildRequires:	python-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:	python-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}

%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


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

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

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

%if %{with python3}
%endif # with python3


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

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


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

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

# Needed for help2man.
%endif # with python3

# Needed for help2man.

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

for f in %{buildroot}%{_bindir}/* ; do
	file="$(%{_bindir}/basename ${f})"
	LC_ALL=en_US.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}

# 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

%{__python2} test
%if %{with python3}
LC_ALL=en_US.utf-8 LANG=en_US.utf-8 %{__python3} test

%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}
%else  # with python3
%endif # with python3

%if %{with python3}
%files -n python3-%{pypi_name}
%license LICENSE
%doc README.rst
%exclude %{_bindir}/*-%{python2_version}
%exclude %{_mandir}/man1/*-%{python2_version}.1.*
%endif # with python3

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

* Thu Jul 27 2017 Fedora Release Engineering <> - 0.1-0.7.git20160814.f916017
- Rebuilt for

* Sat Feb 11 2017 Fedora Release Engineering <> - 0.1-0.6.git20160814.f916017
- Rebuilt for

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

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

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

* Mon Oct 24 2016 Björn Esser <> - 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 <> - 0.1-0.1.git20160814.f916017
- Initial package (rhbz 1387834)