#NEWLINE# def command_import_tmuxinator( args ) : #NEWLINE# #INDENT# 'Import tmuxinator config to tmuxp format.' #NEWLINE# if args . list : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# configs_in_user = config . in_dir ( tmuxinator_config_dir , extensions = 'yml' ) #NEWLINE# #UNINDENT# except OSError : #NEWLINE# #INDENT# configs_in_user = [ ] #NEWLINE# #UNINDENT# configs_in_cwd = config . in_dir ( config_dir = cwd_dir , extensions = 'yml' ) #NEWLINE# output = '' #NEWLINE# if ( not os . path . exists ( tmuxinator_config_dir ) ) : #NEWLINE# #INDENT# output += ( "# %s: \n\tDirectory doesn't exist.\n" % tmuxinator_config_dir ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not configs_in_user ) : #NEWLINE# #INDENT# output += ( '# %s: \n\tNone found.\n' % tmuxinator_config_dir ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# output += ( '# %s: \n\t%s\n' % ( config_dir , ', ' . join ( configs_in_user ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# if configs_in_cwd : #NEWLINE# #INDENT# output += ( '# current directory:\n\t%s' % ', ' . join ( configs_in_cwd ) ) #NEWLINE# #UNINDENT# print ( output ) #NEWLINE# #UNINDENT# if args . config : #NEWLINE# #INDENT# configfile = os . path . abspath ( os . path . relpath ( os . path . expanduser ( args . config ) ) ) #NEWLINE# configparser = kaptan . Kaptan ( handler = 'yaml' ) #NEWLINE# if os . path . exists ( configfile ) : #NEWLINE# #INDENT# print ( configfile ) #NEWLINE# configparser . import_config ( configfile ) #NEWLINE# newconfig = config . import_tmuxinator ( configparser . get ( ) ) #NEWLINE# configparser . import_config ( newconfig ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# sys . exit ( ( 'File not found: %s' % configfile ) ) #NEWLINE# #UNINDENT# 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 ) #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 tmuxinator 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# dest_prompt = prompt ( 'Save to: ' , os . path . abspath ( os . path . join ( config_dir , ( 'myimport.%s' % config_format ) ) ) ) #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# buf = open ( args , '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 ( )