tropo_tail 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 19973f75affc985122ba2610e70e4b336a5e9eec
4
+ data.tar.gz: f408a5fb6cab3906eaf8ff0097083200424227f3
5
+ SHA512:
6
+ metadata.gz: 4eb338e2a8fc3dd53ea84638b074297aa08cc0d2ed0efad3933668a93834c9ecfd08a3f617c28bc41908335e3e68c7ae24cda185dff6d63412a06750b808638a
7
+ data.tar.gz: 4dae8633f9298673267ed97173e0f13108e2d1d1cbcccae67a0530ff9dce50559d1015576b05c0f2fb871d2527ad5684199492cfddff51c46ff306b5f91ba825
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ results.html
3
+ pkg
4
+ html
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ gem 'colorize'
3
+ # Specify your gem's dependencies in tropo_tail.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # TropoTail
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/tropo_tail`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'tropo_tail'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install tropo_tail
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tropo_tail.
36
+
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = tropo_tail - DESCRIBE YOUR GEM
2
+
3
+ Author:: YOUR NAME (YOUR EMAIL)
4
+ Copyright:: Copyright (c) 2016 YOUR NAME
5
+
6
+
7
+ DESCRIBE YOUR GEM HERE
8
+
9
+ == Links
10
+
11
+ * {Source on Github}[LINK TO GITHUB]
12
+ * RDoc[LINK TO RDOC.INFO]
13
+
14
+ == Install
15
+
16
+ == Examples
17
+
18
+ == Contributing
19
+
data/Rakefile ADDED
@@ -0,0 +1,61 @@
1
+ def dump_load_path
2
+ puts $LOAD_PATH.join("\n")
3
+ found = nil
4
+ $LOAD_PATH.each do |path|
5
+ if File.exists?(File.join(path,"rspec"))
6
+ puts "Found rspec in #{path}"
7
+ if File.exists?(File.join(path,"rspec","core"))
8
+ puts "Found core"
9
+ if File.exists?(File.join(path,"rspec","core","rake_task"))
10
+ puts "Found rake_task"
11
+ found = path
12
+ else
13
+ puts "!! no rake_task"
14
+ end
15
+ else
16
+ puts "!!! no core"
17
+ end
18
+ end
19
+ end
20
+ if found.nil?
21
+ puts "Didn't find rspec/core/rake_task anywhere"
22
+ else
23
+ puts "Found in #{path}"
24
+ end
25
+ end
26
+ require 'bundler'
27
+ require 'rake/clean'
28
+
29
+ require 'rake/testtask'
30
+
31
+ require 'cucumber'
32
+ require 'cucumber/rake/task'
33
+ gem 'rdoc' # we need the installed RDoc gem, not the system one
34
+ require 'rdoc/task'
35
+
36
+ include Rake::DSL
37
+
38
+ Bundler::GemHelper.install_tasks
39
+
40
+
41
+ Rake::TestTask.new do |t|
42
+ t.pattern = 'test/tc_*.rb'
43
+ end
44
+
45
+
46
+ CUKE_RESULTS = 'results.html'
47
+ CLEAN << CUKE_RESULTS
48
+ Cucumber::Rake::Task.new(:features) do |t|
49
+ t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty --no-source -x"
50
+ t.fork = false
51
+ end
52
+
53
+ Rake::RDocTask.new do |rd|
54
+
55
+ rd.main = "README.rdoc"
56
+
57
+ rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
58
+ end
59
+
60
+ task :default => [:test,:features]
61
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tropo_tail"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/bin/tropo_tail ADDED
@@ -0,0 +1,113 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'methadone'
5
+ require 'tropo_tail.rb'
6
+ require 'net/ftp'
7
+ require 'colorize'
8
+
9
+ class App
10
+ include Methadone::Main
11
+ include Methadone::CLILogging
12
+
13
+ main do # Add args you want: |like,so|
14
+ @ftp = Net::FTP.new('ftp.tropo.com')
15
+ run
16
+ @ftp.login(@username, @password)
17
+ @ftp.chdir('logs')
18
+ get_latest
19
+ if @filename.nil?
20
+ puts "No new logs"
21
+ else
22
+ tail
23
+ end
24
+ end
25
+
26
+ # supplemental methods here
27
+ def self.run
28
+ puts "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
29
+ puts "Please type your Tropo Username..."
30
+ @username = gets.chomp
31
+ begin
32
+ puts "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
33
+ puts "Please enter your Tropo Password"
34
+ system 'stty -echo'
35
+ @password = gets.chomp
36
+ system 'stty echo'
37
+ rescue
38
+ system 'stty echo'
39
+ exit
40
+ end
41
+ end
42
+
43
+ def self.get_latest
44
+ @ftp.list.each do |file|
45
+ if file[-4..-1] == ".txt"
46
+ @filename = file[-19..-1]
47
+ end
48
+ end
49
+ end
50
+
51
+ def self.tail
52
+ maxline = 0
53
+ orig_log = @filename
54
+ while 0 < 1
55
+ get_latest
56
+ if orig_log != @filename
57
+ maxline = 0
58
+ orig_log = @filename
59
+ end
60
+ linecount = 0
61
+ @ftp.gettextfile(@filename, nil) do |line|
62
+ info = /(?<=PRISM )(?<=PRISM )(\d{7}\/\d{7}\/)(\w{32}\/|0\/)(\w{32}\/)(1\/)(\S{1,50}\/)(\[\S{1,50}\])/.match(line).to_s.yellow
63
+ linecount += 1
64
+ if linecount > maxline
65
+ maxline = linecount
66
+ if options['truncate']
67
+ puts "#{line[0..19].blue} #{line[(info.length + 38)..-1]}"
68
+ else
69
+ puts "#{line[0..19].blue}#{line[21..50].yellow} #{info}#{line[(info.length + 38)..-1]}"
70
+ end
71
+ end
72
+ end
73
+ sleep 3
74
+ end
75
+ end
76
+
77
+ def self.log_line_break
78
+ Thread.new do
79
+ while 0 < 1
80
+ char = STDIN.getc
81
+ if char == "\r"
82
+ puts ""
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+
89
+ # Declare command-line interface here
90
+
91
+ # description "one line description of your app"
92
+ #
93
+ # Accept flags via:
94
+ # on("--flag VAL","Some flag")
95
+ # options[flag] will contain VAL
96
+ #
97
+ # Specify switches via:
98
+ on("--truncate","Some switch")
99
+ #
100
+ # Or, just call OptionParser methods on opts
101
+ #
102
+ # Require an argument
103
+ # arg :some_arg
104
+ #
105
+ # # Make an argument optional
106
+ # arg :optional_arg, :optional
107
+
108
+ version TropoTail::VERSION
109
+
110
+ use_log_level_option :toggle_debug_on_signal => 'USR1'
111
+
112
+ go!
113
+ end
@@ -0,0 +1,3 @@
1
+ module TropoTail
2
+ VERSION = "0.1.0"
3
+ end
data/lib/tropo_tail.rb ADDED
@@ -0,0 +1,92 @@
1
+ require "tropo_tail/version"
2
+
3
+ #module TropoTail
4
+ #end
5
+
6
+ require 'net/ftp'
7
+ require 'colorize'
8
+
9
+ class TropoTail
10
+
11
+ def initialize
12
+ @ftp = Net::FTP.new('ftp.tropo.com')
13
+ run
14
+ @ftp.login(@username, @password)
15
+ @ftp.chdir('logs')
16
+ get_latest
17
+ if @filename.nil?
18
+ puts "No new logs"
19
+ else
20
+ tail
21
+ end
22
+ end
23
+
24
+ def run
25
+ puts "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
26
+ puts "Please type your Tropo Username..."
27
+ @username = gets.chomp
28
+ begin
29
+ puts "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
30
+ puts "Please enter your Tropo Password"
31
+ system 'stty -echo'
32
+ @password = gets.chomp
33
+ system 'stty echo'
34
+ rescue
35
+ system 'stty echo'
36
+ exit
37
+ end
38
+ puts "Input 1 for full Tropo logs or 2 for truncated logs"
39
+ @log_display = gets.chomp
40
+ end
41
+
42
+ def get_latest
43
+ @ftp.list.each do |file|
44
+ if file[-4..-1] == ".txt"
45
+ @filename = file[-19..-1]
46
+ end
47
+ end
48
+ end
49
+
50
+ def tail
51
+ maxline = 0
52
+ orig_log = @filename
53
+ while 0 < 1
54
+ get_latest
55
+ if orig_log != @filename
56
+ maxline = 0
57
+ orig_log = @filename
58
+ end
59
+ linecount = 0
60
+ @ftp.gettextfile(@filename, nil) do |line|
61
+ info = /(?<=PRISM )(\d{7})(\/)(\d{7})(\/)(\w{32}\/|0)(\/)(\w{32})(\/)(1)(\/)(\S{1,50}\/)(\[\S{1,50}\])/.match(line).to_s.yellow
62
+ linecount += 1
63
+ if linecount > maxline
64
+ maxline = linecount
65
+ if @log_display == "1"
66
+ puts "#{line[0..19].blue}#{line[21..50].yellow} #{info}#{line[(info.length + 38)..-1]}"
67
+ elsif @log_display == "2"
68
+ puts "#{line[0..19].blue} #{line[(info.length + 38)..-1]}"
69
+ else
70
+ puts "invalid log display option"
71
+ return false
72
+ end
73
+ end
74
+ end
75
+ sleep 3
76
+ end
77
+ end
78
+
79
+ def log_line_break
80
+ Thread.new do
81
+ while 0 < 1
82
+ char = STDIN.getc
83
+ if char == "\r"
84
+ puts ""
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+ end
91
+
92
+ tt = TropoTail.new
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tropo_tail/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tropo_tail"
8
+ spec.license="Nonstandard"
9
+ spec.version = TropoTail::VERSION
10
+ spec.authors = ["Jeffrey Gisin"]
11
+ spec.email = ["jgisin@gmail.com"]
12
+
13
+ spec.summary = "A log tailing application for Tropo's scripting API"
14
+ spec.description = "Currently the only way to access Tropo logs is to download a text file from the Tropo FTP site. This requires constant redownloads of files that can grow to very large sizes. Tropo tail allows you to live tail your logs with log rollovers when Tropo creates a new log file, for a better development experience."
15
+ spec.homepage = "http://www.cloverhound.com"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ #if spec.respond_to?(:metadata)
20
+ #spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ #else
22
+ #raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ #end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.11"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency('rdoc')
33
+ spec.add_development_dependency('aruba')
34
+ spec.add_dependency('methadone', '~> 1.9.2')
35
+ spec.add_development_dependency('test-unit')
36
+ spec.add_dependency('colorize')
37
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tropo_tail
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeffrey Gisin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rdoc
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: aruba
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: methadone
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.9.2
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.9.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: test-unit
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: colorize
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Currently the only way to access Tropo logs is to download a text file
112
+ from the Tropo FTP site. This requires constant redownloads of files that can grow
113
+ to very large sizes. Tropo tail allows you to live tail your logs with log rollovers
114
+ when Tropo creates a new log file, for a better development experience.
115
+ email:
116
+ - jgisin@gmail.com
117
+ executables: []
118
+ extensions: []
119
+ extra_rdoc_files: []
120
+ files:
121
+ - ".gitignore"
122
+ - Gemfile
123
+ - README.md
124
+ - README.rdoc
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - bin/tropo_tail
129
+ - lib/tropo_tail.rb
130
+ - lib/tropo_tail/version.rb
131
+ - tropo_tail.gemspec
132
+ homepage: http://www.cloverhound.com
133
+ licenses:
134
+ - Nonstandard
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.6.3
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: A log tailing application for Tropo's scripting API
156
+ test_files: []
157
+ has_rdoc: