<s> """<STR_LIT>""" <EOL> RELOADER = '<STR_LIT>' <EOL> import imp , sys <EOL> if RELOADER in sys . modules : <EOL> imp . reload ( sys . modules [ RELOADER ] ) <EOL> __import__ ( RELOADER ) <EOL> import os <EOL> from sublime import error_message , load_settings , message_dialog <EOL> from sublime_plugin import TextCommand <EOL> from scold import git <EOL> from scold . system import mailto <EOL> from scold . util import discrete_ranges <EOL> class Scold ( TextCommand ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( Scold , self ) . __init__ ( * args , ** kwargs ) <EOL> self . _settings = load_settings ( '<STR_LIT>' ) <EOL> def run ( self , edit ) : <EOL> if not self . view . file_name ( ) : <EOL> message_dialog ( "<STR_LIT>" ) <EOL> return <EOL> numbered_lines = self . _get_selected_lines ( ) <EOL> authors = self . _retrieve_authors ( numbered_lines ) <EOL> if not authors : <EOL> error_message ( "<STR_LIT>" ) <EOL> return <EOL> recipients = '<STR_LIT>' . join ( authors ) <EOL> subject = self . _format_mail_subject ( numbered_lines ) <EOL> body = self . _compose_mail_body ( numbered_lines ) <EOL> mailto ( recipients , subject = subject , body = body ) <EOL> def _get_selected_lines ( self ) : <EOL> """<STR_LIT>""" <EOL> numbered_lines = [ ] <EOL> line_indices = set ( ) <EOL> for region in self . view . sel ( ) : <EOL> lines = self . view . lines ( region ) <EOL> for line in lines : <EOL> index , _ = self . view . rowcol ( line . begin ( ) ) <EOL> if index not in line_indices : <EOL> line_indices . add ( index ) <EOL> numbered_lines . append ( ( index + <NUM_LIT:1> , line ) ) <EOL> return numbered_lines <EOL> def _retrieve_authors ( self , numbered_lines ) : <EOL> """<STR_LIT>""" <EOL> filename = self . view . file_name ( ) <EOL> line_number_ranges = discrete_ranges ( nr for ( nr , _ ) in numbered_lines ) <EOL> authors = set ( ) <EOL> for line_range in line_number_ranges : <EOL> blamed_lines = git . blame ( filename , lines = line_range ) <EOL> for line in blamed_lines : <EOL> author_email = line [ '<STR_LIT>' ] <EOL> if author_email != git . NO_AUTHOR_EMAIL : <EOL> authors . add ( author_email ) <EOL> return authors <EOL> def _format_mail_subject ( self , numbered_lines ) : <EOL> """<STR_LIT>""" <EOL> template = self . _get_template ( '<STR_LIT>' ) <EOL> if not template : <EOL> return "<STR_LIT>" <EOL> _ , first_line = numbered_lines [ <NUM_LIT:0> ] <EOL> return template . strip ( ) . format ( line = first_line ) <EOL> def _compose_mail_body ( self , numbered_lines ) : <EOL> """<STR_LIT>""" <EOL> template = self . _get_template ( '<STR_LIT:body>' ) <EOL> if not template : <EOL> return "<STR_LIT>" <EOL> lines = [ self . view . substr ( region ) for ( _ , region ) in numbered_lines ] <EOL> overdue = len ( lines ) - self . _max_lines_count <EOL> if overdue > <NUM_LIT:0> : <EOL> ellipsis_text = "<STR_LIT>" % overdue <EOL> lines [ self . _max_lines_count : ] = [ ellipsis_text ] <EOL> return template . strip ( ) . format ( code = os . linesep . join ( lines ) ) <EOL> def _get_template ( self , kind ) : <EOL> """<STR_LIT>""" <EOL> template = self . _settings . get ( '<STR_LIT>' % kind ) <EOL> if isinstance ( template , list ) : <EOL> template = os . linesep . join ( template ) <EOL> return template <EOL> @ property <EOL> def _max_lines_count ( self ) : <EOL> return self . _settings . get ( '<STR_LIT>' ) or <NUM_LIT:10> </s>
