<s> import yaml <EOL> import argparse <EOL> import os <EOL> import sys <EOL> from . import __version__ <EOL> from . logger import Logger <EOL> from . git import Git <EOL> from . tmux import TmuxException <EOL> from . workspace import Workspace , WorkspaceException <EOL> WORKSPACE_COMMANDS = [ '<STR_LIT>' , '<STR_LIT:start>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> GIT_COMMANDS = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:status>' ] <EOL> def main ( ) : <EOL> """<STR_LIT>""" <EOL> parser = argparse . ArgumentParser ( <EOL> description = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT:action>' , type = str , nargs = '<STR_LIT:?>' , default = '<STR_LIT:start>' , <EOL> choices = WORKSPACE_COMMANDS + GIT_COMMANDS , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , type = str , nargs = '<STR_LIT:?>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT:-c>' , '<STR_LIT>' , type = str , default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:version>' , <EOL> version = '<STR_LIT>' . format ( __version__ ) ) <EOL> args = parser . parse_args ( ) <EOL> cache_dir = os . environ . get ( '<STR_LIT>' , <EOL> os . path . join ( os . environ . get ( '<STR_LIT>' ) , '<STR_LIT>' ) ) <EOL> pool_dir = os . path . join ( cache_dir , '<STR_LIT>' ) <EOL> if args . session : <EOL> cfg_path = os . path . join ( pool_dir , '<STR_LIT>' . format ( args . session ) ) <EOL> else : <EOL> cfg_path = os . path . realpath ( args . config ) <EOL> log = Logger ( ) <EOL> if not os . path . isfile ( cfg_path ) : <EOL> if args . action == '<STR_LIT>' : <EOL> schema = Workspace . initialize ( os . getcwd ( ) ) <EOL> with open ( cfg_path , '<STR_LIT:w>' ) as cfg_file : <EOL> cfg_file . write ( <EOL> yaml . safe_dump ( schema , default_flow_style = False ) ) <EOL> args . action = '<STR_LIT:status>' <EOL> else : <EOL> log . echo ( '<STR_LIT>' <EOL> . format ( cfg_path ) ) <EOL> sys . exit ( <NUM_LIT:2> ) <EOL> try : <EOL> with open ( cfg_path , '<STR_LIT:r>' ) as stream : <EOL> config = yaml . load ( stream ) <EOL> run ( config , args . action ) <EOL> if not os . path . isdir ( pool_dir ) : <EOL> os . makedirs ( pool_dir ) <EOL> link = os . path . join ( pool_dir , '<STR_LIT>' . format ( config . get ( '<STR_LIT:name>' ) ) ) <EOL> if not os . path . isfile ( link ) : <EOL> os . symlink ( cfg_path , link ) <EOL> except ( WorkspaceException , TmuxException ) as e : <EOL> if hasattr ( e , '<STR_LIT>' ) and e . __context__ : <EOL> log . echo ( '<STR_LIT>' . format ( e . __context__ ) ) <EOL> if hasattr ( e , '<STR_LIT>' ) : <EOL> log . echo ( '<STR_LIT>' . format ( e . message , e . errors ) ) <EOL> else : <EOL> log . echo ( '<STR_LIT>' . format ( str ( e ) ) ) <EOL> sys . exit ( <NUM_LIT:3> ) <EOL> def run ( config , action ) : <EOL> """<STR_LIT>""" <EOL> if action in WORKSPACE_COMMANDS : <EOL> workspace = Workspace ( config ) <EOL> getattr ( workspace , action ) ( ) <EOL> elif action in GIT_COMMANDS : <EOL> git = Git ( config ) <EOL> getattr ( git , action ) ( ) </s>
