forked from polaris-gslb/polaris-gslb
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup.py
94 lines (75 loc) · 2.73 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
#-*- coding: utf-8 -*-
"""Polaris setup
By default will install to /opt/polaris, to install to a different folder
set POLARIS_INSTALL_PREFIX env before running "python3 setup.py install"
"""
import os
import sys
import inspect
import shutil
import setuptools
VERSION = '0.6.0'
def main():
# setup packages
setuptools.setup(
version=VERSION,
author='Anton Gavrik',
name='polaris-gslb',
description=('An extendable Global Server Load Balancing(GSLB) '
'solution, DNS-based traffic manager.'),
packages = setuptools.find_packages('.'),
install_requires=[
'pyyaml',
'python-memcached',
'python-daemon-3K'
],
license='BSD 3-Clause',
url='https://github.com/polaris-gslb/polaris-gslb',
download_url=('https://github.com/polaris-gslb/polaris-gslb/tarball/v{}'
.format(VERSION)),
classifiers=[
'Programming Language :: Python :: 3',
]
)
# use value from POLARIS_INSTALL_PREFIX env if set
try:
install_prefix = os.environ['POLARIS_INSTALL_PREFIX']
except KeyError:
install_prefix = os.path.join(os.sep, 'opt', 'polaris')
# determine the directory where setup.py is located
pwd = os.path.abspath(
os.path.split(inspect.getfile(inspect.currentframe()))[0])
print('Creating directory topology...')
for path in [
os.path.join(install_prefix, 'etc'),
os.path.join(install_prefix, 'bin'),
os.path.join(install_prefix, 'run'),
]:
try:
os.makedirs(path)
except FileExistsError:
continue
print('Copying dist configuration and executables...')
for dirname in [ 'etc', 'bin' ]:
copy_files(os.path.join(pwd, dirname),
os.path.join(install_prefix, dirname))
print('Creating /etc/default/polaris...')
py3_path = ''
if not sys.executable:
print('Unable to determine Python3 executable path, '
'add the path manually to /etc/default/polaris')
else:
py3_path = os.path.split(sys.executable)[0]
with open(os.path.join(os.sep, 'etc', 'default', 'polaris'), 'w') as f:
f.write('export PATH=$PATH:{}\n'.format(py3_path))
f.write('export POLARIS_INSTALL_PREFIX={}\n'
.format(install_prefix))
def copy_files(src_dir, dst_dir):
"""Copy all files from src_dir to dst_dir"""
src_files = os.listdir(src_dir)
for file_name in src_files:
full_file_name = os.path.join(src_dir, file_name)
if (os.path.isfile(full_file_name)):
shutil.copy(full_file_name, dst_dir)
if __name__ == '__main__':
main()