<s> import os <EOL> import re <EOL> import sys <EOL> import glob <EOL> from karesansui . lib . dict_op import DictOp <EOL> from karesansui . lib . parser . base . xml_like_conf_parser import xmlLikeConfParser as Parser <EOL> from karesansui . lib . utils import preprint_r , r_chgrp , r_chmod <EOL> from karesansui . lib . const import VENDOR_SYSCONF_DIR , COLLECTD_DATA_DIR , KARESANSUI_GROUP <EOL> """<STR_LIT>""" <EOL> PARSER_COLLECTD_PLUGIN_DIR = "<STR_LIT>" % VENDOR_SYSCONF_DIR <EOL> class collectdpluginParser : <EOL> _module = "<STR_LIT>" <EOL> def __init__ ( self ) : <EOL> self . dop = DictOp ( ) <EOL> self . dop . addconf ( self . _module , { } ) <EOL> self . parser = Parser ( ) <EOL> self . parser . set_delim ( "<STR_LIT>" ) <EOL> self . parser . set_new_delim ( "<STR_LIT:\t>" ) <EOL> self . parser . set_comment ( "<STR_LIT:#>" ) <EOL> self . base_parser_name = self . parser . __class__ . __name__ <EOL> from karesansui . lib . parser . collectd import collectdParser <EOL> collectdp = collectdParser ( ) <EOL> self . parser . set_opt_uni ( collectdp . opt_uni ) <EOL> self . parser . set_opt_multi ( collectdp . opt_multi ) <EOL> self . parser . set_opt_sect ( collectdp . opt_sect ) <EOL> pass <EOL> def set_footer ( self , footer = "<STR_LIT>" ) : <EOL> self . parser . set_footer ( footer ) <EOL> def source_file ( self ) : <EOL> retval = [ ] <EOL> glob_str = "<STR_LIT>" % ( PARSER_COLLECTD_PLUGIN_DIR , ) <EOL> for _afile in glob . glob ( glob_str ) : <EOL> retval . append ( _afile ) <EOL> return retval <EOL> def read_conf ( self , extra_args = None ) : <EOL> retval = { } <EOL> for _afile in self . source_file ( ) : <EOL> plugin_name = re . sub ( "<STR_LIT>" , "<STR_LIT>" , os . path . basename ( _afile ) ) <EOL> try : <EOL> extra_args [ '<STR_LIT>' ] <EOL> if not re . search ( extra_args [ '<STR_LIT>' ] , plugin_name ) : <EOL> continue <EOL> except : <EOL> pass <EOL> self . parser . set_source_file ( [ _afile ] ) <EOL> conf_arr = self . parser . read_conf ( ) <EOL> try : <EOL> self . dop . set ( self . _module , [ plugin_name ] , conf_arr [ _afile ] [ '<STR_LIT:value>' ] ) <EOL> except : <EOL> pass <EOL> self . dop . set ( self . _module , [ '<STR_LIT>' ] , self . base_parser_name ) <EOL> return self . dop . getconf ( self . _module ) <EOL> def _pre_write_conf ( self , conf_arr = { } ) : <EOL> if os . path . exists ( COLLECTD_DATA_DIR ) : <EOL> if os . getuid ( ) == <NUM_LIT:0> : <EOL> r_chgrp ( COLLECTD_DATA_DIR , KARESANSUI_GROUP ) <EOL> r_chmod ( COLLECTD_DATA_DIR , "<STR_LIT>" ) <EOL> r_chmod ( COLLECTD_DATA_DIR , "<STR_LIT>" ) <EOL> dop = DictOp ( ) <EOL> dop . addconf ( "<STR_LIT>" , conf_arr ) <EOL> if dop . isset ( "<STR_LIT>" , [ "<STR_LIT>" ] ) is True : <EOL> dop . cdp_unset ( "<STR_LIT>" , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , multiple_file = True ) <EOL> orders = [ ] <EOL> orders . append ( [ '<STR_LIT>' ] ) <EOL> orders . append ( [ '<STR_LIT>' ] ) <EOL> orders . append ( [ '<STR_LIT>' ] ) <EOL> orders . append ( [ '<STR_LIT>' ] ) <EOL> orders . append ( [ '<STR_LIT>' ] ) <EOL> orders . append ( [ '<STR_LIT>' ] ) <EOL> dop . cdp_set ( "<STR_LIT>" , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , orders , is_opt_multi = True , multiple_file = True ) <EOL> return dop . getconf ( "<STR_LIT>" ) <EOL> def write_conf ( self , conf_arr = { } , extra_args = None , dryrun = False ) : <EOL> retval = True <EOL> conf_arr = self . _pre_write_conf ( conf_arr ) <EOL> for plugin_name , _v in conf_arr . iteritems ( ) : <EOL> _afile = "<STR_LIT>" % ( PARSER_COLLECTD_PLUGIN_DIR , plugin_name , ) <EOL> try : <EOL> _v [ '<STR_LIT:action>' ] <EOL> if _v [ '<STR_LIT:action>' ] == "<STR_LIT>" : <EOL> if os . path . exists ( _afile ) : <EOL> os . unlink ( _afile ) <EOL> continue <EOL> except : <EOL> pass <EOL> try : <EOL> _v [ '<STR_LIT:value>' ] <EOL> self . dop . addconf ( "<STR_LIT>" , { } ) <EOL> self . dop . set ( "<STR_LIT>" , [ _afile ] , _v [ '<STR_LIT:value>' ] ) <EOL> arr = self . dop . getconf ( "<STR_LIT>" ) <EOL> self . parser . write_conf ( arr , dryrun = dryrun ) <EOL> except : <EOL> pass <EOL> return retval <EOL> """<STR_LIT:U+0020>""" <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> """<STR_LIT>""" <EOL> parser = collectdpluginParser ( ) <EOL> dop = DictOp ( ) <EOL> dop . addconf ( "<STR_LIT>" , parser . read_conf ( ) ) <EOL> new_plugin_name = "<STR_LIT>" <EOL> dop . add ( "<STR_LIT>" , [ new_plugin_name , "<STR_LIT>" ] , [ "<STR_LIT:foo>" , [ [ "<STR_LIT>" , "<STR_LIT>" ] , "<STR_LIT>" ] ] ) <EOL> dop . cdp_set ( "<STR_LIT>" , [ new_plugin_name , "<STR_LIT>" ] , "<STR_LIT:bar>" , multiple_file = True ) <EOL> dop . cdp_set_pre_comment ( "<STR_LIT>" , [ new_plugin_name , "<STR_LIT>" ] , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , multiple_file = True ) <EOL> dop . cdp_set_post_comment ( "<STR_LIT>" , [ new_plugin_name , "<STR_LIT>" ] , "<STR_LIT>" , multiple_file = True ) <EOL> dop . cdp_set ( "<STR_LIT>" , [ new_plugin_name , "<STR_LIT>" , "<STR_LIT>" ] , "<STR_LIT>" , multiple_file = True , is_opt_multi = True ) <EOL> dop . cdp_set_pre_comment ( "<STR_LIT>" , [ new_plugin_name , "<STR_LIT>" , "<STR_LIT>" ] , [ "<STR_LIT>" , "<STR_LIT>" ] , multiple_file = True ) <EOL> dop . cdp_set ( "<STR_LIT>" , [ new_plugin_name , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , "<STR_LIT:true>" , multiple_file = True ) <EOL> dop . cdp_set ( "<STR_LIT>" , [ new_plugin_name , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , "<STR_LIT:false>" , multiple_file = True ) <EOL> dop . cdp_set_pre_comment ( "<STR_LIT>" , [ new_plugin_name , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , "<STR_LIT>" , multiple_file = True ) <EOL> dop . cdp_set_post_comment ( "<STR_LIT>" , [ new_plugin_name , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , "<STR_LIT>" , multiple_file = True ) <EOL> dop . cdp_set ( "<STR_LIT>" , [ new_plugin_name , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , "<STR_LIT>" , multiple_file = True ) <EOL> dop . cdp_set_post_comment ( "<STR_LIT>" , [ new_plugin_name , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , "<STR_LIT>" , multiple_file = True ) <EOL> print dop . get ( "<STR_LIT>" , [ "<STR_LIT>" , "<STR_LIT>" ] , multiple_file = True ) <EOL> key = [ new_plugin_name , "<STR_LIT>" , "<STR_LIT>" ] <EOL> dop . insert_order ( "<STR_LIT>" , key , <NUM_LIT:0> , is_parent_parser = True ) <EOL> key = [ new_plugin_name , "<STR_LIT>" , "<STR_LIT>" ] <EOL> dop . insert_order ( "<STR_LIT>" , key , <NUM_LIT:0> , is_parent_parser = True ) <EOL> key = [ new_plugin_name , "<STR_LIT>" ] <EOL> dop . insert_order ( "<STR_LIT>" , key , <NUM_LIT:0> , is_parent_parser = True ) <EOL> conf = dop . getconf ( "<STR_LIT>" ) <EOL> preprint_r ( conf ) <EOL> parser . write_conf ( conf , dryrun = True ) </s>
