Skip to content

Commit d6aa1d3

Browse files
committed
resolve package:// path strings
This fixes fmauch#1
1 parent 6dbfe32 commit d6aa1d3

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

script/create_session

+22-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@
2020
# -- END LICENSE BLOCK ------------------------------------------------
2121

2222
from __future__ import print_function
23+
import os
2324
import subprocess
2425
import sys
2526

27+
import rospkg
28+
2629
import argparse
2730

2831
from catmux.session import Session as CatmuxSession
@@ -41,7 +44,7 @@ def safe_call(cmd_list):
4144
def parse_arguments(debug=False):
4245
"""Parse command line arguments"""
4346
parser = argparse.ArgumentParser(description='Create a new catmux session')
44-
parser.add_argument('session_config', metavar='config',
47+
parser.add_argument('session_config',
4548
help="Session configuration. Should be a yaml-file.")
4649
parser.add_argument('-n', '--session_name', default='catmux',
4750
help="Name used for the tmux session")
@@ -60,12 +63,28 @@ def parse_arguments(debug=False):
6063
return args
6164

6265

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+
6381
def main():
6482
"""Creates a new tmux session if it does not yet exist"""
6583
args = parse_arguments()
6684

85+
6786
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))
6988

7089
try:
7190
subprocess.check_call(['tmux', 'has-session', '-t', args.session_name])
@@ -79,7 +98,7 @@ def main():
7998

8099
command = ['tmux']
81100
if args.tmux_config:
82-
command += ['-f', args.tmux_config]
101+
command += ['-f', resolve_path(args.tmux_config)]
83102
command += ['new-session', '-s', args.session_name]
84103
command.append('-d')
85104
if not safe_call(command):

0 commit comments

Comments
 (0)