librelist archives

« back to archive

Re: More silliness... I don't know what I broke

Re: More silliness... I don't know what I broke

From:
Scott Harman
Date:
2013-08-07 @ 05:45
Previous message rejected due to length - trying again

> Hi guys
> I was so very close to having this script working in both Red and Green
> Shoes (no joy at all under Shoes4 sadly)
> I've included the whole code inline below, and it's currently configured
> for Red Shoes (even though the stack and flow blocks are miles out of
> alignment
>
> Basically, it connects to one of of servers, and retrieves a table from a
> particular SNMP OID, which shows the amount of storage we have per server
> (reported in what we call protons, but are effectively 128KB blocks)
> Normally, we'd fetch this every 5 minutes, but I'm fetching every 10
> seconds for debug purposes
>
> I've finally managed to work out how to store an appropriate string in
> case the manager isn't running just for test purposes
> What's weird is that under green shoes, it now crashes on 2nd execution,
> but on red shoes, it doesn't seem to loop.
> I have been trying to replace the content of the output block each time,
> and before I did this, red shoes was just appending what was there (so I
> added a clock to see what it was doing)
>
> It appears to be a basic flow control issue, and all I really want to do
> is create a lightweight deployable app that a customer can just run to get
> space reporting on their media manager's desktops.
> At the moment, they have to connect to a web service for our 'manager'
> app, which isn't really safe for non-technical users to access (as it's an
> engineering tool) and we don't report space in anything other than
> 'protons' and 'atoms'
> I've hardcoded our storage matrix into the app, so it makes it trivial to
> choose the right combination
>
> Does anyone have any ideas of what I'm doing wrong?
> Kind regards,
> Scott
> ========
>
> #Uncomment for Red Shoes (and vice versa)
> Shoes.setup do
>   gem 'snmp'
>   require 'snmp'
>   #require 'optparse'
> end
> #
> #
> #Uncomment for Green Shoes (and vice versa)
> #begin
> #  gem'green_shoes'
> #rescue LoadError
> #  system("gem install green_shoes")
> #end
> #begin
> #  gem 'snmp'
> #rescue LoadError
> #  system("gem install snmp")
> #end
> #require 'green_shoes'
> #require 'snmp'
>
> class Conf
>   class << self
>     attr_accessor :hostname, :framerate, :vidtype, :videoformat,
> :videonumber, :browseformat, :browsenumber, :audioformat, :audionumber
>     def hostname
>       @hostname
>     end
>
>     def framerate
>       @framerate
>     end
>
>     def vidtype
>       @vidtype
>     end
>
>     def audioformat
>       @audioformat
>     end
>
>     def videoformat
>       @videoformat
>     end
>
>     def browseformat
>       @browseformat
>     end
>
>     def audionumber
>       @audionumber
>     end
>
>     def videonumber
>       @videonumber
>     end
>
>     def browsenumber
>       @browsenumber
>     end
>   end
> end
>
> class SNMPManager < Shoes
>   url "/", :configure
>   url "/settings", :check_settings
>   url "/update", :update_capacity
>
>   include SNMP
>   #attr_accessor :hostname, :framerate, :vidtype
>   def initialize(params = {})
>     # @step=0
>    #  Gtk.running=true
>
>   end
>
>   def LookupRatio(formatnumber)
> #text too long - dummy entry
>     return 1
>   end
>
>   def AudioFormats(framerate)
>     @NTSCformats = {
>       24=>"Legacy 8 Audio 4 channel 30 fps",
>       68=>"Legacy 9 Audio 4 channel 30 fps",
>       265=>"Audio 4 channel 16bit 30 fps",
>       269=>"Audio 4 channel 24bit 30 fps",
>       270=>"Audio 8 channel 16bit 30 fps",
>       271=>"Audio 8 channel 24bit 30 fps"
>     }
>     @PALformats = {
>       33=>"Legacy 8 Audio 4 channel 25 fps",
>       73=>"Legacy 9 Audio 4 channel 25 fps",
>       521=>"Audio 4 channel 16bit 25 fps",
>       522=>"Audio 4 channel 24bit 25 fps",
>       523=>"Audio 8 channel 16bit 25 fps",
>       524=>"Audio 8 channel 24bit 25 fps"
>     }
>
>     if (Conf.framerate == 25)
>       choicelist=@PALformats
>     elsif (Conf.framerate == 30)
>       choicelist=@NTSCformats
>     end
>     Conf.audioformat=choicelist.values[1]
>     Conf.audionumber=choicelist.keys[1]
>     list_box :items => choicelist.values, :choose => choicelist.values[1]
> do |list|
>       Conf.audioformat=list.text
>       Conf.audionumber=choicelist.key(list.text)
>     end
>
>   end
>
>   def VideoFormats(framerate, vidtype)
>     @SDNTSCformats = {
>       17=>"Legacy 8 Mpeg 30 480i30",
>       #      18=>"Legacy 8 Mpeg 40 480i30",
>       #      19=>"Legacy 8 Mpeg 50 480i30",
>       65=>"Legacy 9 Mpeg 30 480i30",
>       66=>"Legacy 9 Mpeg 40 480i30",
>       67=>"Legacy 9 Mpeg 50 480i30",
>       86=>"Legacy 9E Mpeg 30 480i30",
>       87=>"Legacy 9E Mpeg 40 480i30",
>       88=>"Legacy 9E Mpeg 50 480i30",
>       #   262=>"Mpeg 30 480i30",
>       #   263=>"Mpeg 40 480i30",
>       #  264=>"Mpeg 50 480i30",
>       #  275=>"Mpeg 30 480i30 15f",
>       #  276=>"Mpeg 40 480i30 11f",
>       #  277=>"Mpeg 50 480i30 10f",
>       710=>"DVCPRO50 525i30 8f",
>       711=>"DVCPRO25 525i30 10f",
>       712=>"DV 525i30 10f"
>     }
>     @HDNTSCformats = {
>       #      20=>"Legacy 8 DV100 720p60",
>       #      23=>"Legacy 8 DV100 1080i30",
>       78=>"Legacy 9 DV100 720p60",
>       81=>"Legacy 9 DV100 1080i30",
>       256=>"DV100 720p60",
>       259=>"DV100 1080i30",
>       280=>"DV100 720p60 6f",
>       281=>"DV100 1080i30 6f",
>       600=>"AVC-I 50 1080i30 9f",
>       601=>"AVC-I 100 1080i30 7f",
>       602=>"AVC-I 50 720p60 9f",
>       603=>"AVC-I 100 720p60 7f",
>       622=>"AVC-I 100 1080p60 6f",
>       623=>"AVC-I 200 1080p60 3f"
>     }
>     @SDPALformats = {
>       26=>"Legacy 8 Mpeg 30 576i25",
>       #      27=>"Legacy 8 Mpeg 40 576i25",
>       #      28=>"Legacy 8 Mpeg 50 576i25",
>       70=>"Legacy 9 Mpeg 30 576i25",
>       71=>"Legacy 9 Mpeg 40 576i25",
>       72=>"Legacy 9 Mpeg 50 576i25",
>       89=>"Legacy 9E Mpeg 30 576i25",
>       90=>"Legacy 9E Mpeg 40 576i25",
>       91=>"Legacy 9E Mpeg 50 576i25",
>       #   518=>"Mpeg 30 576i25",
>       #   519=>"Mpeg 40 576i25",
>       #   520=>"Mpeg 50 576i25",
>       #   525=>"Mpeg 30 576i25 14f",
>       #   526=>"Mpeg 40 576i25 12f",
>       #   527=>"Mpeg 50 576i25 12f",
>       700=>"DVCPRO50 625i25  7f",
>       701=>"DVCPRO25 625i25 10f",
>       702=>"DV 625i25 10f"
>     }
>     @HDPALformats = {
>       512=>"DV100 720p50",
>       515=>"DV100 1080i25",
>       530=>"DV100 1080i25 5f",
>       610=>"AVC-I 50 1080i25 11f",
>       611=>"AVC-I 100 1080i25 5f",
>       612=>"AVC-I 50 720p50 11f",
>       613=>"AVC-I 100 720p50 6f",
>       620=>"AVC-I 100 1080p50 5f",
>       621=>"AVC-I 200 1080p50 3f"
>     }
>
>     if (Conf.framerate == 25 &&  Conf.vidtype == "HD")
>       choicelist = @HDPALformats
>     elsif (Conf.framerate == 25 && Conf.vidtype == "SD")
>       choicelist = @SDPALformats
>     elsif (Conf.framerate == 30 && Conf.vidtype == "HD")
>       choicelist = @HDNTSCformats
>     elsif (Conf.framerate == 30 &&  Conf.vidtype == "SD")
>       choicelist = @SDNTSCformats
>     end
>     Conf.videoformat=choicelist.values[1]
>     Conf.videonumber=choicelist.keys[1]
>     list_box :items => choicelist.values, :choose => choicelist.values[1]
> do |list|
>       Conf.videoformat=list.text
>       Conf.videonumber=choicelist.key(list.text)
>     end
>
>   end
>
>   def BrowseFormats(framerate)
>     @BNTSCformats = {
>       #      37=>"Legacy 8 Browse Video 30 fps",
>       77=>"Legacy 9 Browse Video 30 fps",
>       260=>"Browse Video 30 fps"
>       #   291=>"MPEG-2 Browse Video 30 fps",
>       #   301=>"H.264 Browse Video 30 fps",
>       #   303=>"H.264 SIF Browse Video 30 fps",
>       #    311=>"H.264 640x360 30 fps",
>       #    313=>"H.264 640x480 30 fps"
>     }
>     @BPALformats = {
>       #      34=>"Legacy 8 Browse Video 25 fps",
>       74=>"Legacy 9 Browse Video 25 fps",
>       #    290=>"MPEG-2 Browse Video 25 fps",
>       #    300=>"H.264 Browse Video 25 fps",
>       #   302=>"H.264 SIF Browse Video 25 fps",
>       #    310=>"H.264 640x360 25 fps",
>       #   312=>"H.264 640x480 25 fps",
>       516=>"Browse Video 25 fps"
>     }
>
>     if (Conf.framerate == 25)
>       choicelist=@BPALformats
>     elsif (Conf.framerate == 30)
>       choicelist=@BNTSCformats
>     end
>     Conf.browseformat=choicelist.values[1]
>     Conf.browsenumber=choicelist.keys[1]
>     list_box :items => choicelist.values, :choose => choicelist.values[1]
> do |list|
>       Conf.browseformat=list.text
>       Conf.browsenumber=choicelist.key(list.text)
>     end
>
>   end
>
>   def configure
>     Conf.new
>     Conf.framerate=25
>     Conf.vidtype="SD"
>     background rgb(50,50,125)
>     #style Shoes::Para, stroke: white, size: 'xx-small'
>     # green shoes - x-small is small enough   style Shoes::Para, :stroke=>
> white, :size=> 'x-small'
>     style Shoes::Para, :stroke=> white, :size=> 'xx-small'
>     stack do
>       para "Enter Hostname:"
>       edit_line("localhost") do |e|
>         Conf.hostname = e.text
>       end
>
>       para "Choose an frame rate:"
>       list_box :items => [25, 30],:choose=>Conf.framerate do |list|
>         Conf.framerate =  list.text.to_i
>       end
>       para "Choose SD or HD formats"
>       list_box :items => ["SD", "HD"],:choose=>Conf.vidtype do |list|
>         Conf.vidtype = list.text
>       end
>     end
>
>     button "Confirm Settings" do
>       visit "/settings"
>     end
>   end
>
>   def check_settings
>     background rgb(50,50,125)
>     #style Shoes::Para, stroke: white, size: 'xx-small'
>     # green shoes - x-small is small enough   style Shoes::Para, :stroke=>
> white, :size=> 'x-small'
>     style Shoes::Para, :stroke=> white, :size=> 'xx-small'
>     stack do
>       para "Choose an Video format:"
>       VideoFormats(Conf.framerate, Conf.vidtype)
>
>       para "Choose an Audio format:"
>       AudioFormats(Conf.framerate)
>
>       para "Choose Browse format:"
>       BrowseFormats(Conf.framerate)
>
>       button "Update Settings" do
>         visit "/update"
>       end
>     end
>   end
>
>   def update_capacity
>     background rgb(50,50,125)
>     #style Shoes::Para, stroke: white, size: 'xx-small'
>     # green shoes - x-small is small enough   style Shoes::Para, :stroke=>
> white, :size=> 'x-small'
>     style Shoes::Para, :stroke=> white, :size=> '8'
>     output.new
>     every(10) {
>       output.new
>     }
>   end
>
>   def calchours(protons)
>     rate = (protons.to_i /
> 
(LookupRatio(Conf.videonumber)+LookupRatio(Conf.audionumber)+LookupRatio(Conf.browsenumber))/Conf.framerate.to_i/60/60).round(2)
>     #SANITY CHECK PROTONS AS HOURS
>     #puts rate
>     return rate
>   end
>
>   def getValues
>     Manager.open(:host => Conf.hostname) do |manager|
>       #puts Conf.hostname
>       poolArray = []
>       poolsTable = ObjectId.new("1.3.6.1.4.1.15248.2.5.1.3.1")
>       manager.walk(poolsTable) do |row|
>         poolArray.push(row.to_s)
>       end
>       if poolArray.empty?
>         #puts "Manager Down"
>         poolArray = [
>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.1.8650, value=8650
> (INTEGER)]',
>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.1.8651, value=8651
> (INTEGER)]',
>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.2.8650, value=QNewsAK (OCTET
> STRING)]',
>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.2.8651, value=QSuite4AK
> (OCTET STRING)]',
>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.3.8650, value=46835255
> (INTEGER)]',
>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.3.8651, value=11041721
> (INTEGER)]',
>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.4.8650, value=8442357
> (INTEGER)]',
>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.4.8651, value=5717570
> (INTEGER)]',
>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.5.8650, value=0 (INTEGER)]',
>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.5.8651, value=0 (INTEGER)]',
>         ]
>         #debug when running as console app
>         #else puts "Manager Up"
>       end
>       groups = poolArray.group_by{ |s| s.split(',').first[/\d+$/] }
>       values = groups.map{ |key, ary| ary.map{ |s| s[/value=(\S+)/,
> 1].to_s } }
>       #Dump values to check syntax
>       #  puts "Values: #{@values}"
>       return values
>     end
>   end
>
>   def output
>     time = Time.now
>     stack :margin=>1, :width=>440  do
>       #clear do
>       border blue..white, :strokewidth => 1
>       para time.strftime("%a %b %d, %Y %I:%M.%S")
>       getValues.each {|v|
>         flow :width=>'100%', :margin=>2 do
>           border white..lightblue, :strokewidth => 2
>           para "#{v[1]} (Pool: #{v[0]})"
>           stack :width=>'33%' do
>             para "Free Hours"
>             para "#{calchours(v[3])}"
>           end
>           stack :width=>'33%' do
>             para "Used Hours:"
>             para "#{calchours(v[2])}"
>           end
>           stack :width=>'33%' do
>             para "Percent Free: "
>             para "#{(v[3].to_f/v[2].to_f*100).round(2)}%\r\n"
>           end
>         end
>       }
>     end
>     #end
>
>
>   end
> #end
> #  def para(text='')
> #    super text, :family=> "Calibri", :stroke=> white, :size=>'small'
> #  end
> end
>
>   Shoes.app(:title=> "Quantel SNMP Space Monitor",
>   :width=> 450,
>   :height=> 300)
>
>
> ========
>
>
>

Re: [shoes] Re: More silliness... I don't know what I broke

From:
Arne Brasseur
Date:
2013-08-07 @ 13:24
Hey Scott,

Just a tip, for sharing more than a few lines of code it's recommended to
use gist.github.com or a similar "pastie" service. Depending on email
reader and device it can be quite a pain to read code in emails.

Best,
Arne
On 07 Aug 2013 07:46, "Scott Harman" <scott@harman.tv> wrote:

> Previous message rejected due to length - trying again
>
>> Hi guys
>> I was so very close to having this script working in both Red and Green
>> Shoes (no joy at all under Shoes4 sadly)
>> I've included the whole code inline below, and it's currently configured
>> for Red Shoes (even though the stack and flow blocks are miles out of
>> alignment
>>
>> Basically, it connects to one of of servers, and retrieves a table from a
>> particular SNMP OID, which shows the amount of storage we have per server
>> (reported in what we call protons, but are effectively 128KB blocks)
>> Normally, we'd fetch this every 5 minutes, but I'm fetching every 10
>> seconds for debug purposes
>>
>> I've finally managed to work out how to store an appropriate string in
>> case the manager isn't running just for test purposes
>> What's weird is that under green shoes, it now crashes on 2nd execution,
>> but on red shoes, it doesn't seem to loop.
>> I have been trying to replace the content of the output block each time,
>> and before I did this, red shoes was just appending what was there (so I
>> added a clock to see what it was doing)
>>
>> It appears to be a basic flow control issue, and all I really want to do
>> is create a lightweight deployable app that a customer can just run to get
>> space reporting on their media manager's desktops.
>> At the moment, they have to connect to a web service for our 'manager'
>> app, which isn't really safe for non-technical users to access (as it's an
>> engineering tool) and we don't report space in anything other than
>> 'protons' and 'atoms'
>> I've hardcoded our storage matrix into the app, so it makes it trivial to
>> choose the right combination
>>
>> Does anyone have any ideas of what I'm doing wrong?
>> Kind regards,
>> Scott
>> ========
>>
>> #Uncomment for Red Shoes (and vice versa)
>> Shoes.setup do
>>   gem 'snmp'
>>   require 'snmp'
>>   #require 'optparse'
>> end
>> #
>> #
>> #Uncomment for Green Shoes (and vice versa)
>> #begin
>> #  gem'green_shoes'
>> #rescue LoadError
>> #  system("gem install green_shoes")
>> #end
>> #begin
>> #  gem 'snmp'
>> #rescue LoadError
>> #  system("gem install snmp")
>> #end
>> #require 'green_shoes'
>> #require 'snmp'
>>
>> class Conf
>>   class << self
>>     attr_accessor :hostname, :framerate, :vidtype, :videoformat,
>> :videonumber, :browseformat, :browsenumber, :audioformat, :audionumber
>>     def hostname
>>       @hostname
>>     end
>>
>>     def framerate
>>       @framerate
>>     end
>>
>>     def vidtype
>>       @vidtype
>>     end
>>
>>     def audioformat
>>       @audioformat
>>     end
>>
>>     def videoformat
>>       @videoformat
>>     end
>>
>>     def browseformat
>>       @browseformat
>>     end
>>
>>     def audionumber
>>       @audionumber
>>     end
>>
>>     def videonumber
>>       @videonumber
>>     end
>>
>>     def browsenumber
>>       @browsenumber
>>     end
>>   end
>> end
>>
>> class SNMPManager < Shoes
>>   url "/", :configure
>>   url "/settings", :check_settings
>>   url "/update", :update_capacity
>>
>>   include SNMP
>>   #attr_accessor :hostname, :framerate, :vidtype
>>   def initialize(params = {})
>>     # @step=0
>>    #  Gtk.running=true
>>
>>   end
>>
>>   def LookupRatio(formatnumber)
>> #text too long - dummy entry
>>     return 1
>>   end
>>
>>   def AudioFormats(framerate)
>>     @NTSCformats = {
>>       24=>"Legacy 8 Audio 4 channel 30 fps",
>>       68=>"Legacy 9 Audio 4 channel 30 fps",
>>       265=>"Audio 4 channel 16bit 30 fps",
>>       269=>"Audio 4 channel 24bit 30 fps",
>>       270=>"Audio 8 channel 16bit 30 fps",
>>       271=>"Audio 8 channel 24bit 30 fps"
>>     }
>>     @PALformats = {
>>       33=>"Legacy 8 Audio 4 channel 25 fps",
>>       73=>"Legacy 9 Audio 4 channel 25 fps",
>>       521=>"Audio 4 channel 16bit 25 fps",
>>       522=>"Audio 4 channel 24bit 25 fps",
>>       523=>"Audio 8 channel 16bit 25 fps",
>>       524=>"Audio 8 channel 24bit 25 fps"
>>     }
>>
>>     if (Conf.framerate == 25)
>>       choicelist=@PALformats
>>     elsif (Conf.framerate == 30)
>>       choicelist=@NTSCformats
>>     end
>>     Conf.audioformat=choicelist.values[1]
>>     Conf.audionumber=choicelist.keys[1]
>>     list_box :items => choicelist.values, :choose => choicelist.values[1]
>> do |list|
>>       Conf.audioformat=list.text
>>       Conf.audionumber=choicelist.key(list.text)
>>     end
>>
>>   end
>>
>>   def VideoFormats(framerate, vidtype)
>>     @SDNTSCformats = {
>>       17=>"Legacy 8 Mpeg 30 480i30",
>>       #      18=>"Legacy 8 Mpeg 40 480i30",
>>       #      19=>"Legacy 8 Mpeg 50 480i30",
>>       65=>"Legacy 9 Mpeg 30 480i30",
>>       66=>"Legacy 9 Mpeg 40 480i30",
>>       67=>"Legacy 9 Mpeg 50 480i30",
>>       86=>"Legacy 9E Mpeg 30 480i30",
>>       87=>"Legacy 9E Mpeg 40 480i30",
>>       88=>"Legacy 9E Mpeg 50 480i30",
>>       #   262=>"Mpeg 30 480i30",
>>       #   263=>"Mpeg 40 480i30",
>>       #  264=>"Mpeg 50 480i30",
>>       #  275=>"Mpeg 30 480i30 15f",
>>       #  276=>"Mpeg 40 480i30 11f",
>>       #  277=>"Mpeg 50 480i30 10f",
>>       710=>"DVCPRO50 525i30 8f",
>>       711=>"DVCPRO25 525i30 10f",
>>       712=>"DV 525i30 10f"
>>     }
>>     @HDNTSCformats = {
>>       #      20=>"Legacy 8 DV100 720p60",
>>       #      23=>"Legacy 8 DV100 1080i30",
>>       78=>"Legacy 9 DV100 720p60",
>>       81=>"Legacy 9 DV100 1080i30",
>>       256=>"DV100 720p60",
>>       259=>"DV100 1080i30",
>>       280=>"DV100 720p60 6f",
>>       281=>"DV100 1080i30 6f",
>>       600=>"AVC-I 50 1080i30 9f",
>>       601=>"AVC-I 100 1080i30 7f",
>>       602=>"AVC-I 50 720p60 9f",
>>       603=>"AVC-I 100 720p60 7f",
>>       622=>"AVC-I 100 1080p60 6f",
>>       623=>"AVC-I 200 1080p60 3f"
>>     }
>>     @SDPALformats = {
>>       26=>"Legacy 8 Mpeg 30 576i25",
>>       #      27=>"Legacy 8 Mpeg 40 576i25",
>>       #      28=>"Legacy 8 Mpeg 50 576i25",
>>       70=>"Legacy 9 Mpeg 30 576i25",
>>       71=>"Legacy 9 Mpeg 40 576i25",
>>       72=>"Legacy 9 Mpeg 50 576i25",
>>       89=>"Legacy 9E Mpeg 30 576i25",
>>       90=>"Legacy 9E Mpeg 40 576i25",
>>       91=>"Legacy 9E Mpeg 50 576i25",
>>       #   518=>"Mpeg 30 576i25",
>>       #   519=>"Mpeg 40 576i25",
>>       #   520=>"Mpeg 50 576i25",
>>       #   525=>"Mpeg 30 576i25 14f",
>>       #   526=>"Mpeg 40 576i25 12f",
>>       #   527=>"Mpeg 50 576i25 12f",
>>       700=>"DVCPRO50 625i25  7f",
>>       701=>"DVCPRO25 625i25 10f",
>>       702=>"DV 625i25 10f"
>>     }
>>     @HDPALformats = {
>>       512=>"DV100 720p50",
>>       515=>"DV100 1080i25",
>>       530=>"DV100 1080i25 5f",
>>       610=>"AVC-I 50 1080i25 11f",
>>       611=>"AVC-I 100 1080i25 5f",
>>       612=>"AVC-I 50 720p50 11f",
>>       613=>"AVC-I 100 720p50 6f",
>>       620=>"AVC-I 100 1080p50 5f",
>>       621=>"AVC-I 200 1080p50 3f"
>>     }
>>
>>     if (Conf.framerate == 25 &&  Conf.vidtype == "HD")
>>       choicelist = @HDPALformats
>>     elsif (Conf.framerate == 25 && Conf.vidtype == "SD")
>>       choicelist = @SDPALformats
>>     elsif (Conf.framerate == 30 && Conf.vidtype == "HD")
>>       choicelist = @HDNTSCformats
>>     elsif (Conf.framerate == 30 &&  Conf.vidtype == "SD")
>>       choicelist = @SDNTSCformats
>>     end
>>     Conf.videoformat=choicelist.values[1]
>>     Conf.videonumber=choicelist.keys[1]
>>     list_box :items => choicelist.values, :choose => choicelist.values[1]
>> do |list|
>>       Conf.videoformat=list.text
>>       Conf.videonumber=choicelist.key(list.text)
>>     end
>>
>>   end
>>
>>   def BrowseFormats(framerate)
>>     @BNTSCformats = {
>>       #      37=>"Legacy 8 Browse Video 30 fps",
>>       77=>"Legacy 9 Browse Video 30 fps",
>>       260=>"Browse Video 30 fps"
>>       #   291=>"MPEG-2 Browse Video 30 fps",
>>       #   301=>"H.264 Browse Video 30 fps",
>>       #   303=>"H.264 SIF Browse Video 30 fps",
>>       #    311=>"H.264 640x360 30 fps",
>>       #    313=>"H.264 640x480 30 fps"
>>     }
>>     @BPALformats = {
>>       #      34=>"Legacy 8 Browse Video 25 fps",
>>       74=>"Legacy 9 Browse Video 25 fps",
>>       #    290=>"MPEG-2 Browse Video 25 fps",
>>       #    300=>"H.264 Browse Video 25 fps",
>>       #   302=>"H.264 SIF Browse Video 25 fps",
>>       #    310=>"H.264 640x360 25 fps",
>>       #   312=>"H.264 640x480 25 fps",
>>       516=>"Browse Video 25 fps"
>>     }
>>
>>     if (Conf.framerate == 25)
>>       choicelist=@BPALformats
>>     elsif (Conf.framerate == 30)
>>       choicelist=@BNTSCformats
>>     end
>>     Conf.browseformat=choicelist.values[1]
>>     Conf.browsenumber=choicelist.keys[1]
>>     list_box :items => choicelist.values, :choose => choicelist.values[1]
>> do |list|
>>       Conf.browseformat=list.text
>>       Conf.browsenumber=choicelist.key(list.text)
>>     end
>>
>>   end
>>
>>   def configure
>>     Conf.new
>>     Conf.framerate=25
>>     Conf.vidtype="SD"
>>     background rgb(50,50,125)
>>     #style Shoes::Para, stroke: white, size: 'xx-small'
>>     # green shoes - x-small is small enough   style Shoes::Para,
>> :stroke=> white, :size=> 'x-small'
>>     style Shoes::Para, :stroke=> white, :size=> 'xx-small'
>>     stack do
>>       para "Enter Hostname:"
>>       edit_line("localhost") do |e|
>>         Conf.hostname = e.text
>>       end
>>
>>       para "Choose an frame rate:"
>>       list_box :items => [25, 30],:choose=>Conf.framerate do |list|
>>         Conf.framerate =  list.text.to_i
>>       end
>>       para "Choose SD or HD formats"
>>       list_box :items => ["SD", "HD"],:choose=>Conf.vidtype do |list|
>>         Conf.vidtype = list.text
>>       end
>>     end
>>
>>     button "Confirm Settings" do
>>       visit "/settings"
>>     end
>>   end
>>
>>   def check_settings
>>     background rgb(50,50,125)
>>     #style Shoes::Para, stroke: white, size: 'xx-small'
>>     # green shoes - x-small is small enough   style Shoes::Para,
>> :stroke=> white, :size=> 'x-small'
>>     style Shoes::Para, :stroke=> white, :size=> 'xx-small'
>>     stack do
>>       para "Choose an Video format:"
>>       VideoFormats(Conf.framerate, Conf.vidtype)
>>
>>       para "Choose an Audio format:"
>>       AudioFormats(Conf.framerate)
>>
>>       para "Choose Browse format:"
>>       BrowseFormats(Conf.framerate)
>>
>>       button "Update Settings" do
>>         visit "/update"
>>       end
>>     end
>>   end
>>
>>   def update_capacity
>>     background rgb(50,50,125)
>>     #style Shoes::Para, stroke: white, size: 'xx-small'
>>     # green shoes - x-small is small enough   style Shoes::Para,
>> :stroke=> white, :size=> 'x-small'
>>     style Shoes::Para, :stroke=> white, :size=> '8'
>>     output.new
>>     every(10) {
>>       output.new
>>     }
>>   end
>>
>>   def calchours(protons)
>>     rate = (protons.to_i /
>> 
(LookupRatio(Conf.videonumber)+LookupRatio(Conf.audionumber)+LookupRatio(Conf.browsenumber))/Conf.framerate.to_i/60/60).round(2)
>>     #SANITY CHECK PROTONS AS HOURS
>>     #puts rate
>>     return rate
>>   end
>>
>>   def getValues
>>     Manager.open(:host => Conf.hostname) do |manager|
>>       #puts Conf.hostname
>>       poolArray = []
>>       poolsTable = ObjectId.new("1.3.6.1.4.1.15248.2.5.1.3.1")
>>       manager.walk(poolsTable) do |row|
>>         poolArray.push(row.to_s)
>>       end
>>       if poolArray.empty?
>>         #puts "Manager Down"
>>         poolArray = [
>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.1.8650, value=8650
>> (INTEGER)]',
>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.1.8651, value=8651
>> (INTEGER)]',
>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.2.8650, value=QNewsAK (OCTET
>> STRING)]',
>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.2.8651, value=QSuite4AK
>> (OCTET STRING)]',
>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.3.8650, value=46835255
>> (INTEGER)]',
>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.3.8651, value=11041721
>> (INTEGER)]',
>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.4.8650, value=8442357
>> (INTEGER)]',
>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.4.8651, value=5717570
>> (INTEGER)]',
>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.5.8650, value=0 (INTEGER)]',
>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.5.8651, value=0 (INTEGER)]',
>>         ]
>>         #debug when running as console app
>>         #else puts "Manager Up"
>>       end
>>       groups = poolArray.group_by{ |s| s.split(',').first[/\d+$/] }
>>       values = groups.map{ |key, ary| ary.map{ |s| s[/value=(\S+)/,
>> 1].to_s } }
>>       #Dump values to check syntax
>>       #  puts "Values: #{@values}"
>>       return values
>>     end
>>   end
>>
>>   def output
>>     time = Time.now
>>     stack :margin=>1, :width=>440  do
>>       #clear do
>>       border blue..white, :strokewidth => 1
>>       para time.strftime("%a %b %d, %Y %I:%M.%S")
>>       getValues.each {|v|
>>         flow :width=>'100%', :margin=>2 do
>>           border white..lightblue, :strokewidth => 2
>>           para "#{v[1]} (Pool: #{v[0]})"
>>           stack :width=>'33%' do
>>             para "Free Hours"
>>             para "#{calchours(v[3])}"
>>           end
>>           stack :width=>'33%' do
>>             para "Used Hours:"
>>             para "#{calchours(v[2])}"
>>           end
>>           stack :width=>'33%' do
>>             para "Percent Free: "
>>             para "#{(v[3].to_f/v[2].to_f*100).round(2)}%\r\n"
>>           end
>>         end
>>       }
>>     end
>>     #end
>>
>>
>>   end
>> #end
>> #  def para(text='')
>> #    super text, :family=> "Calibri", :stroke=> white, :size=>'small'
>> #  end
>> end
>>
>>   Shoes.app(:title=> "Quantel SNMP Space Monitor",
>>   :width=> 450,
>>   :height=> 300)
>>
>>
>> ========
>>
>>
>>
>

Re: [shoes] Re: More silliness... I don't know what I broke

From:
Scott Harman
Date:
2013-08-07 @ 22:59
Hi Arne -
Thanks - I will do that
Cheers


On Wed, Aug 7, 2013 at 11:24 PM, Arne Brasseur <arne.brasseur@gmail.com>wrote:

> Hey Scott,
>
> Just a tip, for sharing more than a few lines of code it's recommended to
> use gist.github.com or a similar "pastie" service. Depending on email
> reader and device it can be quite a pain to read code in emails.
>
> Best,
> Arne
> On 07 Aug 2013 07:46, "Scott Harman" <scott@harman.tv> wrote:
>
>> Previous message rejected due to length - trying again
>>
>>> Hi guys
>>> I was so very close to having this script working in both Red and Green
>>> Shoes (no joy at all under Shoes4 sadly)
>>> I've included the whole code inline below, and it's currently configured
>>> for Red Shoes (even though the stack and flow blocks are miles out of
>>> alignment
>>>
>>> Basically, it connects to one of of servers, and retrieves a table from
>>> a particular SNMP OID, which shows the amount of storage we have per server
>>> (reported in what we call protons, but are effectively 128KB blocks)
>>> Normally, we'd fetch this every 5 minutes, but I'm fetching every 10
>>> seconds for debug purposes
>>>
>>> I've finally managed to work out how to store an appropriate string in
>>> case the manager isn't running just for test purposes
>>> What's weird is that under green shoes, it now crashes on 2nd execution,
>>> but on red shoes, it doesn't seem to loop.
>>> I have been trying to replace the content of the output block each time,
>>> and before I did this, red shoes was just appending what was there (so I
>>> added a clock to see what it was doing)
>>>
>>> It appears to be a basic flow control issue, and all I really want to do
>>> is create a lightweight deployable app that a customer can just run to get
>>> space reporting on their media manager's desktops.
>>> At the moment, they have to connect to a web service for our 'manager'
>>> app, which isn't really safe for non-technical users to access (as it's an
>>> engineering tool) and we don't report space in anything other than
>>> 'protons' and 'atoms'
>>> I've hardcoded our storage matrix into the app, so it makes it trivial
>>> to choose the right combination
>>>
>>> Does anyone have any ideas of what I'm doing wrong?
>>> Kind regards,
>>> Scott
>>> ========
>>>
>>> #Uncomment for Red Shoes (and vice versa)
>>> Shoes.setup do
>>>   gem 'snmp'
>>>   require 'snmp'
>>>   #require 'optparse'
>>> end
>>> #
>>> #
>>> #Uncomment for Green Shoes (and vice versa)
>>> #begin
>>> #  gem'green_shoes'
>>> #rescue LoadError
>>> #  system("gem install green_shoes")
>>> #end
>>> #begin
>>> #  gem 'snmp'
>>> #rescue LoadError
>>> #  system("gem install snmp")
>>> #end
>>> #require 'green_shoes'
>>> #require 'snmp'
>>>
>>> class Conf
>>>   class << self
>>>     attr_accessor :hostname, :framerate, :vidtype, :videoformat,
>>> :videonumber, :browseformat, :browsenumber, :audioformat, :audionumber
>>>     def hostname
>>>       @hostname
>>>     end
>>>
>>>     def framerate
>>>       @framerate
>>>     end
>>>
>>>     def vidtype
>>>       @vidtype
>>>     end
>>>
>>>     def audioformat
>>>       @audioformat
>>>     end
>>>
>>>     def videoformat
>>>       @videoformat
>>>     end
>>>
>>>     def browseformat
>>>       @browseformat
>>>     end
>>>
>>>     def audionumber
>>>       @audionumber
>>>     end
>>>
>>>     def videonumber
>>>       @videonumber
>>>     end
>>>
>>>     def browsenumber
>>>       @browsenumber
>>>     end
>>>   end
>>> end
>>>
>>> class SNMPManager < Shoes
>>>   url "/", :configure
>>>   url "/settings", :check_settings
>>>   url "/update", :update_capacity
>>>
>>>   include SNMP
>>>   #attr_accessor :hostname, :framerate, :vidtype
>>>   def initialize(params = {})
>>>     # @step=0
>>>    #  Gtk.running=true
>>>
>>>   end
>>>
>>>   def LookupRatio(formatnumber)
>>> #text too long - dummy entry
>>>     return 1
>>>   end
>>>
>>>   def AudioFormats(framerate)
>>>     @NTSCformats = {
>>>       24=>"Legacy 8 Audio 4 channel 30 fps",
>>>       68=>"Legacy 9 Audio 4 channel 30 fps",
>>>       265=>"Audio 4 channel 16bit 30 fps",
>>>       269=>"Audio 4 channel 24bit 30 fps",
>>>       270=>"Audio 8 channel 16bit 30 fps",
>>>       271=>"Audio 8 channel 24bit 30 fps"
>>>     }
>>>     @PALformats = {
>>>       33=>"Legacy 8 Audio 4 channel 25 fps",
>>>       73=>"Legacy 9 Audio 4 channel 25 fps",
>>>       521=>"Audio 4 channel 16bit 25 fps",
>>>       522=>"Audio 4 channel 24bit 25 fps",
>>>       523=>"Audio 8 channel 16bit 25 fps",
>>>       524=>"Audio 8 channel 24bit 25 fps"
>>>     }
>>>
>>>     if (Conf.framerate == 25)
>>>       choicelist=@PALformats
>>>     elsif (Conf.framerate == 30)
>>>       choicelist=@NTSCformats
>>>     end
>>>     Conf.audioformat=choicelist.values[1]
>>>     Conf.audionumber=choicelist.keys[1]
>>>     list_box :items => choicelist.values, :choose =>
>>> choicelist.values[1] do |list|
>>>       Conf.audioformat=list.text
>>>       Conf.audionumber=choicelist.key(list.text)
>>>     end
>>>
>>>   end
>>>
>>>   def VideoFormats(framerate, vidtype)
>>>     @SDNTSCformats = {
>>>       17=>"Legacy 8 Mpeg 30 480i30",
>>>       #      18=>"Legacy 8 Mpeg 40 480i30",
>>>       #      19=>"Legacy 8 Mpeg 50 480i30",
>>>       65=>"Legacy 9 Mpeg 30 480i30",
>>>       66=>"Legacy 9 Mpeg 40 480i30",
>>>       67=>"Legacy 9 Mpeg 50 480i30",
>>>       86=>"Legacy 9E Mpeg 30 480i30",
>>>       87=>"Legacy 9E Mpeg 40 480i30",
>>>       88=>"Legacy 9E Mpeg 50 480i30",
>>>       #   262=>"Mpeg 30 480i30",
>>>       #   263=>"Mpeg 40 480i30",
>>>       #  264=>"Mpeg 50 480i30",
>>>       #  275=>"Mpeg 30 480i30 15f",
>>>       #  276=>"Mpeg 40 480i30 11f",
>>>       #  277=>"Mpeg 50 480i30 10f",
>>>       710=>"DVCPRO50 525i30 8f",
>>>       711=>"DVCPRO25 525i30 10f",
>>>       712=>"DV 525i30 10f"
>>>     }
>>>     @HDNTSCformats = {
>>>       #      20=>"Legacy 8 DV100 720p60",
>>>       #      23=>"Legacy 8 DV100 1080i30",
>>>       78=>"Legacy 9 DV100 720p60",
>>>       81=>"Legacy 9 DV100 1080i30",
>>>       256=>"DV100 720p60",
>>>       259=>"DV100 1080i30",
>>>       280=>"DV100 720p60 6f",
>>>       281=>"DV100 1080i30 6f",
>>>       600=>"AVC-I 50 1080i30 9f",
>>>       601=>"AVC-I 100 1080i30 7f",
>>>       602=>"AVC-I 50 720p60 9f",
>>>       603=>"AVC-I 100 720p60 7f",
>>>       622=>"AVC-I 100 1080p60 6f",
>>>       623=>"AVC-I 200 1080p60 3f"
>>>     }
>>>     @SDPALformats = {
>>>       26=>"Legacy 8 Mpeg 30 576i25",
>>>       #      27=>"Legacy 8 Mpeg 40 576i25",
>>>       #      28=>"Legacy 8 Mpeg 50 576i25",
>>>       70=>"Legacy 9 Mpeg 30 576i25",
>>>       71=>"Legacy 9 Mpeg 40 576i25",
>>>       72=>"Legacy 9 Mpeg 50 576i25",
>>>       89=>"Legacy 9E Mpeg 30 576i25",
>>>       90=>"Legacy 9E Mpeg 40 576i25",
>>>       91=>"Legacy 9E Mpeg 50 576i25",
>>>       #   518=>"Mpeg 30 576i25",
>>>       #   519=>"Mpeg 40 576i25",
>>>       #   520=>"Mpeg 50 576i25",
>>>       #   525=>"Mpeg 30 576i25 14f",
>>>       #   526=>"Mpeg 40 576i25 12f",
>>>       #   527=>"Mpeg 50 576i25 12f",
>>>       700=>"DVCPRO50 625i25  7f",
>>>       701=>"DVCPRO25 625i25 10f",
>>>       702=>"DV 625i25 10f"
>>>     }
>>>     @HDPALformats = {
>>>       512=>"DV100 720p50",
>>>       515=>"DV100 1080i25",
>>>       530=>"DV100 1080i25 5f",
>>>       610=>"AVC-I 50 1080i25 11f",
>>>       611=>"AVC-I 100 1080i25 5f",
>>>       612=>"AVC-I 50 720p50 11f",
>>>       613=>"AVC-I 100 720p50 6f",
>>>       620=>"AVC-I 100 1080p50 5f",
>>>       621=>"AVC-I 200 1080p50 3f"
>>>     }
>>>
>>>     if (Conf.framerate == 25 &&  Conf.vidtype == "HD")
>>>       choicelist = @HDPALformats
>>>     elsif (Conf.framerate == 25 && Conf.vidtype == "SD")
>>>       choicelist = @SDPALformats
>>>     elsif (Conf.framerate == 30 && Conf.vidtype == "HD")
>>>       choicelist = @HDNTSCformats
>>>     elsif (Conf.framerate == 30 &&  Conf.vidtype == "SD")
>>>       choicelist = @SDNTSCformats
>>>     end
>>>     Conf.videoformat=choicelist.values[1]
>>>     Conf.videonumber=choicelist.keys[1]
>>>     list_box :items => choicelist.values, :choose =>
>>> choicelist.values[1] do |list|
>>>       Conf.videoformat=list.text
>>>       Conf.videonumber=choicelist.key(list.text)
>>>     end
>>>
>>>   end
>>>
>>>   def BrowseFormats(framerate)
>>>     @BNTSCformats = {
>>>       #      37=>"Legacy 8 Browse Video 30 fps",
>>>       77=>"Legacy 9 Browse Video 30 fps",
>>>       260=>"Browse Video 30 fps"
>>>       #   291=>"MPEG-2 Browse Video 30 fps",
>>>       #   301=>"H.264 Browse Video 30 fps",
>>>       #   303=>"H.264 SIF Browse Video 30 fps",
>>>       #    311=>"H.264 640x360 30 fps",
>>>       #    313=>"H.264 640x480 30 fps"
>>>     }
>>>     @BPALformats = {
>>>       #      34=>"Legacy 8 Browse Video 25 fps",
>>>       74=>"Legacy 9 Browse Video 25 fps",
>>>       #    290=>"MPEG-2 Browse Video 25 fps",
>>>       #    300=>"H.264 Browse Video 25 fps",
>>>       #   302=>"H.264 SIF Browse Video 25 fps",
>>>       #    310=>"H.264 640x360 25 fps",
>>>       #   312=>"H.264 640x480 25 fps",
>>>       516=>"Browse Video 25 fps"
>>>     }
>>>
>>>     if (Conf.framerate == 25)
>>>       choicelist=@BPALformats
>>>     elsif (Conf.framerate == 30)
>>>       choicelist=@BNTSCformats
>>>     end
>>>     Conf.browseformat=choicelist.values[1]
>>>     Conf.browsenumber=choicelist.keys[1]
>>>     list_box :items => choicelist.values, :choose =>
>>> choicelist.values[1] do |list|
>>>       Conf.browseformat=list.text
>>>       Conf.browsenumber=choicelist.key(list.text)
>>>     end
>>>
>>>   end
>>>
>>>   def configure
>>>     Conf.new
>>>     Conf.framerate=25
>>>     Conf.vidtype="SD"
>>>     background rgb(50,50,125)
>>>     #style Shoes::Para, stroke: white, size: 'xx-small'
>>>     # green shoes - x-small is small enough   style Shoes::Para,
>>> :stroke=> white, :size=> 'x-small'
>>>     style Shoes::Para, :stroke=> white, :size=> 'xx-small'
>>>     stack do
>>>       para "Enter Hostname:"
>>>       edit_line("localhost") do |e|
>>>         Conf.hostname = e.text
>>>       end
>>>
>>>       para "Choose an frame rate:"
>>>       list_box :items => [25, 30],:choose=>Conf.framerate do |list|
>>>         Conf.framerate =  list.text.to_i
>>>       end
>>>       para "Choose SD or HD formats"
>>>       list_box :items => ["SD", "HD"],:choose=>Conf.vidtype do |list|
>>>         Conf.vidtype = list.text
>>>       end
>>>     end
>>>
>>>     button "Confirm Settings" do
>>>       visit "/settings"
>>>     end
>>>   end
>>>
>>>   def check_settings
>>>     background rgb(50,50,125)
>>>     #style Shoes::Para, stroke: white, size: 'xx-small'
>>>     # green shoes - x-small is small enough   style Shoes::Para,
>>> :stroke=> white, :size=> 'x-small'
>>>     style Shoes::Para, :stroke=> white, :size=> 'xx-small'
>>>     stack do
>>>       para "Choose an Video format:"
>>>       VideoFormats(Conf.framerate, Conf.vidtype)
>>>
>>>       para "Choose an Audio format:"
>>>       AudioFormats(Conf.framerate)
>>>
>>>       para "Choose Browse format:"
>>>       BrowseFormats(Conf.framerate)
>>>
>>>       button "Update Settings" do
>>>         visit "/update"
>>>       end
>>>     end
>>>   end
>>>
>>>   def update_capacity
>>>     background rgb(50,50,125)
>>>     #style Shoes::Para, stroke: white, size: 'xx-small'
>>>     # green shoes - x-small is small enough   style Shoes::Para,
>>> :stroke=> white, :size=> 'x-small'
>>>     style Shoes::Para, :stroke=> white, :size=> '8'
>>>     output.new
>>>     every(10) {
>>>       output.new
>>>     }
>>>   end
>>>
>>>   def calchours(protons)
>>>     rate = (protons.to_i /
>>> 
(LookupRatio(Conf.videonumber)+LookupRatio(Conf.audionumber)+LookupRatio(Conf.browsenumber))/Conf.framerate.to_i/60/60).round(2)
>>>     #SANITY CHECK PROTONS AS HOURS
>>>     #puts rate
>>>     return rate
>>>   end
>>>
>>>   def getValues
>>>     Manager.open(:host => Conf.hostname) do |manager|
>>>       #puts Conf.hostname
>>>       poolArray = []
>>>       poolsTable = ObjectId.new("1.3.6.1.4.1.15248.2.5.1.3.1")
>>>       manager.walk(poolsTable) do |row|
>>>         poolArray.push(row.to_s)
>>>       end
>>>       if poolArray.empty?
>>>         #puts "Manager Down"
>>>         poolArray = [
>>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.1.8650, value=8650
>>> (INTEGER)]',
>>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.1.8651, value=8651
>>> (INTEGER)]',
>>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.2.8650, value=QNewsAK
>>> (OCTET STRING)]',
>>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.2.8651, value=QSuite4AK
>>> (OCTET STRING)]',
>>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.3.8650, value=46835255
>>> (INTEGER)]',
>>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.3.8651, value=11041721
>>> (INTEGER)]',
>>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.4.8650, value=8442357
>>> (INTEGER)]',
>>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.4.8651, value=5717570
>>> (INTEGER)]',
>>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.5.8650, value=0 (INTEGER)]',
>>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.5.8651, value=0 (INTEGER)]',
>>>         ]
>>>         #debug when running as console app
>>>         #else puts "Manager Up"
>>>       end
>>>       groups = poolArray.group_by{ |s| s.split(',').first[/\d+$/] }
>>>       values = groups.map{ |key, ary| ary.map{ |s| s[/value=(\S+)/,
>>> 1].to_s } }
>>>       #Dump values to check syntax
>>>       #  puts "Values: #{@values}"
>>>       return values
>>>     end
>>>   end
>>>
>>>   def output
>>>     time = Time.now
>>>     stack :margin=>1, :width=>440  do
>>>       #clear do
>>>       border blue..white, :strokewidth => 1
>>>       para time.strftime("%a %b %d, %Y %I:%M.%S")
>>>       getValues.each {|v|
>>>         flow :width=>'100%', :margin=>2 do
>>>           border white..lightblue, :strokewidth => 2
>>>           para "#{v[1]} (Pool: #{v[0]})"
>>>           stack :width=>'33%' do
>>>             para "Free Hours"
>>>             para "#{calchours(v[3])}"
>>>           end
>>>           stack :width=>'33%' do
>>>             para "Used Hours:"
>>>             para "#{calchours(v[2])}"
>>>           end
>>>           stack :width=>'33%' do
>>>             para "Percent Free: "
>>>             para "#{(v[3].to_f/v[2].to_f*100).round(2)}%\r\n"
>>>           end
>>>         end
>>>       }
>>>     end
>>>     #end
>>>
>>>
>>>   end
>>> #end
>>> #  def para(text='')
>>> #    super text, :family=> "Calibri", :stroke=> white, :size=>'small'
>>> #  end
>>> end
>>>
>>>   Shoes.app(:title=> "Quantel SNMP Space Monitor",
>>>   :width=> 450,
>>>   :height=> 300)
>>>
>>>
>>> ========
>>>
>>>
>>>
>>

Re: [shoes] Re: More silliness... I don't know what I broke

From:
Scott Harman
Date:
2013-08-08 @ 01:31
https://gist.github.com/scottharman/58c2a22c2062d1ab009e

I've posted the code in the gist above
If anyone has any thoughts, that would be awesome -
I'd really like to be able to just run this as a red shoes app, and just
deploy it as a standalone exe, without having to get customers to install
ruby too
Cheers


On Thu, Aug 8, 2013 at 8:59 AM, Scott Harman <scott@harman.tv> wrote:

> Hi Arne -
> Thanks - I will do that
> Cheers
>
>
> On Wed, Aug 7, 2013 at 11:24 PM, Arne Brasseur <arne.brasseur@gmail.com>wrote:
>
>> Hey Scott,
>>
>> Just a tip, for sharing more than a few lines of code it's recommended to
>> use gist.github.com or a similar "pastie" service. Depending on email
>> reader and device it can be quite a pain to read code in emails.
>>
>> Best,
>> Arne
>> On 07 Aug 2013 07:46, "Scott Harman" <scott@harman.tv> wrote:
>>
>>> Previous message rejected due to length - trying again
>>>
>>>> Hi guys
>>>> I was so very close to having this script working in both Red and Green
>>>> Shoes (no joy at all under Shoes4 sadly)
>>>> I've included the whole code inline below, and it's currently
>>>> configured for Red Shoes (even though the stack and flow blocks are miles
>>>> out of alignment
>>>>
>>>> Basically, it connects to one of of servers, and retrieves a table from
>>>> a particular SNMP OID, which shows the amount of storage we have per server
>>>> (reported in what we call protons, but are effectively 128KB blocks)
>>>> Normally, we'd fetch this every 5 minutes, but I'm fetching every 10
>>>> seconds for debug purposes
>>>>
>>>> I've finally managed to work out how to store an appropriate string in
>>>> case the manager isn't running just for test purposes
>>>> What's weird is that under green shoes, it now crashes on 2nd
>>>> execution, but on red shoes, it doesn't seem to loop.
>>>> I have been trying to replace the content of the output block each
>>>> time, and before I did this, red shoes was just appending what was there
>>>> (so I added a clock to see what it was doing)
>>>>
>>>> It appears to be a basic flow control issue, and all I really want to
>>>> do is create a lightweight deployable app that a customer can just run to
>>>> get space reporting on their media manager's desktops.
>>>> At the moment, they have to connect to a web service for our 'manager'
>>>> app, which isn't really safe for non-technical users to access (as it's an
>>>> engineering tool) and we don't report space in anything other than
>>>> 'protons' and 'atoms'
>>>> I've hardcoded our storage matrix into the app, so it makes it trivial
>>>> to choose the right combination
>>>>
>>>> Does anyone have any ideas of what I'm doing wrong?
>>>> Kind regards,
>>>> Scott
>>>> ========
>>>>
>>>> #Uncomment for Red Shoes (and vice versa)
>>>> Shoes.setup do
>>>>   gem 'snmp'
>>>>   require 'snmp'
>>>>   #require 'optparse'
>>>> end
>>>> #
>>>> #
>>>> #Uncomment for Green Shoes (and vice versa)
>>>> #begin
>>>> #  gem'green_shoes'
>>>> #rescue LoadError
>>>> #  system("gem install green_shoes")
>>>> #end
>>>> #begin
>>>> #  gem 'snmp'
>>>> #rescue LoadError
>>>> #  system("gem install snmp")
>>>> #end
>>>> #require 'green_shoes'
>>>> #require 'snmp'
>>>>
>>>> class Conf
>>>>   class << self
>>>>     attr_accessor :hostname, :framerate, :vidtype, :videoformat,
>>>> :videonumber, :browseformat, :browsenumber, :audioformat, :audionumber
>>>>     def hostname
>>>>       @hostname
>>>>     end
>>>>
>>>>     def framerate
>>>>       @framerate
>>>>     end
>>>>
>>>>     def vidtype
>>>>       @vidtype
>>>>     end
>>>>
>>>>     def audioformat
>>>>       @audioformat
>>>>     end
>>>>
>>>>     def videoformat
>>>>       @videoformat
>>>>     end
>>>>
>>>>     def browseformat
>>>>       @browseformat
>>>>     end
>>>>
>>>>     def audionumber
>>>>       @audionumber
>>>>     end
>>>>
>>>>     def videonumber
>>>>       @videonumber
>>>>     end
>>>>
>>>>     def browsenumber
>>>>       @browsenumber
>>>>     end
>>>>   end
>>>> end
>>>>
>>>> class SNMPManager < Shoes
>>>>   url "/", :configure
>>>>   url "/settings", :check_settings
>>>>   url "/update", :update_capacity
>>>>
>>>>   include SNMP
>>>>   #attr_accessor :hostname, :framerate, :vidtype
>>>>   def initialize(params = {})
>>>>     # @step=0
>>>>    #  Gtk.running=true
>>>>
>>>>   end
>>>>
>>>>   def LookupRatio(formatnumber)
>>>> #text too long - dummy entry
>>>>     return 1
>>>>   end
>>>>
>>>>   def AudioFormats(framerate)
>>>>     @NTSCformats = {
>>>>       24=>"Legacy 8 Audio 4 channel 30 fps",
>>>>       68=>"Legacy 9 Audio 4 channel 30 fps",
>>>>       265=>"Audio 4 channel 16bit 30 fps",
>>>>       269=>"Audio 4 channel 24bit 30 fps",
>>>>       270=>"Audio 8 channel 16bit 30 fps",
>>>>       271=>"Audio 8 channel 24bit 30 fps"
>>>>     }
>>>>     @PALformats = {
>>>>       33=>"Legacy 8 Audio 4 channel 25 fps",
>>>>       73=>"Legacy 9 Audio 4 channel 25 fps",
>>>>       521=>"Audio 4 channel 16bit 25 fps",
>>>>       522=>"Audio 4 channel 24bit 25 fps",
>>>>       523=>"Audio 8 channel 16bit 25 fps",
>>>>       524=>"Audio 8 channel 24bit 25 fps"
>>>>     }
>>>>
>>>>     if (Conf.framerate == 25)
>>>>       choicelist=@PALformats
>>>>     elsif (Conf.framerate == 30)
>>>>       choicelist=@NTSCformats
>>>>     end
>>>>     Conf.audioformat=choicelist.values[1]
>>>>     Conf.audionumber=choicelist.keys[1]
>>>>     list_box :items => choicelist.values, :choose =>
>>>> choicelist.values[1] do |list|
>>>>       Conf.audioformat=list.text
>>>>       Conf.audionumber=choicelist.key(list.text)
>>>>     end
>>>>
>>>>   end
>>>>
>>>>   def VideoFormats(framerate, vidtype)
>>>>     @SDNTSCformats = {
>>>>       17=>"Legacy 8 Mpeg 30 480i30",
>>>>       #      18=>"Legacy 8 Mpeg 40 480i30",
>>>>       #      19=>"Legacy 8 Mpeg 50 480i30",
>>>>       65=>"Legacy 9 Mpeg 30 480i30",
>>>>       66=>"Legacy 9 Mpeg 40 480i30",
>>>>       67=>"Legacy 9 Mpeg 50 480i30",
>>>>       86=>"Legacy 9E Mpeg 30 480i30",
>>>>       87=>"Legacy 9E Mpeg 40 480i30",
>>>>       88=>"Legacy 9E Mpeg 50 480i30",
>>>>       #   262=>"Mpeg 30 480i30",
>>>>       #   263=>"Mpeg 40 480i30",
>>>>       #  264=>"Mpeg 50 480i30",
>>>>       #  275=>"Mpeg 30 480i30 15f",
>>>>       #  276=>"Mpeg 40 480i30 11f",
>>>>       #  277=>"Mpeg 50 480i30 10f",
>>>>       710=>"DVCPRO50 525i30 8f",
>>>>       711=>"DVCPRO25 525i30 10f",
>>>>       712=>"DV 525i30 10f"
>>>>     }
>>>>     @HDNTSCformats = {
>>>>       #      20=>"Legacy 8 DV100 720p60",
>>>>       #      23=>"Legacy 8 DV100 1080i30",
>>>>       78=>"Legacy 9 DV100 720p60",
>>>>       81=>"Legacy 9 DV100 1080i30",
>>>>       256=>"DV100 720p60",
>>>>       259=>"DV100 1080i30",
>>>>       280=>"DV100 720p60 6f",
>>>>       281=>"DV100 1080i30 6f",
>>>>       600=>"AVC-I 50 1080i30 9f",
>>>>       601=>"AVC-I 100 1080i30 7f",
>>>>       602=>"AVC-I 50 720p60 9f",
>>>>       603=>"AVC-I 100 720p60 7f",
>>>>       622=>"AVC-I 100 1080p60 6f",
>>>>       623=>"AVC-I 200 1080p60 3f"
>>>>     }
>>>>     @SDPALformats = {
>>>>       26=>"Legacy 8 Mpeg 30 576i25",
>>>>       #      27=>"Legacy 8 Mpeg 40 576i25",
>>>>       #      28=>"Legacy 8 Mpeg 50 576i25",
>>>>       70=>"Legacy 9 Mpeg 30 576i25",
>>>>       71=>"Legacy 9 Mpeg 40 576i25",
>>>>       72=>"Legacy 9 Mpeg 50 576i25",
>>>>       89=>"Legacy 9E Mpeg 30 576i25",
>>>>       90=>"Legacy 9E Mpeg 40 576i25",
>>>>       91=>"Legacy 9E Mpeg 50 576i25",
>>>>       #   518=>"Mpeg 30 576i25",
>>>>       #   519=>"Mpeg 40 576i25",
>>>>       #   520=>"Mpeg 50 576i25",
>>>>       #   525=>"Mpeg 30 576i25 14f",
>>>>       #   526=>"Mpeg 40 576i25 12f",
>>>>       #   527=>"Mpeg 50 576i25 12f",
>>>>       700=>"DVCPRO50 625i25  7f",
>>>>       701=>"DVCPRO25 625i25 10f",
>>>>       702=>"DV 625i25 10f"
>>>>     }
>>>>     @HDPALformats = {
>>>>       512=>"DV100 720p50",
>>>>       515=>"DV100 1080i25",
>>>>       530=>"DV100 1080i25 5f",
>>>>       610=>"AVC-I 50 1080i25 11f",
>>>>       611=>"AVC-I 100 1080i25 5f",
>>>>       612=>"AVC-I 50 720p50 11f",
>>>>       613=>"AVC-I 100 720p50 6f",
>>>>       620=>"AVC-I 100 1080p50 5f",
>>>>       621=>"AVC-I 200 1080p50 3f"
>>>>     }
>>>>
>>>>     if (Conf.framerate == 25 &&  Conf.vidtype == "HD")
>>>>       choicelist = @HDPALformats
>>>>     elsif (Conf.framerate == 25 && Conf.vidtype == "SD")
>>>>       choicelist = @SDPALformats
>>>>     elsif (Conf.framerate == 30 && Conf.vidtype == "HD")
>>>>       choicelist = @HDNTSCformats
>>>>     elsif (Conf.framerate == 30 &&  Conf.vidtype == "SD")
>>>>       choicelist = @SDNTSCformats
>>>>     end
>>>>     Conf.videoformat=choicelist.values[1]
>>>>     Conf.videonumber=choicelist.keys[1]
>>>>     list_box :items => choicelist.values, :choose =>
>>>> choicelist.values[1] do |list|
>>>>       Conf.videoformat=list.text
>>>>       Conf.videonumber=choicelist.key(list.text)
>>>>     end
>>>>
>>>>   end
>>>>
>>>>   def BrowseFormats(framerate)
>>>>     @BNTSCformats = {
>>>>       #      37=>"Legacy 8 Browse Video 30 fps",
>>>>       77=>"Legacy 9 Browse Video 30 fps",
>>>>       260=>"Browse Video 30 fps"
>>>>       #   291=>"MPEG-2 Browse Video 30 fps",
>>>>       #   301=>"H.264 Browse Video 30 fps",
>>>>       #   303=>"H.264 SIF Browse Video 30 fps",
>>>>       #    311=>"H.264 640x360 30 fps",
>>>>       #    313=>"H.264 640x480 30 fps"
>>>>     }
>>>>     @BPALformats = {
>>>>       #      34=>"Legacy 8 Browse Video 25 fps",
>>>>       74=>"Legacy 9 Browse Video 25 fps",
>>>>       #    290=>"MPEG-2 Browse Video 25 fps",
>>>>       #    300=>"H.264 Browse Video 25 fps",
>>>>       #   302=>"H.264 SIF Browse Video 25 fps",
>>>>       #    310=>"H.264 640x360 25 fps",
>>>>       #   312=>"H.264 640x480 25 fps",
>>>>       516=>"Browse Video 25 fps"
>>>>     }
>>>>
>>>>     if (Conf.framerate == 25)
>>>>       choicelist=@BPALformats
>>>>     elsif (Conf.framerate == 30)
>>>>       choicelist=@BNTSCformats
>>>>     end
>>>>     Conf.browseformat=choicelist.values[1]
>>>>     Conf.browsenumber=choicelist.keys[1]
>>>>     list_box :items => choicelist.values, :choose =>
>>>> choicelist.values[1] do |list|
>>>>       Conf.browseformat=list.text
>>>>       Conf.browsenumber=choicelist.key(list.text)
>>>>     end
>>>>
>>>>   end
>>>>
>>>>   def configure
>>>>     Conf.new
>>>>     Conf.framerate=25
>>>>     Conf.vidtype="SD"
>>>>     background rgb(50,50,125)
>>>>     #style Shoes::Para, stroke: white, size: 'xx-small'
>>>>     # green shoes - x-small is small enough   style Shoes::Para,
>>>> :stroke=> white, :size=> 'x-small'
>>>>     style Shoes::Para, :stroke=> white, :size=> 'xx-small'
>>>>     stack do
>>>>       para "Enter Hostname:"
>>>>       edit_line("localhost") do |e|
>>>>         Conf.hostname = e.text
>>>>       end
>>>>
>>>>       para "Choose an frame rate:"
>>>>       list_box :items => [25, 30],:choose=>Conf.framerate do |list|
>>>>         Conf.framerate =  list.text.to_i
>>>>       end
>>>>       para "Choose SD or HD formats"
>>>>       list_box :items => ["SD", "HD"],:choose=>Conf.vidtype do |list|
>>>>         Conf.vidtype = list.text
>>>>       end
>>>>     end
>>>>
>>>>     button "Confirm Settings" do
>>>>       visit "/settings"
>>>>     end
>>>>   end
>>>>
>>>>   def check_settings
>>>>     background rgb(50,50,125)
>>>>     #style Shoes::Para, stroke: white, size: 'xx-small'
>>>>     # green shoes - x-small is small enough   style Shoes::Para,
>>>> :stroke=> white, :size=> 'x-small'
>>>>     style Shoes::Para, :stroke=> white, :size=> 'xx-small'
>>>>     stack do
>>>>       para "Choose an Video format:"
>>>>       VideoFormats(Conf.framerate, Conf.vidtype)
>>>>
>>>>       para "Choose an Audio format:"
>>>>       AudioFormats(Conf.framerate)
>>>>
>>>>       para "Choose Browse format:"
>>>>       BrowseFormats(Conf.framerate)
>>>>
>>>>       button "Update Settings" do
>>>>         visit "/update"
>>>>       end
>>>>     end
>>>>   end
>>>>
>>>>   def update_capacity
>>>>     background rgb(50,50,125)
>>>>     #style Shoes::Para, stroke: white, size: 'xx-small'
>>>>     # green shoes - x-small is small enough   style Shoes::Para,
>>>> :stroke=> white, :size=> 'x-small'
>>>>     style Shoes::Para, :stroke=> white, :size=> '8'
>>>>     output.new
>>>>     every(10) {
>>>>       output.new
>>>>     }
>>>>   end
>>>>
>>>>   def calchours(protons)
>>>>     rate = (protons.to_i /
>>>> 
(LookupRatio(Conf.videonumber)+LookupRatio(Conf.audionumber)+LookupRatio(Conf.browsenumber))/Conf.framerate.to_i/60/60).round(2)
>>>>     #SANITY CHECK PROTONS AS HOURS
>>>>     #puts rate
>>>>     return rate
>>>>   end
>>>>
>>>>   def getValues
>>>>     Manager.open(:host => Conf.hostname) do |manager|
>>>>       #puts Conf.hostname
>>>>       poolArray = []
>>>>       poolsTable = ObjectId.new("1.3.6.1.4.1.15248.2.5.1.3.1")
>>>>       manager.walk(poolsTable) do |row|
>>>>         poolArray.push(row.to_s)
>>>>       end
>>>>       if poolArray.empty?
>>>>         #puts "Manager Down"
>>>>         poolArray = [
>>>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.1.8650, value=8650
>>>> (INTEGER)]',
>>>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.1.8651, value=8651
>>>> (INTEGER)]',
>>>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.2.8650, value=QNewsAK
>>>> (OCTET STRING)]',
>>>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.2.8651, value=QSuite4AK
>>>> (OCTET STRING)]',
>>>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.3.8650, value=46835255
>>>> (INTEGER)]',
>>>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.3.8651, value=11041721
>>>> (INTEGER)]',
>>>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.4.8650, value=8442357
>>>> (INTEGER)]',
>>>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.4.8651, value=5717570
>>>> (INTEGER)]',
>>>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.5.8650, value=0
>>>> (INTEGER)]',
>>>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.5.8651, value=0
>>>> (INTEGER)]',
>>>>         ]
>>>>         #debug when running as console app
>>>>         #else puts "Manager Up"
>>>>       end
>>>>       groups = poolArray.group_by{ |s| s.split(',').first[/\d+$/] }
>>>>       values = groups.map{ |key, ary| ary.map{ |s| s[/value=(\S+)/,
>>>> 1].to_s } }
>>>>       #Dump values to check syntax
>>>>       #  puts "Values: #{@values}"
>>>>       return values
>>>>     end
>>>>   end
>>>>
>>>>   def output
>>>>     time = Time.now
>>>>     stack :margin=>1, :width=>440  do
>>>>       #clear do
>>>>       border blue..white, :strokewidth => 1
>>>>       para time.strftime("%a %b %d, %Y %I:%M.%S")
>>>>       getValues.each {|v|
>>>>         flow :width=>'100%', :margin=>2 do
>>>>           border white..lightblue, :strokewidth => 2
>>>>           para "#{v[1]} (Pool: #{v[0]})"
>>>>           stack :width=>'33%' do
>>>>             para "Free Hours"
>>>>             para "#{calchours(v[3])}"
>>>>           end
>>>>           stack :width=>'33%' do
>>>>             para "Used Hours:"
>>>>             para "#{calchours(v[2])}"
>>>>           end
>>>>           stack :width=>'33%' do
>>>>             para "Percent Free: "
>>>>             para "#{(v[3].to_f/v[2].to_f*100).round(2)}%\r\n"
>>>>           end
>>>>         end
>>>>       }
>>>>     end
>>>>     #end
>>>>
>>>>
>>>>   end
>>>> #end
>>>> #  def para(text='')
>>>> #    super text, :family=> "Calibri", :stroke=> white, :size=>'small'
>>>> #  end
>>>> end
>>>>
>>>>   Shoes.app(:title=> "Quantel SNMP Space Monitor",
>>>>   :width=> 450,
>>>>   :height=> 300)
>>>>
>>>>
>>>> ========
>>>>
>>>>
>>>>
>>>
>

Re: [shoes] Re: More silliness... I don't know what I broke

From:
Arne Brasseur
Date:
2013-08-08 @ 09:49
Hey Scott,

I'm trying to run your code under Green and Red Shoes to see if I can
shed some light on your issue. But I'm completely unfamiliar with
SNMP. What's the easiest way for me to test this? Is it easy to run a
local SNMP server (I'm on Ubuntu)? Is there a public server I can
connect to?

Thanks,
Arne

On 8 August 2013 03:31, Scott Harman <scott@harman.tv> wrote:
> https://gist.github.com/scottharman/58c2a22c2062d1ab009e
>
> I've posted the code in the gist above
> If anyone has any thoughts, that would be awesome -
> I'd really like to be able to just run this as a red shoes app, and just
> deploy it as a standalone exe, without having to get customers to install
> ruby too
> Cheers
>
>
> On Thu, Aug 8, 2013 at 8:59 AM, Scott Harman <scott@harman.tv> wrote:
>>
>> Hi Arne -
>> Thanks - I will do that
>> Cheers
>>
>>
>> On Wed, Aug 7, 2013 at 11:24 PM, Arne Brasseur <arne.brasseur@gmail.com>
>> wrote:
>>>
>>> Hey Scott,
>>>
>>> Just a tip, for sharing more than a few lines of code it's recommended to
>>> use gist.github.com or a similar "pastie" service. Depending on email reader
>>> and device it can be quite a pain to read code in emails.
>>>
>>> Best,
>>> Arne
>>>
>>> On 07 Aug 2013 07:46, "Scott Harman" <scott@harman.tv> wrote:
>>>>
>>>> Previous message rejected due to length - trying again
>>>>>
>>>>> Hi guys
>>>>> I was so very close to having this script working in both Red and Green
>>>>> Shoes (no joy at all under Shoes4 sadly)
>>>>> I've included the whole code inline below, and it's currently
>>>>> configured for Red Shoes (even though the stack and flow blocks are miles
>>>>> out of alignment
>>>>>
>>>>> Basically, it connects to one of of servers, and retrieves a table from
>>>>> a particular SNMP OID, which shows the amount of storage we have per server
>>>>> (reported in what we call protons, but are effectively 128KB blocks)
>>>>> Normally, we'd fetch this every 5 minutes, but I'm fetching every 10
>>>>> seconds for debug purposes
>>>>>
>>>>> I've finally managed to work out how to store an appropriate string in
>>>>> case the manager isn't running just for test purposes
>>>>> What's weird is that under green shoes, it now crashes on 2nd
>>>>> execution, but on red shoes, it doesn't seem to loop.
>>>>> I have been trying to replace the content of the output block each
>>>>> time, and before I did this, red shoes was just appending what was there (so
>>>>> I added a clock to see what it was doing)
>>>>>
>>>>> It appears to be a basic flow control issue, and all I really want to
>>>>> do is create a lightweight deployable app that a customer can just run to
>>>>> get space reporting on their media manager's desktops.
>>>>> At the moment, they have to connect to a web service for our 'manager'
>>>>> app, which isn't really safe for non-technical users to access (as it's an
>>>>> engineering tool) and we don't report space in anything other than 'protons'
>>>>> and 'atoms'
>>>>> I've hardcoded our storage matrix into the app, so it makes it trivial
>>>>> to choose the right combination
>>>>>
>>>>> Does anyone have any ideas of what I'm doing wrong?
>>>>> Kind regards,
>>>>> Scott
>>>>> ========
>>>>>
>>>>> #Uncomment for Red Shoes (and vice versa)
>>>>> Shoes.setup do
>>>>>   gem 'snmp'
>>>>>   require 'snmp'
>>>>>   #require 'optparse'
>>>>> end
>>>>> #
>>>>> #
>>>>> #Uncomment for Green Shoes (and vice versa)
>>>>> #begin
>>>>> #  gem'green_shoes'
>>>>> #rescue LoadError
>>>>> #  system("gem install green_shoes")
>>>>> #end
>>>>> #begin
>>>>> #  gem 'snmp'
>>>>> #rescue LoadError
>>>>> #  system("gem install snmp")
>>>>> #end
>>>>> #require 'green_shoes'
>>>>> #require 'snmp'
>>>>>
>>>>> class Conf
>>>>>   class << self
>>>>>     attr_accessor :hostname, :framerate, :vidtype, :videoformat,
>>>>> :videonumber, :browseformat, :browsenumber, :audioformat, :audionumber
>>>>>     def hostname
>>>>>       @hostname
>>>>>     end
>>>>>
>>>>>     def framerate
>>>>>       @framerate
>>>>>     end
>>>>>
>>>>>     def vidtype
>>>>>       @vidtype
>>>>>     end
>>>>>
>>>>>     def audioformat
>>>>>       @audioformat
>>>>>     end
>>>>>
>>>>>     def videoformat
>>>>>       @videoformat
>>>>>     end
>>>>>
>>>>>     def browseformat
>>>>>       @browseformat
>>>>>     end
>>>>>
>>>>>     def audionumber
>>>>>       @audionumber
>>>>>     end
>>>>>
>>>>>     def videonumber
>>>>>       @videonumber
>>>>>     end
>>>>>
>>>>>     def browsenumber
>>>>>       @browsenumber
>>>>>     end
>>>>>   end
>>>>> end
>>>>>
>>>>> class SNMPManager < Shoes
>>>>>   url "/", :configure
>>>>>   url "/settings", :check_settings
>>>>>   url "/update", :update_capacity
>>>>>
>>>>>   include SNMP
>>>>>   #attr_accessor :hostname, :framerate, :vidtype
>>>>>   def initialize(params = {})
>>>>>     # @step=0
>>>>>    #  Gtk.running=true
>>>>>
>>>>>   end
>>>>>
>>>>>   def LookupRatio(formatnumber)
>>>>> #text too long - dummy entry
>>>>>     return 1
>>>>>   end
>>>>>
>>>>>   def AudioFormats(framerate)
>>>>>     @NTSCformats = {
>>>>>       24=>"Legacy 8 Audio 4 channel 30 fps",
>>>>>       68=>"Legacy 9 Audio 4 channel 30 fps",
>>>>>       265=>"Audio 4 channel 16bit 30 fps",
>>>>>       269=>"Audio 4 channel 24bit 30 fps",
>>>>>       270=>"Audio 8 channel 16bit 30 fps",
>>>>>       271=>"Audio 8 channel 24bit 30 fps"
>>>>>     }
>>>>>     @PALformats = {
>>>>>       33=>"Legacy 8 Audio 4 channel 25 fps",
>>>>>       73=>"Legacy 9 Audio 4 channel 25 fps",
>>>>>       521=>"Audio 4 channel 16bit 25 fps",
>>>>>       522=>"Audio 4 channel 24bit 25 fps",
>>>>>       523=>"Audio 8 channel 16bit 25 fps",
>>>>>       524=>"Audio 8 channel 24bit 25 fps"
>>>>>     }
>>>>>
>>>>>     if (Conf.framerate == 25)
>>>>>       choicelist=@PALformats
>>>>>     elsif (Conf.framerate == 30)
>>>>>       choicelist=@NTSCformats
>>>>>     end
>>>>>     Conf.audioformat=choicelist.values[1]
>>>>>     Conf.audionumber=choicelist.keys[1]
>>>>>     list_box :items => choicelist.values, :choose =>
>>>>> choicelist.values[1] do |list|
>>>>>       Conf.audioformat=list.text
>>>>>       Conf.audionumber=choicelist.key(list.text)
>>>>>     end
>>>>>
>>>>>   end
>>>>>
>>>>>   def VideoFormats(framerate, vidtype)
>>>>>     @SDNTSCformats = {
>>>>>       17=>"Legacy 8 Mpeg 30 480i30",
>>>>>       #      18=>"Legacy 8 Mpeg 40 480i30",
>>>>>       #      19=>"Legacy 8 Mpeg 50 480i30",
>>>>>       65=>"Legacy 9 Mpeg 30 480i30",
>>>>>       66=>"Legacy 9 Mpeg 40 480i30",
>>>>>       67=>"Legacy 9 Mpeg 50 480i30",
>>>>>       86=>"Legacy 9E Mpeg 30 480i30",
>>>>>       87=>"Legacy 9E Mpeg 40 480i30",
>>>>>       88=>"Legacy 9E Mpeg 50 480i30",
>>>>>       #   262=>"Mpeg 30 480i30",
>>>>>       #   263=>"Mpeg 40 480i30",
>>>>>       #  264=>"Mpeg 50 480i30",
>>>>>       #  275=>"Mpeg 30 480i30 15f",
>>>>>       #  276=>"Mpeg 40 480i30 11f",
>>>>>       #  277=>"Mpeg 50 480i30 10f",
>>>>>       710=>"DVCPRO50 525i30 8f",
>>>>>       711=>"DVCPRO25 525i30 10f",
>>>>>       712=>"DV 525i30 10f"
>>>>>     }
>>>>>     @HDNTSCformats = {
>>>>>       #      20=>"Legacy 8 DV100 720p60",
>>>>>       #      23=>"Legacy 8 DV100 1080i30",
>>>>>       78=>"Legacy 9 DV100 720p60",
>>>>>       81=>"Legacy 9 DV100 1080i30",
>>>>>       256=>"DV100 720p60",
>>>>>       259=>"DV100 1080i30",
>>>>>       280=>"DV100 720p60 6f",
>>>>>       281=>"DV100 1080i30 6f",
>>>>>       600=>"AVC-I 50 1080i30 9f",
>>>>>       601=>"AVC-I 100 1080i30 7f",
>>>>>       602=>"AVC-I 50 720p60 9f",
>>>>>       603=>"AVC-I 100 720p60 7f",
>>>>>       622=>"AVC-I 100 1080p60 6f",
>>>>>       623=>"AVC-I 200 1080p60 3f"
>>>>>     }
>>>>>     @SDPALformats = {
>>>>>       26=>"Legacy 8 Mpeg 30 576i25",
>>>>>       #      27=>"Legacy 8 Mpeg 40 576i25",
>>>>>       #      28=>"Legacy 8 Mpeg 50 576i25",
>>>>>       70=>"Legacy 9 Mpeg 30 576i25",
>>>>>       71=>"Legacy 9 Mpeg 40 576i25",
>>>>>       72=>"Legacy 9 Mpeg 50 576i25",
>>>>>       89=>"Legacy 9E Mpeg 30 576i25",
>>>>>       90=>"Legacy 9E Mpeg 40 576i25",
>>>>>       91=>"Legacy 9E Mpeg 50 576i25",
>>>>>       #   518=>"Mpeg 30 576i25",
>>>>>       #   519=>"Mpeg 40 576i25",
>>>>>       #   520=>"Mpeg 50 576i25",
>>>>>       #   525=>"Mpeg 30 576i25 14f",
>>>>>       #   526=>"Mpeg 40 576i25 12f",
>>>>>       #   527=>"Mpeg 50 576i25 12f",
>>>>>       700=>"DVCPRO50 625i25  7f",
>>>>>       701=>"DVCPRO25 625i25 10f",
>>>>>       702=>"DV 625i25 10f"
>>>>>     }
>>>>>     @HDPALformats = {
>>>>>       512=>"DV100 720p50",
>>>>>       515=>"DV100 1080i25",
>>>>>       530=>"DV100 1080i25 5f",
>>>>>       610=>"AVC-I 50 1080i25 11f",
>>>>>       611=>"AVC-I 100 1080i25 5f",
>>>>>       612=>"AVC-I 50 720p50 11f",
>>>>>       613=>"AVC-I 100 720p50 6f",
>>>>>       620=>"AVC-I 100 1080p50 5f",
>>>>>       621=>"AVC-I 200 1080p50 3f"
>>>>>     }
>>>>>
>>>>>     if (Conf.framerate == 25 &&  Conf.vidtype == "HD")
>>>>>       choicelist = @HDPALformats
>>>>>     elsif (Conf.framerate == 25 && Conf.vidtype == "SD")
>>>>>       choicelist = @SDPALformats
>>>>>     elsif (Conf.framerate == 30 && Conf.vidtype == "HD")
>>>>>       choicelist = @HDNTSCformats
>>>>>     elsif (Conf.framerate == 30 &&  Conf.vidtype == "SD")
>>>>>       choicelist = @SDNTSCformats
>>>>>     end
>>>>>     Conf.videoformat=choicelist.values[1]
>>>>>     Conf.videonumber=choicelist.keys[1]
>>>>>     list_box :items => choicelist.values, :choose =>
>>>>> choicelist.values[1] do |list|
>>>>>       Conf.videoformat=list.text
>>>>>       Conf.videonumber=choicelist.key(list.text)
>>>>>     end
>>>>>
>>>>>   end
>>>>>
>>>>>   def BrowseFormats(framerate)
>>>>>     @BNTSCformats = {
>>>>>       #      37=>"Legacy 8 Browse Video 30 fps",
>>>>>       77=>"Legacy 9 Browse Video 30 fps",
>>>>>       260=>"Browse Video 30 fps"
>>>>>       #   291=>"MPEG-2 Browse Video 30 fps",
>>>>>       #   301=>"H.264 Browse Video 30 fps",
>>>>>       #   303=>"H.264 SIF Browse Video 30 fps",
>>>>>       #    311=>"H.264 640x360 30 fps",
>>>>>       #    313=>"H.264 640x480 30 fps"
>>>>>     }
>>>>>     @BPALformats = {
>>>>>       #      34=>"Legacy 8 Browse Video 25 fps",
>>>>>       74=>"Legacy 9 Browse Video 25 fps",
>>>>>       #    290=>"MPEG-2 Browse Video 25 fps",
>>>>>       #    300=>"H.264 Browse Video 25 fps",
>>>>>       #   302=>"H.264 SIF Browse Video 25 fps",
>>>>>       #    310=>"H.264 640x360 25 fps",
>>>>>       #   312=>"H.264 640x480 25 fps",
>>>>>       516=>"Browse Video 25 fps"
>>>>>     }
>>>>>
>>>>>     if (Conf.framerate == 25)
>>>>>       choicelist=@BPALformats
>>>>>     elsif (Conf.framerate == 30)
>>>>>       choicelist=@BNTSCformats
>>>>>     end
>>>>>     Conf.browseformat=choicelist.values[1]
>>>>>     Conf.browsenumber=choicelist.keys[1]
>>>>>     list_box :items => choicelist.values, :choose =>
>>>>> choicelist.values[1] do |list|
>>>>>       Conf.browseformat=list.text
>>>>>       Conf.browsenumber=choicelist.key(list.text)
>>>>>     end
>>>>>
>>>>>   end
>>>>>
>>>>>   def configure
>>>>>     Conf.new
>>>>>     Conf.framerate=25
>>>>>     Conf.vidtype="SD"
>>>>>     background rgb(50,50,125)
>>>>>     #style Shoes::Para, stroke: white, size: 'xx-small'
>>>>>     # green shoes - x-small is small enough   style Shoes::Para,
>>>>> :stroke=> white, :size=> 'x-small'
>>>>>     style Shoes::Para, :stroke=> white, :size=> 'xx-small'
>>>>>     stack do
>>>>>       para "Enter Hostname:"
>>>>>       edit_line("localhost") do |e|
>>>>>         Conf.hostname = e.text
>>>>>       end
>>>>>
>>>>>       para "Choose an frame rate:"
>>>>>       list_box :items => [25, 30],:choose=>Conf.framerate do |list|
>>>>>         Conf.framerate =  list.text.to_i
>>>>>       end
>>>>>       para "Choose SD or HD formats"
>>>>>       list_box :items => ["SD", "HD"],:choose=>Conf.vidtype do |list|
>>>>>         Conf.vidtype = list.text
>>>>>       end
>>>>>     end
>>>>>
>>>>>     button "Confirm Settings" do
>>>>>       visit "/settings"
>>>>>     end
>>>>>   end
>>>>>
>>>>>   def check_settings
>>>>>     background rgb(50,50,125)
>>>>>     #style Shoes::Para, stroke: white, size: 'xx-small'
>>>>>     # green shoes - x-small is small enough   style Shoes::Para,
>>>>> :stroke=> white, :size=> 'x-small'
>>>>>     style Shoes::Para, :stroke=> white, :size=> 'xx-small'
>>>>>     stack do
>>>>>       para "Choose an Video format:"
>>>>>       VideoFormats(Conf.framerate, Conf.vidtype)
>>>>>
>>>>>       para "Choose an Audio format:"
>>>>>       AudioFormats(Conf.framerate)
>>>>>
>>>>>       para "Choose Browse format:"
>>>>>       BrowseFormats(Conf.framerate)
>>>>>
>>>>>       button "Update Settings" do
>>>>>         visit "/update"
>>>>>       end
>>>>>     end
>>>>>   end
>>>>>
>>>>>   def update_capacity
>>>>>     background rgb(50,50,125)
>>>>>     #style Shoes::Para, stroke: white, size: 'xx-small'
>>>>>     # green shoes - x-small is small enough   style Shoes::Para,
>>>>> :stroke=> white, :size=> 'x-small'
>>>>>     style Shoes::Para, :stroke=> white, :size=> '8'
>>>>>     output.new
>>>>>     every(10) {
>>>>>       output.new
>>>>>     }
>>>>>   end
>>>>>
>>>>>   def calchours(protons)
>>>>>     rate = (protons.to_i /
>>>>> 
(LookupRatio(Conf.videonumber)+LookupRatio(Conf.audionumber)+LookupRatio(Conf.browsenumber))/Conf.framerate.to_i/60/60).round(2)
>>>>>     #SANITY CHECK PROTONS AS HOURS
>>>>>     #puts rate
>>>>>     return rate
>>>>>   end
>>>>>
>>>>>   def getValues
>>>>>     Manager.open(:host => Conf.hostname) do |manager|
>>>>>       #puts Conf.hostname
>>>>>       poolArray = []
>>>>>       poolsTable = ObjectId.new("1.3.6.1.4.1.15248.2.5.1.3.1")
>>>>>       manager.walk(poolsTable) do |row|
>>>>>         poolArray.push(row.to_s)
>>>>>       end
>>>>>       if poolArray.empty?
>>>>>         #puts "Manager Down"
>>>>>         poolArray = [
>>>>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.1.8650, value=8650
>>>>> (INTEGER)]',
>>>>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.1.8651, value=8651
>>>>> (INTEGER)]',
>>>>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.2.8650, value=QNewsAK
>>>>> (OCTET STRING)]',
>>>>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.2.8651, value=QSuite4AK
>>>>> (OCTET STRING)]',
>>>>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.3.8650, value=46835255
>>>>> (INTEGER)]',
>>>>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.3.8651, value=11041721
>>>>> (INTEGER)]',
>>>>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.4.8650, value=8442357
>>>>> (INTEGER)]',
>>>>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.4.8651, value=5717570
>>>>> (INTEGER)]',
>>>>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.5.8650, value=0
>>>>> (INTEGER)]',
>>>>>           '[name=1.3.6.1.4.1.15248.2.5.1.3.1.5.8651, value=0
>>>>> (INTEGER)]',
>>>>>         ]
>>>>>         #debug when running as console app
>>>>>         #else puts "Manager Up"
>>>>>       end
>>>>>       groups = poolArray.group_by{ |s| s.split(',').first[/\d+$/] }
>>>>>       values = groups.map{ |key, ary| ary.map{ |s| s[/value=(\S+)/,
>>>>> 1].to_s } }
>>>>>       #Dump values to check syntax
>>>>>       #  puts "Values: #{@values}"
>>>>>       return values
>>>>>     end
>>>>>   end
>>>>>
>>>>>   def output
>>>>>     time = Time.now
>>>>>     stack :margin=>1, :width=>440  do
>>>>>       #clear do
>>>>>       border blue..white, :strokewidth => 1
>>>>>       para time.strftime("%a %b %d, %Y %I:%M.%S")
>>>>>       getValues.each {|v|
>>>>>         flow :width=>'100%', :margin=>2 do
>>>>>           border white..lightblue, :strokewidth => 2
>>>>>           para "#{v[1]} (Pool: #{v[0]})"
>>>>>           stack :width=>'33%' do
>>>>>             para "Free Hours"
>>>>>             para "#{calchours(v[3])}"
>>>>>           end
>>>>>           stack :width=>'33%' do
>>>>>             para "Used Hours:"
>>>>>             para "#{calchours(v[2])}"
>>>>>           end
>>>>>           stack :width=>'33%' do
>>>>>             para "Percent Free: "
>>>>>             para "#{(v[3].to_f/v[2].to_f*100).round(2)}%\r\n"
>>>>>           end
>>>>>         end
>>>>>       }
>>>>>     end
>>>>>     #end
>>>>>
>>>>>
>>>>>   end
>>>>> #end
>>>>> #  def para(text='')
>>>>> #    super text, :family=> "Calibri", :stroke=> white, :size=>'small'
>>>>> #  end
>>>>> end
>>>>>
>>>>>   Shoes.app(:title=> "Quantel SNMP Space Monitor",
>>>>>   :width=> 450,
>>>>>   :height=> 300)
>>>>>
>>>>>
>>>>> ========
>>>>>
>>>>>
>>>>
>>
>

Re: [shoes] Re: More silliness... I don't know what I broke

From:
ashbb
Date:
2013-08-08 @ 12:23
Hi Scott,

Try this out: http://pastebin.com/WUk9QpdF

I also commented out a few lines for snmp, but it will help you to
understand the behavior of Shoes. ;-)

Cheers,
ashbb

Re: [shoes] Re: More silliness... I don't know what I broke

From:
Scott Harman
Date:
2013-08-08 @ 23:06
Hi ashbb
Thanks - I didn't even think of doing that!
It's kind of obvious now - I thought I needed an event timer, and would
just call the output block each time, rather than just calling myself.

Hi Arne, the SNMP blockjust connects to an SNMP service over TCP and
retrieves a table - commenting out all of that as ashbb has done is what I
should have done initially
I was originally doing everything in Corba, but in Ruby it's not easily
deployable - but if I can deploy red shoes, then I might be able to package
my Corba version (which is vastly more flexible than SNMP but requires much
more work to get it up and running)


On Thu, Aug 8, 2013 at 10:23 PM, ashbb <ashbbb@gmail.com> wrote:

> Hi Scott,
>
> Try this out: http://pastebin.com/WUk9QpdF
>
> I also commented out a few lines for snmp, but it will help you to
> understand the behavior of Shoes. ;-)
>
> Cheers,
> ashbb
>