forked from lfbear/ansible-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
101 lines (89 loc) · 3.67 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
#!/usr/bin/env python
# coding: utf-8
# A restful HTTP API for ansible
# Base on ansible-runner and sanic
# Github <https://github.com/lfbear/ansible-api>
# Author: lfbear
from setuptools.command.install import install
from setuptools import setup, find_packages
from distutils.version import LooseVersion
import os
import sys
import pkg_resources
sys.path.insert(0, os.path.abspath('src'))
from ansible_api import __version__
ABSIBLE_REQUIRE = '2.6.0'
ABSIBLER_REQUIRE = '1.2.0'
SANIC_REQUIRE = '0.8.0'
PYTHON_REQUIRE = '3.7'
# do something after install
class CustomInstall(install):
_configfiles = [('/etc/ansible/', ['data/api.cfg'])]
def run(self):
cur_python_ver = "%d.%d" % (sys.version_info[0], sys.version_info[1])
if LooseVersion(cur_python_ver) < LooseVersion(PYTHON_REQUIRE):
print("Error: Python version " + cur_python_ver + " < " + PYTHON_REQUIRE)
return False
os.system("%s -m pip install ansible>=%s" % (sys.executable, ABSIBLE_REQUIRE))
os.system("%s -m pip install ansible-runner>=%s" % (sys.executable, ABSIBLER_REQUIRE))
os.system("%s -m pip install sanic>=%s" % (sys.executable, SANIC_REQUIRE))
try:
import ansible
import ansible_runner
except ImportError:
print("Error: I can NOT work without ansible-runner")
# path = os.path.dirname(ansible.__file__)
if LooseVersion(ansible.__version__) >= LooseVersion(ABSIBLE_REQUIRE) and \
LooseVersion(pkg_resources.require("ansible_runner")[0].version) >= LooseVersion(ABSIBLER_REQUIRE):
install.run(self)
self.init_config_file()
print("\033[1;37mAnsible-api v%s install complete.\033[0m" %
__version__)
else:
print("Error: ansible [%s] or ansible-runner [%s] version too low" %
(ansible_runner.__version__, pkg_resources.require("ansible_runner")[0].version))
def init_config_file(self):
for p in self._configfiles:
path = p[0]
for f in p[1]:
file = os.path.join(path, os.path.basename(f))
if not os.path.isfile(file):
os.system(' '.join(['cp', f, file]))
print(
"\033[1;36mConfiguration file: %s has been copied\033[0m" % file)
else:
print(
"\033[4;37mConfiguration file exists: %s\033[0m" % file)
with open("README.md", "r") as fh:
long_description = fh.read()
setup(
name='ansible-api',
version=__version__,
scripts=['bin/ansible-api'],
package_dir={'': 'src'},
packages=find_packages('src'),
python_requires='>=' + PYTHON_REQUIRE,
install_requires=['sanic>=' + SANIC_REQUIRE,
'ansible>=' + ABSIBLE_REQUIRE,
'ansible-runner>=' + ABSIBLER_REQUIRE],
cmdclass={'install': CustomInstall},
author="lfbear",
author_email="[email protected]",
description="A restful HTTP API for ansible",
long_description=long_description,
long_description_content_type="text/markdown",
license="GPLv3",
url="https://github.com/lfbear/ansible-api",
classifiers=[
"Development Status :: 5 - Production/Stable",
"Programming Language :: Python :: 3.7",
"Operating System :: OS Independent",
"Topic :: System :: Systems Administration",
"Topic :: Utilities",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
],
project_urls={ # Optional
'Bug Reports': 'https://github.com/lfbear/ansible-api/issues',
'Source': 'https://github.com/lfbear/ansible-api',
},
)