|
17 | 17 | # https://github.com/aziz/tmuxinator |
18 | 18 |
|
19 | 19 |
|
| 20 | +def tmuxinator_to_tmuxp(sconf): |
| 21 | + ''' |
| 22 | +
|
| 23 | + :param sconf: python dict for session configuration |
| 24 | + :type sconf: dict |
| 25 | + ''' |
| 26 | + |
| 27 | + tmuxp_config = {} |
| 28 | + |
| 29 | + tmuxp_config['session_name'] = None |
| 30 | + |
| 31 | + tmuxp_config['windows'] = [] |
| 32 | + for w in sconf['windows']: |
| 33 | + for k, v in w.items(): |
| 34 | + |
| 35 | + windowdict = {} |
| 36 | + |
| 37 | + windowdict['window_name'] = k |
| 38 | + if 'panes' in v: |
| 39 | + windowdict['panes'] = v['panes'] |
| 40 | + if isinstance(v, basestring): |
| 41 | + windowdict['panes'] = [v] |
| 42 | + if 'layout' in v: |
| 43 | + windowdict['layout'] = v['layout'] |
| 44 | + tmuxp_config['windows'].append(windowdict) |
| 45 | + |
| 46 | + return tmuxp_config |
| 47 | + |
| 48 | + |
20 | 49 | class TmuxinatorTest(unittest.TestCase): |
21 | 50 |
|
22 | 51 | tmuxinator_yaml = """\ |
@@ -50,12 +79,39 @@ class TmuxinatorTest(unittest.TestCase): |
50 | 79 | ] |
51 | 80 | } |
52 | 81 |
|
| 82 | + tmuxp_dict = { |
| 83 | + 'session_name': None, |
| 84 | + 'windows': [ |
| 85 | + { |
| 86 | + 'window_name': 'editor', |
| 87 | + 'layout': 'main-vertical', |
| 88 | + 'panes': [ |
| 89 | + 'vim', |
| 90 | + 'guard' |
| 91 | + ] |
| 92 | + }, |
| 93 | + { |
| 94 | + 'window_name': 'server', |
| 95 | + 'panes': [ |
| 96 | + 'bundle exec rails s' |
| 97 | + ] |
| 98 | + }, |
| 99 | + { |
| 100 | + 'window_name': 'logs', |
| 101 | + 'panes': [ |
| 102 | + 'tail -f logs/development.log' |
| 103 | + ] |
| 104 | + } |
| 105 | + ] |
| 106 | + } |
| 107 | + |
53 | 108 | def test_config_to_dict(self): |
54 | 109 | configparser = kaptan.Kaptan(handler='yaml') |
55 | 110 | test_config = configparser.import_config(self.tmuxinator_yaml) |
56 | 111 | yaml_to_dict = test_config.get() |
57 | 112 | self.assertDictEqual(yaml_to_dict, self.tmuxinator_dict) |
58 | 113 |
|
| 114 | + self.assertEqual(tmuxinator_to_tmuxp(yaml_to_dict), self.tmuxp_dict) |
59 | 115 |
|
60 | 116 | class TmuxinatorDeprecationsTest(unittest.TestCase): |
61 | 117 |
|
|
0 commit comments