Class: RokuBuilder::Loader

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

Overview

Load/Unload/Build roku applications

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Plugin

commands, dependencies, parse_options, validate

Methods inherited from Util

#initialize

Constructor Details

This class inherits a constructor from RokuBuilder::Util

Class Method Details

.commandsObject



13
14
15
16
17
18
19
20
# File 'lib/roku_builder/plugins/loader.rb', line 13

def self.commands
  {
    sideload: {source: true, device: true, stage: true},
    build: {source: true, stage: true, exclude: true},
    delete: {device: true},
    squash: {device: true}
  }
end

.dependenciesObject



48
49
50
# File 'lib/roku_builder/plugins/loader.rb', line 48

def self.dependencies
  [Navigator]
end

.parse_options(parser:, options:) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/roku_builder/plugins/loader.rb', line 22

def self.parse_options(parser:, options:)
  parser.separator "Commands:"
  parser.on("-l", "--sideload", "Sideload an app") do
    options[:sideload] = true
  end
  parser.on("-d", "--delete", "Delete the currently sideloaded app") do
    options[:delete] = true
  end
  parser.on("-b", "--build", "Build a zip to be sideloaded") do
    options[:build] = true
  end
  parser.on("--squash", "Convert currently sideloaded application to squashfs") do
    options[:squash] = true
  end
  parser.separator "Options:"
  parser.on("-x", "--exclude", "Apply exclude config to sideload") do
    options[:exclude] = true
  end
  parser.on("--remote-debug", "Sideload will enable remote debug") do
    options[:remoteDebug] = true
  end
  parser.on("--build-dir DIR", "The directory to load files from when building the app") do |dir|
    options[:build_dir] = dir
  end
end

Instance Method Details

#build(options:) ⇒ Object

Build an app to sideload later



83
84
85
86
87
88
89
90
91
# File 'lib/roku_builder/plugins/loader.rb', line 83

def build(options:)
  @options = options
  build_zip(setup_build_content)
  if options.command == :build or (options.command == :sideload and options[:out])
    @logger.info "File Path: "+file_path(:out)
  end
  @config.in = @config.out #setting in path for possible sideload
  file_path(:out)
end

#copy(options:, path:) ⇒ Object



123
124
125
126
127
# File 'lib/roku_builder/plugins/loader.rb', line 123

def copy(options:, path:)
  @options = options
  @target = path
  copy_channel_files(setup_build_content)
end

#delete(options:, ignoreFailure: false) ⇒ Object

Remove the currently sideloaded app



94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/roku_builder/plugins/loader.rb', line 94

def delete(options:, ignoreFailure: false)
  payload =  {
    mysubmit: make_param("Delete"),
    archive: make_param("", "application/octet-stream")
  }
  response = nil
  multipart_connection do |conn|
    response = conn.post "/plugin_install", payload
  end
  unless response.status == 200 and response.body =~ /Delete Succeeded/ or ignoreFailure
    raise ExecutionError, "Failed Unloading"
  end
end

#initObject



9
10
11
# File 'lib/roku_builder/plugins/loader.rb', line 9

def init
  @warningFileSize = 500 * 1024
end

#sideload(options:, device: nil) ⇒ Object

Sideload an app onto a roku device



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/roku_builder/plugins/loader.rb', line 53

def sideload(options:, device: nil)
  if !options[:logfile].nil?
    if options[:logfile].match("config")
      options[:logfile] = @config.console_log
    end
    if options[:clearfile]
      if !options[:logfile].nil?
        File.delete(options[:logfile]) if File.exist?(options[:logfile])
      else
        @logger.unknown "Cannot clear, console_log file not set."
      end
    end
  end
  did_build = false
  unless options[:in]
    did_build = true
    build(options: options)
  end
  keep_build_file = is_build_command(options) and options[:out]
  upload(options: options, device: device)
  # Cleanup
  begin
    File.delete(file_path(:in)) if did_build and not keep_build_file
  rescue Errno::EACCES
    @logger.warn "Unable to delete: " + file_path(:in)
  end
end

#squash(options:, device: nil, ignoreFailure: false) ⇒ Object

Convert sideloaded app to squashfs



109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/roku_builder/plugins/loader.rb', line 109

def squash(options:, device: nil, ignoreFailure: false)
  payload =  {
    mysubmit: "Convert to squashfs",
    archive: make_param("", "application/octet-stream")
  }
  response = nil
  multipart_connection(device: device) do |conn|
    response = conn.post "/plugin_install", payload
  end
  unless response.status == 200 and response.body =~ /Conversion succeeded/ or ignoreFailure
    raise ExecutionError, "Failed Converting to Squashfs"
  end
end