setup.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #!/usr/bin/env python
  2. import os
  3. import subprocess
  4. from distutils.core import setup
  5. from distutils.command.build_py import build_py as _build_py
  6. from distutils.command.install_data import install_data as _install_data
  7. from searxqt.version import __version__
  8. ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
  9. LOCALES_PATH = os.path.join(ROOT_PATH, 'locales')
  10. THEMES_PATH = os.path.join(ROOT_PATH, 'themes')
  11. def compileLocales():
  12. """ Compiles all found locales .po to .mo files.
  13. """
  14. cmd = os.path.join(ROOT_PATH, 'utils', 'locale_tool.sh')
  15. cmd += " -m all"
  16. if os.system(cmd) != 0:
  17. print("Failed to compile locales.")
  18. return False
  19. return True
  20. def genMoList():
  21. """ Returns the 'data_files' for all found .mo files.
  22. """
  23. data_files = []
  24. for langDir in os.listdir(LOCALES_PATH):
  25. path = os.path.join(LOCALES_PATH, langDir)
  26. if not os.path.isdir(path):
  27. continue
  28. moPath = os.path.join(path, "LC_MESSAGES", "searx-qt.mo")
  29. if not os.path.exists(moPath):
  30. continue
  31. targetPath = os.path.join("share/locale", langDir, "LC_MESSAGES")
  32. data_files.append(
  33. (targetPath, [moPath])
  34. )
  35. return data_files
  36. def makeThemes():
  37. """ Compiles the resource files for all themes. (.qrc to .rcc)
  38. """
  39. cmd = 'python utils/themes_tool.py make all'
  40. if os.system(cmd) != 0:
  41. print("Failed to make all themes.")
  42. return False
  43. return True
  44. def themeDataFiles():
  45. """ Returns the 'data_files' for all found theme files.
  46. """
  47. cmd = 'python ./utils/themes_tool.py list'
  48. proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
  49. stdout, err = proc.communicate()
  50. if proc.returncode != 0:
  51. print('Failed to list themes.')
  52. sys.exit(1)
  53. data_files = []
  54. for key in stdout.decode().split('\n'):
  55. if not key:
  56. continue
  57. cmd = 'python ./utils/themes_tool.py files {0}'.format(key)
  58. proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
  59. stdout, err = proc.communicate()
  60. if proc.returncode != 0:
  61. print(
  62. 'Failed to get file list for theme with key \'{0}\''
  63. .format(key)
  64. )
  65. continue
  66. files = []
  67. for filepath in stdout.decode().split('\n'):
  68. if not filepath:
  69. continue
  70. files.append(filepath)
  71. data_files.append(
  72. (os.path.join("share/searx-qt/themes", key), files)
  73. )
  74. return data_files
  75. class build_py(_build_py):
  76. def run(self):
  77. if not compileLocales():
  78. return None
  79. if not makeThemes():
  80. return None
  81. return _build_py.run(self)
  82. class install_data(_install_data):
  83. def run(self):
  84. if os.path.exists(LOCALES_PATH):
  85. self.data_files += genMoList()
  86. if os.path.exists(THEMES_PATH):
  87. self.data_files += themeDataFiles()
  88. return _install_data.run(self)
  89. setup(name='searx-qt',
  90. version=__version__,
  91. license='GPLv3',
  92. description=('Lightweight desktop application for Searx.'),
  93. author='CYBERDEViL',
  94. url='https://notabug.org/cyberdevil',
  95. packages=[
  96. 'searxqt',
  97. 'searxqt.widgets',
  98. 'searxqt.models',
  99. 'searxqt.views',
  100. 'searxqt.core',
  101. 'searxqt.utils'
  102. ],
  103. classifiers=[
  104. 'Development Status :: 3 - Alpha',
  105. 'Environment :: X11 Applications :: Qt',
  106. 'Topic :: Internet',
  107. 'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
  108. 'Topic :: Internet :: WWW/HTTP'
  109. ],
  110. scripts=[
  111. 'bin/searx-qt'
  112. ],
  113. data_files=[
  114. ('share/applications', ['share/searx-qt.desktop']),
  115. ('share/doc/searx-qt', ['COPYING', 'README.md', 'CHANGELOG.md'])
  116. ],
  117. cmdclass={
  118. 'build_py': build_py,
  119. 'install_data': install_data
  120. })