-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
105 lines (89 loc) · 3.48 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
import os
import re
import codecs
from setuptools import setup, find_packages
from setuptools.command.install import install
here = os.path.abspath(os.path.dirname(__file__))
def read(*parts):
return codecs.open(os.path.join(here, *parts), 'r').read()
def find_version(*file_paths):
version_file = read(*file_paths)
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
version_file, re.M)
if version_match:
return version_match.group(1)
raise RuntimeError("Unable to find version string.")
def install_completion_script():
import os
has_bash = False
for path in os.environ["PATH"].split(os.pathsep):
path = path.strip('"')
exe_file = os.path.join(path, 'bash')
if os.path.isfile(exe_file) and os.access(exe_file, os.X_OK):
has_bash = True
if not has_bash:
if os.system('complete') != 0:
print('\033[93mWarning: you do not have "complete" command, '
'the completion feature won\'t be installed.\033[0m')
else:
print('\033[93mWarning: "bash" not found, the completion feature won\'t be installed.\033[0m')
return
if not os.path.isdir('/etc'):
print('\033[93mWarning: you do not have an unix environment, I cannot install the completion script.'
'Please install it manually by copying ovhcli_complete.sh to the correct folder '
'so it is executed at startup.\033[0m')
return
if not os.path.isdir('/etc/bash_completion.d'):
print('\033[93mWarning: you do not have a "/etc/bash_completion.d" folder, the completion script will not '
'be installed. If you want to activate it, source ovhcli_complete.sh.\033[0m')
return
with open('/etc/bash_completion.d/ovhcli', 'w+') as f:
f.write(read('ovhcli_complete.sh'))
try:
os.chmod('/etc/bash_completion.d/ovhcli', 0o644)
except OSError:
pass
print('\033[94mOVH CLI completion script installed at "/etc/bash_completion.d/ovhcli".\n'
'You will need to reload your shell or source it to activate the script.\033[0m')
class PostInstallCommand(install):
def run(self):
install_completion_script()
install.run(self)
setup(
name="ovh_api_cli",
version=find_version("ovh_api_cli", "__init__.py"),
description="A wrapper over OVH's API with killer autocomplete feature.",
long_description=read('README.rst'),
classifiers=[
"Topic :: Utilities",
"Environment :: Console",
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
],
keywords='ovh cli api apiv6',
author='Cyril DEMINGEON',
author_email='cyril.demingeon@corp.ovh.com',
url='https://api.ovh.com/',
license='MIT',
packages=find_packages(),
include_package_data=True,
package_data={
'data': ['README.md', 'ovhcli_complete.sh', '*.py']
},
entry_points={
"console_scripts": [
"ovhcli=ovh_api_cli:main"
],
},
cmdclass={
'install': PostInstallCommand,
}
)