Class: RokuBuilder::Inspector

Inherits:
Util
  • Object
show all
Extended by:
Plugin
Defined in:
lib/roku_builder/plugins/inspector.rb

Overview

Collects information on a package for submission

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Plugin

commands, dependencies, parse_options

Methods inherited from Util

#initialize

Constructor Details

This class inherits a constructor from RokuBuilder::Util

Class Method Details

.commandsObject



9
10
11
12
13
14
# File 'lib/roku_builder/plugins/inspector.rb', line 9

def self.commands
  {
    inspect: {device: true, source: true},
    screencapture: {device: true}
  }
end

.parse_options(parser:, options:) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/roku_builder/plugins/inspector.rb', line 16

def self.parse_options(parser:, options:)
  parser.separator "Commands:"
  parser.on("--inspect", "Print out information about a packaged app") do
    options[:inspect] = true
  end
  parser.on("-S", "--screencapture", "Save a screencapture to the output file/folder") do
    options[:screencapture] = true
  end
  parser.separator "Options:"
  parser.on("--password PASSWORD", "Password used for inspect") do |p|
    options[:password] = p
  end
end

Instance Method Details

#inspect(options:) ⇒ Object

Inspects the given pkg



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/roku_builder/plugins/inspector.rb', line 31

def inspect(options:)
  pkg = File.join(@config.in[:folder], @config.in[:file])
  pkg = pkg+".pkg" unless pkg.end_with?(".pkg")
  # upload new key with password
  path = "/plugin_inspect"
  conn = multipart_connection
  payload =  {
    mysubmit: "Inspect",
    passwd: options[:password],
    archive: Faraday::UploadIO.new(pkg, 'application/octet-stream')
  }
  response = conn.post path, payload

  app_name = /App Name:\s*<\/td>\s*<td>\s*<font[^>]*>([^<]*)<\/font>\s*<\/td>/.match(response.body)
  dev_id = nil
  creation_date = nil
  dev_zip = nil
  if app_name
    app_name = app_name[1]
    dev_id = /Dev ID:\s*<\/td>\s*<td>\s*<font[^>]*>([^<]*)<\/font>\s*<\/td>/.match(response.body)[1]
    creation_date = /new Date\(([^)]*)\)/.match(response.body.delete("\n"))[1]
    dev_zip = /dev.zip:\s*<\/td>\s*<td>\s*<font[^>]*>([^<]*)<\/font>\s*<\/td>/.match(response.body)[1]
  else
    app_name = /App Name:[^<]*<div[^>]*>([^<]*)<\/div>/.match(response.body)[1]
    dev_id = /Dev ID:[^<]*<div[^>]*><font[^>]*>([^<]*)<\/font><\/div>/.match(response.body)[1]
    creation_date = /new Date\(([^\/]*)\)/.match(response.body.delete("\n"))[1]
    dev_zip = /dev.zip:[^<]*<div[^>]*><font[^>]*>([^<]*)<\/font><\/div>/.match(response.body)[1]
  end

  info = {app_name: app_name, dev_id: dev_id, creation_date: Time.at(creation_date.to_i).to_s, dev_zip: dev_zip}

  inspect_logger = ::Logger.new(STDOUT)
  inspect_logger.formatter = proc {|_severity, _datetime, _progname, msg|
    "%s\n\r" % [msg]
  }
  inspect_logger.unknown "=============================================================="
  inspect_logger.unknown "App Name: #{info[:app_name]}"
  inspect_logger.unknown "Dev ID: #{info[:dev_id]}"
  inspect_logger.unknown "Creation Date: #{info[:creation_date]}"
  inspect_logger.unknown "dev.zip: #{info[:dev_zip]}"
  inspect_logger.unknown "=============================================================="

end

#screencapture(options:) ⇒ Boolean

Capture a screencapture for the currently sideloaded app

Returns:

  • (Boolean)

    Success

Raises:



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/roku_builder/plugins/inspector.rb', line 77

def screencapture(options:)
  out = @config.out
  payload =  {
    mysubmit: "Screenshot",
    passwd: @dev_password,
    archive: Faraday::UploadIO.new(File::NULL, 'application/octet-stream')
  }
  response = multipart_connection.post "/plugin_inspect", payload

  path = /<img src="([^"]*)">/.match(response.body)
  raise ExecutionError, "Failed to capture screen" unless path
  path = path[1]

  unless out[:file]
    out[:file] = /time=([^"]*)">/.match(response.body)
    out_ext = /dev.([^"]*)\?/.match(response.body)
    out[:file] = "dev_#{out[:file][1]}.#{out_ext[1]}" if out[:file]
  end

  response = simple_connection.get path

  File.open(File.join(out[:folder], out[:file]), "wb") do |io|
    io.write(response.body)
  end
  @logger.info "Screen captured to #{File.join(out[:folder], out[:file])}"
end