Module: Prremote::RuntimeManager
- Defined in:
- lib/prremote/runtime_manager.rb
Constant Summary collapse
- BOARDS =
%w[pico picow esp32 esp32c6].freeze
- ESP32_BOARDS =
%w[esp32 esp32c6].freeze
Class Method Summary collapse
-
.artifact_filename(version, board) ⇒ Object
Pico boards ship as UF2 (copied to the BOOTSEL drive); ESP32 family ships as a single merged .bin (bootloader + partition table + app) flashed at 0x0 with esptool.
- .cache_dir ⇒ Object
- .cached_path(version, board) ⇒ Object
- .download(url, dest, redirects = 5) ⇒ Object
- .fetch(version, board) ⇒ Object
- .release_url(version, board) ⇒ Object
Class Method Details
.artifact_filename(version, board) ⇒ Object
Pico boards ship as UF2 (copied to the BOOTSEL drive); ESP32 family ships as a single merged .bin (bootloader + partition table + app) flashed at 0x0 with esptool.
13 14 15 16 |
# File 'lib/prremote/runtime_manager.rb', line 13 def self.artifact_filename(version, board) ext = ESP32_BOARDS.include?(board) ? 'bin' : 'uf2' "prremote-#{board}-runtime-#{version}.#{ext}" end |
.cache_dir ⇒ Object
22 23 24 |
# File 'lib/prremote/runtime_manager.rb', line 22 def self.cache_dir File.join(Dir.home, '.prremote', 'runtime') end |
.cached_path(version, board) ⇒ Object
26 27 28 |
# File 'lib/prremote/runtime_manager.rb', line 26 def self.cached_path(version, board) File.join(cache_dir, artifact_filename(version, board)) end |
.download(url, dest, redirects = 5) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/prremote/runtime_manager.rb', line 42 def self.download(url, dest, redirects = 5) raise 'Too many redirects' if redirects.zero? uri = URI.parse(url) response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http| http.request(Net::HTTP::Get.new(uri)) end case response when Net::HTTPRedirection download(response['Location'], dest, redirects - 1) when Net::HTTPSuccess File.binwrite(dest, response.body) else FileUtils.rm_f(dest) raise "Download failed: #{response.code} #{response.}" end end |
.fetch(version, board) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/prremote/runtime_manager.rb', line 30 def self.fetch(version, board) path = cached_path(version, board) return path if File.exist?(path) FileUtils.mkdir_p(cache_dir) $stderr.print "Downloading #{artifact_filename(version, board)}..." $stderr.flush download(release_url(version, board), path) warn ' done.' path end |
.release_url(version, board) ⇒ Object
18 19 20 |
# File 'lib/prremote/runtime_manager.rb', line 18 def self.release_url(version, board) "https://github.com/lumbermill/prremote/releases/download/runtime-#{version}/#{artifact_filename(version, board)}" end |