<s> import sys <EOL> from os import getcwd <EOL> from argparse import ArgumentParser <EOL> from textwrap import dedent <EOL> from git import Repo , InvalidGitRepositoryError <EOL> from gitsweep . inspector import Inspector <EOL> from gitsweep . deleter import Deleter <EOL> class CommandLine ( object ) : <EOL> """<STR_LIT>""" <EOL> parser = ArgumentParser ( <EOL> description = '<STR_LIT>' , <EOL> usage = '<STR_LIT>' , <EOL> ) <EOL> _sub_parsers = parser . add_subparsers ( title = '<STR_LIT:action>' , <EOL> description = '<STR_LIT>' ) <EOL> _origin_kwargs = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:default>' : '<STR_LIT>' } <EOL> _master_kwargs = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:default>' : '<STR_LIT>' } <EOL> _skip_kwargs = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:default>' : '<STR_LIT>' } <EOL> _no_fetch_kwargs = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:action>' : '<STR_LIT>' , <EOL> '<STR_LIT:default>' : True } <EOL> _preview_usage = dedent ( '''<STR_LIT>''' . strip ( ) ) <EOL> _preview = _sub_parsers . add_parser ( '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> usage = _preview_usage ) <EOL> _preview . add_argument ( '<STR_LIT>' , ** _origin_kwargs ) <EOL> _preview . add_argument ( '<STR_LIT>' , ** _master_kwargs ) <EOL> _preview . add_argument ( '<STR_LIT>' , ** _no_fetch_kwargs ) <EOL> _preview . add_argument ( '<STR_LIT>' , ** _skip_kwargs ) <EOL> _preview . set_defaults ( action = '<STR_LIT>' ) <EOL> _cleanup_usage = dedent ( '''<STR_LIT>''' . strip ( ) ) <EOL> _cleanup = _sub_parsers . add_parser ( '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> usage = _cleanup_usage ) <EOL> _cleanup . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = False , <EOL> dest = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> _cleanup . add_argument ( '<STR_LIT>' , ** _origin_kwargs ) <EOL> _cleanup . add_argument ( '<STR_LIT>' , ** _master_kwargs ) <EOL> _cleanup . add_argument ( '<STR_LIT>' , ** _no_fetch_kwargs ) <EOL> _cleanup . add_argument ( '<STR_LIT>' , ** _skip_kwargs ) <EOL> _cleanup . set_defaults ( action = '<STR_LIT>' ) <EOL> def __init__ ( self , args ) : <EOL> self . args = args [ <NUM_LIT:1> : ] <EOL> def run ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> if not self . args : <EOL> self . parser . print_help ( ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> self . _sweep ( ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> except InvalidGitRepositoryError : <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> except Exception as e : <EOL> sys . stdout . write ( str ( e ) + '<STR_LIT:\n>' ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> def _sweep ( self ) : <EOL> """<STR_LIT>""" <EOL> args = self . parser . parse_args ( self . args ) <EOL> dry_run = True if args . action == '<STR_LIT>' else False <EOL> fetch = args . fetch <EOL> skips = [ i . strip ( ) for i in args . skips . split ( '<STR_LIT:U+002C>' ) ] <EOL> repo = Repo ( getcwd ( ) ) <EOL> remote_name = args . origin <EOL> if fetch : <EOL> for remote in repo . remotes : <EOL> if remote . name == remote_name : <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> remote . fetch ( ) <EOL> master_branch = args . master <EOL> inspector = Inspector ( repo , remote_name = remote_name , <EOL> master_branch = master_branch ) <EOL> ok_to_delete = inspector . merged_refs ( skip = skips ) <EOL> if ok_to_delete : <EOL> sys . stdout . write ( <EOL> '<STR_LIT>' . format ( <EOL> master_branch ) ) <EOL> else : <EOL> sys . stdout . write ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> for ref in ok_to_delete : <EOL> sys . stdout . write ( '<STR_LIT>' . format ( ref . remote_head ) ) <EOL> if not dry_run : <EOL> deleter = Deleter ( repo , remote_name = remote_name , <EOL> master_branch = master_branch ) <EOL> if not args . force : <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> answer = raw_input ( ) <EOL> if args . force or answer . lower ( ) . startswith ( '<STR_LIT:y>' ) : <EOL> sys . stdout . write ( '<STR_LIT:\n>' ) <EOL> for ref in ok_to_delete : <EOL> sys . stdout . write ( '<STR_LIT>' . format ( ref . remote_head ) ) <EOL> deleter . remove_remote_refs ( [ ref ] ) <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> sys . stdout . write ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> else : <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> elif ok_to_delete : <EOL> sysv_copy = self . args [ : ] <EOL> sysv_copy [ <NUM_LIT:0> ] = '<STR_LIT>' <EOL> command = '<STR_LIT>' . format ( '<STR_LIT:U+0020>' . join ( sysv_copy ) ) <EOL> sys . stdout . write ( <EOL> '<STR_LIT>' . format ( command ) ) </s>
