add show-status command

It shows BUILD_ID, AOSP tag, platform security patch level and stock OS image availability for
each of specified devices.
This commit is contained in:
Dmitry Muhomor 2023-08-26 18:27:27 +03:00 committed by Daniel Micay
parent 3bf5977e81
commit 2aaa970886
3 changed files with 94 additions and 0 deletions

View file

@ -0,0 +1,81 @@
import { Command } from '@oclif/command'
import chalk from 'chalk'
import { DEVICE_CONFIG_FLAGS, DeviceConfig, getDeviceNames, loadDeviceConfigs } from '../config/device'
import { ImageType, loadBuildIndex } from '../images/build-index'
import { DeviceImage } from '../images/device-image'
import { updateMultiMap } from '../util/data'
import { loadBuildIdToTagMap } from './update-aosp-tag-index'
export default class ShowStatus extends Command {
static flags = {
...DEVICE_CONFIG_FLAGS
}
async run() {
let { flags } = this.parse(ShowStatus)
let configs = await loadDeviceConfigs(flags.devices)
let buildIdMap = new Map<string, DeviceConfig[]>()
// platform security patch levels
let psplMap = new Map<string, DeviceConfig[]>()
let imageIndex = await loadBuildIndex()
let presentImages = new Map<string, DeviceConfig[]>()
let missingImages = new Map<string, DeviceConfig[]>()
let unknownImages = new Map<string, DeviceConfig[]>()
let imageTypes = [ImageType.Factory, ImageType.Ota]
for (let config of configs) {
updateMultiMap(buildIdMap, config.device.build_id, config)
updateMultiMap(psplMap, config.device.platform_security_patch_level_override, config)
for (let type of imageTypes) {
let image: DeviceImage
try {
image = DeviceImage.get(imageIndex, config, config.device.build_id, type)
} catch {
updateMultiMap(unknownImages, type, config)
continue
}
if (await image.isPresent()) {
updateMultiMap(presentImages, type, config)
} else {
updateMultiMap(missingImages, type, config)
}
}
}
let buildIdToTag = await loadBuildIdToTagMap()
this.log(chalk.bold('Tag | Build ID:'))
for (let [buildId, configs] of buildIdMap.entries()) {
this.log(`${buildIdToTag?.get(buildId) ?? '[no tag]'} | ${buildId}: ` + getDeviceNames(configs))
}
if (psplMap.size > 0) {
this.log(chalk.bold('\nPlatform security patch level:'))
for (let [spl, configs] of psplMap.entries()) {
this.log((spl === undefined ? 'default' : spl) + ': ' + getDeviceNames(configs))
}
}
this.log(chalk.bold('\nStock image:'))
for (let type of imageTypes) {
this.log(` ${type}:`)
this.maybeLogImageStatus(type, presentImages, 'present')
this.maybeLogImageStatus(type, missingImages, 'known')
this.maybeLogImageStatus(type, unknownImages, chalk.bold(chalk.red('unknown')))
}
if (unknownImages.size !== 0) {
process.exit(1)
}
}
maybeLogImageStatus(type: ImageType, map: Map<string, DeviceConfig[]>, mapName: string) {
let devices = map.get(type)
if (devices !== undefined && devices.length > 0) {
this.log(` ${mapName}: ${getDeviceNames(devices)}`)
}
}
}

View file

@ -231,3 +231,7 @@ async function loadDeviceConfigsFromPath(configPath: string): Promise<Promise<De
}
throw new Error(`Unknown config type ${type}`)
}
export function getDeviceNames(configs: DeviceConfig[]) {
return configs.map(c => c.device.name).join(' ')
}

View file

@ -17,3 +17,12 @@ export function setDifference<Value>(a: Set<Value>, b: Set<Value>) {
}
return set
}
export function updateMultiMap<K, V>(map: Map<K, V[]>, key: K, value: V) {
let cur = map.get(key)
if (cur === undefined) {
map.set(key, [value])
} else {
cur.push(value)
}
}