<s> import sys , os <EOL> import argparse <EOL> import argcomplete <EOL> import textwrap <EOL> class Base ( object ) : <EOL> always_complete_options = True <EOL> def __init__ ( self , args ) : <EOL> self . inputs = args <EOL> @ classmethod <EOL> def _get_description ( klass ) : <EOL> return klass . __doc__ . split ( "<STR_LIT>" ) [ <NUM_LIT:0> ] <EOL> @ classmethod <EOL> def _get_epilog ( klass ) : <EOL> return "<STR_LIT>" . join ( klass . __doc__ . split ( "<STR_LIT>" ) [ <NUM_LIT:1> : ] ) <EOL> def prep_parser ( self ) : <EOL> prog = None <EOL> if self . inputs : <EOL> prog = self . inputs [ <NUM_LIT:0> ] <EOL> epilog = textwrap . dedent ( self . _get_epilog ( ) ) <EOL> description = self . _get_description ( ) <EOL> self . parser = argparse . ArgumentParser ( prog = prog , <EOL> description = description <EOL> , epilog = epilog <EOL> , formatter_class = argparse . RawDescriptionHelpFormatter ) <EOL> def configure_parser ( self , parser ) : <EOL> pass <EOL> def prolog ( self ) : <EOL> pass <EOL> def get_described_parser ( self ) : <EOL> self . prep_parser ( ) <EOL> self . configure_parser ( self . parser ) <EOL> return self . parser <EOL> def epilog ( self ) : <EOL> pass <EOL> def __call__ ( self ) : <EOL> self . prep_parser ( ) <EOL> self . configure_parser ( self . parser ) <EOL> argcomplete . autocomplete ( self . parser , always_complete_options = self . always_complete_options ) ; <EOL> self . args = self . parser . parse_args ( self . inputs ) <EOL> self . prolog ( ) <EOL> self . run ( self . args ) <EOL> self . epilog ( ) <EOL> def run ( self , args ) : <EOL> print self . inputs <EOL> print args <EOL> from openaps import config <EOL> class ConfigApp ( Base ) : <EOL> def read_config ( self ) : <EOL> cfg_file = os . environ . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if not os . path . exists ( cfg_file ) : <EOL> print "<STR_LIT>" <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> pwd = os . getcwd ( ) <EOL> cfg_dir = os . path . dirname ( cfg_file ) <EOL> if cfg_dir and os . getcwd ( ) != cfg_dir : <EOL> os . chdir ( os . path . dirname ( cfg_file ) ) <EOL> self . config = config . Config . Read ( cfg_file ) <EOL> def prolog ( self ) : <EOL> self . read_config ( ) <EOL> def epilog ( self ) : <EOL> self . create_git_commit ( ) <EOL> def git_repo ( self ) : <EOL> from git import Repo , GitCmdObjectDB <EOL> self . repo = getattr ( self , '<STR_LIT>' , Repo ( os . getcwd ( ) , odbt = GitCmdObjectDB ) ) <EOL> return self . repo <EOL> def create_git_commit ( self ) : <EOL> self . git_repo ( ) <EOL> if self . repo . is_dirty ( ) or self . repo . index . diff ( None ) : <EOL> diffs = self . repo . index . diff ( None ) <EOL> for diff in diffs : <EOL> self . repo . git . add ( [ diff . b_path ] , write_extension_data = False ) <EOL> git = self . repo . git <EOL> msg = """<STR_LIT>""" . format ( self . parser . prog , '<STR_LIT:U+0020>' . join ( sys . argv [ <NUM_LIT:1> : ] ) , '<STR_LIT:U+0020>' . join ( sys . argv ) ) <EOL> self . repo . index . commit ( msg ) <EOL> self . repo . git . gc ( auto = True ) </s>
