PageRenderTime 91ms CodeModel.GetById 40ms RepoModel.GetById 1ms app.codeStats 0ms

/Server/setup.py

https://github.com/beaker-project/beaker
Python | 253 lines | 216 code | 22 blank | 15 comment | 33 complexity | 82dacfaa65e9e7b61d58cfb08f50dded MD5 | raw file
Possible License(s): GPL-2.0, CC-BY-SA-3.0
  1. __requires__ = ['CherryPy < 3.0']
  2. from setuptools import setup, find_packages
  3. import glob
  4. import re
  5. import os
  6. import commands
  7. from distutils import log
  8. from distutils.core import Command
  9. from distutils.util import change_root
  10. from distutils.command.build_py import build_py
  11. from distutils.command.build import build as _build
  12. from setuptools.command.install import install as _install
  13. import sys
  14. sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'Common'))
  15. sys.path.insert(1, os.path.dirname(__file__))
  16. poFiles = filter(os.path.isfile, glob.glob('po/*.po'))
  17. SUBSTFILES = ('bkr/server/config/app.cfg')
  18. def systemd_unit_dir():
  19. status, output = commands.getstatusoutput('pkg-config --variable systemdsystemunitdir systemd')
  20. if status or not output:
  21. return None # systemd not found
  22. return output.strip()
  23. def systemd_tmpfiles_dir():
  24. # There doesn't seem to be a specific pkg-config variable for this
  25. status, output = commands.getstatusoutput('pkg-config --variable prefix systemd')
  26. if status or not output:
  27. return None # systemd not found
  28. return output.strip() + '/lib/tmpfiles.d'
  29. class Build(_build, object):
  30. '''
  31. Build the package, changing the directories that data files are installed.
  32. '''
  33. user_options = _build.user_options
  34. user_options.extend([('install-data=', None,
  35. 'Installation directory for data files')])
  36. # These are set in finalize_options()
  37. substitutions = {'@DATADIR@': None, '@LOCALEDIR@': None}
  38. subRE = re.compile('(' + '|'.join(substitutions.keys()) + ')+')
  39. def initialize_options(self):
  40. self.install_data = None
  41. super(Build, self).initialize_options()
  42. def finalize_options(self):
  43. if self.install_data:
  44. self.substitutions['@DATADIR@'] = self.install_data + '/bkr/server'
  45. self.substitutions['@LOCALEDIR@'] = self.install_data + '/locale'
  46. else:
  47. self.substitutions['@DATADIR@'] = '%(top_level_dir)s'
  48. self.substitutions['@LOCALEDIR@'] = '%(top_level_dir)s/../locale'
  49. super(Build, self).finalize_options()
  50. def run(self):
  51. '''Substitute special variables for our installation locations.'''
  52. for filename in SUBSTFILES:
  53. # Change files to reference the data directory in the proper
  54. # location
  55. infile = filename + '.in'
  56. if not os.path.exists(infile):
  57. continue
  58. try:
  59. f = file(infile, 'r')
  60. except IOError:
  61. if not self.dry_run:
  62. raise
  63. f = None
  64. outf = file(filename, 'w')
  65. for line in f.readlines():
  66. matches = self.subRE.search(line)
  67. if matches:
  68. for pattern in self.substitutions:
  69. line = line.replace(pattern,
  70. self.substitutions[pattern])
  71. outf.writelines(line)
  72. outf.close()
  73. f.close()
  74. # Make empty en.po
  75. dirname = 'locale/'
  76. if not os.path.isdir(dirname):
  77. os.makedirs(dirname)
  78. #shutil.copy('po/LINGUAS', 'locale/')
  79. for pofile in poFiles:
  80. # Compile PO files
  81. lang = os.path.basename(pofile).rsplit('.', 1)[0]
  82. dirname = 'locale/%s/LC_MESSAGES/' % lang
  83. if not os.path.isdir(dirname):
  84. os.makedirs(dirname)
  85. # Hardcoded gettext domain: 'server'
  86. mofile = dirname + 'server' + '.mo'
  87. subprocess.call(['/usr/bin/msgfmt', pofile, '-o', mofile])
  88. super(Build, self).run()
  89. # from http://trac.turbogears.org/changeset/6869
  90. class build_py_and_kid(build_py):
  91. """Build pure Python modules and Kid templates."""
  92. def byte_compile(self, files):
  93. """Byte-compile all Python modules and all Kid templates."""
  94. build_py.byte_compile(self, files)
  95. kid_files = [f for f in files if f.endswith('.kid')]
  96. if not kid_files:
  97. return
  98. from distutils import log
  99. try:
  100. from kid.compiler import compile_file
  101. except ImportError:
  102. log.warn("Kid templates cannot be compiled,"
  103. " because Kid is not installed.")
  104. return
  105. if self.dry_run:
  106. return
  107. for kid_file in kid_files:
  108. if compile_file(kid_file, force=self.force):
  109. log.info("byte-compiling %s", kid_file)
  110. else:
  111. log.debug("skipping byte-compilation of %s", kid_file)
  112. class Install(_install):
  113. sub_commands = _install.sub_commands + [
  114. ('install_assets', None),
  115. ]
  116. class InstallAssets(Command):
  117. description = 'install web assets'
  118. user_options = []
  119. def initialize_options(self):
  120. self.install_data = None
  121. def finalize_options(self):
  122. self.set_undefined_options('install', ('install_data', 'install_data'))
  123. self.install_dir = os.path.join(self.install_data, 'bkr/server/assets')
  124. self.source_dir = 'assets'
  125. def run(self):
  126. from bkr.server import assets
  127. for filename in assets.list_asset_sources(self.source_dir):
  128. source_path = os.path.join(self.source_dir, filename)
  129. dest_path = os.path.join(self.install_dir, filename)
  130. self.mkpath(os.path.dirname(dest_path), mode=0755)
  131. self.copy_file(source_path, dest_path)
  132. def find_data_recursive(dest_dir, src_dir, exclude=frozenset()):
  133. if src_dir[-1] != '/':
  134. src_dir = src_dir + '/'
  135. for dirpath, dirnames, filenames in os.walk(src_dir):
  136. assert dirpath.startswith(src_dir)
  137. yield (os.path.join(dest_dir, dirpath[len(src_dir):]),
  138. [os.path.join(dirpath, filename) for filename in filenames
  139. if filename not in exclude])
  140. data_files = \
  141. list(find_data_recursive('bkr/server/static', 'bkr/server/static/')) + [
  142. ("/etc/beaker", ["server.cfg"]),
  143. ("/etc/httpd/conf.d", ["apache/beaker-server.conf"]),
  144. ("/etc/cron.d", ["cron.d/beaker"]),
  145. ("/etc/rsyslog.d", ["rsyslog.d/beaker-server.conf"]),
  146. ("/etc/logrotate.d", ["logrotate.d/beaker"]),
  147. ("/usr/share/bkr", filter(os.path.isfile, glob.glob("apache/*.wsgi"))),
  148. ("/var/log/beaker", []),
  149. ("/var/cache/beaker/assets", []),
  150. ("/var/www/beaker/logs", []),
  151. ("/var/www/beaker/rpms", []),
  152. ("/var/www/beaker/repos", []),
  153. ]
  154. if systemd_unit_dir():
  155. data_files.extend([
  156. (systemd_unit_dir(), ['systemd/beakerd.service']),
  157. (systemd_tmpfiles_dir(), ['tmpfiles.d/beaker-server.conf']),
  158. ('/run/beaker', []),
  159. ])
  160. else:
  161. data_files.extend([
  162. ('/etc/init.d', ['init.d/beakerd']),
  163. ('/var/run/beaker', []),
  164. ])
  165. setup(
  166. name='beaker-server',
  167. namespace_packages = ['bkr'],
  168. version='28.2',
  169. description='Beaker scheduler and web interface',
  170. long_description=
  171. 'Beaker is a system for full stack software integration testing '
  172. '(including hardware compatibility testing).',
  173. author='Red Hat, Inc.',
  174. author_email='beaker-devel@lists.fedorahosted.org',
  175. url='https://beaker-project.org/',
  176. cmdclass = {
  177. 'build': Build,
  178. 'build_py': build_py_and_kid,
  179. 'install': Install,
  180. 'install_assets': InstallAssets,
  181. },
  182. install_requires=[
  183. 'TurboGears >= 1.1',
  184. 'sqlalchemy >= 0.6',
  185. 'Flask',
  186. ],
  187. scripts=[],
  188. zip_safe=False,
  189. data_files = data_files,
  190. packages = find_packages(),
  191. package_data={
  192. 'bkr.server.tests': ['unit-test.cfg', '*.rpm'],
  193. 'bkr.server.config': ['*.cfg'],
  194. 'bkr.server.templates': ['*.kid'],
  195. 'bkr.server': [
  196. 'data-migrations/*',
  197. 'kickstarts/*',
  198. 'snippets/*',
  199. 'reporting-queries/*/*.sql',
  200. 'reporting-queries/*.sql',
  201. 'mail-templates/*',
  202. ],
  203. 'bkr.server.alembic': ['versions/*.py', 'env.py'],
  204. },
  205. keywords=[
  206. 'turbogears.app',
  207. ],
  208. classifiers=[
  209. 'Development Status :: 5 - Production/Stable',
  210. 'Operating System :: POSIX :: Linux',
  211. 'Programming Language :: Python',
  212. 'Framework :: TurboGears',
  213. 'Framework :: TurboGears :: Applications',
  214. 'License :: OSI Approved :: GNU General Public License (GPL)',
  215. ],
  216. test_suite='nose.collector',
  217. entry_points = {
  218. 'console_scripts': (
  219. 'beaker-init = bkr.server.tools.init:main',
  220. 'product-update = bkr.server.tools.product_update:main',
  221. 'beakerd = bkr.server.tools.beakerd:main',
  222. 'beaker-usage-reminder = bkr.server.tools.usage_reminder:main',
  223. 'beaker-log-delete = bkr.server.tools.log_delete:main',
  224. 'beaker-create-ipxe-image = bkr.server.tools.ipxe_image:main',
  225. 'beaker-refresh-ldap = bkr.server.tools.refresh_ldap:main',
  226. 'beaker-repo-update = bkr.server.tools.repo_update:main',
  227. 'beaker-sync-tasks = bkr.server.tools.sync_tasks:main',
  228. 'beaker-create-kickstart = bkr.server.tools.create_kickstart:main'
  229. ),
  230. }
  231. )