<s> """<STR_LIT>""" <EOL> import diamond . collector <EOL> import diamond . convertor <EOL> import os <EOL> import subprocess <EOL> class UserScriptsCollector ( diamond . collector . Collector ) : <EOL> def get_default_config_help ( self ) : <EOL> config_help = super ( UserScriptsCollector , <EOL> self ) . get_default_config_help ( ) <EOL> config_help . update ( { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> } ) <EOL> return config_help <EOL> def get_default_config ( self ) : <EOL> """<STR_LIT>""" <EOL> config = super ( UserScriptsCollector , self ) . get_default_config ( ) <EOL> config . update ( { <EOL> '<STR_LIT:path>' : '<STR_LIT:.>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:4> , <EOL> } ) <EOL> return config <EOL> def collect ( self ) : <EOL> scripts_path = self . config [ '<STR_LIT>' ] <EOL> if not os . access ( scripts_path , os . R_OK ) : <EOL> return None <EOL> for script in os . listdir ( scripts_path ) : <EOL> absolutescriptpath = os . path . join ( scripts_path , script ) <EOL> executable = os . access ( absolutescriptpath , os . X_OK ) <EOL> is_file = os . path . isfile ( absolutescriptpath ) <EOL> if is_file : <EOL> if not executable : <EOL> self . log . info ( "<STR_LIT>" % absolutescriptpath ) <EOL> continue <EOL> else : <EOL> continue <EOL> out = None <EOL> self . log . debug ( "<STR_LIT>" % absolutescriptpath ) <EOL> try : <EOL> proc = subprocess . Popen ( [ absolutescriptpath ] , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE ) <EOL> ( out , err ) = proc . communicate ( ) <EOL> except subprocess . CalledProcessError , e : <EOL> self . log . error ( "<STR_LIT>" % <EOL> ( absolutescriptpath , e ) ) <EOL> continue <EOL> if proc . returncode : <EOL> self . log . error ( "<STR_LIT>" % <EOL> ( absolutescriptpath , proc . returncode ) ) <EOL> if not out : <EOL> self . log . info ( "<STR_LIT>" % absolutescriptpath ) <EOL> continue <EOL> if err : <EOL> self . log . error ( "<STR_LIT>" % <EOL> ( absolutescriptpath , err ) ) <EOL> for line in filter ( None , out . split ( '<STR_LIT:\n>' ) ) : <EOL> try : <EOL> name , value = line . split ( ) <EOL> float ( value ) <EOL> except ValueError : <EOL> self . log . error ( "<STR_LIT>" % <EOL> ( absolutescriptpath , line ) ) <EOL> continue <EOL> name , value = line . split ( ) <EOL> floatprecision = <NUM_LIT:0> <EOL> if "<STR_LIT:.>" in value : <EOL> floatprecision = self . config [ '<STR_LIT>' ] <EOL> self . publish ( name , value , precision = floatprecision ) </s>
