VirtualBox

Ignore:
Timestamp:
Aug 14, 2020 9:29:46 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
139936
Message:

VBoxManage/checkupdate: machine readable output. bugref:7983

Location:
trunk/src/VBox/Frontends/VBoxManage
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h

    r85778 r85780  
    261261HRESULT showBandwidthGroups(ComPtr<IBandwidthControl> &bwCtrl,
    262262                            VMINFO_DETAILS details);
     263void outputMachineReadableString(const char *pszName, const char *pszValue);
     264void outputMachineReadableString(const char *pszName, com::Bstr const *pbstrValue);
     265void outputMachineReadableBool(const char *pszName, BOOL const *pfValue);
     266void outputMachineReadableBool(const char *pszName, bool const *pfValue);
     267void outputMachineReadableULong(const char *pszName, ULONG *uValue);
     268void outputMachineReadableLong64(const char *pszName, LONG64 *uValue);
    263269
    264270/* VBoxManageList.cpp */
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageInfo.cpp

    r85779 r85780  
    231231 * @param   pszValue            The value.
    232232 */
    233 static void outputMachineReadableString(const char *pszName, const char *pszValue)
     233void outputMachineReadableString(const char *pszName, const char *pszValue)
    234234{
    235235    Assert(strpbrk(pszName, "\"\\") == NULL);
     
    268268 * @param   pbstrValue          The value.
    269269 */
    270 static void outputMachineReadableString(const char *pszName, Bstr const *pbstrValue)
     270void outputMachineReadableString(const char *pszName, Bstr const *pbstrValue)
    271271{
    272272    com::Utf8Str strValue(*pbstrValue);
    273273    outputMachineReadableString(pszName, strValue.c_str());
    274274}
     275
     276
     277/**
     278 * Machine readable outputting of a boolean value.
     279 */
     280void outputMachineReadableBool(const char *pszName, BOOL const *pfValue)
     281{
     282    RTPrintf("%s=\"%s\"\n", pszName, *pfValue ? "on" : "off");
     283}
     284
     285
     286/**
     287 * Machine readable outputting of a boolean value.
     288 */
     289void outputMachineReadableBool(const char *pszName, bool const *pfValue)
     290{
     291    RTPrintf("%s=\"%s\"\n", pszName, *pfValue ? "on" : "off");
     292}
     293
     294
     295/**
     296 * Machine readable outputting of a ULONG value.
     297 */
     298void outputMachineReadableULong(const char *pszName, ULONG *puValue)
     299{
     300    RTPrintf("%s=\"%u\"\n", pszName, *puValue);
     301}
     302
     303
     304/**
     305 * Machine readable outputting of a LONG64 value.
     306 */
     307void outputMachineReadableLong64(const char *pszName, LONG64 *puValue)
     308{
     309    RTPrintf("%s=\"%llu\"\n", pszName, *puValue);
     310}
     311
    275312
    276313/**
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageUpdateCheck.cpp

    r85778 r85780  
    5151    static const RTGETOPTDEF s_aOptions[] =
    5252    {
    53         { "--verbose",       'v',        RTGETOPT_REQ_NOTHING }
     53        { "--machine-readable", 'm', RTGETOPT_REQ_NOTHING }
    5454    };
    5555    RTGETOPTSTATE GetState;
     
    5757    AssertRCReturn(vrc, RTEXITCODE_INIT);
    5858
     59    bool fMachineReadable = false;
     60
    5961    int c;
    6062    RTGETOPTUNION ValueUnion;
     
    6365        switch (c)
    6466        {
     67            case 'm':
     68                fMachineReadable = true;
     69                break;
     70
    6571            default:
    6672                return errorGetOpt(c, &ValueUnion);
     
    7682    BOOL fVBoxUpdateEnabled;
    7783    CHECK_ERROR2I_RET(pSystemProperties, COMGETTER(VBoxUpdateEnabled)(&fVBoxUpdateEnabled), RTEXITCODE_FAILURE);
    78     RTPrintf("Enabled:                %s\n", fVBoxUpdateEnabled ? "yes" : "no");
     84    if (fMachineReadable)
     85        outputMachineReadableBool("enabled", &fVBoxUpdateEnabled);
     86    else
     87        RTPrintf("Enabled:                %s\n", fVBoxUpdateEnabled ? "yes" : "no");
    7988
    8089    ULONG cVBoxUpdateCount;
    8190    CHECK_ERROR2I_RET(pSystemProperties, COMGETTER(VBoxUpdateCount)(&cVBoxUpdateCount), RTEXITCODE_FAILURE);
    82     RTPrintf("Count:                  %u\n", cVBoxUpdateCount);
    83 
    84     ULONG uVBoxUpdateFrequency;
    85     CHECK_ERROR2I_RET(pSystemProperties, COMGETTER(VBoxUpdateFrequency)(&uVBoxUpdateFrequency), RTEXITCODE_FAILURE);
    86     if (uVBoxUpdateFrequency == 0)
    87         RTPrintf("Frequency:              never\n");
    88     else if (uVBoxUpdateFrequency == 1)
     91    if (fMachineReadable)
     92        outputMachineReadableULong("count", &cVBoxUpdateCount);
     93    else
     94        RTPrintf("Count:                  %u\n", cVBoxUpdateCount);
     95
     96    ULONG cDaysFrequencey;
     97    CHECK_ERROR2I_RET(pSystemProperties, COMGETTER(VBoxUpdateFrequency)(&cDaysFrequencey), RTEXITCODE_FAILURE);
     98    if (fMachineReadable)
     99        outputMachineReadableULong("frequency", &cDaysFrequencey);
     100    else if (cDaysFrequencey == 0)
     101        RTPrintf("Frequency:              never\n"); /** @todo r=bird: Two inconsistencies here. HostUpdateImpl.cpp code will indicate the need for updating if no last-check-date.  modifysettings cannot set it to zero (I added the error message, you just skipped setting it originally). */
     102    else if (cDaysFrequencey == 1)
    89103        RTPrintf("Frequency:              every day\n");
    90104    else
    91         RTPrintf("Frequency:              every %u days\n", uVBoxUpdateFrequency);
     105        RTPrintf("Frequency:              every %u days\n", cDaysFrequencey);
    92106
    93107    VBoxUpdateTarget_T enmVBoxUpdateTarget;
    94108    CHECK_ERROR2I_RET(pSystemProperties, COMGETTER(VBoxUpdateTarget)(&enmVBoxUpdateTarget), RTEXITCODE_FAILURE);
    95109    const char *psz;
     110    const char *pszMachine;
    96111    switch (enmVBoxUpdateTarget)
    97112    {
    98113        case VBoxUpdateTarget_Stable:
    99114            psz = "Stable - new minor and maintenance releases";
     115            pszMachine = "stable";
    100116            break;
    101117        case VBoxUpdateTarget_AllReleases:
    102118            psz = "All releases - new minor, maintenance, and major releases";
     119            pszMachine = "all-releases";
    103120            break;
    104121        case VBoxUpdateTarget_WithBetas:
    105122            psz = "With Betas - new minor, maintenance, major, and beta releases";
     123            pszMachine = "with-betas";
    106124            break;
    107125        default:
     126            AssertFailed();
    108127            psz = "Unset";
     128            pszMachine = "invalid";
    109129            break;
    110130    }
    111     RTPrintf("Target:                 %s\n", psz);
    112 
    113     Bstr strVBoxUpdateLastCheckDate;
    114     CHECK_ERROR2I_RET(pSystemProperties, COMGETTER(VBoxUpdateLastCheckDate)(strVBoxUpdateLastCheckDate.asOutParam()),
     131    if (fMachineReadable)
     132        outputMachineReadableString("target", pszMachine);
     133    else
     134        RTPrintf("Target:                 %s\n", psz);
     135
     136    Bstr bstrLastCheckDate;
     137    CHECK_ERROR2I_RET(pSystemProperties, COMGETTER(VBoxUpdateLastCheckDate)(bstrLastCheckDate.asOutParam()),
    115138                      RTEXITCODE_FAILURE);
    116     if (!strVBoxUpdateLastCheckDate.isEmpty())
    117         RTPrintf("Last Check Date:        %ls\n", strVBoxUpdateLastCheckDate.raw());
     139    if (fMachineReadable)
     140        outputMachineReadableString("last-check-date", &bstrLastCheckDate);
     141    else if (bstrLastCheckDate.isNotEmpty())
     142        RTPrintf("Last Check Date:        %ls\n", bstrLastCheckDate.raw());
    118143
    119144    return RTEXITCODE_SUCCESS;
     
    220245    static const RTGETOPTDEF s_aOptions[] =
    221246    {
    222         { "--verbose",       'v',        RTGETOPT_REQ_NOTHING }
     247        { "--machine-readable", 'm', RTGETOPT_REQ_NOTHING }
    223248    };
    224249    RTGETOPTSTATE GetState;
     
    226251    AssertRCReturn(vrc, RTEXITCODE_INIT);
    227252
     253    bool fMachineReadable = false;
     254
    228255    int c;
    229256    RTGETOPTUNION ValueUnion;
     
    232259        switch (c)
    233260        {
     261            case 'm':
     262                fMachineReadable = true;
     263                break;
     264
    234265            default:
    235266                return errorGetOpt(c, &ValueUnion);
     
    277308    CHECK_ERROR2I_RET(pHostUpdate, COMGETTER(UpdateResponse)(&fUpdateNeeded), RTEXITCODE_FAILURE);
    278309
    279     if (!fUpdateNeeded)
    280         RTPrintf("You are already running the most recent version of VirtualBox.\n");
    281     else
     310    if (fMachineReadable)
     311        outputMachineReadableBool("update-needed", &fUpdateNeeded);
     312
     313    if (fUpdateNeeded)
    282314    {
    283315        Bstr bstrUpdateVersion;
     
    286318        CHECK_ERROR2I_RET(pHostUpdate, COMGETTER(UpdateURL)(bstrUpdateURL.asOutParam()), RTEXITCODE_FAILURE);
    287319
    288         RTPrintf("A new version of VirtualBox has been released! Version %ls is available at virtualbox.org.\n"
    289                  "You can download this version here: %ls\n", bstrUpdateVersion.raw(), bstrUpdateURL.raw());
    290     }
     320        if (fMachineReadable)
     321            RTPrintf("A new version of VirtualBox has been released! Version %ls is available at virtualbox.org.\n"
     322                     "You can download this version here: %ls\n", bstrUpdateVersion.raw(), bstrUpdateURL.raw());
     323        else
     324        {
     325            outputMachineReadableString("update-version", &bstrUpdateVersion);
     326            outputMachineReadableString("update-url", &bstrUpdateURL);
     327        }
     328    }
     329    else if (!fMachineReadable)
     330        RTPrintf("You are already running the most recent version of VirtualBox.\n");
    291331
    292332    return RTEXITCODE_SUCCESS;
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette