MrMurano 1.5.4 → 1.5.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 19ed883f1122316d6a5fef1d112d1493f2db527c
4
- data.tar.gz: 296deaeb1328e5da115bcfc43b65d53a068e8eb1
3
+ metadata.gz: 3ac31eaa1f880c2269de0ebf0b44af394c8c7d80
4
+ data.tar.gz: b060f57b1dc7ec60242408458a4541963a7b061b
5
5
  SHA512:
6
- metadata.gz: 91a9311aa80db4f70058059aad657d78371ede8e77ae7b5cbb89c777a31e96001232e28012efbd4f107bc2daa8d64fbb3c55a18ed571677dc7d28d2e472f97f4
7
- data.tar.gz: d16cb066bc361d0b8f176ff8da3e64406b0e36508c96185ce158610840353b6991c92e978797563f01eefee987266d53e2a22fba7872d14677c6cb2f491dba69
6
+ metadata.gz: d711b5f10c54a489ffef3cf03584014516be2035db33b92434935ac485d53731faf95a53b20ddd648e7faf37d188b7da1f89563ef452b678ed2d48088f74bbcc
7
+ data.tar.gz: 79c236e485bf9fccf3c865a0bcfdcec932a1b786830af0e5443e068dada40928415d63d7872f4f20805ccdc7fe7fbdb60b9e2f09103beefa7de7d086e7eba8c7
data/Rakefile CHANGED
@@ -2,7 +2,6 @@ require "bundler/gem_tasks"
2
2
 
3
3
  task :default => [:test]
4
4
 
5
- # TODO: figure out better way to test.
6
5
  desc "Install gem in user dir"
7
6
  task :bob do
8
7
  sh %{gem install --user-install pkg/MrMurano-#{Bundler::GemHelper.gemspec.version}.gem}
@@ -17,6 +16,19 @@ task :echo do
17
16
  puts "= #{Bundler::GemHelper.gemspec.version} ="
18
17
  end
19
18
 
19
+ desc "Push only develop, master, and tags to origin"
20
+ task :gitpush do
21
+ sh %{git checkout develop}
22
+ sh %{git push}
23
+ sh %{git checkout master}
24
+ sh %{git push}
25
+ sh %{git push --tags}
26
+ end
27
+
28
+ #task :gempush do
29
+ # sh %{gem push pkg/MrMurano-#{Bundler::GemHelper.gemspec.version}.gem}
30
+ #end
31
+
20
32
  desc "Prints a cmd to test this in another directory"
21
33
  task :testwith do
22
34
  pwd=Dir.pwd.sub(Dir.home, '~')
@@ -18,106 +18,99 @@ command :logs do |c|
18
18
 
19
19
  lasttime = ""
20
20
 
21
- sol = MrMurano::Solution.new
22
- begin
23
- begin
24
- ret = sol.get('/logs') # TODO: ('/logs?polling=true') Currently ignored.
25
-
26
- if ret.kind_of?(Hash) and ret.has_key?(:items) then
27
- ret[:items].reverse.each do |line|
28
- curtime = ""
29
- if line.kind_of?(String) then
30
-
31
- line.sub!(/^\[[^\]]*\]/) {|m| m.color(:red).background(:aliceblue)}
32
- line.sub!(/\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.\d+)(?:\+\d\d:\d\d)/) {|m|
33
- if options.localtime then
34
- m = DateTime.parse(m).to_time.localtime.to_datetime.iso8601(3)
35
- end
36
- curtime = m
37
- m.color(:blue)
38
- }
39
-
40
- line.gsub!(/\{(?>[^}{]+|\g<0>)*\}/m) do |m|
41
- if options.pretty then
42
- js = JSON.parse(m, {:allow_nan=>true, :create_additions=>false})
43
- ret = JSON.pretty_generate(js).to_s
44
- ret[0] = ret[0].color(:magenta)
45
- ret[-1] = ret[-1].color(:magenta)
46
- ret
47
- else
48
- m.sub!(/^{/){|ml| ml.color(:magenta)}
49
- m.sub!(/}$/){|ml| ml.color(:magenta)}
50
- m
51
- end
52
- end
21
+ def makePretty(line, options)
22
+ out=''
23
+ if line.has_key?(:type) then
24
+ out << "#{line[:type]} ".upcase.color(:red).background(:aliceblue)
25
+ end
26
+ out << "[#{line[:subject]}]".color(:red).background(:aliceblue)
27
+ out << " "
28
+ if options.localtime then
29
+ curtime = Time.at(line[:timestamp]).localtime.to_datetime.iso8601(3)
30
+ else
31
+ curtime = Time.at(line[:timestamp]).to_datetime.iso8601(3)
32
+ end
33
+ out << curtime.color(:blue)
34
+ out << ":\n"
35
+ if line.has_key?(:data) then
36
+ data = line[:data]
37
+
38
+ if data.kind_of?(Hash) and data.has_key?(:request) and data.has_key?(:response) then
39
+ out << "---------\nrequest:"
40
+ if options.pretty then
41
+ ret = JSON.pretty_generate(data[:request]).to_s
42
+ ret[0] = ret[0].color(:magenta)
43
+ ret[-1] = ret[-1].color(:magenta)
44
+ out << ret
45
+ else
46
+ out << data[:request].to_json
47
+ end
48
+
49
+ out << "\n---------\nresponse:"
50
+ if options.pretty then
51
+ ret = JSON.pretty_generate(data[:response]).to_s
52
+ ret[0] = ret[0].color(:magenta)
53
+ ret[-1] = ret[-1].color(:magenta)
54
+ out << ret
55
+ else
56
+ out << data[:response].to_json
57
+ end
53
58
 
54
- out = line
59
+ else
60
+ out << data.to_s
61
+ end
55
62
 
56
- elsif line.kind_of?(Hash) then
57
- out=""
63
+ else
64
+ out << line.to_s
65
+ end
66
+ out
67
+ end
58
68
 
59
- if line.has_key?(:type) then
60
- out << "#{line[:type]} ".upcase.color(:red).background(:aliceblue)
61
- end
62
- out << "[#{line[:subject]}]".color(:red).background(:aliceblue)
63
- out << " "
64
- if options.localtime then
65
- curtime = Time.at(line[:timestamp]).localtime.to_datetime.iso8601(3)
66
- else
67
- curtime = Time.at(line[:timestamp]).to_datetime.iso8601(3)
69
+ sol = MrMurano::Solution.new
70
+
71
+ if options.follow then
72
+ # open a lasting connection and continueally feed makePretty()
73
+ begin
74
+ sol.get('/logs?polling=true') do |request, http|
75
+ request["Accept-Encoding"] = "None"
76
+ http.request(request) do |response|
77
+ remainder=''
78
+ response.read_body do |chunk|
79
+ chunk = remainder + chunk unless remainder.empty?
80
+
81
+ # for all complete JSON blobs, make them pretty.
82
+ chunk.gsub!(/\{(?>[^}{]+|\g<0>)*\}/m) do |m|
83
+ js = JSON.parse(m, {:allow_nan=>true,
84
+ :symbolize_names => true,
85
+ :create_additions=>false})
86
+ puts makePretty(js, options)
87
+ '' #remove
68
88
  end
69
- out << curtime.color(:blue)
70
- out << ":\n"
71
- if line.has_key?(:data) then
72
- data = line[:data]
73
-
74
- if data.kind_of?(Hash) and data.has_key?(:request) and data.has_key?(:response) then
75
- out << "---------\nrequest:"
76
- if options.pretty then
77
- ret = JSON.pretty_generate(data[:request]).to_s
78
- ret[0] = ret[0].color(:magenta)
79
- ret[-1] = ret[-1].color(:magenta)
80
- out << ret
81
- else
82
- out << data[:request].to_json
83
- end
84
-
85
- out << "\n---------\nresponse:"
86
- if options.pretty then
87
- ret = JSON.pretty_generate(data[:response]).to_s
88
- ret[0] = ret[0].color(:magenta)
89
- ret[-1] = ret[-1].color(:magenta)
90
- out << ret
91
- else
92
- out << data[:response].to_json
93
- end
94
-
95
- else
96
- out << data.to_s
97
- end
98
-
99
- else
100
- out << line.to_s
89
+
90
+ # is there an incomplete one?
91
+ if chunk.match(/(\{.*$)/m) then
92
+ remainder = $1
101
93
  end
102
94
 
103
95
  end
96
+ end
97
+ end
98
+ rescue Interrupt => e
99
+ end
104
100
 
105
- if curtime > lasttime then
106
- lasttime = curtime
107
- puts out
108
- end
101
+ else
102
+ ret = sol.get('/logs')
109
103
 
110
- end
111
- else
112
- say_error "Couldn't get logs: #{ret}"
113
- break
104
+ if ret.kind_of?(Hash) and ret.has_key?(:items) then
105
+ ret[:items].reverse.each do |line|
106
+ puts makePretty(line, options)
114
107
  end
108
+ else
109
+ say_error "Couldn't get logs: #{ret}"
110
+ break
111
+ end
115
112
 
116
- sleep(options.pollrate) if options.follow
117
- end while options.follow
118
- rescue Interrupt => e
119
113
  end
120
-
121
114
  end
122
115
  end
123
116
  # vim: set ai et sw=2 ts=2 :
data/lib/MrMurano/http.rb CHANGED
@@ -56,12 +56,11 @@ module MrMurano
56
56
  request
57
57
  end
58
58
 
59
- def tryToPrettyJSON(data)
59
+ def isJSON(data)
60
60
  begin
61
- ret = JSON.parse(data, json_opts)
62
- return JSON.pretty_generate(ret)
61
+ return true, JSON.parse(data, json_opts)
63
62
  rescue
64
- return data
63
+ return false, data
65
64
  end
66
65
  end
67
66
 
@@ -76,7 +75,19 @@ module MrMurano
76
75
  puts "Got #{response.code} #{response.message}"
77
76
  response.each_capitalized{|k,v| puts "< #{k}: #{v}"}
78
77
  end
79
- say_error "Request Failed: #{response.code}: #{tryToPrettyJSON(response.body)}"
78
+ isj, jsn = isJSON(response.body)
79
+ resp = "Request Failed: #{response.code}: "
80
+ if isj then
81
+ if $cfg['tool.fullerror'] then
82
+ resp << JSON.pretty_generate(jsn)
83
+ else
84
+ resp << "[#{jsn[:statusCode]}] " if jsn.has_key? :statusCode
85
+ resp << jsn[:message] if jsn.has_key? :message
86
+ end
87
+ else
88
+ resp << jsn
89
+ end
90
+ say_error resp
80
91
  end
81
92
 
82
93
  def workit(request, &block)
@@ -1,4 +1,4 @@
1
1
  module MrMurano
2
- VERSION = '1.5.4'.freeze
2
+ VERSION = '1.5.5'.freeze
3
3
  end
4
4
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: MrMurano
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.4
4
+ version: 1.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Conrad Tadpol Tilstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-30 00:00:00.000000000 Z
11
+ date: 2016-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander