File python-rsa.spec of Package python-rsa

# spec file for package python-rsa
# Copyright (c) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany.
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via

Name:           python-rsa
Version:        3.1.2
Release:        0
Summary:        Pure-Python RSA Implementation
License:        Apache-2.0
Group:          Development/Languages/Python
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildRequires:  python-devel
BuildRequires:  python-setuptools
BuildRequires:  python-pyasn1
Requires:       python-pyasn1
Requires(post): update-alternatives
Requires(postun): update-alternatives
%if 0%{?suse_version} && 0%{?suse_version} <= 1110
%{!?python_sitelib: %global python_sitelib %(python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
BuildArch:      noarch

Python-RSA is a pure-Python RSA implementation. It supports encryption and
decryption, signing and verifying signatures, and key generation according to
PKCS#1 version 1.5.

%setup -q -n rsa-%{version}
sed -i "s/pyrsa-priv2pub/pyrsa-priv2pub-%{py_ver}/"
sed -i "s/pyrsa-keygen/pyrsa-keygen-%{py_ver}/"
sed -i "s/pyrsa-encrypt =/pyrsa-encrypt-%{py_ver} =/"
sed -i "s/pyrsa-decrypt =/pyrsa-decrypt-%{py_ver} =/"
sed -i "s/pyrsa-sign/pyrsa-sign-%{py_ver}/"
sed -i "s/pyrsa-verify/pyrsa-verify-%{py_ver}/"
sed -i "s/pyrsa-encrypt-bigfile =/pyrsa-encrypt-bigfile-%{py_ver} =/"
sed -i "s/pyrsa-decrypt-bigfile =/pyrsa-decrypt-bigfile-%{py_ver} =/"

python build

python install --prefix=%{_prefix} --root=%{buildroot}
ln -s %{_bindir}/pyrsa-priv2pub-%{py_ver} %{buildroot}%{_bindir}/pyrsa-priv2pub
ln -s %{_bindir}/pyrsa-keygen-%{py_ver} %{buildroot}%{_bindir}/pyrsa-keygen
ln -s %{_bindir}/pyrsa-encrypt-%{py_ver} %{buildroot}%{_bindir}/pyrsa-encrypt
ln -s %{_bindir}/pyrsa-decrypt-%{py_ver} %{buildroot}%{_bindir}/pyrsa-decrypt
ln -s %{_bindir}/pyrsa-sign-%{py_ver} %{buildroot}%{_bindir}/pyrsa-sign
ln -s %{_bindir}/pyrsa-verify-%{py_ver} %{buildroot}%{_bindir}/pyrsa-verify
ln -s %{_bindir}/pyrsa-encrypt-bigfile-%{py_ver} %{buildroot}%{_bindir}/pyrsa-encrypt-bigfile
ln -s %{_bindir}/pyrsa-decrypt-bigfile-%{py_ver} %{buildroot}%{_bindir}/pyrsa-decrypt-bigfile

python test

# Since binaries became ghosted to be used with update-alternatives, we have to get rid
# of the old binary resulting from the non-update-alternativies-ified package:
[[ ! -L %{_bindir}/pyrsa-priv2pub ]] && rm -f %{_bindir}/pyrsa-priv2pub 
[[ ! -L %{_bindir}/pyrsa-keygen ]] && rm -f %{_bindir}/pyrsa-keygen  
[[ ! -L %{_bindir}/pyrsa-encrypt ]] && rm -f %{_bindir}/pyrsa-encrypt 
[[ ! -L %{_bindir}/pyrsa-decrypt ]] && rm -f %{_bindir}/pyrsa-decrypt 
[[ ! -L %{_bindir}/pyrsa-sign ]] && rm -f %{_bindir}/pyrsa-sign 
[[ ! -L %{_bindir}/pyrsa-verify ]] && rm -f %{_bindir}/pyrsa-verify
[[ ! -L %{_bindir}/pyrsa-encrypt-bigfile ]] && rm -f %{_bindir}/pyrsa-encrypt-bigfile
[[ ! -L %{_bindir}/pyrsa-decrypt-bigfile ]] && rm -f %{_bindir}/pyrsa-decrypt-bigfile
exit 0

update-alternatives \
    --install %{_bindir}/pyrsa-priv2pub pyrsa-priv2pub %{_bindir}/pyrsa-priv2pub-%{py_ver} 30 \
    --slave %{_bindir}/pyrsa-keygen pyrsa-keygen %{_bindir}/pyrsa-keygen-%{py_ver} \
    --slave %{_bindir}/pyrsa-encrypt pyrsa-encrypt %{_bindir}/pyrsa-encrypt-%{py_ver} \
    --slave %{_bindir}/pyrsa-decrypt pyrsa-decrypt %{_bindir}/pyrsa-decrypt-%{py_ver} \
    --slave %{_bindir}/pyrsa-sign pyrsa-sign %{_bindir}/pyrsa-sign-%{py_ver} \
    --slave %{_bindir}/pyrsa-verify pyrsa-verify %{_bindir}/pyrsa-verify-%{py_ver} \
    --slave %{_bindir}/pyrsa-encrypt-bigfile pyrsa-encrypt-bigfile %{_bindir}/pyrsa-encrypt-bigfile-%{py_ver} \
    --slave %{_bindir}/pyrsa-decrypt-bigfile pyrsa-decrypt-bigfile %{_bindir}/pyrsa-decrypt-bigfile-%{py_ver} \

if [ $1 -eq 0 ] ; then
    update-alternatives --remove pyrsa-priv2pub %{_bindir}/pyrsa-priv2pub-%{py_ver}

%ghost %{_bindir}/pyrsa-priv2pub
%ghost %{_bindir}/pyrsa-keygen
%ghost %{_bindir}/pyrsa-encrypt
%ghost %{_bindir}/pyrsa-decrypt
%ghost %{_bindir}/pyrsa-sign
%ghost %{_bindir}/pyrsa-verify
%ghost %{_bindir}/pyrsa-encrypt-bigfile
%ghost %{_bindir}/pyrsa-decrypt-bigfile