PKGBUILD 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # Contributor: Sławomir Kowalski <suawekk+aur@gmail.com>
  2. # Contributor: bill-auger <bill-auger@programmer.net>
  3. pkgname=anki-ccbc
  4. pkgver=0.1.0
  5. _pyqt4topyqt5_cid='ca307cdcf66cee7f0c4838ea4ef5174b95d6b6f8'
  6. pkgrel=1
  7. pkgdesc="helps you remember facts (eg: foreign words/phrases) efficiently (front-end for anki flash cards)"
  8. arch=(any)
  9. url=https://github.com/lovac42/CCBC
  10. license=(AGPL3)
  11. depends=(desktop-file-utils python-beautifulsoup4 python-decorator python-httplib2
  12. python-markdown python-pillow python-pyaudio python-pyqt5 python-requests python-send2trash
  13. python-sqlalchemy qt5-webkit)
  14. optdepends=("mplayer: for playing sounds")
  15. provides=(anki)
  16. conflicts=(anki)
  17. replaces=(anki)
  18. install=${pkgname}.install
  19. source=(${pkgname}-${pkgver}.tar.gz::https://github.com/lovac42/CCBC/archive/v${pkgver}.tar.gz
  20. pyqt4topyqt5-${_pyqt4topyqt5_cid}.tar.gz::https://github.com/rferrazz/pyqt4topyqt5/archive/${_pyqt4topyqt5_cid}.tar.gz
  21. pyqt4topyqt5-binary-to-utf.patch)
  22. sha512sums=('674a1bc5d4733be9f2068ffa7878fe7ad7639deab04ca3fdde12c398adfadade7d594bcd6ab3e9d8754d653a105be8c182f5aa2218ed5198934d0f1892b747ff'
  23. '0bdf2a7f8d58e51fd2d32d87b1ab8f91fc8a7f822b1ed29c7e22a61aebfd7768cef6a077829e0f0e0e1791c800e2c71a188be68c3a33b897f9a585c3e1a4091f'
  24. '4626a231cd14b86bc9af2927ac5ead5685c4c1aaf10fd0d3ca7020aeb96ec928975be7290a4dc4814ff9c70c8f8e1d80f271e45c4130d7afe6cd90ef618e740f')
  25. prepare()
  26. {
  27. mv "${srcdir}"/{CCBC,${pkgname}}-${pkgver}
  28. cd "${srcdir}"/${pkgname}-${pkgver}/
  29. ## convert pyqt4 to pyqt5 ##
  30. local rx='s!s = SIGNAL("triggered()")!!g; s!\(self.connect([^,]\+, \)s\([^)]\+\))!\1SIGNAL("triggered()")\2)!g'
  31. sed -i "${rx}" aqt/main.py
  32. local pyqt4to5_script=../pyqt4topyqt5-${_pyqt4topyqt5_cid}/pyqt4topyqt5.py
  33. local pyqt4to5_patch="${srcdir}"/pyqt4topyqt5.patch
  34. local success_msg="pyqt4topyqt5.py: generated and applied diff file: ${pyqt4to5_patch#${srcdir}/*}"
  35. ## generate pyqt4topyqt5 patch file for source package ##
  36. # pyqt4topyqt5 creates malformed patch files
  37. # https://github.com/rferrazz/pyqt4topyqt5/pull/24
  38. patch ${pyqt4to5_script} < "${srcdir}"/pyqt4topyqt5-binary-to-utf.patch
  39. python ${pyqt4to5_script} --nolog --diff=${pyqt4to5_patch} -o ../${pkgname}-qt5 . > /dev/null
  40. cp -a ../${pkgname}-qt5/* . ; rm -rf ../${pkgname}-qt5/ ;
  41. # validate and sanitize patch
  42. if [[ -f ${pyqt4to5_patch} ]]
  43. then echo ${success_msg}
  44. perl -0777 -i -pe "s|^--- ${srcdir}/${pkgname}-${pkgver}/([^\t\n]*)[^\n]*\n\+\+\+ [^\n]*$|--- \1\n+++ \1|gms" ${pyqt4to5_patch}
  45. else echo "pyqt4topyqt5 failure" ; return 1 ;
  46. fi
  47. ## more pyqt4 to pyqt5 adaptations ##
  48. # QIcon and QPixmap are now in Gui
  49. rx='s!QtWidgets.Q\(Icon\|Pixmap\)!QtGui.Q\1!g;'
  50. sed -i "${rx}" aqt/{,forms/}*.py
  51. # Some enums and defaults are now somewhere else
  52. rx='s!QDesktopServices.storageLocation!QStandardPaths.standardLocations!g;'
  53. sed -i "${rx}" aqt/{,forms/}*.py
  54. rx='s!QDesktopServices.\(Documents\|Home\)\(Location\)!QStandardPaths.\1\2!g;'
  55. sed -i "${rx}" aqt/{,forms/}*.py
  56. # For some reason, it was fine to combine Core and Gui into Widgets
  57. rx='s!\(from PyQt5 import \)\(.*QtCore, QtGui\).*as.*\( QtWidgets\)!\1\2\n\1\3!g;'
  58. sed -i "${rx}" aqt/forms/*.py
  59. # QMessageBox is now in QtWidgets
  60. rx='s!\(from PyQt5\.\)\(QtGui\)\( import \*\)!\1\2\3\n\1\QtWidgets\3!g'
  61. sed -i "${rx}" aqt/qt.py
  62. # 'loc' is originally a list, but needs to be a string.
  63. # Get the last element (consider first as alternative)
  64. rx='s!\(if loc\[\):\(-1\] == QStandardPaths.standardLocations\)!\1\2!g; s!\(return os.path.join(loc\)\(, "Anki")\)!\1[-1]\2!g'
  65. sed -i "${rx}" aqt/profiles.py
  66. # cgi.escape has been depreceated in Python 3.8
  67. # https://github.com/posativ/isso/issues/603
  68. sed -i 's!cgi!html!g' aqt/{browser.py,reviewer.py}
  69. sed -i 's!\(import cgi\)!\# \1!g' aqt/{browser.py,reviewer.py}
  70. ## tweak Makefile ##
  71. # defer XDG integration to .install hook
  72. sed -i 's!^ -xdg-mime .*!!g' Makefile
  73. }
  74. package()
  75. {
  76. cd "${srcdir}"/${pkgname}-${pkgver}/
  77. make install DESTDIR="${pkgdir}"
  78. # rename system meta-data files
  79. mv "${pkgdir}"/usr/share/{anki,${pkgname}}/
  80. mv "${pkgdir}"/usr/share/applications/{anki,${pkgname}}.desktop
  81. sed -i "s!/usr/share/anki!/usr/share/${pkgname}!" "${pkgdir}"/usr/bin/anki
  82. # install XDG meta-data
  83. install -Dm644 anki.xml "${pkgdir}"/usr/share/${pkgname}/anki.xml
  84. }