# This spec is from community: https://github.com/mike-fabian/langtable/blob/master/langtable.spec
%global with_python2 1

Name:           langtable
Version:        0.0.43
Release:        1
Summary:        Guessing reasonable defaults for locale, keyboard layout, territory, and language.
Group:          Development/Tools
# the translations in languages.xml and territories.xml are (mostly)
# imported from CLDR and are thus under the Unicode license, the
# short name for this license is "MIT"
License:        GPLv3+
URL:            https://github.com/mike-fabian/langtable
Source0:        https://github.com/mike-fabian/langtable/releases/download/%{version}/%{name}-%{version}.tar.gz
BuildArch:      noarch
BuildRequires:  perl-interpreter
%if 0%{?with_python2}
BuildRequires:  python2-devel
%endif
BuildRequires:  python3-devel

%description
langtable is used to guess reasonable defaults for locale, keyboard layout,
territory, and language, if part of that information is already known. For
example, guess the territory and the keyboard layout if the language
is known or guess the language and keyboard layout if the territory is
already known.

%if 0%{?with_python2}
%package -n python2-langtable
%{?python_provide:%python_provide python2-langtable}
Provides: %{name}-python%{?_isa} = %{version}-%{release}
Obsoletes: %{name}-python < %{version}-%{release}
Summary:        Python module to query the langtable-data
Group:          Development/Tools
License:        GPLv3+
Requires:       %{name} = %{version}-%{release}
Requires:       %{name}-data = %{version}-%{release}

%description -n python2-langtable
This package contains a Python module to query the data
from langtable-data.
%endif

%package -n python3-langtable
Summary:        Python module to query the langtable-data
Group:          Development/Tools
License:        GPLv3+
Requires:       %{name} = %{version}-%{release}
Requires:       %{name}-data = %{version}-%{release}
# Remove before F30
Provides:       %{name}-python3 = %{version}-%{release}
Provides:       %{name}-python3%{?_isa} = %{version}-%{release}
Obsoletes:      %{name}-python3 < %{version}-%{release}

%description -n python3-langtable
This package contains a Python module to query the data
from langtable-data.

%package data
Summary:        Data files for langtable
Group:          Development/Tools
License:        GPLv3+ and MIT
Requires:       %{name} = %{version}-%{release}

%description data
This package contains the data files for langtable.

%prep
%setup -q

%build
perl -pi -e "s,_datadir = '(.*)',_datadir = '%{_datadir}/langtable'," langtable.py
%if 0%{?with_python2}
%py2_build
%endif

%py3_build

%install
%if 0%{?with_python2}
%py2_install -- --install-data=%{_datadir}/langtable
gzip --force --best $RPM_BUILD_ROOT/%{_datadir}/langtable/*.xml
%endif

%py3_install -- --install-data=%{_datadir}/langtable
# the .xml files copied by the “python3 setup.py install” are identical
# to those copied in the “python2 setup.py install”,
# it does not hurt to gzip them again:
gzip --force --best $RPM_BUILD_ROOT/%{_datadir}/langtable/*.xml

%check
%if 0%{?with_python2}
(cd $RPM_BUILD_DIR/%{name}-%{version}/data; PYTHONPATH=.. %{__python2} ../test_cases.py; %{__python2} ../langtable.py)
%endif
(cd $RPM_BUILD_DIR/%{name}-%{version}/data; LC_CTYPE=en_US.UTF-8 PYTHONPATH=.. %{__python3} ../test_cases.py; %{__python3} ../langtable.py)
xmllint --noout --relaxng $RPM_BUILD_ROOT/%{_datadir}/langtable/schemas/keyboards.rng $RPM_BUILD_ROOT/%{_datadir}/langtable/keyboards.xml.gz
xmllint --noout --relaxng $RPM_BUILD_ROOT/%{_datadir}/langtable/schemas/languages.rng $RPM_BUILD_ROOT/%{_datadir}/langtable/languages.xml.gz
xmllint --noout --relaxng $RPM_BUILD_ROOT/%{_datadir}/langtable/schemas/territories.rng $RPM_BUILD_ROOT/%{_datadir}/langtable/territories.xml.gz
xmllint --noout --relaxng $RPM_BUILD_ROOT/%{_datadir}/langtable/schemas/timezoneidparts.rng $RPM_BUILD_ROOT/%{_datadir}/langtable/timezoneidparts.xml.gz
xmllint --noout --relaxng $RPM_BUILD_ROOT/%{_datadir}/langtable/schemas/timezones.rng $RPM_BUILD_ROOT/%{_datadir}/langtable/timezones.xml.gz

%files
%license COPYING unicode-license.txt
%doc README ChangeLog test_cases.py
%dir %{_datadir}/langtable/
%{_datadir}/langtable/schemas

%if 0%{?with_python2}
%files -n python2-langtable
%{python2_sitelib}/*
%endif

%files -n python3-langtable
%{python3_sitelib}/langtable.py
%{python3_sitelib}/langtable-*.egg-info
%{python3_sitelib}/__pycache__/*

%files data
%dir %{_datadir}/langtable/
%{_datadir}/langtable/*.xml.gz


%changelog
* Mon Aug 31 2020 zoulin <zoulin13@huawei.com> - 0.0.43-1
- Update langtable to 0.0.43

* Wed May 20 2020 wangchen <wangchen137@huawei.com> - 0.0.38-9
- remodify

* Tue May 19 2020 wangchen <wangchen137@huawei.com> - 0.0.38-16
- change release version

* Mon Oct 21 2019 openEuler Buildteam <buildteam@openeuler.org> - 0.0.38-8.h7
- update spec info

* Tue Aug 20 2019 fangyufa<fangyufa1@huawei.com> - 0.0.38-8.h6
- Type:bugfix
- ID:NA
- SUG:NA
- DESC: modify name of patch

* Fri Aug 09 2019 fangyufa<fangyufa1@huawei.com> - 0.0.38-8.h5
- Type:bugfix
- ID:NA
- SUG:NA
- DESC: modify info of patch

* Thu Aug 08 2019 fangyufa<fangyufa1@huawei.com> - 0.0.38-8.h4
- Type:bugfix
- ID:NA
- SUG:NA
- DESC: add reason of patch

* Mon Aug 05 2019 zhuguodong <zhuguodong7@huawei.com> - 0.0.38-8.h3
- Type:bugfix
- ID:NA
- SUG:NA
- DESC: openEuler Debranding

* Mon Feb 11 2019 cangyi<cangyi@huawei.com> - 0.0.38-8.h2
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:add Beijing timezone and delete others languages

* Mon Jan 28 2019 Shouping Wang<wangshouping@huawei.com> - 0.0.38-8.h1
- Type:enhancement
- ID:NA
- SUG:restart
- DESC:build python2-langtable

* Tue Jul 17 2018 zhuguodong <zhuguodong7@huawei.com> - 0.0.38-8
- Package  Initialization
