<s> """<STR_LIT>""" <EOL> import sys <EOL> import os . path <EOL> import platform <EOL> import subprocess <EOL> from distutils . version import LooseVersion <EOL> import pkg_resources <EOL> import acmd <EOL> DEFAULT_COMPLETION_DIR = '<STR_LIT>' <EOL> HOMEBREW_COMPLETION_DIR = '<STR_LIT>' <EOL> def get_current_version ( ) : <EOL> """<STR_LIT>""" <EOL> return LooseVersion ( acmd . __version__ ) <EOL> def setup_rcfile ( rcfilename ) : <EOL> """<STR_LIT>""" <EOL> template = _read_config_template ( ) <EOL> if os . path . isfile ( rcfilename ) : <EOL> acmd . warning ( "<STR_LIT>" . format ( rcfilename ) ) <EOL> target = open ( rcfilename , '<STR_LIT:wb>' ) <EOL> target . write ( template ) <EOL> def _read_config_template ( ) : <EOL> return pkg_resources . resource_string ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> def deploy_bash_completion ( paths = None ) : <EOL> """<STR_LIT>""" <EOL> path = _locate_bash_completion_dir ( paths ) <EOL> if path is not None : <EOL> acmd . log ( "<STR_LIT>" . format ( path ) ) <EOL> install_script ( path ) <EOL> return path <EOL> else : <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> def _locate_bash_completion_dir ( paths = None ) : <EOL> """<STR_LIT>""" <EOL> if paths is None : <EOL> paths = [ DEFAULT_COMPLETION_DIR , HOMEBREW_COMPLETION_DIR ] <EOL> for path in paths : <EOL> if os . path . exists ( path ) and os . path . isdir ( path ) : <EOL> return path <EOL> return None <EOL> def install_script ( path ) : <EOL> """<STR_LIT>""" <EOL> template = pkg_resources . resource_string ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> target_path = os . path . join ( path , '<STR_LIT>' ) <EOL> if os . path . isfile ( target_path ) : <EOL> acmd . warning ( "<STR_LIT>" . format ( target_path ) ) <EOL> with open ( target_path , '<STR_LIT:wb>' ) as target : <EOL> target . write ( template ) <EOL> if _get_bash_version ( ) < <NUM_LIT:4> : <EOL> acmd . warning ( "<STR_LIT>" ) <EOL> if _is_mac ( ) : <EOL> acmd . warning ( "<STR_LIT>" ) <EOL> def _get_bash_version ( ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> full_text = subprocess . check_output ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> first_line = full_text . split ( '<STR_LIT:\n>' ) [ <NUM_LIT:0> ] <EOL> version_string = first_line . lstrip ( "<STR_LIT>" ) <EOL> major = LooseVersion ( version_string ) . version [ <NUM_LIT:0> ] <EOL> return major <EOL> except Exception as e : <EOL> acmd . log ( "<STR_LIT>" + e . message ) <EOL> return <NUM_LIT:0> <EOL> def _is_mac ( ) : <EOL> """<STR_LIT>""" <EOL> return platform . system ( ) == '<STR_LIT>' </s>
