-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
120 lines (108 loc) · 4.53 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
#!/usr/bin/env python3
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
"""Setup tools for phoenix"""
import sys
import os
import imp
import gzip
import argparse
import subprocess
from distutils.core import Command
from distutils.core import setup
from distutils.command.sdist import sdist
from distutils.command.bdist_rpm import bdist_rpm
class GenerateMan(Command):
"""Custom command to generate man pages"""
description = 'Generate man pages'
user_options = []
def __init__(self, args):
Command.__init__(self, args)
self.author = args.get_author()
self.scripts = args.scripts
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
for script in self.scripts:
scriptname = script.split('/')[-1]
sys.dont_write_bytecode = True
module = imp.load_source(scriptname, script)
parser = module.get_parser()
sys.dont_write_bytecode = False
print("Running generate man for ", script)
if not os.path.exists('man/man1'):
os.makedirs('man/man1')
with gzip.open('man/man1/%s.1.gz' % scriptname, 'w') as mpage:
mpage.write(".TH %s 1\n" % scriptname.upper())
mpage.write(".SH NAME\n")
mpage.write("%s - %s\n" % (scriptname, parser.description))
mpage.write(".SH SYNOPSIS\n")
parser.print_usage(mpage)
mpage.write(".SH DESCRIPTION\n")
for action_group in parser._action_groups:
mpage.write(".SS %s\n" % action_group.title)
for action in action_group._group_actions:
if action.help == argparse.SUPPRESS:
continue
mpage.write(".TP\n");
if len(action.option_strings) == 0:
mpage.write('\\fB%s\\fR ' % action.dest)
else:
for opt in action.option_strings:
mpage.write('\\fB%s\\fR ' % opt)
if action.choices:
mpage.write("{%s}" % ",".join(action.choices))
elif action.dest and action.nargs is None:
mpage.write('%s ' % action.dest.upper())
mpage.write("\n%s\n" % action.help)
mpage.write(".SH AUTHOR\n")
mpage.write("%s\n" % self.author)
class CustomSdist(sdist):
"""Override sdist to generate man pages"""
def run(self):
#self.run_command('generate_man')
sdist.run(self)
class bdist_rpm_custom(bdist_rpm):
"""bdist_rpm that sets custom options: release, requires"""
def finalize_package_data (self):
if self.release is None:
self.release = release+"%{?dist}"
if self.requires is None:
self.requires = requires
bdist_rpm.finalize_package_data(self)
# Add the phoenix lib to the python path
basedir = os.path.dirname(__file__)
if basedir == "":
basedir = os.getcwd()
sys.path.insert(0,"%s/lib" % basedir)
scripts = [x for x in os.listdir('bin') if os.path.isfile('bin/%s' % x)]
requires = [ 'python3-clustershell', 'python3-Jinja2' ]
try:
ver=subprocess.check_output(["git", "describe"]).decode().strip().split('-')
except:
ver=['0.1']
try:
release = ver[1]
except IndexError:
release = '0'
setup(name = 'phoenix',
version = ver[0].strip('v'),
description = 'Phoenix provisioning tool',
long_description = 'A set of utilities to configure, boot, and manage a cluster',
author = 'ORNL HPC Operations',
author_email = '[email protected]',
url = 'https://gitlab.ccs.ornl.gov/hpc-admins/phoenix',
package_dir={'': 'lib'},
packages = [ 'phoenix', 'phoenix.bootloader', 'phoenix.command', 'phoenix.datasource', 'phoenix.dhcp', 'phoenix.oob', 'phoenix.plugins' ],
#packages=find_packages('lib'),
scripts = ['bin/%s' % x for x in scripts],
cmdclass = { 'bdist_rpm': bdist_rpm_custom, 'sdist': CustomSdist, 'generate_man': GenerateMan },
data_files = [ #('/usr/share/man/man1', ['man/man1/%s.1.gz' % x for x in scripts]),
('/etc/phoenix', []),
('/etc/phoenix/recipes', []),
('/var/opt/phoenix/data', []),
('/etc/clustershell/groups.conf.d', ['contrib/clustershell/phoenix.conf']),
('/usr/lib/systemd/system', ['contrib/pxbootfile.service'])
],
)