setup.py 4.9 KB

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