<s> """<STR_LIT>""" <EOL> import os <EOL> import re <EOL> import Bcfg2 . Options <EOL> import Bcfg2 . Client . Tools <EOL> class FreeBSDInit ( Bcfg2 . Client . Tools . SvcTool ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> __execs__ = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> __handles__ = [ ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> __req__ = { '<STR_LIT>' : [ '<STR_LIT:name>' , '<STR_LIT:status>' ] } <EOL> rcvar_re = re . compile ( r'<STR_LIT>' ) <EOL> def get_svc_command ( self , service , action ) : <EOL> return '<STR_LIT>' % ( service . get ( '<STR_LIT:name>' ) , action ) <EOL> def verify_bootstatus ( self , entry , bootstatus ) : <EOL> """<STR_LIT>""" <EOL> cmd = self . get_svc_command ( entry , '<STR_LIT>' ) <EOL> current_bootstatus = bool ( self . cmd . run ( cmd ) ) <EOL> if bootstatus == '<STR_LIT>' : <EOL> if current_bootstatus : <EOL> entry . set ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return False <EOL> return True <EOL> elif not current_bootstatus : <EOL> entry . set ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return False <EOL> return True <EOL> def check_service ( self , entry ) : <EOL> cmd = self . get_svc_command ( entry , '<STR_LIT>' ) <EOL> return bool ( self . cmd . run ( cmd ) ) <EOL> def stop_service ( self , service ) : <EOL> self . logger . debug ( '<STR_LIT>' % service . get ( '<STR_LIT:name>' ) ) <EOL> return self . cmd . run ( self . get_svc_command ( service , '<STR_LIT>' ) ) <EOL> def VerifyService ( self , entry , _ ) : <EOL> """<STR_LIT>""" <EOL> entry . set ( '<STR_LIT>' , entry . get ( '<STR_LIT:status>' ) ) <EOL> bootstatus = self . get_bootstatus ( entry ) <EOL> if bootstatus is None : <EOL> return True <EOL> current_bootstatus = self . verify_bootstatus ( entry , bootstatus ) <EOL> if entry . get ( '<STR_LIT:status>' ) == '<STR_LIT:ignore>' : <EOL> current_svcstatus = True <EOL> svcstatus = True <EOL> else : <EOL> svcstatus = self . check_service ( entry ) <EOL> if entry . get ( '<STR_LIT:status>' ) == '<STR_LIT>' : <EOL> if svcstatus : <EOL> current_svcstatus = True <EOL> else : <EOL> current_svcstatus = False <EOL> elif entry . get ( '<STR_LIT:status>' ) == '<STR_LIT>' : <EOL> if svcstatus : <EOL> current_svcstatus = False <EOL> else : <EOL> current_svcstatus = True <EOL> if svcstatus : <EOL> entry . set ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> else : <EOL> entry . set ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return current_bootstatus and current_svcstatus <EOL> def InstallService ( self , entry ) : <EOL> """<STR_LIT>""" <EOL> self . logger . info ( "<STR_LIT>" % ( entry . get ( '<STR_LIT:name>' ) ) ) <EOL> bootstatus = self . get_bootstatus ( entry ) <EOL> all_services_cmd = '<STR_LIT>' <EOL> all_services = self . cmd . run ( all_services_cmd ) . stdout . splitlines ( ) <EOL> if entry . get ( '<STR_LIT:name>' ) not in all_services : <EOL> self . logger . debug ( "<STR_LIT>" % entry . get ( '<STR_LIT:name>' ) ) <EOL> return False <EOL> vars = set ( ) <EOL> rcvar_cmd = self . get_svc_command ( entry , '<STR_LIT>' ) <EOL> for line in self . cmd . run ( rcvar_cmd ) . stdout . splitlines ( ) : <EOL> match = self . rcvar_re . match ( line ) <EOL> if match : <EOL> vars . add ( match . group ( '<STR_LIT>' ) ) <EOL> if bootstatus is not None : <EOL> bootcmdrv = True <EOL> sysrcstatus = None <EOL> if bootstatus == '<STR_LIT>' : <EOL> sysrcstatus = '<STR_LIT>' <EOL> elif bootstatus == '<STR_LIT>' : <EOL> sysrcstatus = '<STR_LIT>' <EOL> if sysrcstatus is not None : <EOL> for var in vars : <EOL> if not self . cmd . run ( '<STR_LIT>' % ( var , sysrcstatus ) ) : <EOL> bootcmdrv = False <EOL> break <EOL> if Bcfg2 . Options . setup . service_mode == '<STR_LIT>' : <EOL> return bootcmdrv <EOL> buildmode = Bcfg2 . Options . setup . service_mode == '<STR_LIT>' <EOL> if ( entry . get ( '<STR_LIT:status>' ) == '<STR_LIT>' and not buildmode ) and entry . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> svccmdrv = self . start_service ( entry ) <EOL> elif ( entry . get ( '<STR_LIT:status>' ) == '<STR_LIT>' or buildmode ) and entry . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> svccmdrv = self . stop_service ( entry ) <EOL> else : <EOL> svccmdrv = True <EOL> return bootcmdrv and svccmdrv <EOL> else : <EOL> return True <EOL> def FindExtra ( self ) : <EOL> """<STR_LIT>""" <EOL> specified = [ entry . get ( '<STR_LIT:name>' ) for entry in self . getSupportedEntries ( ) ] <EOL> extra = set ( ) <EOL> for path in self . cmd . run ( "<STR_LIT>" ) . stdout . splitlines ( ) : <EOL> name = os . path . basename ( path ) <EOL> if name not in specified : <EOL> extra . add ( name ) <EOL> return [ Bcfg2 . Client . XML . Element ( '<STR_LIT>' , name = name , type = '<STR_LIT>' ) <EOL> for name in list ( extra ) ] <EOL> def Remove ( self , _ ) : <EOL> """<STR_LIT>""" <EOL> return </s>
