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


# parabola changes and rationale
# - replace documentation usage examples with FSDG-fit operating systems
# - remove explicit support for non-FSDG-fit operating systems


pkgbase=virt-manager
pkgname=(virt-install virt-manager)
pkgver=3.1.0
pkgrel=1
pkgrel+=.parabola1
arch=('any')
url="https://virt-manager.org/"
license=('GPL')
makedepends=('python-docutils')
checkdepends=('python-pytest' 'libosinfo' 'libvirt-python' 'python-gobject' 'python-requests' 'cpio' 'cdrtools')
source=("https://virt-manager.org/download/sources/virt-manager/virt-manager-$pkgver.tar.gz")
source+=('libre.patch' 'libre-docs.patch')
b2sums=('729a16ee419cfc9f118e4a59336e961f17f38908ab3aaa3598c83bff3e8bca75b150f0f38b021c5ccb839a7c43e87f071859f68c2a81425715e236e14d0a7929')
b2sums+=('379d25a508a361dfa204ff79b16e92120d7860c00c19877606e44ed0f689cec8813e7704d8f2d51e680523f03cecd78334da70f0455d20a50246c77467fc6a05'
         'ca82cbc21fd520d4253940ec37299771486958885425ecf15571e77be63ac0dad7c780b161248a00d6566fc5f33a49d4fc65459f37f75ee9576575c451e1ce37')


prepare() {
  cd $pkgbase-$pkgver

  patch -p1 -i ../libre.patch
  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 LXC container guests using the libvirt hypervisor"
  pkgdesc+=", without non-FSDG OS definitions"
  depends=('libosinfo' 'libvirt-python' 'python-gobject' 'python-requests')

  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/"
}
