-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·199 lines (159 loc) · 5.77 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/usr/bin/env python
"""
Standard build script.
"""
__docformat__ = 'restructuredtext'
import os
import sys
from distutils.core import Command, setup
from os import path
sys.path.insert(0, 'src')
from loki import __version__, __license__, __author__
class SetupBuildCommand(Command):
"""
Master setup build command to subclass from.
"""
user_options = []
def initialize_options(self):
"""
Setup the current dir.
"""
self._dir = os.getcwd()
def finalize_options(self):
"""
No clue ... but it's required.
"""
pass
class SphinxCommand(SetupBuildCommand):
"""
Creates HTML documentation using Sphinx.
"""
description = "Generate documentation via sphinx"
def run(self):
"""
Run the DocCommand.
"""
print "Creating html documentation ..."
try:
from sphinx.application import Sphinx
if not os.access(path.join('docs', 'html'), os.F_OK):
os.mkdir(path.join('docs', 'html'))
buildername = 'html'
outdir = path.abspath(path.join('docs', 'html'))
doctreedir = os.path.join(outdir, '.doctrees')
confdir = path.abspath('docs')
srcdir = path.abspath('docs')
freshenv = False
# Create the builder
app = Sphinx(srcdir, confdir, outdir, doctreedir, buildername,
{}, sys.stdout, sys.stderr, freshenv)
# And build!
app.builder.build_all()
print "Your docs are now in %s" % outdir
except ImportError, ie:
print >> sys.stderr, "You don't seem to have the following which"
print >> sys.stderr, "are required to make documentation:"
print >> sys.stderr, "\tsphinx.application.Sphinx"
print >> sys.stderr, ie
except Exception, ex:
print >> sys.stderr, "FAIL! exiting ... (%s)" % ex
class RPMBuildCommand(SetupBuildCommand):
"""
Creates an RPM based off spec files.
"""
description = "Build an rpm based off of the top level spec file(s)"
def run(self):
"""
Run the RPMBuildCommand.
"""
try:
if os.system('./setup.py sdist'):
raise Exception("Couldn't call ./setup.py sdist!")
sys.exit(1)
if not os.access('dist/rpms/', os.F_OK):
os.mkdir('dist/rpms/')
dist_dir = os.path.join(os.getcwd(), 'dist')
rpm_cmd = 'rpmbuild -ba --clean \
--define "_rpmdir %s/rpms/" \
--define "_srcrpmdir %s/rpms/" \
--define "_sourcedir %s" *spec' % (
dist_dir, dist_dir, dist_dir)
if os.system(rpm_cmd):
raise Exception("Could not create the rpms!")
except Exception, ex:
print >> sys.stderr, str(ex)
class ViewDocCommand(SetupBuildCommand):
"""
Quick command to view generated docs.
"""
def run(self):
"""
Opens a webbrowser on docs/html/index.html
"""
import webbrowser
print ("NOTE: If you have not created the docs first this will not be "
"helpful. If you don't see any documentation in your browser "
"run ./setup.py doc first.")
if not webbrowser.open('docs/html/index.html'):
print >> sys.stderr, "Could not open on your webbrowser."
class DjangoTestCommand(SetupBuildCommand):
"""
Quick command to view generated docs.
"""
def run(self):
"""
Simply executes the django test cases.
"""
try:
# Import yaml just to make sure it's available since the
# tests need it
import yaml
os.system('./src/example_project/manage.py test')
except ImportError, ie:
print >> sys.stderr, "You must have PyYAML installed to test."
def get_sources(map_list):
"""
Simple function to make it easy to get everything under a directory as
a source list.
:Parameters:
- `src`: the location on the file system to use as a root.
- `dst`: the target location to use as a root.
- `recursive`: include subdirs.
"""
file_list = []
for map in map_list:
dst, src, recursive = map
for afile in os.listdir(src):
this_dir_list = []
full_path = os.path.join(src, afile)
if os.path.isfile(full_path):
this_dir_list.append(full_path)
else:
if recursive:
file_list.extend(
get_sources([(os.path.join(dst, afile),
full_path,
recursive)]))
file_list.append((dst, this_dir_list))
return file_list
setup(name = "Django-app-loki",
version = __version__,
description = "A buildbot management application",
long_description = "A buildbot management application",
author = __author__,
author_email = '[email protected]',
url = "http://www.fedorahosted.org/loki/",
platforms = ['linux'],
license = __license__,
classifiers = [
'License :: OSI Approved :: GNU General Public License (GPL)',
'Development Status :: 5 - Production/Stable',
'Programming Language :: Python'],
data_files = get_sources([('share/django/apps/loki',
os.path.join('src',
'loki'),
True)]),
cmdclass = {'rpm': RPMBuildCommand,
'doc': SphinxCommand,
'viewdoc': ViewDocCommand,
'test': DjangoTestCommand})