-
Notifications
You must be signed in to change notification settings - Fork 6
/
setup.py
66 lines (51 loc) · 1.55 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
#!/usr/bin/env python
from __future__ import print_function
import os, shutil, sys
#sys.args.append('build')
from distutils.core import setup, Extension
# pr2_without_sensor_ik_files
# python setup.py build
LEFT_IK = 'ikLeft'
RIGHT_IK = 'ikRight'
LIBRARY_TEMPLATE = '{}.so' # might need to be '{}.pyd' on windows
leftModule = Extension(LEFT_IK, sources=['left_arm_ik.cpp'])
rightModule = Extension(RIGHT_IK, sources=['right_arm_ik.cpp'])
setup(name=LEFT_IK,
version='1.0',
description="IK for PR2's left arm",
ext_modules=[leftModule])
setup(name=RIGHT_IK,
version='1.0',
description="IK for PR2's right arm",
ext_modules=[rightModule])
LEFT_LIBRARY = LIBRARY_TEMPLATE.format(LEFT_IK)
RIGHT_LIBRARY = LIBRARY_TEMPLATE.format(RIGHT_IK)
ik_folder = os.getcwd()
# TODO: refactor
left_path = None
right_path = None
build_folder = os.path.join(os.getcwd(), 'build')
for dirpath, _, filenames in os.walk(build_folder):
for file in filenames:
if LEFT_IK in file:
left_path = os.path.join(dirpath, file)
LEFT_LIBRARY = file
elif RIGHT_IK in file:
right_path = os.path.join(dirpath, file)
RIGHT_LIBRARY = file
left_target = os.path.join(ik_folder, LEFT_LIBRARY)
right_target = os.path.join(ik_folder, RIGHT_LIBRARY)
ik_files = os.listdir(ik_folder)
if LEFT_LIBRARY in ik_files:
os.remove(left_target)
if RIGHT_IK in ik_files:
os.remove(right_target)
os.rename(left_path, left_target)
os.rename(right_path, right_target)
shutil.rmtree(build_folder)
try:
import ikLeft, ikRight
print('IK Successful')
except ImportError as e:
print('IK Failed')
raise e