Skip to content

Commit

Permalink
Mega refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ryukoposting committed Feb 22, 2024
1 parent fa09125 commit 4bb2e73
Show file tree
Hide file tree
Showing 16 changed files with 1,309 additions and 1,242 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/deb-beta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Create beta deb package
on:
push:
tags:
- v*
jobs:
deb:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'
- name: Find package version
id: ver
run: |
echo "full=$(echo $GITHUB_REF | cut -d / -f 3- | sed 's,/,-,g')" >> "$GITHUB_OUTPUT"
echo "num=$(echo $GITHUB_REF | cut -d / -f 3 | cut -c2-)" >> "$GITHUB_OUTPUT"
- name: Build and test with Rake
run: |
gem install bundler
bundle install --jobs 4 --retry 3
bundle exec rake
- name: Install gem2deb
run: |
apt update -yqq && apt install -yqq --no-install-recommends gem2deb
- name: Show version ids
run: |
echo ${{ steps.ver.outputs.num }}
echo ${{ steps.ver.outputs.full }}
- name: Create deb
run: |
export EMAIL=$(git log -n 1 --pretty=format:%ae)
gem2deb -p sensething sensething-${{ steps.ver.outputs.num }}.gem
- name: Upload source artifact
uses: actions/upload-artifact@v4
with:
name: sensething-${{ steps.ver.outputs.full }}-source
path: |
lib/**/*.rb
bin/sensething
Gemfile
Gemfile.lock
Rakefile
LICENSE
sensething.gemspec
- name: Upload source artifact
uses: actions/upload-artifact@v4
with:
name: sensething_${{ steps.ver.outputs.full }}_deb
path: sensething_${{ steps.ver.outputs.num }}_all.deb
4 changes: 2 additions & 2 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Ruby
name: Ruby build and test
on:
push:
branches: [ master ]
Expand All @@ -12,7 +12,7 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '2.7'
ruby-version: '3.0'
- name: Build and test with Rake
run: |
gem install bundler
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ gem 'nokogiri', '~> 1.16.2'
gem 'rackup', '~> 2.1.0'
gem 'rake', '~> 13.0.0'
gem 'rubocop', '~> 1.60'
gem 'sinatra', '~> 4.0.0'
gem 'net-http-server', '~> 0.2.3'

gem 'open3'
22 changes: 6 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,25 @@ GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
base64 (0.2.0)
gserver (0.0.1)
json (2.7.1)
language_server-protocol (3.17.0.3)
minitest (5.21.2)
mocha (2.1.0)
ruby2_keywords (>= 0.0.5)
mustermann (3.0.0)
ruby2_keywords (~> 0.0.1)
net-http-server (0.2.3)
gserver (~> 0.0)
parslet (~> 1.0)
nokogiri (1.16.2-x86_64-linux)
racc (~> 1.4)
open3 (0.1.2)
parallel (1.24.0)
parser (3.3.0.5)
ast (~> 2.4.1)
racc
parslet (1.8.2)
racc (1.7.3)
rack (3.0.9)
rack-protection (4.0.0)
base64 (>= 0.1.0)
rack (>= 3.0.0, < 4)
rack-session (2.0.0)
rack (>= 3.0.0)
rackup (2.1.0)
rack (>= 3)
webrick (~> 1.8)
Expand All @@ -46,13 +43,6 @@ GEM
parser (>= 3.2.1.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
sinatra (4.0.0)
mustermann (~> 3.0)
rack (>= 3.0.0, < 4)
rack-protection (= 4.0.0)
rack-session (>= 2.0.0, < 3)
tilt (~> 2.0)
tilt (2.3.0)
unicode-display_width (2.5.0)
webrick (1.8.1)

Expand All @@ -62,12 +52,12 @@ PLATFORMS
DEPENDENCIES
minitest (~> 5.21.2)
mocha (~> 2.1.0)
net-http-server (~> 0.2.3)
nokogiri (~> 1.16.2)
open3
rackup (~> 2.1.0)
rake (~> 13.0.0)
rubocop (~> 1.60)
sinatra (~> 4.0.0)

BUNDLED WITH
2.4.10
35 changes: 22 additions & 13 deletions bin/sensething
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
require 'sensething'
require 'csv'
require 'json'
require 'sinatra'
require 'nokogiri'

set :run, false
require 'net/http/server'

def gather_sensors
result = {}
Expand Down Expand Up @@ -146,16 +144,17 @@ def log_sensors(names, format, interval, units, timer)
end
end

class Webui < Sinatra::Base
@sensors = []
class << self
attr_reader :sensors
class Webui
attr_reader :sensors

def initialize
@sensors = []
end

get '/' do
def html
sensor_groups = {}

self.class.sensors.each do |sensor|
sensors.each do |sensor|
group_name, subname = sensor.name.split '/', 2
sensor_groups[group_name] = [] unless sensor_groups[group_name]
sensor_groups[group_name] << [subname, sensor]
Expand Down Expand Up @@ -185,14 +184,24 @@ class Webui < Sinatra::Base
end

def serve_webui(address, port)
webui = Webui.new

SenseThing.discover_devices do |dev|
dev.each_sensor do |sensor|
Webui.sensors << sensor
webui.sensors << sensor
end
end
Webui.set :bind, address if address
Webui.set :port, port if port
Webui.run!

address ||= '127.0.0.1'
port = port ? Integer(port) : 4567

Net::HTTP::Server.run(port: port, host: address) do |request, _stream|
headers = {
'Content-Type': 'text/html'
}

[200, headers, [webui.html]]
end
end

args = SenseThing::Cli.parse_command_line
Expand Down
12 changes: 6 additions & 6 deletions lib/sensething/cli.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'optparse'
require 'optparse/version'
require 'set'
require 'io/console'

Expand All @@ -17,6 +18,10 @@ def initialize(name, &blk)
on('-h', '--help', 'Show help message and exit') do
full_help_message
end
on('-v', '--version', 'Show version and exit') do
puts "SenseThing #{VERSION}"
exit 0
end
end

def command(name, &block)
Expand Down Expand Up @@ -99,12 +104,7 @@ def match_cmd(argv)
end

@option_parser = Command.new('sensething') do |parser| # rubocop:disable Metrics/BlockLength
parser.banner = 'sensething'

parser.on '-v', '--version', 'Show version info and exit' do
puts "Sensething #{VERSION}"
exit 0
end
parser.banner = 'SenseThing'

parser.on '--license', 'Show license info and exit' do
puts <<~GNU
Expand Down
6 changes: 4 additions & 2 deletions lib/sensething/nvidia/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

require_relative '../common/attribute'

module Nvidia
class Attribute < SenseThing::Attribute
module SenseThing
module Nvidia
class Attribute < SenseThing::Attribute
end
end
end
16 changes: 9 additions & 7 deletions lib/sensething/nvidia/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

require_relative '../common/device'

module Nvidia
class Device < SenseThing::Device
attr_reader :name, :uuid
module SenseThing
module Nvidia
class Device < SenseThing::Device
attr_reader :name, :uuid

def initialize(name, uuid)
super()
@name = name
@uuid = uuid
def initialize(name, uuid)
super()
@name = name
@uuid = uuid
end
end
end
end
Loading

0 comments on commit 4bb2e73

Please sign in to comment.