cloudbase / PyMI

A blazing fast replacement for the Python WMI module
Apache License 2.0
21 stars 14 forks source link

Implements __str__ method for PyMI objects #31

Closed claudiubelu closed 6 years ago

claudiubelu commented 7 years ago

Currently, PyMI debugging using PyMI can be a bit difficult, when compared to the old WMI.

For example, the old WMI has an object string representation implementation, meaning that WMI objects can easily and usefully be printed, while PyMI doesn't:

>>> print new_wmi.Msvm_VirtualSystemSettingData()[0]
<wmi._Instance object at 0x0000000002E45CC0>

This patch adds a similar str implementation to PyMI.

claudiubelu commented 6 years ago

FWIW, this is how it looks now:

>>> vms = conn.Msvm_ComputerSystem()
>>> vms[0]
<pymi_object: \\WIN-SRVR2\root\virtualization\v2:Msvm_ComputerSystem.Name="WIN-SRVR2",CreationClassName="Msvm_ComputerSystem">
>>> print(vms[0])
instance of Msvm_ComputerSystem
{
        Caption = "Hosting Computer System";
        Description = "Microsoft Hosting Computer System";
        ElementName = "WIN-SRVR2";
        InstanceID = "None";
        CommunicationStatus = None;
        DetailedStatus = None;
        HealthState = 5;
        InstallDate = None;
        Name = "WIN-SRVR2";
        OperatingStatus = None;
        OperationalStatus = (2,);
        PrimaryStatus = None;
        Status = "OK";
        StatusDescriptions = ('OK',);
        AvailableRequestedStates = None;
        EnabledDefault = 2;
        EnabledState = 2;
        OtherEnabledState = "None";
        RequestedState = 12;
        TimeOfLastStateChange = None;
        TransitioningToState = None;
        CreationClassName = "Msvm_ComputerSystem";
        IdentifyingDescriptions = None;
        NameFormat = "None";
        OtherIdentifyingInfo = None;
        PrimaryOwnerContact = "None";
        PrimaryOwnerName = "None";
        Roles = None;
        Dedicated = None;
        OtherDedicatedDescriptions = None;
        PowerManagementCapabilities = None;
        ResetCapability = 1;
        EnhancedSessionModeState = None;
        FailedOverReplicationType = None;
        LastApplicationConsistentReplicationTime = None;
        LastReplicationTime = None;
        LastReplicationType = None;
        LastSuccessfulBackupTime = None;
        NumberOfNumaNodes = 1;
        OnTimeInMilliseconds = None;
        ProcessID = None;
        ReplicationHealth = None;
        ReplicationMode = None;
        ReplicationState = None;
        TimeOfLastConfigurationChange = None;
};
>>> vms[0].RequestStateChange
<function RequestStateChange (RequestedState, TimeoutPeriod)>
mickare commented 6 years ago

Works like a charm, why is this not accepted?