20
20
# -- END LICENSE BLOCK ------------------------------------------------
21
21
22
22
from __future__ import print_function
23
+ import os
23
24
import subprocess
24
25
import sys
25
26
27
+ import rospkg
28
+
26
29
import argparse
27
30
28
31
from catmux .session import Session as CatmuxSession
@@ -41,7 +44,7 @@ def safe_call(cmd_list):
41
44
def parse_arguments (debug = False ):
42
45
"""Parse command line arguments"""
43
46
parser = argparse .ArgumentParser (description = 'Create a new catmux session' )
44
- parser .add_argument ('session_config' , metavar = 'config' ,
47
+ parser .add_argument ('session_config' ,
45
48
help = "Session configuration. Should be a yaml-file." )
46
49
parser .add_argument ('-n' , '--session_name' , default = 'catmux' ,
47
50
help = "Name used for the tmux session" )
@@ -60,12 +63,28 @@ def parse_arguments(debug=False):
60
63
return args
61
64
62
65
66
+ def resolve_path (path_string ):
67
+ """Resolves a package:// path string"""
68
+ if path_string .find ('package://' ) >= 0 :
69
+ rospack = rospkg .RosPack ()
70
+ relevant_path = path_string .split ('://' )[1 ]
71
+ split_path = relevant_path .split ('/' , 1 )
72
+ try :
73
+ package_path = rospack .get_path (split_path [0 ])
74
+ except rospkg .ResourceNotFound :
75
+ print ('ERROR: Package with name "{}" could not be found' .
76
+ format (split_path [0 ]))
77
+ sys .exit (1 )
78
+ path_string = os .path .join (package_path , split_path [1 ])
79
+ return path_string
80
+
63
81
def main ():
64
82
"""Creates a new tmux session if it does not yet exist"""
65
83
args = parse_arguments ()
66
84
85
+
67
86
session_config = CatmuxSession (args .overwrite )
68
- session_config .init_from_filepath (args .session_config )
87
+ session_config .init_from_filepath (resolve_path ( args .session_config ) )
69
88
70
89
try :
71
90
subprocess .check_call (['tmux' , 'has-session' , '-t' , args .session_name ])
@@ -79,7 +98,7 @@ def main():
79
98
80
99
command = ['tmux' ]
81
100
if args .tmux_config :
82
- command += ['-f' , args .tmux_config ]
101
+ command += ['-f' , resolve_path ( args .tmux_config ) ]
83
102
command += ['new-session' , '-s' , args .session_name ]
84
103
command .append ('-d' )
85
104
if not safe_call (command ):
0 commit comments