<s> import dbus <EOL> SYSTEMD_BUS = '<STR_LIT>' <EOL> SYSTEMD_PATH = '<STR_LIT>' <EOL> MANAGER_IFACE = '<STR_LIT>' <EOL> PROP_IFACE = '<STR_LIT>' <EOL> UNIT_IFACE = '<STR_LIT>' <EOL> SVC_IFACE = '<STR_LIT>' <EOL> class DBusClient : <EOL> SVC_PROPERTIES = [ '<STR_LIT>' ] <EOL> UNIT_PROPERTIES = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> def __init__ ( self ) : <EOL> self . bus = dbus . SystemBus ( ) <EOL> self . proxy = self . bus . get_object ( SYSTEMD_BUS , SYSTEMD_PATH ) <EOL> self . interface = dbus . Interface ( self . proxy , MANAGER_IFACE ) <EOL> def get_properties ( self , name , prop_names , property_interface ) : <EOL> objpath = self . interface . GetUnit ( name ) <EOL> proxy = self . bus . get_object ( SYSTEMD_BUS , objpath ) <EOL> interface = dbus . Interface ( proxy , PROP_IFACE ) <EOL> properties = interface . GetAll ( property_interface ) <EOL> if prop_names : <EOL> tmp_properties = { } <EOL> for item in prop_names : <EOL> if item in properties : <EOL> tmp_properties [ item ] = properties [ item ] <EOL> else : <EOL> tmp_properties [ item ] = None <EOL> properties = tmp_properties <EOL> return properties <EOL> def get_unit_properties ( self , unit_name , property_names = UNIT_PROPERTIES ) : <EOL> return self . get_properties ( unit_name , property_names , UNIT_IFACE ) <EOL> def get_service_properties ( self , unit_name , property_names = SVC_PROPERTIES ) : <EOL> return self . get_properties ( unit_name , property_names , SVC_IFACE ) <EOL> def get_services ( units ) : <EOL> out = [ ] <EOL> client = DBusClient ( ) <EOL> for unit_id , display_name in units . iteritems ( ) : <EOL> service = { } <EOL> service [ '<STR_LIT>' ] = display_name <EOL> service [ '<STR_LIT>' ] = [ ] <EOL> try : <EOL> instance = { } <EOL> instance . update ( client . get_unit_properties ( unit_id ) ) <EOL> instance . update ( client . get_service_properties ( unit_id ) ) <EOL> instance [ '<STR_LIT:state>' ] = instance [ '<STR_LIT>' ] <EOL> service [ '<STR_LIT>' ] . append ( instance ) <EOL> except dbus . exceptions . DBusException : <EOL> pass <EOL> out . append ( service ) <EOL> return out </s>
