#NEWLINE# @ authenticated #NEWLINE# def get( self ) : #NEWLINE# #INDENT# query = unquote ( self . get_argument ( 'q' , '' ) ) #NEWLINE# if ( query == '' ) : #NEWLINE# #INDENT# self . redirect ( '/' ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# results = str ( grep ( '-R' , '--exclude-dir' , '.git' , query , self . settings . repo ) ) #NEWLINE# #UNINDENT# except ErrorReturnCode_1 as e : #NEWLINE# #INDENT# results = '' #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# results += str ( find ( self . settings . repo , '-type' , 'f' , '-name' , ( ( '*' + query ) + '*' ) , '-not' , '(' , '-path' , ( '%s/%s/*' % ( self . settings . repo , '.git' ) ) ) ) #NEWLINE# #UNINDENT# except ErrorReturnCode_1 as e : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# results = results . replace ( self . settings . repo , '' ) . split ( '\n' ) [ : ( - 1 ) ] #NEWLINE# formatted_results = [ ] #NEWLINE# for result in results : #NEWLINE# #INDENT# if ( ( 'Binary file' in result ) or ( result == '' ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# stuff = result . split ( ':' ) #NEWLINE# filename = stuff [ 0 ] #NEWLINE# if path . basename ( filename ) . startswith ( '.' ) : #NEWLINE# #INDENT# filename = path . join ( path . dirname ( filename ) , path . basename ( filename ) [ 1 : ] ) #NEWLINE# #UNINDENT# string = '' . join ( stuff [ 1 : ] ) #NEWLINE# string = self . highlight ( string , query ) #NEWLINE# formatted_results . append ( { #NEWLINE# #INDENT# 'filename' : filename , #NEWLINE# 'string' : string , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# self . render ( 'search.html' , query = query , results = formatted_results )