mirror of
https://github.com/openstf/stf
synced 2025-10-06 03:50:04 +02:00
Move utility plugins into their own folder. They don't go into the support folder because they're not standalone units and require interaction with the main units. Further refactoring pending.
This commit is contained in:
parent
252f778598
commit
361bf9caea
13 changed files with 20 additions and 22 deletions
20
lib/units/device/plugins/util/data.js
Normal file
20
lib/units/device/plugins/util/data.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
var syrup = require('stf-syrup')
|
||||
var deviceData = require('stf-device-db')
|
||||
|
||||
var logger = require('../../../../util/logger')
|
||||
|
||||
module.exports = syrup.serial()
|
||||
.dependency(require('./identity'))
|
||||
.define(function(options, identity) {
|
||||
var log = logger.createLogger('device:plugins:data')
|
||||
|
||||
function find() {
|
||||
var data = deviceData.find(identity)
|
||||
if (!data) {
|
||||
log.warn('Unable to find device data', identity)
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
return find()
|
||||
})
|
71
lib/units/device/plugins/util/display.js
Normal file
71
lib/units/device/plugins/util/display.js
Normal file
|
@ -0,0 +1,71 @@
|
|||
var util = require('util')
|
||||
|
||||
var syrup = require('stf-syrup')
|
||||
var EventEmitter = require('eventemitter3').EventEmitter
|
||||
|
||||
var logger = require('../../../../util/logger')
|
||||
var streamutil = require('../../../../util/streamutil')
|
||||
|
||||
module.exports = syrup.serial()
|
||||
.dependency(require('../../support/adb'))
|
||||
.dependency(require('../../resources/minicap'))
|
||||
.dependency(require('../service'))
|
||||
.dependency(require('../screen/options'))
|
||||
.define(function(options, adb, minicap, service, screenOptions) {
|
||||
var log = logger.createLogger('device:plugins:display')
|
||||
|
||||
function Display(id, properties) {
|
||||
this.id = id
|
||||
this.properties = properties
|
||||
}
|
||||
|
||||
util.inherits(Display, EventEmitter)
|
||||
|
||||
Display.prototype.updateRotation = function(newRotation) {
|
||||
log.info('Rotation changed to %d', newRotation)
|
||||
this.properties.rotation = newRotation
|
||||
this.emit('rotationChange', newRotation)
|
||||
}
|
||||
|
||||
function infoFromMinicap(id) {
|
||||
return minicap.run(util.format('-d %d -i', id))
|
||||
.then(streamutil.readAll)
|
||||
.then(function(out) {
|
||||
var match
|
||||
if ((match = /^ERROR: (.*)$/.exec(out))) {
|
||||
throw new Error(match[1])
|
||||
}
|
||||
|
||||
try {
|
||||
return JSON.parse(out)
|
||||
}
|
||||
catch (e) {
|
||||
throw new Error(out.toString())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function infoFromService(id) {
|
||||
return service.getDisplay(id)
|
||||
}
|
||||
|
||||
function readInfo(id) {
|
||||
log.info('Reading display info')
|
||||
return infoFromService(id)
|
||||
.catch(function() {
|
||||
return infoFromMinicap(id)
|
||||
})
|
||||
.then(function(properties) {
|
||||
properties.url = screenOptions.publicUrl
|
||||
return new Display(id, properties)
|
||||
})
|
||||
}
|
||||
|
||||
return readInfo(0).then(function(display) {
|
||||
service.on('rotationChange', function(data) {
|
||||
display.updateRotation(data.rotation)
|
||||
})
|
||||
|
||||
return display
|
||||
})
|
||||
})
|
16
lib/units/device/plugins/util/flags.js
Normal file
16
lib/units/device/plugins/util/flags.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
var syrup = require('stf-syrup')
|
||||
|
||||
module.exports = syrup.serial()
|
||||
.dependency(require('./data'))
|
||||
.define(function(options, data) {
|
||||
return {
|
||||
has: function(flag) {
|
||||
return data && data.flags && !!data.flags[flag]
|
||||
}
|
||||
, get: function(flag, defaultValue) {
|
||||
return data && data.flags && data.flags[flag] !== void 0
|
||||
? data.flags[flag]
|
||||
: defaultValue
|
||||
}
|
||||
}
|
||||
})
|
22
lib/units/device/plugins/util/identity.js
Normal file
22
lib/units/device/plugins/util/identity.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
var syrup = require('stf-syrup')
|
||||
|
||||
var devutil = require('../../../../util/devutil')
|
||||
var logger = require('../../../../util/logger')
|
||||
|
||||
module.exports = syrup.serial()
|
||||
.dependency(require('../../support/properties'))
|
||||
.dependency(require('./display'))
|
||||
.dependency(require('./phone'))
|
||||
.define(function(options, properties, display, phone) {
|
||||
var log = logger.createLogger('device:plugins:identity')
|
||||
|
||||
function solve() {
|
||||
log.info('Solving identity')
|
||||
var identity = devutil.makeIdentity(options.serial, properties)
|
||||
identity.display = display.properties
|
||||
identity.phone = phone
|
||||
return identity
|
||||
}
|
||||
|
||||
return solve()
|
||||
})
|
21
lib/units/device/plugins/util/phone.js
Normal file
21
lib/units/device/plugins/util/phone.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
var syrup = require('stf-syrup')
|
||||
|
||||
var logger = require('../../../../util/logger')
|
||||
|
||||
module.exports = syrup.serial()
|
||||
.dependency(require('../service'))
|
||||
.define(function(options, service) {
|
||||
var log = logger.createLogger('device:plugins:phone')
|
||||
|
||||
function fetch() {
|
||||
log.info('Fetching phone info')
|
||||
return service.getProperties([
|
||||
'imei'
|
||||
, 'phoneNumber'
|
||||
, 'iccid'
|
||||
, 'network'
|
||||
])
|
||||
}
|
||||
|
||||
return fetch()
|
||||
})
|
|
@ -3,8 +3,8 @@ var _ = require('lodash')
|
|||
var tr = require('transliteration')
|
||||
|
||||
module.exports = syrup.serial()
|
||||
.dependency(require('../identity'))
|
||||
.dependency(require('../data'))
|
||||
.dependency(require('./identity'))
|
||||
.dependency(require('./data'))
|
||||
.define(function(options, identity, data) {
|
||||
function createSlug() {
|
||||
var model = identity.model
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue