xtop 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NjViMzMzYmJmYjI4ZWVmYWU4ZTA1OTIyNDJkYTMwZjgzNGZmYjI0MA==
5
+ data.tar.gz: !binary |-
6
+ ZDk1MDJlZGUyNzc1ZWViOGQ4ZWU4OTM1MDM5NTk4ZTc5OWJmY2IyMA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MmE1OWEyNjYzYTFiZWE0NjEwNTQyZjU4MmE5N2EzYjY3MDRmOTA3NTgwYTY2
10
+ NTU4MjExOWZhM2JhYzlkY2M2YjY4ZjIxMmYwYWE0YjNiMzUyOGVhMzE4YTk1
11
+ YzAxMzJkNGJmNmRkMGNhYTE2OGJiNWMwZmUxYWY4ZTQwYjM5ZDI=
12
+ data.tar.gz: !binary |-
13
+ MjhlNTY3MmZhZmQyYjkwMDhlNjU2MDBjZmRmYTNjYTdhMjJmZTAxOWFlYTEz
14
+ Y2Q4NzAxZDIwOTM3ZGI3NWZmZjZhY2VlODBlODJiZTNhODg1ZTVlMzIzZjI1
15
+ MjFkYzY0ZGFlNmJjOTRhZWIwMDc3OTFmNzZjOWFjYjQzMjZlMjQ=
@@ -0,0 +1,5 @@
1
+ .*~
2
+ *~
3
+
4
+ .bundle
5
+ .yardoc
@@ -0,0 +1 @@
1
+ 1.9.3-p392
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.8.7"
4
+ - "1.9.2"
5
+ - "1.9.3"
6
+ - "2.0.0"
7
+ - jruby-18mode # JRuby in 1.8 mode
8
+ - jruby-19mode # JRuby in 1.9 mode
9
+ - rbx-18mode
10
+ - rbx-19mode
11
+ matrix:
12
+ allow_failures:
13
+ - rvm: 1.8.7
14
+ - rvm: jruby-18mode
15
+ - rvm: rbx-18mode
@@ -0,0 +1,5 @@
1
+ {
2
+ "google.com" => proc { sleep Random.rand(5)/4.0; :ok },
3
+ "yahoo.com" => proc { :error },
4
+ "bing.com" => proc { :ok }
5
+ }
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in xtop.gemspec
4
+ gemspec
@@ -0,0 +1,8 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+
5
+ PLATFORMS
6
+ ruby
7
+
8
+ DEPENDENCIES
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 RentPath, Inc.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,74 @@
1
+ Xtop
2
+ =========
3
+ [![Code Climate](https://codeclimate.com/github/primedia/xtop.png)](https://codeclimate.com/github/primedia/xtop)
4
+ [![Build Status](https://travis-ci.org/primedia/xtop.png)](https://travis-ci.org/primedia/xtop)
5
+ [![Coverage Status](https://coveralls.io/repos/primedia/xtop/badge.png?branch=dev)](https://coveralls.io/r/primedia/xtop?branch=dev)
6
+ [![Dependency Status](https://gemnasium.com/primedia/xtop.png)](https://gemnasium.com/primedia/xtop)
7
+ [![Gem Version](https://badge.fury.io/rb/xtop.png)](http://badge.fury.io/rb/xtop)
8
+
9
+ ## Requirements
10
+
11
+ Ruby 1.9.3 or greater. Ruby 2.0 support is untested right now, so please file an issue if you
12
+ experience a problem.
13
+
14
+ ## Installation (Gemfile)
15
+
16
+ Add the Primedia gem source to your Gemfile:
17
+
18
+ source 'http://gems.idg.primedia.com'
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ gem 'xtop'
23
+
24
+ And then execute:
25
+
26
+ $ bundle install
27
+
28
+ ## Installation (Shell)
29
+
30
+ Add the Primedia gem source:
31
+
32
+ gem sources -a http://gems01.lab.primedia.com/
33
+
34
+ Install it via the gem command:
35
+
36
+ $ gem install xtop
37
+
38
+ ## Usage
39
+
40
+ To use Xtop, run the command:
41
+
42
+ xtop
43
+
44
+ You should have a .xtop.rb file either:
45
+
46
+ 1. In the directory you are calling it from
47
+ 2. In your $HOME directory
48
+
49
+ If you don't have either one, it will exit immediately with no output.
50
+
51
+ ## Contributing
52
+
53
+ 1. Fork it
54
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
55
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
56
+ 4. Push to the branch (`git push origin my-new-feature`)
57
+ 5. Create new Pull Request
58
+
59
+ ## Running the Tests
60
+
61
+ There are currently no tests.
62
+
63
+ ## Credits
64
+
65
+ Jack Morrill
66
+ Edward Leung
67
+ Eric Toulson
68
+ Colin Rymer
69
+ Tyler Long
70
+ Tyler Boyd
71
+
72
+ ## License
73
+
74
+ Xtop is released under the MIT License. See the bundled LICENSE file for details.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+ require 'xtop'
3
+
4
+ include Xtop
5
+
6
+ file = `pwd`.chomp + "/.xtop.rb"
7
+
8
+ Thread.abort_on_exception = true
9
+
10
+ if File.exists?(file)
11
+ view = XtopView.new(eval(File.read(file)))
12
+ elsif File.exists?(File.expand_path("~/.xtop.rb"))
13
+ view = XtopView.new(eval(File.read(File.expand_path("~/.xtop.rb"))))
14
+ else
15
+ XtopLoop.exit_xtop
16
+ end
17
+
18
+ XtopLoop.start(view) do |key|
19
+ case key
20
+ when "q"
21
+ XtopLoop.exit_xtop
22
+ when "r"
23
+ view.update_status("google.com", "red")
24
+ end
25
+ end
@@ -0,0 +1,4 @@
1
+ require "xtop/version"
2
+ require "xtop/url_checker"
3
+ require "xtop/xtop_view"
4
+ require "xtop/xtop_loop"
@@ -0,0 +1,44 @@
1
+ # UrlChecker: Check the status of a given URL by passing a Proc that
2
+ # calls the URL and performs some test on the result. A checker must
3
+ # return :ok for green and :error for red. Any other result or a timeout
4
+ # causes the status line ot be yellow.
5
+ module Xtop
6
+ class UrlChecker
7
+ TIMEOUT = 15
8
+ INTERVAL = 0.5
9
+
10
+ def self.check(view, checkers={})
11
+ checker_threads = {}
12
+
13
+ checkers.each do |url, checker|
14
+ checker_threads[url] = Thread.new do
15
+ case checker.call
16
+ when :ok
17
+ view.update_status(url, "green")
18
+ when :error
19
+ view.update_status(url, "red")
20
+ else
21
+ view.update_status(url, "yellow")
22
+ end
23
+ end
24
+
25
+ Thread.new do
26
+ time_elapsed = 0.0
27
+ while true
28
+ sleep(0.1)
29
+ time_elapsed += INTERVAL
30
+
31
+ if checker_threads[url].status == false # thread has exited
32
+ break
33
+
34
+ elsif time_elapsed > TIMEOUT
35
+ view.update_status(url, "yellow")
36
+ Thread.kill(checker_threads[url])
37
+ break
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module Xtop
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,29 @@
1
+ require 'curses'
2
+
3
+ # XtopLoop: Fetch input from user and respond.
4
+ class XtopLoop
5
+ extend Curses
6
+
7
+ def self.exit_xtop
8
+ close_screen
9
+ exit(0)
10
+ end
11
+
12
+ def self.start(view)
13
+ begin
14
+ Signal.trap("SIGINT") do
15
+ exit(0)
16
+ end
17
+
18
+ cbreak
19
+
20
+ while true
21
+ view.redraw
22
+ yield(getch)
23
+ end
24
+ ensure
25
+ close_screen
26
+ end
27
+ end
28
+ end
29
+
@@ -0,0 +1,64 @@
1
+ require "curses"
2
+ require File.expand_path('../url_checker.rb', __FILE__)
3
+
4
+ # XtopView: a simple view for the status of each URL. Colors, unit tests,
5
+ # refactoring is pending. resizing smoothly is out of scope (see top's
6
+ # behavior) -TB
7
+ module Xtop
8
+ class XtopView
9
+ include Curses
10
+
11
+ # use this to update the status of a single URL.
12
+ def update_status(key, value)
13
+ @statuses[key] = value
14
+ redraw
15
+ end
16
+
17
+ # redraw the main view
18
+ def redraw
19
+ clear # clear screen
20
+ setpos(0, 0) # start at top of screen
21
+ add_col2_line("Xtop", "RentPath") # render title line
22
+
23
+ setpos(2, 0) # skip a line
24
+ add_col2_line("URL", "STATUS") # render column headers
25
+ @statuses.each do |k,v| # render each line
26
+ add_col2_line(k, v, color: @colormap[v.to_sym])
27
+ end
28
+ curs_set(0) # clear cursor
29
+ refresh # show
30
+ end
31
+
32
+ def initialize(checkers)
33
+ init_screen
34
+ init_colors
35
+
36
+ @statuses = Hash[checkers.map { |k,v| [k, "white"] }]
37
+
38
+ Thread.new do
39
+ while true
40
+ UrlChecker.check(self, checkers)
41
+ sleep(0.8)
42
+ end
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ def init_colors(colormap=[:green, :yellow, :red, :white])
49
+ constants = {green: COLOR_GREEN, yellow: COLOR_YELLOW, red: COLOR_RED, white: COLOR_WHITE}
50
+ start_color # initialize color output
51
+ @colormap = {}
52
+ colormap.each_with_index do |color, i|
53
+ @colormap[color] = i+1
54
+ init_pair(i+1, constants[color], COLOR_BLACK) # save a fg/bg color pair at index i+1
55
+ end
56
+ end
57
+
58
+ def add_col2_line(val1, val2, opts={color: 4})
59
+ attron(color_pair(opts[:color])) # change color
60
+ addstr(sprintf("%-#{cols-10}s%-10s", val1, val2)) # write string
61
+ attroff(color_pair(opts[:color])) # change color back
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'xtop/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "xtop"
8
+ spec.version = Xtop::VERSION
9
+ spec.authors = ["Jack Morrill", "Eric Toulson", "Edward Leung", "Tyler Long", "Tyler Boyd"]
10
+ spec.email = ["IWS_ADMIN@rentpath.com"]
11
+ spec.summary = %q{Command-line dashboard for external services}
12
+ spec.description = %q{Command-line dashboard for external services}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ #spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xtop
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Jack Morrill
8
+ - Eric Toulson
9
+ - Edward Leung
10
+ - Tyler Long
11
+ - Tyler Boyd
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+ date: 2014-05-07 00:00:00.000000000 Z
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: bundler
19
+ requirement: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: '1.5'
24
+ type: :development
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: '1.5'
31
+ - !ruby/object:Gem::Dependency
32
+ name: rake
33
+ requirement: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ description: Command-line dashboard for external services
46
+ email:
47
+ - IWS_ADMIN@rentpath.com
48
+ executables:
49
+ - xtop
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - .ruby-version
55
+ - .travis.yml
56
+ - .xtop.rb.sample
57
+ - Gemfile
58
+ - Gemfile.lock
59
+ - LICENSE
60
+ - README.md
61
+ - Rakefile
62
+ - bin/xtop
63
+ - lib/xtop.rb
64
+ - lib/xtop/url_checker.rb
65
+ - lib/xtop/version.rb
66
+ - lib/xtop/xtop_loop.rb
67
+ - lib/xtop/xtop_view.rb
68
+ - xtop.gemspec
69
+ - xtop/.gitignore
70
+ homepage: ''
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.2.2
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Command-line dashboard for external services
94
+ test_files: []
95
+ has_rdoc: