#NEWLINE# def __init__( self , server = None , palette = 'default' , keymap = 'default' , path = DEFAULT_CONFIG_PATH ) : #NEWLINE# #INDENT# self . path = os . path . expanduser ( path ) #NEWLINE# if ( not os . path . exists ( self . path ) ) : #NEWLINE# #INDENT# self . printSample ( ) #NEWLINE# exit ( 1 ) #NEWLINE# #UNINDENT# self . config = yaml . load ( open ( self . path ) ) #NEWLINE# schema = ConfigSchema ( ) . getSchema ( self . config ) #NEWLINE# schema ( self . config ) #NEWLINE# server = self . getServer ( server ) #NEWLINE# self . server = server #NEWLINE# url = server [ 'url' ] #NEWLINE# if ( not url . endswith ( '/' ) ) : #NEWLINE# #INDENT# url += '/' #NEWLINE# #UNINDENT# self . url = url #NEWLINE# result = urlparse . urlparse ( url ) #NEWLINE# self . hostname = result . netloc #NEWLINE# self . username = server [ 'username' ] #NEWLINE# self . password = server . get ( 'password' ) #NEWLINE# if ( self . password is None ) : #NEWLINE# #INDENT# self . password = getpass . getpass ( ( 'Password for %s (%s): ' % ( self . url , self . username ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# mode = ( os . stat ( self . path ) . st_mode & 511 ) #NEWLINE# if ( not ( mode == 384 ) ) : #NEWLINE# #INDENT# print ( "Error: Config file '{}' contains a password and does not have permissions set to 0600.\nPermissions are: {}" . format ( self . path , oct ( mode ) ) ) #NEWLINE# exit ( 1 ) #NEWLINE# #UNINDENT# #UNINDENT# self . auth_type = server . get ( 'auth-type' , 'digest' ) #NEWLINE# auth_types = [ 'digest' , 'basic' ] #NEWLINE# if ( self . auth_type not in auth_types ) : #NEWLINE# #INDENT# self . auth_type = 'digest' #NEWLINE# #UNINDENT# self . verify_ssl = server . get ( 'verify-ssl' , True ) #NEWLINE# if ( not self . verify_ssl ) : #NEWLINE# #INDENT# os . environ [ 'GIT_SSL_NO_VERIFY' ] = 'true' #NEWLINE# #UNINDENT# self . ssl_ca_path = server . get ( 'ssl-ca-path' , None ) #NEWLINE# if ( self . ssl_ca_path is not None ) : #NEWLINE# #INDENT# self . ssl_ca_path = os . path . expanduser ( self . ssl_ca_path ) #NEWLINE# os . environ [ 'REQUESTS_CA_BUNDLE' ] = self . ssl_ca_path #NEWLINE# os . environ [ 'GIT_SSL_CAINFO' ] = self . ssl_ca_path #NEWLINE# #UNINDENT# self . git_root = os . path . expanduser ( server [ 'git-root' ] ) #NEWLINE# git_url = server . get ( 'git-url' , ( self . url + 'p/' ) ) #NEWLINE# if ( not git_url . endswith ( '/' ) ) : #NEWLINE# #INDENT# git_url += '/' #NEWLINE# #UNINDENT# self . git_url = git_url #NEWLINE# self . dburi = server . get ( 'dburi' , ( 'sqlite:///' + os . path . expanduser ( '~/.gertty.db' ) ) ) #NEWLINE# socket_path = server . get ( 'socket' , '~/.gertty.sock' ) #NEWLINE# self . socket_path = os . path . expanduser ( socket_path ) #NEWLINE# log_file = server . get ( 'log-file' , '~/.gertty.log' ) #NEWLINE# self . log_file = os . path . expanduser ( log_file ) #NEWLINE# self . palettes = { #NEWLINE# #INDENT# 'default' : gertty . palette . Palette ( { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) , #NEWLINE# 'light' : gertty . palette . Palette ( gertty . palette . LIGHT_PALETTE ) , #NEWLINE# #UNINDENT# } #NEWLINE# for p in self . config . get ( 'palettes' , [ ] ) : #NEWLINE# #INDENT# if ( p [ 'name' ] not in self . palettes ) : #NEWLINE# #INDENT# self . palettes [ p [ 'name' ] ] = gertty . palette . Palette ( p ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . palettes [ p [ 'name' ] ] . update ( p ) #NEWLINE# #UNINDENT# #UNINDENT# self . palette = self . palettes [ self . config . get ( 'palette' , palette ) ] #NEWLINE# self . keymaps = { #NEWLINE# #INDENT# 'default' : gertty . keymap . KeyMap ( { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) , #NEWLINE# 'vi' : gertty . keymap . KeyMap ( gertty . keymap . VI_KEYMAP ) , #NEWLINE# #UNINDENT# } #NEWLINE# for p in self . config . get ( 'keymaps' , [ ] ) : #NEWLINE# #INDENT# if ( p [ 'name' ] not in self . keymaps ) : #NEWLINE# #INDENT# self . keymaps [ p [ 'name' ] ] = gertty . keymap . KeyMap ( p ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . keymaps [ p [ 'name' ] ] . update ( p ) #NEWLINE# #UNINDENT# #UNINDENT# self . keymap = self . keymaps [ self . config . get ( 'keymap' , keymap ) ] #NEWLINE# self . commentlinks = [ gertty . commentlink . CommentLink ( c ) for c in self . config . get ( 'commentlinks' , [ ] ) ] #NEWLINE# self . commentlinks . append ( gertty . commentlink . CommentLink ( dict ( match = '(?P<url>https?://\\S*)' , replacements = [ dict ( link = dict ( text = '{url}' , url = '{url}' ) ) ] ) ) ) #NEWLINE# self . project_change_list_query = self . config . get ( 'change-list-query' , 'status:open' ) #NEWLINE# self . diff_view = self . config . get ( 'diff-view' , 'side-by-side' ) #NEWLINE# self . dashboards = OrderedDict ( ) #NEWLINE# for d in self . config . get ( 'dashboards' , [ ] ) : #NEWLINE# #INDENT# self . dashboards [ d [ 'key' ] ] = d #NEWLINE# self . dashboards [ d [ 'key' ] ] #NEWLINE# #UNINDENT# self . reviewkeys = OrderedDict ( ) #NEWLINE# for k in self . config . get ( 'reviewkeys' , [ ] ) : #NEWLINE# #INDENT# self . reviewkeys [ k [ 'key' ] ] = k #NEWLINE# #UNINDENT# self . hide_comments = [ ] #NEWLINE# for h in self . config . get ( 'hide-comments' , [ ] ) : #NEWLINE# #INDENT# self . hide_comments . append ( re . compile ( h [ 'author' ] ) ) #NEWLINE# #UNINDENT# self . thread_changes = self . config . get ( 'thread-changes' , True ) #NEWLINE# self . utc = self . config . get ( 'display-times-in-utc' , False ) #NEWLINE# self . handle_mouse = self . config . get ( 'handle-mouse' , True ) #NEWLINE# change_list_options = self . config . get ( 'change-list-options' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# self . change_list_options = { #NEWLINE# #INDENT# 'sort-by' : change_list_options . get ( 'sort-by' , 'number' ) , #NEWLINE# 'reverse' : change_list_options . get ( 'reverse' , False ) , #NEWLINE# #UNINDENT# } #NEWLINE# self . expire_age = self . config . get ( 'expire-age' , '2 months' )