forked from faucetsdn/faucet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·87 lines (73 loc) · 3.2 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
#!/usr/bin/env python
from __future__ import print_function
import errno
import os
import shutil
import sys
from pkg_resources import resource_filename
from setuptools import setup
if sys.version_info < (3,):
print("""You are trying to install faucet on python {py}
Faucet is not compatible with python 2, please upgrade to python 3.5 or newer."""
.format(py='.'.join([str(v) for v in sys.version_info[:3]])), file=sys.stderr)
sys.exit(1)
elif sys.version_info < (3, 5):
print("""You are trying to install faucet on python {py}
Faucet 1.9.0 and above are no longer compatible with older versions of python 3.
Please upgrade to python 3.5 or newer."""
.format(py='.'.join([str(v) for v in sys.version_info[:3]])))
sys.exit(1)
def install_configs():
""" Install configuration files to /etc """
dst_ryu_conf_dir = '/etc/faucet/'
dst_ryu_conf = os.path.join(dst_ryu_conf_dir, 'ryu.conf')
dst_faucet_conf_dir = '/etc/faucet/'
src_ryu_conf = resource_filename(__name__, "etc/faucet/ryu.conf")
src_faucet_conf_dir = resource_filename(__name__, "etc/faucet/")
faucet_log_dir = '/var/log/faucet/'
old_ryu_conf = '/etc/ryu/ryu.conf'
old_faucet_conf_dir = '/etc/ryu/faucet/'
try:
if not os.path.exists(dst_ryu_conf_dir):
print("Creating %s" % dst_ryu_conf_dir)
os.makedirs(dst_ryu_conf_dir)
if not os.path.isfile(dst_ryu_conf):
if os.path.exists(old_ryu_conf) and os.path.isfile(old_ryu_conf):
print("Migrating %s to %s" % (old_ryu_conf, dst_ryu_conf))
shutil.copy(old_ryu_conf, dst_ryu_conf)
else:
print("Copying %s to %s" % (src_ryu_conf, dst_ryu_conf))
shutil.copy(src_ryu_conf, dst_ryu_conf)
if not os.path.exists(dst_faucet_conf_dir):
print("Creating %s" % dst_faucet_conf_dir)
os.makedirs(dst_faucet_conf_dir)
for file_name in os.listdir(src_faucet_conf_dir):
src_file = os.path.join(src_faucet_conf_dir, file_name)
dst_file = os.path.join(dst_faucet_conf_dir, file_name)
alt_src = os.path.join(old_faucet_conf_dir, file_name)
if os.path.isfile(dst_file):
continue
elif os.path.isfile(alt_src):
print("Migrating %s to %s" % (alt_src, dst_file))
shutil.copy(alt_src, dst_file)
elif os.path.isfile(src_file):
print("Copying %s to %s" % (src_file, dst_file))
shutil.copy(src_file, dst_file)
if not os.path.exists(faucet_log_dir):
print("Creating %s" % faucet_log_dir)
os.makedirs(faucet_log_dir)
except OSError as exception:
if exception.errno == errno.EACCES:
print("Permission denied creating %s, skipping copying configs"
% exception.filename)
else:
raise
setup(
name='faucet',
setup_requires=['pbr>=1.9', 'setuptools>=17.1'],
python_requires='>=3.5',
pbr=True
)
if 'install' in sys.argv or 'bdist_wheel' in sys.argv:
if os.getenv("DEBINSTALL") is None or (os.getenv("DEBINSTALL") is not None and int(os.environ['DEBINSTALL']) < 1):
install_configs()