setup.py 4.5 KB

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