File texamator.spec of Package texamator

#
# spec file for package texamator
#
# Copyright (c) 2018 SUSE LINUX 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 http://bugs.opensuse.org/
#


Name:           texamator
Version:        2.4.5+git.20180405.a54eed3
Release:        0
Summary:        Manage databases of exercises written in (La)TeX
License:        GPL-3.0-only
Group:          Productivity/Publishing/TeX/Utilities
Url:            http://alexisfles.ch/en/texamator/texamator.html
Source0:        %{name}-%{version}.tar.gz
Source1:        %{name}.in
BuildRequires:  ImageMagick
BuildRequires:  fdupes
BuildRequires:  hicolor-icon-theme
BuildRequires:  python-base
BuildRequires:  update-desktop-files
# Check list of dependencies:
BuildRequires:  python-qt4
Requires:       python-qt4
Requires:       texlive-latex
Recommends:     python-kde4
Recommends:     %{name}-lang
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildArch:      noarch

%description
TeXamator is written in Python/Qt4. It is aimed at helping you making your
exercise sheets. Basically, it browses a specified directory, looks for
.tex files containing exercices and builds a tree with all your exercises.
You can click on an element of the tree to have a preview of the exercise
sheet and then add exercises to a list if you wish to. Then you can save
your work to a .tex file or you can generate a .dvi (or a pdf or a ps)
file.

%lang_package

%prep
%setup -q

cp %{SOURCE1} .

sed -e 's|@python_sitelib@|%{python_sitelib}/%{name}|' \
    -e 's|@name@|%{name}.py|' \
    < %{name}.in > %{name}

%build
# There is nothing to build.

%install
mkdir -p %{buildroot}%{python_sitelib}/%{name}
for _dir in $(ls -1F | grep '.*\/' | sed 's/\/$//'); do
  cp -rp $_dir %{buildroot}%{python_sitelib}/%{name}
done

pushd %{buildroot}%{python_sitelib}
for _file in $(grep -rl '^\#\!'); do
  find -name ${_file##*/} -type f -perm -644 -exec sed '/^\#\!/d' -i {} \;
done
%py_compile .
popd

install -Dm0755 %{name} %{buildroot}%{_bindir}/%{name}
install -Dm0755 %{name}.py %{buildroot}%{python_sitelib}/%{name}

_file=$(find -name TeXamator.png)
_width=$(identify -format %w $_file)
_height=$(identify -format %h $_file)
if [ "$_width" -eq $_height ]; then
  if [ "$_width" -ge 256 ]; then
    for s in 16 32 48 64 128 256; do
      mkdir -p %{buildroot}%{_datadir}/icons/hicolor/${s}x${s}/apps
      convert -strip \
        $_file -resize $s \
        %{buildroot}%{_datadir}/icons/hicolor/${s}x${s}/apps/%{name}.png
    done
  fi
fi

%{suse_update_desktop_file -c \
%{name} TeXamator "Manage databases of exercises written in (La)TeX" %{name} %{name} Qt Office Database}

langlist=$PWD/%{name}.lang
langdir=%{python_sitelib}/%{name}/ts_files
basedir=$(basename $langdir)
pushd $basedir
  /bin/ls -1 *.qm | while read qm; do
    [ -e "$qm" ] || continue
    if ! grep -wqs "\%dir\ $langdir" $langlist; then
      echo "%dir $langdir" >> $langlist
    fi
    install -Dm0644 $qm %{buildroot}$langdir/$qm
    lang=$(echo $qm | sed 's/.*\_\(.*\)\..*/\1/')
    [ "$(echo $lang | wc -c)" -le 6 ] || exit $?
    lang=${lang:+%lang($lang)\ }
    echo "$lang$langdir/$qm" >> $langlist
  done
popd

find %{buildroot} -type f \( -name \*.sh -o -name \*.ts \) -delete -print

%fdupes -s %{buildroot}%{python_sitelib}

%post
%icon_theme_cache_post

%postun
%icon_theme_cache_postun

%files
%defattr(-,root,root)
%doc README.md gpl-3.0.txt
%{_bindir}/%{name}
%{_datadir}/applications/%{name}.desktop
%{_datadir}/icons/hicolor/*/apps/%{name}.??g
%{python_sitelib}/%{name}/
%exclude %{python_sitelib}/%{name}/ts_files

%files lang -f %{name}.lang
%defattr(-,root,root,-)

%changelog
openSUSE Build Service is sponsored by