<s> import os <EOL> import subprocess <EOL> import ajenti <EOL> from ajenti . api import * <EOL> from ajenti . plugins . main . api import SectionPlugin <EOL> from ajenti . ui import on <EOL> from ajenti . ui . binder import Binder <EOL> from reconfigure . configs import CTDBConfig , CTDBNodesConfig , CTDBPublicAddressesConfig <EOL> from reconfigure . items . ctdb import NodeData , PublicAddressData <EOL> @ plugin <EOL> class CTDB ( SectionPlugin ) : <EOL> nodes_file = '<STR_LIT>' <EOL> addresses_file = '<STR_LIT>' <EOL> def init ( self ) : <EOL> self . title = _ ( '<STR_LIT>' ) <EOL> self . icon = '<STR_LIT>' <EOL> self . category = _ ( '<STR_LIT>' ) <EOL> self . append ( self . ui . inflate ( '<STR_LIT>' ) ) <EOL> self . config_path = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } [ ajenti . platform ] <EOL> self . config = CTDBConfig ( path = self . config_path ) <EOL> self . config . load ( ) <EOL> self . binder = Binder ( None , self . find ( '<STR_LIT>' ) ) <EOL> self . n_binder = Binder ( None , self . find ( '<STR_LIT>' ) ) <EOL> self . a_binder = Binder ( None , self . find ( '<STR_LIT>' ) ) <EOL> self . find ( '<STR_LIT>' ) . new_item = lambda c : NodeData ( ) <EOL> self . find ( '<STR_LIT>' ) . new_item = lambda c : self . new_address ( ) <EOL> def new_address ( self ) : <EOL> a = PublicAddressData ( ) <EOL> a . address = '<STR_LIT>' <EOL> return a <EOL> def on_page_load ( self ) : <EOL> n_path = self . config . tree . nodes_file <EOL> self . nodes_config = CTDBNodesConfig ( path = n_path ) <EOL> if not os . path . exists ( n_path ) : <EOL> open ( n_path , '<STR_LIT:w>' ) . close ( ) <EOL> self . nodes_config . load ( ) <EOL> a_path = self . config . tree . public_addresses_file <EOL> self . addresses_config = CTDBPublicAddressesConfig ( path = a_path ) <EOL> if not os . path . exists ( a_path ) : <EOL> open ( a_path , '<STR_LIT:w>' ) . close ( ) <EOL> self . addresses_config . load ( ) <EOL> self . config . load ( ) <EOL> self . binder . setup ( self . config . tree ) . populate ( ) <EOL> self . n_binder . setup ( self . nodes_config . tree ) . populate ( ) <EOL> self . a_binder . setup ( self . addresses_config . tree ) . populate ( ) <EOL> self . refresh ( ) <EOL> @ on ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def refresh ( self ) : <EOL> try : <EOL> self . find ( '<STR_LIT:status>' ) . value = subprocess . check_output ( [ '<STR_LIT>' , '<STR_LIT:status>' ] ) <EOL> self . find ( '<STR_LIT>' ) . value = subprocess . check_output ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> except : <EOL> self . find ( '<STR_LIT:status>' ) . value = _ ( '<STR_LIT>' ) <EOL> @ on ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def save ( self ) : <EOL> self . binder . update ( ) <EOL> self . n_binder . update ( ) <EOL> self . a_binder . update ( ) <EOL> self . config . save ( ) <EOL> self . nodes_config . save ( ) <EOL> self . addresses_config . save ( ) <EOL> self . context . notify ( '<STR_LIT:info>' , _ ( '<STR_LIT>' ) ) </s>
