# Maintainer (arch): Christian Rebischke <chris.rebischke at archlinux.org>
# Contributor: Sergej Pupykin <pupykin.s+arch at gmail.com>
# Contributor: Daniel Micay <danielmicay at gmail.com>
# Contributor: Jonathan Wiersma <archaur at jonw dot org>
# Maintainer: Omar Vega Ramos <ovruni at gnu.org.pe>
# Contributor: André Silva <emulatorman at hyperbola.info>
# Contributor: grizzlyuser <grizzlyuser at protonmail.com>
# Contributor: bill-auger <bill-auger at programmer.net>
# Contributor: Iván Ávalos <avalos at disroot.org>


# parabola changes and rationale
# - replace documentation usage examples with FSDG-fit operating systems
# - remove explicit support for non-FSDG-fit operating systems
# - add explicit support for FSDG-fit operating systems - WIP: (eg: upstream 'libosinfo')


pkgbase=virt-manager
pkgname=(virt-install virt-manager)
pkgver=4.1.0
pkgrel=2
pkgrel+=.parabola1
arch=('any')
url='https://virt-manager.org/'
license=('GPL')
makedepends=('python-docutils' 'python-setuptools')
checkdepends=('python-pytest' 'libosinfo' 'libvirt-python' 'python-gobject' 'python-requests' 'cpio' 'cdrtools')
optdepends=('x11-ssh-askpass: provide password for remote machines connected via ssh tunnel')
source=("https://releases.pagure.org/virt-manager/virt-manager-${pkgver}.tar.gz")
source+=('libre.patch' 'libre-docs.patch')
b2sums=('1b4203be81bd7b82251225d691a4d9068f268e610f049bcadb96de5b539e964ca0b001f22f06ddd8266b58b079f60046f6d11942a1e4eadbc43f0607c46bbddd')
b2sums+=('a0a26b7fbf3576f67453d171e1667ab3ba56163290185e95a85ae183494fc8f39965ac67eebd6c973ecb40314eb7c8f06bd7d017482732a63034c4fb0613f068'
         '319bb66d43e461a63668ae369412eba4bca3d9bc12a99d1d8ad846ac7388312413cc999cae7c0222c7a9c668517541aa3ce09204a9b77fd57cb85dc16188af7a')

prepare() {
  cd ${pkgbase}-${pkgver}

  echo "applying libre.patch"
  patch -p1 -i ../libre.patch

  echo "applying libre-docs.patc"
  patch -p1 -i ../libre-docs.patch
}

build() {
  cd ${pkgbase}-${pkgver}
  python setup.py configure --default-hvs qemu,lxc
  python setup.py build
}

package_virt-install() {
  pkgdesc='Command line tool for creating new KVM , Xen, or Linux container guests using the libvirt hypervisor'
  pkgdesc="${pkgdesc/Linux/LXC}"
  depends=('libosinfo' 'libvirt-python' 'python-gobject' 'python-requests' 'cpio' 'libisoburn')

  cd ${pkgbase}-${pkgver}
  python setup.py --no-update-icon-cache --no-compile-schemas install --root "${pkgdir}"
  python -m compileall "${pkgdir}"/usr/share/virt-manager
  python -O -m compileall "${pkgdir}"/usr/share/virt-manager

  # Split virt-manager
  [[ -d "${srcdir}"/virt-manager ]] && rm -r "${srcdir}"/virt-manager/
  mkdir -p "${srcdir}"/split/usr/{bin,share/{man/man1,virt-manager}}
  mv "${pkgdir}"/usr/bin/virt-manager "${srcdir}"/split/usr/bin/
  mv "${pkgdir}"/usr/share/{applications,glib-2.0,icons,metainfo} "${srcdir}"/split/usr/share/
  mv "${pkgdir}"/usr/share/man/man1/virt-manager.1 "${srcdir}"/split/usr/share/man/man1/
  mv "${pkgdir}"/usr/share/virt-manager/{icons,ui,virtManager} "${srcdir}"/split/usr/share/virt-manager/
}

package_virt-manager() {
  pkgdesc='Desktop user interface for managing virtual machines'
  depends=("virt-install=${pkgver}" 'gtk-vnc' 'libvirt-glib' 'spice-gtk' 'vte3' 'python-cairo' 'gtksourceview4')

  mv -v split/* "${pkgdir}/"
}
