Refactor to not use ConnectionParams

This commit is contained in:
Juan Cruz Viotti 2015-01-12 08:40:27 -03:00
parent 243a05a4e2
commit 975e133d5a
2 changed files with 9 additions and 61 deletions

View File

@ -10,16 +10,13 @@ errors = require('../errors/errors')
exports.download = (params, options) ->
# TODO: Evaluate if ConnectionParams is a good name for this object
# as it includes an application id, which is not connection related
# Maybe we should move appId outside this class?
connectionParams = new resin.connection.ConnectionParams
osParams =
network: options.network
wifiSsid: options.ssid
wifiKey: options.key
appId: params.id
fileName = resin.models.os.generateCacheName(connectionParams)
fileName = resin.models.os.generateCacheName(osParams)
outputFile = options.output or path.join(resin.settings.get('directories.os'), fileName)
@ -37,7 +34,7 @@ exports.download = (params, options) ->
bar = null
received = 0
resin.models.os.download connectionParams, outputFile, callback, (state) ->
resin.models.os.download osParams, outputFile, callback, (state) ->
# TODO: Allow quieting this progress bar
bar ?= new ProgressBar 'Downloading device OS [:bar] :percent :etas',

View File

@ -3,80 +3,31 @@ _ = require('lodash')
# @nodoc
isQuiet = false
# Change log quietness
#
# @param {Boolean} quiet quietness
#
# @note If quiet is true, only resin.log.info will be quieted
#
# @example Set quietness
# resin.log.setQuiet(true)
#
exports.templates =
error: '<%= text %>'
warn: '<%= text %>'
info: '<%= text %>'
log: '<%= text %>'
exports.setQuiet = (quiet) ->
isQuiet = !!quiet
# Check quietness
#
# @return {Boolean} is quiet
#
# @example Check quietness
# resin.log.isQuiet()
#
exports.isQuiet = ->
return isQuiet
# Log an error
#
# @param {...String} message message
#
# @example Log an error
# resin.log.error('Something went wrong!')
#
exports.error = (args...) ->
console.error.apply(null, args)
# Log a warning
#
# @param {...String} message message
#
# @example Log a warning
# resin.log.warning('Something might happened!')
#
exports.warning = (args...) ->
console.warn.apply(null, args)
# Log info
#
# @param {...String} message message
#
# @example Log info
# resin.log.info('Look!')
#
exports.info = (args...) ->
return if exports.isQuiet()
console.info.apply(null, args)
# Log out
#
# @param {...String} message message
#
# @note This will not be quieted even if setQuiet is set to true
#
# @example Log out
# resin.log.out('Hello World!')
#
exports.out = (args...) ->
console.log.apply(null, args)
# Log an array
#
# It will iterate trough the array, calling logFunction for every item
#
# @param {Array} array array
# @param {Function} logFunction log function (e.g: resin.log.info)
#
# @throw {Error} Will throw if logFunction is not a function
#
exports.array = (array, logFunction) ->
return if not array?