<s> """<STR_LIT>""" <EOL> import subprocess <EOL> from cauliflowervest . client . mac import plist <EOL> class Error ( Exception ) : <EOL> """<STR_LIT>""" <EOL> class SystemProfilerError ( Error ) : <EOL> """<STR_LIT>""" <EOL> class SystemProfile ( object ) : <EOL> DATA_TYPES = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> def __init__ ( self , include_only = None ) : <EOL> """<STR_LIT>""" <EOL> self . _profile = { } <EOL> self . _include_only = include_only <EOL> def _GetSystemProfilerOutput ( self ) : <EOL> argv = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> if self . _include_only : <EOL> for data_type in self . _include_only : <EOL> if data_type in self . DATA_TYPES : <EOL> argv . append ( self . DATA_TYPES [ data_type ] ) <EOL> try : <EOL> s = subprocess . Popen ( <EOL> argv , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE ) <EOL> except OSError , e : <EOL> raise SystemProfilerError ( str ( e ) ) <EOL> ( stdout , stderr ) = s . communicate ( ) <EOL> rc = s . wait ( ) <EOL> if rc != <NUM_LIT:0> : <EOL> raise SystemProfilerError ( '<STR_LIT>' % ( rc , stderr ) ) <EOL> return stdout <EOL> def _GetSystemProfile ( self ) : <EOL> sp_xml = self . _GetSystemProfilerOutput ( ) <EOL> p = plist . ApplePlist ( sp_xml ) <EOL> try : <EOL> p . Parse ( ) <EOL> except plist . Error , e : <EOL> raise SystemProfilerError ( '<STR_LIT>' % str ( e ) ) <EOL> self . _system_profile_xml = sp_xml <EOL> self . _system_profile = p . GetContents ( ) <EOL> def _GetDataTypeItems ( self , data_type_key ) : <EOL> """<STR_LIT>""" <EOL> data_type = self . DATA_TYPES . get ( data_type_key ) <EOL> for d in self . _system_profile : <EOL> if data_type and d . get ( '<STR_LIT>' ) == data_type and '<STR_LIT>' in d : <EOL> return d [ '<STR_LIT>' ] <EOL> return [ ] <EOL> def _FindHDDSerial ( self ) : <EOL> """<STR_LIT>""" <EOL> disk_items = ( self . _GetDataTypeItems ( '<STR_LIT>' ) + <EOL> self . _GetDataTypeItems ( '<STR_LIT>' ) + <EOL> self . _GetDataTypeItems ( '<STR_LIT>' ) ) <EOL> for disk_item in disk_items : <EOL> for item in disk_item [ '<STR_LIT>' ] : <EOL> if '<STR_LIT>' in item : <EOL> self . _profile [ '<STR_LIT>' ] = item [ '<STR_LIT>' ] . strip ( ) <EOL> return <EOL> def _FindMachineModel ( self ) : <EOL> """<STR_LIT>""" <EOL> for item in self . _GetDataTypeItems ( '<STR_LIT>' ) : <EOL> if '<STR_LIT>' in item : <EOL> self . _profile [ '<STR_LIT>' ] = item [ '<STR_LIT>' ] <EOL> return <EOL> def _FindPlatformUuid ( self ) : <EOL> """<STR_LIT>""" <EOL> for item in self . _GetDataTypeItems ( '<STR_LIT>' ) : <EOL> if '<STR_LIT>' in item : <EOL> self . _profile [ '<STR_LIT>' ] = item [ '<STR_LIT>' ] <EOL> return <EOL> def _FindSerialNumber ( self ) : <EOL> """<STR_LIT>""" <EOL> for item in self . _GetDataTypeItems ( '<STR_LIT>' ) : <EOL> if '<STR_LIT>' in item : <EOL> self . _profile [ '<STR_LIT>' ] = item [ '<STR_LIT>' ] <EOL> return <EOL> def _FindMacAddresses ( self ) : <EOL> """<STR_LIT>""" <EOL> for item in self . _GetDataTypeItems ( '<STR_LIT>' ) : <EOL> if '<STR_LIT>' in item : <EOL> if '<STR_LIT>' in item and '<STR_LIT>' in item [ '<STR_LIT>' ] : <EOL> intf_mac = item [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> intf_name = item . get ( '<STR_LIT>' , None ) <EOL> if item [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> intf_type = '<STR_LIT>' <EOL> elif item [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> intf_type = '<STR_LIT>' <EOL> elif item [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> intf_type = '<STR_LIT>' <EOL> else : <EOL> intf_type = None <EOL> if intf_type is not None : <EOL> self . _profile [ '<STR_LIT>' % intf_type ] = intf_mac <EOL> if intf_name is not None : <EOL> self . _profile [ '<STR_LIT>' % intf_name ] = intf_type <EOL> def _FindBatteryInfo ( self ) : <EOL> """<STR_LIT>""" <EOL> for item in self . _GetDataTypeItems ( '<STR_LIT>' ) : <EOL> if '<STR_LIT>' in item : <EOL> self . _profile [ '<STR_LIT>' ] = ( <EOL> item [ '<STR_LIT>' ] . get ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def _FindUSBDevices ( self ) : <EOL> """<STR_LIT>""" <EOL> for item in self . _GetDataTypeItems ( '<STR_LIT>' ) : <EOL> if '<STR_LIT>' in item : <EOL> for usb_item in item . get ( '<STR_LIT>' , [ ] ) : <EOL> if usb_item [ '<STR_LIT>' ] . find ( '<STR_LIT>' ) > - <NUM_LIT:1> : <EOL> self . _profile [ '<STR_LIT>' ] = ( <EOL> usb_item . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def _FindAll ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _GetSystemProfile ( ) <EOL> self . _FindHDDSerial ( ) <EOL> self . _FindMachineModel ( ) <EOL> self . _FindSerialNumber ( ) <EOL> self . _FindPlatformUuid ( ) <EOL> self . _FindMacAddresses ( ) <EOL> self . _FindBatteryInfo ( ) <EOL> self . _FindUSBDevices ( ) <EOL> def GetProfile ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . _profile : <EOL> self . _FindAll ( ) <EOL> return self . _profile <EOL> def main ( ) : <EOL> sp = SystemProfile ( ) <EOL> p = sp . GetProfile ( ) <EOL> for k in p : <EOL> print '<STR_LIT>' % ( k , p [ k ] ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
