1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-04 02:09:32 +02:00

Update to new device DB.

This commit is contained in:
Simo Kinnunen 2014-06-18 22:51:39 +09:00
parent 760e09290f
commit b9484019a3
8 changed files with 32 additions and 53 deletions

View file

@ -613,19 +613,19 @@ program
})
program
.command('generate-fake-device')
.command('generate-fake-device [model]')
.description('generates a fake device for testing')
.option('-n, --number <n>'
, 'how many devices to create (defaults to 1)'
, Number
, 1)
.action(function(options) {
.action(function(model, options) {
var log = logger.createLogger('cli:generate-fake-device')
, fake = require('./util/fakedevice')
, n = options.number
function next() {
return fake.generate()
return fake.generate(model)
.then(function(serial) {
log.info('Created fake device "%s"', serial)

View file

@ -197,7 +197,7 @@ dbapi.saveDeviceIdentity = function(serial, identity) {
, sdk: identity.sdk
, display: identity.display
, phone: identity.phone
, name: identity.name
, product: identity.product
}))
}

View file

@ -1,4 +1,5 @@
var syrup = require('syrup')
var deviceData = require('stf-device-db')
var devutil = require('../../../util/devutil')
var logger = require('../../../util/logger')

View file

@ -27,10 +27,10 @@ module.exports = syrup.serial()
, identity.model
, identity.version
, identity.abi
, identity.name
, identity.sdk
, new wire.DeviceDisplayMessage(identity.display)
, new wire.DevicePhoneMessage(identity.phone)
, identity.product
))
])
})

View file

@ -5,53 +5,29 @@ var logger = require('./logger')
var log = logger.createLogger('util:datautil')
var aliases = {
'KYY22': 'L02'
, 'SH-06DNERV': 'SH-06D_NERV'
}
var datautil = module.exports = Object.create(null)
datautil.applyData = function(device) {
var model = device.model
var name = device.name
if (model) {
var match = deviceData.find({model: model, name: name})
if (!match) {
if (aliases[model]) {
match = deviceData.find({model: aliases[model], name: name})
}
else {
if (!match) {
model = model.replace(/ /g, '_')
match = deviceData.find({model: model, name: name})
if (!match) {
model = model.replace(/_/g, '')
match = deviceData.find({model: model, name: name})
}
}
}
}
var match = deviceData.find({
model: device.model
, name: device.product
})
if (match) {
device.name = match.name.id
device.model = match.name.long
device.releasedAt = match.date
device.image = model + '.jpg' // TODO: check for icon/photo file existence
device.image = match.image
device.cpu = match.cpu
device.memory = match.memory
}
else {
log.warn(
'Device database does not have a match for device "%s" (model "%s")'
'Device database does not have a match for device "%s" (model "%s"/"%s")'
, device.serial
, device.model
, device.product
)
}
}
return device
}

View file

@ -133,7 +133,7 @@ devutil.makeIdentity = function(serial, properties) {
, version = properties['ro.build.version.release']
, sdk = properties['ro.build.version.sdk']
, abi = properties['ro.product.cpu.abi']
, name = properties['ro.product.name']
, product = properties['ro.product.name']
// Remove brand prefix for consistency
if (model.substr(0, brand.length) === brand) {
@ -156,6 +156,6 @@ devutil.makeIdentity = function(serial, properties) {
, version: version
, abi: abi
, sdk: sdk
, name: name
, product: product
}
}

View file

@ -4,9 +4,9 @@ var uuid = require('node-uuid')
var _ = require('lodash')
var dbapi = require('../db/api')
var devices = require('stf-device-db')
var devices = require('stf-device-db/dist/devices-latest')
module.exports.generate = function() {
module.exports.generate = function(wantedModel) {
var serial = util.format(
'fake-%s'
, uuid.v4(null, new Buffer(16)).toString('base64')
@ -20,11 +20,12 @@ module.exports.generate = function() {
, status: 'OFFLINE'
})
.then(function() {
var model = wantedModel || _.sample(Object.keys(devices))
return dbapi.saveDeviceIdentity(serial, {
platform: 'Android'
, manufacturer: 'Foo Electronics'
, operator: 'Loss Networks'
, model: _.sample(Object.keys(devices))
, model: model
, version: '4.1.2'
, abi: 'armeabi-v7a'
, sdk: 8 + Math.floor(Math.random() * 12)
@ -46,6 +47,7 @@ module.exports.generate = function() {
, network: 'LTE'
, phoneNumber: '0000000000'
}
, product: model
})
})
.then(function() {

View file

@ -172,10 +172,10 @@ message DeviceIdentityMessage {
required string model = 5;
required string version = 6;
required string abi = 7;
required string name = 12;
required string sdk = 8;
required DeviceDisplayMessage display = 9;
required DevicePhoneMessage phone = 11;
optional string product = 12;
}
message DeviceProperty {