From 97ad75a596d691b59e48a4e45bcdeff8a9b21319 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 21 Jan 2020 10:25:45 +0100 Subject: [PATCH] [cli] Support setting device mode with list of names. Fixes JB#48669 --- ssucli/ssucli.cpp | 91 ++++++++++++++++++++++++++++++++--------------- ssucli/ssucli.h | 1 + 2 files changed, 64 insertions(+), 28 deletions(-) diff --git a/ssucli/ssucli.cpp b/ssucli/ssucli.cpp index c9f4cac..7bc83b8 100644 --- a/ssucli/ssucli.cpp +++ b/ssucli/ssucli.cpp @@ -174,32 +174,35 @@ void SsuCli::optFlavour(QStringList opt) } } +QString SsuCli::getModeString(int mode) { + QStringList modeList; + + if ((mode & Ssu::DisableRepoManager) == Ssu::DisableRepoManager) + modeList.append("DisableRepoManager"); + if ((mode & Ssu::RndMode) == Ssu::RndMode) + modeList.append("RndMode"); + if ((mode & Ssu::ReleaseMode) == Ssu::ReleaseMode) + modeList.append("ReleaseMode"); + if ((mode & Ssu::LenientMode) == Ssu::LenientMode) + modeList.append("LenientMode"); + if ((mode & Ssu::UpdateMode) == Ssu::UpdateMode) + modeList.append("UpdateMode"); + if ((mode & Ssu::AppInstallMode) == Ssu::AppInstallMode) + modeList.append("AppInstallMode"); + + return modeList.join(" | "); +} + void SsuCli::optMode(QStringList opt) { QTextStream qout(stdout); QTextStream qerr(stderr); - // TODO: allow setting meaningful names instead of numbers + int deviceMode = ssu.deviceMode(); if (opt.count() == 2) { - QStringList modeList; - int deviceMode = ssu.deviceMode(); - - if ((deviceMode & Ssu::DisableRepoManager) == Ssu::DisableRepoManager) - modeList.append("DisableRepoManager"); - if ((deviceMode & Ssu::RndMode) == Ssu::RndMode) - modeList.append("RndMode"); - if ((deviceMode & Ssu::ReleaseMode) == Ssu::ReleaseMode) - modeList.append("ReleaseMode"); - if ((deviceMode & Ssu::LenientMode) == Ssu::LenientMode) - modeList.append("LenientMode"); - if ((deviceMode & Ssu::UpdateMode) == Ssu::UpdateMode) - modeList.append("UpdateMode"); - if ((deviceMode & Ssu::AppInstallMode) == Ssu::AppInstallMode) - modeList.append("AppInstallMode"); - - qout << "Device mode is: " << ssu.deviceMode() - << " (" << modeList.join(" | ") << ")" << endl; + qout << "Device mode is: " << deviceMode + << " (" << getModeString(deviceMode) << ")" << endl; if ((deviceMode & Ssu::RndMode) == Ssu::RndMode && (deviceMode & Ssu::ReleaseMode) == Ssu::ReleaseMode) @@ -207,25 +210,53 @@ void SsuCli::optMode(QStringList opt) state = Idle; } else if (opt.count() == 3 && opt.at(2) == "-s") { - qout << ssu.deviceMode(); + qout << deviceMode; state = Idle; - } else if (opt.count() == 3) { - qout << "Setting device mode from " << ssu.deviceMode() - << " to " << opt.at(2) << endl; + return; + } else if (opt.count() >= 3) { + bool isInt; + int newMode = opt.at(2).toInt(&isInt); + + if (!isInt) { + for (int i=2; i reply = ssuProxy->setDeviceMode(opt.at(2).toInt()); + QDBusPendingReply<> reply = ssuProxy->setDeviceMode(newMode); reply.waitForFinished(); if (reply.isError()) { qerr << fallingBackToDirectUse(reply.error()) << endl; - ssu.setDeviceMode(Ssu::DeviceModeFlags(opt.at(2).toInt())); + ssu.setDeviceMode(Ssu::DeviceModeFlags(newMode)); SsuRepoManager repoManager; repoManager.update(); uidWarning(); } - - state = Idle; } + + state = Idle; } void SsuCli::optModel(QStringList opt) @@ -758,12 +789,16 @@ void SsuCli::usage(const QString &message) qout << "\nUsage: ssu [-command-options] [arguments]" << endl << endl << "Repository management:" << endl + << "\tmode, m \tShow repository mode information." << endl + << "\t \tSet repository mode as an integer (see docs)." << endl + << "\t \tCombo of modes to set from: DisableRepoManager RndMode " << endl + << "\t \tReleaseMode LenientMode UpdateMode AppInstallMode" << endl << "\tupdaterepos, ur \tupdate repository files" << endl << "\trepos, lr \tlist configured repositories" << endl << "\t [-m] \tformat output suitable for kickstart" << endl << "\t [device] \tuse repos for 'device'" << endl << "\t [flags] \tadditional flags" << endl - << "\t rnd= \tset rnd or release mode (default: take from host)" << endl + << "\t rnd= \tset rnd or release mode (default: take from host)" << endl << "\taddrepo, ar \tadd this repository" << endl << "\t [url] \tspecify URL, if not configured" << endl << "\tremoverepo, rr \tremove this repository from configuration" << endl diff --git a/ssucli/ssucli.h b/ssucli/ssucli.h index 7b4a0eb..81d9a22 100644 --- a/ssucli/ssucli.h +++ b/ssucli/ssucli.h @@ -54,6 +54,7 @@ public slots: void optBrand(QStringList opt); void optDomain(QStringList opt); void optFlavour(QStringList opt); + QString getModeString(int mode); void optMode(QStringList opt); void optModel(QStringList opt); void optRegister(QStringList opt);