#NEWLINE# def command_freeze( args ) : #NEWLINE# #INDENT# 'Import teamocil config to tmuxp format.' #NEWLINE# ctext = ' ' . join ( args . session_name ) #NEWLINE# t = Server ( socket_name = args . socket_name , socket_path = args . socket_path , colors = args . colors ) #NEWLINE# try : #NEWLINE# #INDENT# session = t . findWhere ( { #NEWLINE# #INDENT# 'session_name' : ctext , #NEWLINE# #UNINDENT# } ) #NEWLINE# if ( not session ) : #NEWLINE# #INDENT# raise exc . TmuxpException ( 'Session not found.' ) #NEWLINE# #UNINDENT# #UNINDENT# except exc . TmuxpException as e : #NEWLINE# #INDENT# print ( e ) #NEWLINE# return #NEWLINE# #UNINDENT# sconf = freeze ( session ) #NEWLINE# configparser = kaptan . Kaptan ( ) #NEWLINE# newconfig = config . inline ( sconf ) #NEWLINE# configparser . import_config ( newconfig ) #NEWLINE# config_format = prompt_choices ( 'Convert to' , choices = [ 'yaml' , 'json' ] , default = 'yaml' ) #NEWLINE# if ( config_format == 'yaml' ) : #NEWLINE# #INDENT# newconfig = configparser . export ( 'yaml' , indent = 2 , default_flow_style = False , safe = True ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( config_format == 'json' ) : #NEWLINE# #INDENT# newconfig = configparser . export ( 'json' , indent = 2 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# sys . exit ( 'Unknown config format.' ) #NEWLINE# #UNINDENT# #UNINDENT# print ( newconfig ) #NEWLINE# print ( '---------------------------------------------------------------' ) #NEWLINE# print ( 'Configuration import does its best to convert teamocil files.\n' ) #NEWLINE# if ( args . answer_yes or prompt_yes_no ( 'The new config *WILL* require adjusting afterwards. Save config?' ) ) : #NEWLINE# #INDENT# dest = None #NEWLINE# while ( not dest ) : #NEWLINE# #INDENT# save_to = os . path . abspath ( os . path . join ( config_dir , ( '%s.%s' % ( sconf . get ( 'session_name' ) , config_format ) ) ) ) #NEWLINE# dest_prompt = prompt ( 'Save to: ' , save_to ) #NEWLINE# if os . path . exists ( dest_prompt ) : #NEWLINE# #INDENT# print ( ( '%s exists. Pick a new filename.' % dest_prompt ) ) #NEWLINE# continue #NEWLINE# #UNINDENT# dest = dest_prompt #NEWLINE# #UNINDENT# dest = os . path . abspath ( os . path . relpath ( os . path . expanduser ( dest ) ) ) #NEWLINE# if ( args . answer_yes or prompt_yes_no ( ( 'Save to %s?' % dest ) ) ) : #NEWLINE# #INDENT# destdir = os . path . dirname ( dest ) #NEWLINE# if ( not os . path . isdir ( destdir ) ) : #NEWLINE# #INDENT# os . makedirs ( destdir ) #NEWLINE# #UNINDENT# buf = open ( dest , 'w' ) #NEWLINE# buf . write ( newconfig ) #NEWLINE# buf . close ( ) #NEWLINE# print ( ( 'Saved to %s.' % dest ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# print ( 'tmuxp has examples in JSON and YAML format at <http://tmuxp.readthedocs.org/en/latest/examples.html>\nView tmuxp docs at <http://tmuxp.readthedocs.org/>.' ) #NEWLINE# sys . exit ( )