-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.py
executable file
·203 lines (163 loc) · 5.58 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
200
201
202
203
#!/usr/bin/env python
"""
Standard build script.
"""
__docformat__ = 'restructuredtext'
import os
import sys
from setuptools import Command, setup#, find_packages, findall
sys.path.insert(0, 'src')
from phacter 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
try:
from sphinx import setup_command
class SphinxCommand(setup_command.BuildDoc):
"""
Wrapper for the sphinx setup command.
"""
def __init__(self, dist):
"""
Overrides some settings before run.
"""
setup_command.BuildDoc.__init__(self, dist)
if not os.path.exists('dist'):
os.mkdir('dist')
if not os.path.exists(os.path.join('dist', 'html')):
os.mkdir(os.path.join('dist', 'html'))
self.source_dir = 'docs'
self.build_dir = os.path.join('dist', 'html')
except ImportError, ie:
class SphinxCommand(SetupBuildCommand):
"""
Dummy 'you don't have sphinx' command/
"""
def __init__(self, dist):
"""
Prints out the error info and exits.
"""
sys.stderr.write("You don't seem to have the following which\n")
sys.stderr.write("are required to make documentation:\n\n")
sys.stderr.write("\tsphinx.setup_command\n")
raise SystemExit(1)
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 os.system('./setup.py man'):
raise Exception("Couldn't call ./setup.py man!")
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:
sys.stderr.write(str(ex))
class ManCommand(SetupBuildCommand):
"""
Generate the man page
"""
description = "generate the man page"
def run(self):
man_cmd = 'help2man --no-info bin/phacter > phacter.1'
if os.system(man_cmd):
raise Exception("Could not create the man page!")
class TestCommand(SetupBuildCommand):
"""
executes the unit tests
"""
description = "run the unit tests"
def run(self):
pass
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'):
sys.stderr.write("Could not open on your webbrowser.\n")
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="python-phacter",
version=__version__,
description="A system facts tool",
long_description="system facts toolon",
author=__author__,
author_email='[email protected]',
#TODO: fix the url
url="https://github.com/radez/phacter",
platforms=['linux','darwin', 'windows'],
license=__license__,
classifiers=[
'License :: OSI Approved :: GNU General Public License (GPL)',
'Development Status :: 5 - Production/Stable',
'Programming Language :: Python'],
package_dir={'': 'src'},
packages=['phacter', 'phacter.utils'],
scripts=['bin/phacter'],
#data_files=get_sources(
# [('lib/phacter', os.path.join('src', 'phacter'), True)]),
zip_safe=False,
cmdclass={'rpm': RPMBuildCommand,
'man': ManCommand,
'doc': SphinxCommand,
'viewdoc': ViewDocCommand,
'test': TestCommand})