#define python_sitelib %(%{__python} -c 'from distutils import sysconfig; print sysconfig.get_python_lib(1)')

Summary: A wireless and wired network manager
Summary(ja): 無線・有線ネットワークマネージャ
Name: wicd
Version: 1.7.2.4
Release: 1%{?_dist_release}
Source0: %{name}-%{version}.tar.gz
Patch0:  wicd-desktop.patch
Patch1:  02-workaround_dhclient_bug.patch
#Patch2:  26-support_etc-network_scripts.patch
Patch3: 770_769.diff
Patch100: add_fix_ja.patch

License: GPLv2
Group: System Environment/Base
BuildRoot: %{_tmppath}/%{name}-%{version}-root
URL: https://launchpad.net/wicd
BuildArch: noarch

BuildRequires: gettext
BuildRequires: desktop-file-utils
BuildRequires: python >= 2.4 python-devel >= 2.4
BuildRequires: python-babel
BuildRequires: python-setuptools

Requires: pm-utils >= 1.2.4

Requires: %{name}-common
Requires: %{name}-curses
Requires: %{name}-gtk

#Requires(post):   chkconfig
#Requires(preun):  chkconfig
#Requires(preun):  /sbin/service
#Requires(postun): /sbin/service

Conflicts: NetworkManager

%description
A complete network connection manager
Wicd supports wired and wireless networks, and capable of
creating and tracking profiles for both.  It has a 
template-based wireless encryption system, which allows the user
to easily add encryption methods used.  It ships with some common
encryption types, such as WPA and WEP. Wicd will automatically
connect at startup to any preferred network within range.

%package common
Summary: Wicd common files
Summary(ja): Wicd の共通ファイル
Group: System Environment/Base
BuildArch: noarch
Requires: dbus
Requires: dbus-python
Requires: dhclient
Requires: ethtool
Requires: iproute
Requires: logrotate
Requires: net-tools
Requires: pm-utils
Requires: wireless-tools
Requires: wpa_supplicant

Requires(post):   chkconfig
Requires(preun):  chkconfig
Requires(preun):  /sbin/service
Requires(postun): /sbin/service
#Requires(preun):  initscripts
#Requires(postun): initscripts

%description common
This package provides the main wicd daemon and the wicd-cli front-end.

%package curses
Summary: Curses client for Wicd
Summary(ja): Wicd の Curse クライアント
Group: Applications/System
BuildArch: noarch
Requires: %{name}-common = %{version}-%{release}
Requires: python-urwid >= 0.9.8.3

%description curses
Client program for wicd that uses a curses interface.

%package gtk
Summary: GTK+ client for Wicd
Summary(ja): Wicd の GTK+ クライアント
Group: Applications/Internet
BuildArch: noarch
Requires: %{name}-common = %{version}-%{release}
Requires: pygtk2 >= 2.10
Requires: pygtk2-libglade >= 2.10
Requires: gksu

%description gtk
Client program for wicd that uses a GTK+ interface.


%prep
%setup -q
%patch0 -p1
%patch1 -p1
#%patch2 -p1
%patch3 -p0
%patch100 -p1

%{__sed} -i 's/\r//' wicd/logfile.py

%build
python setup.py compile_translations

%{__python} setup.py configure --share=%{_datadir}/%{name} \
       --etc=%{_sysconfdir}/%{name} \
       --bin=%{_bindir} \
       --sbin=%{_sbindir} \
       --mandir=%{_mandir} \
       --varlib=%{_sharedstatedir}/wicd \
       --pmutils=%{_libdir}/pm-utils/sleep.d \
       --resume=%{_sysconfdir}/acpi/resume.d \
       --suspend=%{_sysconfdir}/acpi/suspend.d \
       --docdir=%{_docdir}/%{name}-%{version} \
       --log %{_localstatedir}/log \
       --no-install-kde \
       --no-install-docs

python setup.py build
# python-babel currently doesn't support Asturian, using gettext
msgfmt po/ast.po -o translations/ast/LC_MESSAGES/wicd.mo

%install
rm -rf %{buildroot}
python setup.py install -O1 --skip-build --root=%{buildroot}
install -D init/redhat/%{name} %{buildroot}%{_initddir}/%{name}

find %{buildroot} -type f -name ".empty_on_purpose" | xargs rm

desktop-file-install \
    --remove-category="Application" \
    --delete-original \
    --dir=%{buildroot}%{_datadir}/applications \
    %{buildroot}%{_datadir}/applications/wicd.desktop

desktop-file-install \
    --dir=%{buildroot}%{_sysconfdir}/xdg/autostart \
    %{buildroot}%{_sysconfdir}/xdg/autostart/wicd-tray.desktop

%find_lang %{name}

%post common
touch --no-create %{_datadir}/icons/hicolor &>/dev/null || :
/sbin/service %{name} restart >/dev/null 2>&1
/sbin/chkconfig --add %{name}
/sbin/chkconfig --level 345 %{name} on

%preun common
if [ $1 = 0 ] ; then
     /sbin/service %{name} stop >/dev/null 2>&1
     /sbin/chkconfig --del %{name}
fi

%postun common
if [ "$1" -ge "1" ] ; then
    /sbin/service %{name} condrestart >/dev/null 2>&1 || :
fi

if [ $1 -eq 0 ] ; then
    touch --no-create %{_datadir}/icons/hicolor &>/dev/null
    gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :
fi

%post gtk
touch --no-create %{_datadir}/icons/hicolor &>/dev/null || :

%postun gtk
if [ $1 -eq 0 ]; then
    touch --no-create %{_datadir}/icons/hicolor &>/dev/null
    gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :
fi

%posttrans gtk
gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :

%clean
[ -d "$RPM_BUILD_ROOT" -a "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root)
%doc AUTHORS CHANGES INSTALL LICENSE NEWS README other/WHEREAREMYFILES
%{_libdir}/pm-utils/sleep.d/55wicd

%files common -f %{name}.lang
%{_bindir}/wicd-cli
%{_bindir}/wicd-client
%{python_sitelib}/wicd
%{python_sitelib}/*.egg-info
%{_datadir}/applications/wicd.desktop
%{_datadir}/dbus-1/system-services/
%{_datadir}/man/man1/wicd-client.1*
%{_datadir}/man/man5/wicd-manager-settings.conf.5*
%{_datadir}/man/man5/wicd-wired-settings.conf.5*
%{_datadir}/man/man5/wicd-wireless-settings.conf.5*
%{_datadir}/man/man8/wicd-cli.8*
%{_datadir}/man/man8/wicd.8*
%{_datadir}/pixmaps/wicd*
%dir %{_datadir}/wicd
%dir %{_datadir}/wicd/backends
%dir %{_datadir}/wicd/cli
%dir %{_datadir}/wicd/daemon
%{_datadir}/wicd/backends/*
%{_datadir}/wicd/cli/*
%{_datadir}/wicd/daemon/*
%{_mandir}/nl/man?/%{name}*
%{_sysconfdir}/%{name}
%{_sysconfdir}/acpi/resume.d/80-wicd-connect.sh
%{_sysconfdir}/acpi/suspend.d/50-wicd-suspend.sh
%{_sysconfdir}/dbus-1/system.d/wicd.conf
%{_sysconfdir}/logrotate.d/
%{_sysconfdir}/rc.d/init.d/wicd
%{_sysconfdir}/xdg/autostart/wicd-tray.desktop
%{_sbindir}/wicd
%{_localstatedir}/lib/wicd
%exclude /lib/systemd/system/wicd.service

%files curses
%defattr(-,root,root,-)
%dir %{_datadir}/wicd/curses
%{_datadir}/wicd/curses/*
%{_bindir}/wicd-curses
%{_datadir}/man/man8/wicd-curses.8*
%lang(nl) %{_datadir}/man/nl/man8/wicd-curses.8*

%files gtk
%defattr(-,root,root,-)
%dir %{_datadir}/wicd/gtk
%dir %{_datadir}/pixmaps/wicd
%{_sysconfdir}/xdg/autostart/wicd-tray.desktop
%{_datadir}/wicd/gtk/*
%{_datadir}/pixmaps/wicd/*
%{_datadir}/pixmaps/wicd-gtk.xpm
%{_bindir}/wicd-gtk
%{_datadir}/icons/hicolor/*/apps/wicd-gtk.png
%{_datadir}/icons/hicolor/scalable/apps/wicd-gtk.svg

%changelog
* Sat May 05 2012 Toshiharu Kudoh <toshi.kd2@gmail.com> - 1.7.2.4-1
- new upstream release
- dropt patch2
- added Patch3 from upstream
- fixed patch100
- added Requires: %%{name}-common, %%{name}-curses %%{name}-gtk in wicd
- changed URL: https://launchpad.net/wicd

* Sat Feb 18 2012 Toshiharu Kudoh <toshi.kd2@gmail.com> - 1.7.1-1
- dropt almost pathces
  - enabled patch is wicd-desktop.patch (Patch0)
- added patch1 and patch2 from Debian sid
- added patch100 to fix Japanese translation
- added BuildRequires: python-babel

* Sun May 22 2011 Toshiharu Kudoh <toshi.kd2@gmail.com> - 1.7.0-6
- changed BuildArch to noarch
- updated spec
- splitted -common, -curses, -gtk packages
- Added Patch4,5,6,7,8 from Debian

* Wed Jun 9 2010 Toshiharu Kudoh <toshi.kd2@gmail.com> - 1.7.0-5
- improved service start process in %%post section
- changed daemon start runlevel

* Mon Jun 07 2010 Shu KONNO <owa@bg.wakwak.com> - 1.7.0-4
- fixed %%python_sitelib

* Sat Jun 5 2010 Toshiharu Kudoh <toshi.kd2@gmail.com> - 1.7.0-3
- added Rerquires: gksu
- added Patch2,3 from Debian
  - to stop running unexpected files in scripts
  - to fix resolv.conf permission

* Fri Jun 4 2010 Toshiharu Kudoh <toshi.kd2@gmail.com> - 1.7.0-2
- added chkconfig in %post
- added Patch1 to add Japanese description for desktop file

* Fri May 28 2010 Toshiharu Kudoh <toshi.kd2@gmail.com> - 1.7.0-1
- initial build for VineSeed
