forked from faucetsdn/daq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
81 lines (66 loc) · 2.41 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
#!/usr/bin/env python3
from __future__ import absolute_import
import setuptools
import shutil
import os
import tempfile
def get_files_mapping_env():
with open('debian/FILES_MAPPING') as f:
return f.read().split('\n')
def get_version():
return os.popen('git describe').read().strip()
def build_entry_script(tmp):
with open(os.path.join(tmp, 'daq'), 'w') as f:
script = """#!/bin/bash
if [ "$EUID" -ne 0 ]; then
echo Please run DAQ as root
exit
fi
%s
export DAQ_VERSION="%s"
LSB_RAW=$(lsb_release -a)
export DAQ_LSB_RELEASE=$(echo $LSB_RAW)
export DAQ_SYS_UNAME=$(uname -a)
export DAQ_DIR=`python3 -c 'import daq; import os; print(os.path.dirname(daq.__file__))'`
source $DAQ_LIB/bin/config_base.sh
python3 $DAQ_DIR/entry.py $conf_file $@
""" % (";".join(get_files_mapping_env()), get_version())
f.write(script)
return os.path.join(tmp, 'daq')
def build_data_files(prefix, package_prefix):
paths = []
for root, dirs, files in os.walk(prefix):
if files:
paths.append((os.path.join(package_prefix, root[len(prefix) + 1:]),
[os.path.join(root, name) for name in files]))
return paths
def build_source_files(tmp):
shutil.rmtree(tmp, ignore_errors=True)
shutil.copytree('daq', tmp, symlinks=True)
shutil.copytree('faucet/clib', os.path.join(tmp, 'clib'), symlinks=True)
return tmp
dirs = os.listdir('.')
assert all([repo in dirs for repo in ('faucet',)]), \
'Missing dependent repos. Please run bin/setup_dev'
with tempfile.TemporaryDirectory(dir='.') as tmp:
setuptools.setup(
package_dir={
'daq': build_source_files(tmp)
},
package_data={'daq': ['proto/*', 'clib/*', 'forch/proto/*']},
setup_requires=['pbr>=1.9', 'setuptools>=17.1'],
pbr=True,
scripts=[
build_entry_script(tmp),
],
data_files=[
*build_data_files('bin', 'lib/daq/bin'),
*build_data_files('cmd', 'lib/daq/cmd'),
*build_data_files('resources/setups', 'lib/daq/resources/setups'),
*build_data_files('subset', 'lib/daq/subset'),
*build_data_files('usi', 'lib/daq/usi'),
*build_data_files('config/modules', 'lib/daq/config/modules'),
*build_data_files('config/system', 'lib/daq/config/system'),
*build_data_files('config/faucet', 'lib/daq/config/faucet'),
]
)