Merge branch 'master' of git://github.com/dustin/buildbot
[buildbot.git] / contrib / windows / setup.py
blobecb18bc49314b420d3a2cee9327444b834cb5521
1 # setup.py
2 # A distutils setup script to create py2exe binaries for buildbot.
3 # Both a service and standard executable are created.
4 # Usage:
5 # % setup.py py2exe
7 import sys
8 import os
9 import tempfile
10 import shutil
11 import py2exe
13 from os.path import dirname, join, abspath, exists, splitext
15 this_dir = abspath(dirname(__file__))
16 bb_root_dir = abspath(join(this_dir, "..", ".."))
18 from distutils.core import setup
20 includes = []
22 # We try and bundle *all* modules in the following packages:
23 for package in ["buildbot.changes", "buildbot.process", "buildbot.status"]:
24 __import__(package)
25 p = sys.modules[package]
26 for fname in os.listdir(p.__path__[0]):
27 base, ext = splitext(fname)
28 if not fname.startswith("_") and ext == ".py":
29 includes.append(p.__name__ + "." + base)
31 # Other misc modules dynamically imported, so missed by py2exe
32 includes.extend("""
33 buildbot.scheduler
34 buildbot.slave.bot
35 buildbot.master
36 twisted.internet.win32eventreactor
37 twisted.web.resource""".split())
39 # Turn into "," sep py2exe requires
40 includes = ",".join(includes)
42 py2exe_options = {"bundle_files": 1,
43 "includes": includes,
46 # Each "target" executable we create
47 buildbot_target = {
48 "script": join(bb_root_dir, "bin", "buildbot"),
50 # Due to the way py2exe works, we need to rebuild the service code as a
51 # normal console process - this will be executed by the service itself.
53 service_target = {
54 "modules": ["buildbot_service"],
55 "cmdline_style": "custom",
58 # We use the py2exe "bundle" option, so servicemanager.pyd
59 # (which has the message resources) does not exist. Take a copy
60 # of it with a "friendlier" name. The service runtime arranges for this
61 # to be used.
62 import servicemanager
64 msg_file = join(tempfile.gettempdir(), "buildbot.msg")
65 shutil.copy(servicemanager.__file__, msg_file)
67 data_files = [
68 ["", [msg_file]],
69 ["", [join(bb_root_dir, "buildbot", "status", "web", "classic.css")]],
70 ["", [join(bb_root_dir, "buildbot", "buildbot.png")]],
73 try:
74 setup(name="buildbot",
75 # The buildbot script as a normal executable
76 console=[buildbot_target],
77 service=[service_target],
78 options={'py2exe': py2exe_options},
79 data_files = data_files,
80 zipfile = "buildbot.library", # 'library.zip' invites trouble :)
82 finally:
83 os.unlink(msg_file)