logpoop 0.1.1 → 1.0.0

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.
data/Gemfile CHANGED
@@ -1,10 +1,5 @@
1
1
  source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
5
2
 
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
8
3
  group :development do
9
4
  gem "jeweler", "~> 1.5.2"
10
5
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 1.0.0
data/bin/logpoop CHANGED
@@ -1,9 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
  $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
3
3
  require 'logpoop'
4
-
5
- if(['help', '-h', '--help'].include?(ARGV[0]))
6
- puts LogPoop.usage
7
- else
8
- LogPoop.new(ARGV[0], ARGV[1])
9
- end
4
+ LogPoop.new
@@ -0,0 +1,46 @@
1
+ module Runner
2
+ class Context
3
+ # Get an array of open IO objects attached to existing terminal sessions. The current terminal
4
+ # (the one executing this program) will always be first.
5
+ def self.ttys(nums=[])
6
+ this_tty=`tty`.strip
7
+ # macos
8
+ if(this_tty =~ /ttys[0-9]{3}/)
9
+ other_ttys=Dir['/dev/ttys00*']
10
+
11
+ # linux
12
+ elsif(this_tty =~ /\/dev\/pts\/[0-9]{1}/)
13
+ other_ttys=Dir['/dev/pts/*']
14
+ end
15
+
16
+ other_ttys.reject!{|t| t == this_tty}
17
+ [this_tty].concat(other_ttys).map{|f| IO.sysopen(f, 'w')}.map{|n| IO.new(n, 'w')}
18
+ end
19
+
20
+ # A list of the currently-running simulators
21
+ def self.simulators
22
+ @@simulators ||= []
23
+ end
24
+
25
+ def self.logs
26
+ dir = @@options[:log_dir] || "/var/log"
27
+ `ls -S #{dir}/*.log`.split(/\n/)
28
+ end
29
+
30
+ def self.run(options={})
31
+ @@options = options
32
+ runner(@@options[:type]).new.run
33
+ end
34
+
35
+ def self.stop
36
+ simulators.each(&:stop)
37
+ end
38
+
39
+ def self.runner(opt)
40
+ {
41
+ :tail => MultiTail,
42
+ :test => TestRun
43
+ }[opt.to_sym]
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,22 @@
1
+ module Runner
2
+ class MultiTail
3
+ def run
4
+ ttys = Context.ttys
5
+ logs = Context.logs[0..ttys.length-1]
6
+ run_all(ttys,logs)
7
+ end
8
+
9
+ private
10
+ def run_all(ttys,logs)
11
+ threads = []
12
+ ttys.zip(logs).each do |pair|
13
+ threads << Thread.new(pair[0], pair[1]) do |mytty, myfile|
14
+ simulator = Simulator::TailEff.new(mytty, myfile)
15
+ Context.simulators << simulator
16
+ simulator.fake_it
17
+ end
18
+ end
19
+ threads.map(&:join)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ module Runner
2
+ class TestRun
3
+ def run
4
+ stdout, logout = Context.ttys[0..1]
5
+ log = Context.logs[0]
6
+ threads=[]
7
+ threads << Thread.new(stdout) do |myout|
8
+ sim = Simulator::TestRun.new(myout)
9
+ Context.simulators << sim
10
+ sim.fake_it
11
+ end
12
+ if(logout)
13
+ threads << Thread.new(logout, log) do |myout, mylog|
14
+ sim = Simulator::TailEff.new(myout, mylog)
15
+ Context.simulators << sim
16
+ sim.fake_it
17
+ end
18
+ end
19
+ threads.map(&:join)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ module Simulator
2
+ module Base
3
+ # takes an IO instance
4
+ def clear_screen(tty)
5
+ tty.write "\e[2J\e[f"
6
+ end
7
+
8
+ def stop
9
+ @stop = true
10
+ end
11
+
12
+ def simulate
13
+ fake_it
14
+ clear_screen(out)
15
+ end
16
+
17
+ def self.included(base)
18
+ base.class_eval do
19
+ attr_accessor :out
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,64 @@
1
+ #
2
+ # Simulate tail -f in a output stream by spewing chunks of lines
3
+ # from a given log file into it at semi-random speed.
4
+ #
5
+ module Simulator
6
+ class TailEff
7
+ include Simulator::Base
8
+
9
+ attr_accessor :logfile, :speed, :burst_size
10
+
11
+ # The maximum speed of the tailer. The speed will be sampled
12
+ # randomly in a range from 1/2 second to 1/speed seconds.
13
+ # higher = faster
14
+ def speed
15
+ @speed ||= 500
16
+ end
17
+
18
+ # The number of groups of lines that will be logged at a given
19
+ # speed before a new speed is calculated
20
+ def burst_size
21
+ @burst_size ||= 5
22
+ end
23
+
24
+ def initialize(out, logfile, speed=nil, burst_size=nil)
25
+ self.out = out
26
+ self.logfile = logfile
27
+ self.speed = speed
28
+ self.burst_size = burst_size
29
+ end
30
+
31
+ def fake_it
32
+ while !@stop do
33
+ print_lines
34
+ end
35
+ clear_screen(self.out)
36
+ end
37
+
38
+ private
39
+ def print_lines
40
+ bubble_speed, bubble_size = rand_speed, rand_burst
41
+ while(bubble_size > 0)
42
+ num_lines = rand(4) + 1
43
+ rand_pos = rand(loglines.length - 1)
44
+ range = (rand_pos..(rand_pos + num_lines))
45
+ line = loglines[range].map{|li| li.gsub(/'/, "\"")}.join("\n")
46
+ self.out.write(line)
47
+ sleep(1.0 / bubble_speed)
48
+ bubble_size -= 1
49
+ end
50
+ end
51
+
52
+ def loglines
53
+ @loglines ||= File.read(logfile).split(/\n/)
54
+ end
55
+
56
+ def rand_burst
57
+ rand(burst_size) + 1
58
+ end
59
+
60
+ def rand_speed
61
+ rand(speed) + 1
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,32 @@
1
+ module Simulator
2
+ class TestRun
3
+ EF = %w{ E F }
4
+
5
+ include Simulator::Base
6
+
7
+ def initialize(out)
8
+ self.out = out
9
+ end
10
+
11
+ def a_dot_or_an_e_or_an_f
12
+ if(rand(100) % 10 == 0)
13
+ EF[rand(EF.length)]
14
+ else
15
+ "."
16
+ end
17
+ end
18
+
19
+ def fake_it
20
+ clear_screen(self.out)
21
+ self.out.puts(Dir.pwd.strip + " $ rake test")
22
+ self.out.puts("(in #{Dir.pwd.strip})")
23
+ self.out.puts("Started")
24
+ while !@stop do
25
+ out.write(a_dot_or_an_e_or_an_f)
26
+ out.flush
27
+ sleep(rand(20) / 50.0)
28
+ end
29
+ clear_screen(self.out)
30
+ end
31
+ end
32
+ end
data/lib/logpoop.rb CHANGED
@@ -1,82 +1,57 @@
1
- class LogPoop
2
- attr_accessor :go
3
-
4
- def self.usage
1
+ require 'optparse'
2
+ require 'logpoop/runner/context'
3
+ require 'logpoop/runner/multi_tail'
4
+ require 'logpoop/runner/test_run'
5
+ require 'logpoop/simulator/base'
6
+ require 'logpoop/simulator/tail_eff'
7
+ require 'logpoop/simulator/test_run'
8
+
9
+ class LogPoop
10
+ def self.banner
5
11
  <<-STR
6
12
  Description:
7
- Print random lines from log files pulled from somewhere, at randomly varying speeds, to some or all
8
- open terminals.
9
-
10
- Usage: #{$0} [log_dir] [tty_num]
11
- log_dir directory to pull log files from, defaults to /var/log
12
- tty_num tty number to use (e.g. 1). If blank, all open terminals will get pooped on.
13
+ Look busy! Tail some stuff in your open terminals, or even simulate running some tests.
13
14
  STR
14
15
  end
15
- def self.instance
16
- @@instance
17
- end
18
-
19
- # takes an IO instance
20
- def clear_screen(tty)
21
- tty.write "\e[2J\e[f"
22
- end
23
16
 
24
- def loop_some_log_crap(mytty, log)
25
- iter = 0
26
- speed = rand(20)
27
- while @go do
28
- iter += 1
29
- num_lines = rand(4) + 1
30
- rand_pos = rand(log.length - 1)
31
- range = (rand_pos..(rand_pos + num_lines))
32
- line = log[range].map{|li| li.gsub(/'/, "\"")}.join("\n")
33
- mytty.write(line)
34
- sleep(speed / 50.0)
35
- speed = rand(20) if iter % 7 == 0
36
- end
37
- end
17
+ def self.parse_options
18
+ options = {
19
+ :type => :tail,
20
+ :log_dir => "/var/log"
21
+ }
38
22
 
39
- def initialize(log_dir, num)
40
- @@instance = self
41
- @ttys = get_tty_list(num).map{|f| IO.sysopen(f, 'w')}.map{|n| IO.new(n, 'w')}
42
- logs = get_logs(@ttys.length, log_dir || "/var/log")
43
- f = logs.map{|log| File.read(log).split(/\n/)}
44
- @go = true
45
- threads = []
46
- @ttys.each_with_index do |tty, index|
47
- threads << Thread.new(tty, f[index]) do |mytty, mylog|
48
- loop_some_log_crap(mytty, mylog)
23
+ o = OptionParser.new do |opt|
24
+ opt.banner = self.banner
25
+ opt.on("-v", "--version", "Show version") do
26
+ puts File.read(File.join(File.dirname(__FILE__), '..', 'VERSION'))
27
+ exit
49
28
  end
50
- end
51
- threads.each {|t| t.join}
52
- end
53
-
54
- def get_tty_list(num=nil)
55
- if(num.nil?)
56
- Dir.glob("/dev/ttys00*")
57
- else
58
- if(File.exists?("/dev/ttys00#{num}"))
59
- ["/dev/ttys00#{num}"]
60
- else
61
- raise "/dev/ttys00#{num} does not exist"
29
+ opt.on("-d", "--log_dir DIRECTORY", "Log directory") do |d|
30
+ options[:log_dir] = d
31
+ end
32
+ opt.on("-t", "--type TYPE", "Poop type. Available types:\n\ttail - simulate 'tail -f' in all your open terminals\n\ttest - simulate a console test run (needs two terminals open)") do |t|
33
+ options[:type] = t
62
34
  end
63
35
  end
36
+ o.parse!
37
+ options
64
38
  end
65
-
66
- def get_logs(how_many, dir)
67
- `ls -S #{dir}/*.log`.split(/\n/)[1..how_many]
39
+
40
+ def self.instance
41
+ @@instance
68
42
  end
69
-
70
- def stop
71
- @go = false
72
- @ttys.each {|t| clear_screen(t)}
43
+
44
+ def initialize
45
+ options = self.class.parse_options
46
+ Runner::Context.run(options)
73
47
  end
48
+
74
49
  end
75
50
 
76
51
  Signal.trap("INT") do
77
- LogPoop.instance.stop
52
+ Runner::Context.stop
78
53
  end
79
54
 
80
55
  Signal.trap("TERM") do
81
- LogPoop.instance.stop
56
+ Runner::Context.stop
82
57
  end
data/logpoop.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{logpoop}
8
- s.version = "0.1.1"
8
+ s.version = "1.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Billy Reisinger"]
12
- s.date = %q{2011-02-02}
12
+ s.date = %q{2011-12-01}
13
13
  s.default_executable = %q{logpoop}
14
14
  s.description = %q{This gem installs a script called 'logpoop' that, when run, fills up your active terminal sessions with crap (so that you look really busy). }
15
15
  s.email = %q{billy.reisinger@gmail.com}
@@ -28,6 +28,12 @@ Gem::Specification.new do |s|
28
28
  "VERSION",
29
29
  "bin/logpoop",
30
30
  "lib/logpoop.rb",
31
+ "lib/logpoop/runner/context.rb",
32
+ "lib/logpoop/runner/multi_tail.rb",
33
+ "lib/logpoop/runner/test_run.rb",
34
+ "lib/logpoop/simulator/base.rb",
35
+ "lib/logpoop/simulator/tail_eff.rb",
36
+ "lib/logpoop/simulator/test_run.rb",
31
37
  "logpoop.gemspec",
32
38
  "test/helper.rb",
33
39
  "test/test_logpoop.rb"
@@ -35,7 +41,7 @@ Gem::Specification.new do |s|
35
41
  s.homepage = %q{http://github.com/unclebilly/logpoop}
36
42
  s.licenses = ["MIT"]
37
43
  s.require_paths = ["lib"]
38
- s.rubygems_version = %q{1.5.0}
44
+ s.rubygems_version = %q{1.5.2}
39
45
  s.summary = %q{Quick, look busy! Print some poop in your terminals!}
40
46
  s.test_files = [
41
47
  "test/helper.rb",
data/test/helper.rb CHANGED
@@ -8,7 +8,6 @@ rescue Bundler::BundlerError => e
8
8
  exit e.status_code
9
9
  end
10
10
  require 'test/unit'
11
- require 'shoulda'
12
11
 
13
12
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
13
  $LOAD_PATH.unshift(File.dirname(__FILE__))
data/test/test_logpoop.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  require 'helper'
2
2
 
3
3
  class TestLogpoop < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
4
+ def test_test
5
+ ARGV[0], ARGV[1] = "--type", "test"
6
+ LogPoop.new
6
7
  end
7
8
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logpoop
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
- - 0
8
- - 1
9
7
  - 1
10
- version: 0.1.1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Billy Reisinger
@@ -15,10 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-02 00:00:00 -06:00
18
+ date: 2011-12-01 00:00:00 -06:00
19
19
  default_executable: logpoop
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
+ type: :development
22
23
  name: jeweler
23
24
  version_requirements: &id001 !ruby/object:Gem::Requirement
24
25
  none: false
@@ -32,7 +33,6 @@ dependencies:
32
33
  - 2
33
34
  version: 1.5.2
34
35
  prerelease: false
35
- type: :development
36
36
  requirement: *id001
37
37
  description: "This gem installs a script called 'logpoop' that, when run, fills up your active terminal sessions with crap (so that you look really busy). "
38
38
  email: billy.reisinger@gmail.com
@@ -53,6 +53,12 @@ files:
53
53
  - VERSION
54
54
  - bin/logpoop
55
55
  - lib/logpoop.rb
56
+ - lib/logpoop/runner/context.rb
57
+ - lib/logpoop/runner/multi_tail.rb
58
+ - lib/logpoop/runner/test_run.rb
59
+ - lib/logpoop/simulator/base.rb
60
+ - lib/logpoop/simulator/tail_eff.rb
61
+ - lib/logpoop/simulator/test_run.rb
56
62
  - logpoop.gemspec
57
63
  - test/helper.rb
58
64
  - test/test_logpoop.rb
@@ -86,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
92
  requirements: []
87
93
 
88
94
  rubyforge_project:
89
- rubygems_version: 1.5.0
95
+ rubygems_version: 1.5.2
90
96
  signing_key:
91
97
  specification_version: 3
92
98
  summary: Quick, look busy! Print some poop in your terminals!