-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcatkin_create_rqt
executable file
·198 lines (180 loc) · 8.24 KB
/
catkin_create_rqt
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/usr/bin/env python
import argparse
import sys
import os
import stat
from string import Template
class CreateRqtPkg:
def __init__(self, name, dependencies, path, class_name, namespace,
file_name, author, email, is_python):
self.pkg_name = name
self.dependencies = dependencies
if path is not None:
self.path_root = os.path.abspath(path[0])
else:
self.path_root = ''
if class_name is not None:
self.class_name = class_name[0]
else:
self.class_name = 'View'
if namespace is not None:
self.namespace = namespace[0]
else:
self.namespace = self.pkg_name
if file_name is not None:
self.file_name = file_name[0]
else:
self.file_name = self.class_name
if author is not None:
self.author = author[0]
else:
self.author = 'todo'
if email is not None:
self.email = email[0]
else:
self.email = 'todo@todo.com'
self.is_python = is_python
dependencies_1 = ""
dependencies_2 = ""
dependencies_xml = ""
for item in self.dependencies:
dependencies_1 += " " + item + "\n"
dependencies_2 += " " + item + "\n"
dependencies_xml += " <depend>" + item + "</depend>\n"
self.template_fill = {'class_name': self.class_name,
'namespace': self.namespace,
'file_name': self.file_name,
'author': self.author,
'email': self.email,
'dependencies_1': dependencies_1,
'dependencies_2': dependencies_2,
'dependencies_xml': dependencies_xml,
'pkg_name': self.pkg_name}
self.path = os.path.join(self.path_root, self.pkg_name)
self.path_src = os.path.join(self.path, 'src', self.pkg_name)
self.path_include = os.path.join(self.path, 'include', self.pkg_name)
self.path_resource = os.path.join(self.path, 'resource')
self.path_scripts = os.path.join(self.path, 'scripts')
self.path_launch = os.path.join(self.path, 'launch')
if not self.is_python:
template_name = "rqt_template"
else:
template_name = "rqt_template_py"
files = []
files.append((os.path.join(self.path, 'setup.py'),
os.path.join(template_name, 'setup.py')))
files.append((os.path.join(self.path, 'plugin.xml'),
os.path.join(template_name, 'plugin.xml')))
files.append((os.path.join(self.path, 'package.xml'),
os.path.join(template_name, 'package.xml')))
files.append((os.path.join(self.path, 'CMakeLists.txt'),
os.path.join(template_name, 'CMakeLists.txt')))
files.append((os.path.join(self.path_scripts, self.pkg_name),
os.path.join(template_name, 'scripts', template_name)))
files.append((os.path.join(self.path_launch, self.pkg_name + '.launch'),
os.path.join(template_name, 'launch',
template_name + '.launch')))
if not self.is_python:
files.append((os.path.join(self.path_src, self.file_name + '.cpp'),
os.path.join(template_name, 'src', template_name,
'Template.cpp')))
files.append((os.path.join(self.path_include,
self.file_name + '.h'),
os.path.join(template_name, 'include', template_name,
'Template.h')))
files.append((os.path.join(self.path_src, self.file_name + '.ui'),
os.path.join(template_name, 'src', template_name,
'Template.ui')))
files.append((os.path.join(self.path_resource,
'resources.qrc'),
os.path.join(template_name, 'resource',
'resources.qrc')))
else:
files.append((os.path.join(self.path_src,
self.file_name + '.py'),
os.path.join(template_name, 'src', template_name,
'Template.py')))
files.append((os.path.join(self.path_src,
self.file_name + '.ui'),
os.path.join(template_name, 'src', template_name,
'Template.ui')))
files.append((os.path.join(self.path_src, '__init__.py'),
None))
# generate directory tree
self.mkdir()
# generate files
for t in files:
self.apply_template(t)
# make script executable
st = os.stat(os.path.join(self.path_scripts, self.pkg_name))
os.chmod(os.path.join(self.path_scripts, self.pkg_name),
st.st_mode | stat.S_IEXEC)
def mkdir(self):
if os.path.exists(self.path):
print('package ' + self.pkg_name + ' exist already!')
sys.exit(0)
if not os.path.exists(self.path):
os.makedirs(self.path)
if not os.path.exists(self.path_src):
os.makedirs(self.path_src)
if not os.path.exists(self.path_include) and not self.is_python:
os.makedirs(self.path_include)
if not os.path.exists(self.path_resource) and not self.is_python:
os.makedirs(self.path_resource)
if not os.path.exists(self.path_scripts):
os.makedirs(self.path_scripts)
if not os.path.exists(self.path_launch):
os.makedirs(self.path_launch)
def apply_template(self, path_tuple):
try:
file_out = open(path_tuple[0], 'w')
except (OSError, IOError) as os_io_error:
print('could not create ' + path_tuple[0])
print(os_io_error)
sys.exit(0)
if path_tuple[1] is None:
file_out.close()
return
file_in = open(path_tuple[1])
template = Template(file_in.read())
file_out.write(template.substitute(self.template_fill))
file_out.close()
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Creates a new catkin rqt plugin package',
epilog='')
parser.add_argument('name',
nargs=1,
help='The name for the package')
parser.add_argument('dependencies',
nargs='*',
help='Catkin package Dependencies')
parser.add_argument('-p', '--path',
action='append',
help='The path into which the package should be '
'generated')
parser.add_argument('-c', '--class_name',
action='append',
help='Give the base rqt_plugin class a custom name '
'(default = View)')
parser.add_argument('-n', '--namespace',
action='append',
help='Rename the namespace (default = package name)')
parser.add_argument('-f', '--file_name',
action='append',
help='Rename the files .cpp/.h/.ui (default = class '
'name)')
parser.add_argument('-a', '--author',
action='append',
help='Author in package.xml')
parser.add_argument('-e', '--email',
action='append',
help='Email address in package.xml')
parser.add_argument('-y', '--python', dest='is_python',
default=False,
action='store_true',
help='Generate python rqt package')
args = parser.parse_args()
rqt = CreateRqtPkg(args.name[0], args.dependencies, args.path,
args.class_name, args.namespace, args.file_name,
args.author, args.email, args.is_python)