lib/roku_builder/loader.rb in roku_builder-3.11.0 vs lib/roku_builder/loader.rb in roku_builder-3.11.1

- old
+ new

@@ -13,67 +13,61 @@ # Sideload an app onto a roku device # @param root_dir [String] Path to the root directory of the roku app # @param content [Hash] Hash containing arrays for folder, files, and excludes. Default: nil # @return [String] Build version on success, nil otherwise - def sideload(update_manifest: false, content: nil, infile: nil) + def sideload(update_manifest: false, content: nil, infile: nil, out_file: nil) Navigator.new(**@device_config).nav(commands: [:home]) result = FAILED_SIDELOAD - outfile = nil build_version = nil if infile build_version = ManifestManager.build_version(root_dir: infile) - return [MISSING_MANIFEST, nil] if outfile == MISSING_MANIFEST - outfile = infile + out_file = infile else # Update manifest if update_manifest build_version = ManifestManager.update_build(root_dir: @root_dir) - return [MISSING_MANIFEST, nil] if outfile == MISSING_MANIFEST else build_version = ManifestManager.build_version(root_dir: @root_dir) - return [MISSING_MANIFEST, nil] if outfile == MISSING_MANIFEST end - outfile = build(build_version: build_version, content: content) - return [MISSING_MANIFEST, nil] if outfile == MISSING_MANIFEST + @logger.info "Build: #{out_file}" if out_file + out_file = build(build_version: build_version, out_file: out_file, content: content) end + return [MISSING_MANIFEST, nil] if out_file == MISSING_MANIFEST path = "/plugin_install" # Connect to roku and upload file conn = multipart_connection payload = { mysubmit: "Replace", - archive: Faraday::UploadIO.new(outfile, 'application/zip') + archive: Faraday::UploadIO.new(out_file, 'application/zip') } response = conn.post path, payload # Cleanup - File.delete(outfile) unless infile + File.delete(out_file) if infile.nil? and out_file.nil? result = SUCCESS if response.status==200 and response.body=~/Install Success/ result = IDENTICAL_SIDELOAD if response.status==200 and response.body=~/Identical to previous version/ [result, build_version] end # Build an app to sideload later # @param root_dir [String] Path to the root directory of the roku app # @param build_version [String] Version to assigne to the build. If nil will pull the build version form the manifest. Default: nil - # @param outfile [String] Path for the output file. If nil will create a file in /tmp. Default: nil + # @param out_file [String] Path for the output file. If nil will create a file in /tmp. Default: nil # @param content [Hash] Hash containing arrays for folder, files, and excludes. Default: nil # @return [String] Path of the build - def build(build_version: nil, outfile: nil, content: nil) + def build(build_version: nil, out_file: nil, content: nil) build_version = ManifestManager.build_version(root_dir: @root_dir) unless build_version return MISSING_MANIFEST if build_version == MISSING_MANIFEST content ||= {} - unless content and content[:folders] - content[:folders] = Dir.entries(@root_dir).select {|entry| File.directory? File.join(@root_dir, entry) and !(entry =='.' || entry == '..') } - end - unless content and content[:files] - content[:files] = Dir.entries(@root_dir).select {|entry| File.file? File.join(@root_dir, entry)} - end - content[:excludes] = [] unless content and content[:excludes] - outfile = "/tmp/build_#{build_version}.zip" unless outfile - File.delete(outfile) if File.exist?(outfile) - io = Zip::File.open(outfile, Zip::File::CREATE) + content[:folders] ||= Dir.entries(@root_dir).select {|entry| File.directory? File.join(@root_dir, entry) and !(entry =='.' || entry == '..') } + content[:files] ||= Dir.entries(@root_dir).select {|entry| File.file? File.join(@root_dir, entry)} + content[:excludes] ||= [] + out_file = "/tmp/#{build_version}" unless out_file + out_file = out_file+".zip" unless out_file.end_with?(".zip") + File.delete(out_file) if File.exist?(out_file) + io = Zip::File.open(out_file, Zip::File::CREATE) # Add folders to zip content[:folders].each do |folder| base_folder = File.join(@root_dir, folder) if File.exist?(base_folder) entries = Dir.entries(base_folder) @@ -85,10 +79,10 @@ end end # Add file to zip writeEntries(@root_dir, content[:files], "", content[:excludes], io) io.close() - outfile + out_file end # Remove the currently sideloaded app def unload() path = "/plugin_install"