<s> import subprocess <EOL> import re <EOL> import util <EOL> import log <EOL> import config <EOL> LOG = log . get_logger ( ) <EOL> CMD_LIST_SESSIONS = config . CMD_SEP . join ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> CMD_LIST_PANES = config . CMD_SEP . join ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> CMD_CREATE_SESSION = config . CMD_SEP . join ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> CMD_KILL_SESSION = config . CMD_SEP . join ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> CMD_CAPTURE_PANE = config . CMD_SEP . join ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> CMD_SHOW_OPTION = config . CMD_SEP . join ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:%s>' ] ) <EOL> CMD_HAS_SESSION = config . CMD_SEP . join ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> CMD_SET_PANE_PATH = config . CMD_SEP . join ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> CMD_CLEAR_PANE = config . CMD_SEP . join ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> CMD_LIST_WINDOWS = config . CMD_SEP . join ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> CMD_MOVE_WINDOW = config . CMD_SEP . join ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> CMD_RENAME_WINDOW = config . CMD_SEP . join ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:%s>' ] ) <EOL> CMD_NEW_EMPTY_WINDOW = config . CMD_SEP . join ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> CMD_ACTIVE_WINDOW = config . CMD_SEP . join ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> CMD_SPLIT_WINDOW = config . CMD_SEP . join ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> CMD_SET_LAYOUT = config . CMD_SEP . join ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:%s>' ] ) <EOL> CMD_LOAD_CONTENT = config . CMD_SEP . join ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def has_tmux_server ( ) : <EOL> """<STR_LIT>""" <EOL> cmd = CMD_LIST_SESSIONS . split ( config . CMD_SEP ) <EOL> code = util . cmd_return_code ( cmd ) <EOL> return code == <NUM_LIT:0> <EOL> def get_sessions ( ) : <EOL> """<STR_LIT>""" <EOL> cmd = CMD_LIST_SESSIONS . split ( config . CMD_SEP ) <EOL> s = util . exec_cmd ( cmd ) <EOL> return s . split ( '<STR_LIT:\n>' ) <EOL> def get_windows_from_session ( sess_name ) : <EOL> """<STR_LIT>""" <EOL> cmd = ( CMD_LIST_WINDOWS % sess_name ) . split ( config . CMD_SEP ) <EOL> s = util . exec_cmd ( cmd ) <EOL> return s . split ( '<STR_LIT:\n>' ) <EOL> def get_panes_from_sess_win ( sess_name , win_idx ) : <EOL> """<STR_LIT>""" <EOL> p = ( sess_name , win_idx ) <EOL> cmd = ( CMD_LIST_PANES % p ) . split ( config . CMD_SEP ) <EOL> s = util . exec_cmd ( cmd ) <EOL> return s . split ( '<STR_LIT:\n>' ) <EOL> def set_pane_path ( pane_idstr , path ) : <EOL> """<STR_LIT>""" <EOL> cmd = ( CMD_SET_PANE_PATH % ( pane_idstr , path ) ) . split ( config . CMD_SEP ) <EOL> util . exec_cmd ( cmd ) <EOL> cmd = ( CMD_CLEAR_PANE % ( pane_idstr ) ) . split ( config . CMD_SEP ) <EOL> util . exec_cmd ( cmd ) <EOL> def capture_pane ( pane_idstr , filename ) : <EOL> """<STR_LIT>""" <EOL> p = ( '<STR_LIT:e>' if config . CNT_WITH_ESC else '<STR_LIT>' , pane_idstr ) <EOL> cmd = ( CMD_CAPTURE_PANE % p ) . split ( config . CMD_SEP ) <EOL> util . exec_cmd_redir ( cmd , filename ) <EOL> def create_session ( sess_name , size ) : <EOL> p = ( sess_name , size [ <NUM_LIT:0> ] , size [ <NUM_LIT:1> ] ) <EOL> cmd = ( CMD_CREATE_SESSION % p ) . split ( config . CMD_SEP ) <EOL> s = util . exec_cmd ( cmd ) <EOL> def create_empty_window ( sess_name , base_index ) : <EOL> p = ( sess_name , int ( base_index ) ) <EOL> cmd = ( CMD_NEW_EMPTY_WINDOW % p ) . split ( config . CMD_SEP ) <EOL> util . exec_cmd ( cmd ) <EOL> def split_window ( sess_name , win_id , pane_min_id ) : <EOL> p = ( sess_name , int ( win_id ) , int ( pane_min_id ) ) <EOL> cmd = ( CMD_SPLIT_WINDOW % p ) . split ( config . CMD_SEP ) <EOL> util . exec_cmd ( cmd ) <EOL> def active_window ( sess_name , win_id ) : <EOL> p = ( sess_name , win_id ) <EOL> cmd = ( CMD_ACTIVE_WINDOW % p ) . split ( config . CMD_SEP ) <EOL> util . exec_cmd ( cmd ) <EOL> def select_layout ( sess_name , win_id , layout ) : <EOL> p = ( sess_name , win_id , layout ) <EOL> cmd = ( CMD_SET_LAYOUT % p ) . split ( config . CMD_SEP ) <EOL> util . exec_cmd ( cmd ) <EOL> def rename_window ( sess_name , win_id , name ) : <EOL> """<STR_LIT>""" <EOL> p = ( sess_name , win_id , name ) <EOL> cmd = ( CMD_RENAME_WINDOW % p ) . split ( config . CMD_SEP ) <EOL> util . exec_cmd ( cmd ) <EOL> def renumber_window ( sess_name , win_id_from , win_id_to ) : <EOL> """<STR_LIT>""" <EOL> p = ( sess_name + '<STR_LIT::>' + str ( win_id_from ) , sess_name + '<STR_LIT::>' + str ( win_id_to ) ) <EOL> cmd = ( CMD_MOVE_WINDOW % p ) . split ( config . CMD_SEP ) <EOL> util . exec_cmd ( cmd ) <EOL> def get_option ( option ) : <EOL> """<STR_LIT>""" <EOL> cmd = ( CMD_SHOW_OPTION % option ) . split ( config . CMD_SEP ) <EOL> return util . exec_cmd ( cmd ) <EOL> def has_session ( sess_name ) : <EOL> """<STR_LIT>""" <EOL> cmd = ( CMD_HAS_SESSION % sess_name ) . split ( config . CMD_SEP ) <EOL> return util . cmd_return_code ( cmd ) == <NUM_LIT:0> <EOL> def kill_session ( sess_name ) : <EOL> """<STR_LIT>""" <EOL> cmd = ( CMD_KILL_SESSION % sess_name ) . split ( config . CMD_SEP ) <EOL> return util . cmd_return_code ( cmd ) == <NUM_LIT:0> <EOL> def restore_pane_content ( pane_idstr , filename ) : <EOL> """<STR_LIT>""" <EOL> filename = '<STR_LIT:">' + filename + '<STR_LIT:">' <EOL> cmd = ( CMD_LOAD_CONTENT % ( pane_idstr , filename ) ) . split ( config . CMD_SEP ) <EOL> util . exec_cmd ( cmd ) </s>
