debugserver 0.1.1

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,42 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+ puts lib
5
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
6
+
7
+ require 'rubygems'
8
+ require 'optparse'
9
+ require 'debugserver'
10
+
11
+ options = {
12
+ :host => 'localhost',
13
+ :port => 9000
14
+ }
15
+
16
+ optparse = OptionParser.new do |opts|
17
+ opts.banner = "Usage: debugserver [options]"
18
+
19
+ opts.on('-h', '--host HOSTNAME', 'Server hostname') do |host|
20
+ options[:host] = host
21
+ end
22
+
23
+ opts.on('-p', '--port PORT', 'Server port') do |port|
24
+ options[:port] = port
25
+ end
26
+
27
+ opts.on('-i', '--info', 'Get usage information') do
28
+ puts opts
29
+ exit
30
+ end
31
+ end
32
+
33
+ begin
34
+ optparse.parse!
35
+ rescue OptionParser::InvalidOption, OptionParser::MissingArgument
36
+ puts $!.to_s
37
+ puts optparse
38
+ exit
39
+ end
40
+
41
+ DebugServer.configure(options[:host], options[:port])
42
+ DebugServer.start
@@ -0,0 +1,11 @@
1
+ require 'eventmachine'
2
+ require 'json/pure'
3
+
4
+ module DebugServer ; end
5
+
6
+ require 'debugserver/common'
7
+ require 'debugserver/parser'
8
+ require 'debugserver/console'
9
+ require 'debugserver/server'
10
+ require 'debugserver/session'
11
+ require 'debugserver/class_utils'
@@ -0,0 +1,11 @@
1
+ class String
2
+ def red; colorize(self, "\e[1m\e[31m"); end
3
+ def green; colorize(self, "\e[1m\e[32m"); end
4
+ def dark_green; colorize(self, "\e[32m"); end
5
+ def yellow; colorize(self, "\e[1m\e[33m"); end
6
+ def blue; colorize(self, "\e[1m\e[34m"); end
7
+ def dark_blue; colorize(self, "\e[34m"); end
8
+ def purple; colorize(self, "\e[1m\e[35m"); end
9
+ def magenta; colorize(self, "\e[1m\e[36m"); end
10
+ def colorize(text, color_code) "#{color_code}#{text}\e[0m" ; end
11
+ end
@@ -0,0 +1,27 @@
1
+ module DebugServer
2
+ METHOD_CLEAR = 1
3
+ METHOD_MESSAGE = 2
4
+ METHOD_DUMP = 3
5
+
6
+ LEVEL_NONE = 0
7
+ LEVEL_INFO = 1
8
+ LEVEL_WARNING = 2
9
+ LEVEL_ERROR = 3
10
+
11
+ COLORS = {
12
+ LEVEL_INFO => :green,
13
+ LEVEL_WARNING => :yellow,
14
+ LEVEL_ERROR => :red
15
+ }
16
+
17
+ @@config = {}
18
+
19
+ def self.configure(host='localhost', port=9000)
20
+ @@config[:host] = host
21
+ @@config[:port] = port
22
+ end
23
+
24
+ def self.config
25
+ @@config
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ module DebugServer
2
+ module Console
3
+ def print_string(content, level=nil)
4
+ unless level.nil?
5
+ content = content.send(COLORS[level]) if COLORS.include?(level)
6
+ end
7
+ puts content
8
+ end
9
+
10
+ def print_dump(content, name=nil)
11
+ puts "========== #{name} ==========".magenta unless name.nil?
12
+ puts "#{content}\n"
13
+ end
14
+
15
+ def process_output(packet)
16
+ case packet['method']
17
+ when METHOD_CLEAR
18
+ system('clear')
19
+ when METHOD_MESSAGE
20
+ print_string(packet['content']['message'], packet['content']['level'])
21
+ when METHOD_DUMP
22
+ print_dump(packet['content']['object'], packet['content']['name'])
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,15 @@
1
+ module DebugServer
2
+ module Parser
3
+ def parse_data(data)
4
+ packets = []
5
+ data.strip.split("\n").each do |str|
6
+ packets << parse_json(str.strip)
7
+ end
8
+ packets.select { |item| !item.nil? }
9
+ end
10
+
11
+ def parse_json(data)
12
+ JSON.parse(data) rescue nil
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,61 @@
1
+ module DebugServer
2
+ # start server
3
+ def self.start
4
+ server = DebugServer::Server.new
5
+ server.start
6
+ end
7
+
8
+ class Server
9
+ attr_reader :socket
10
+ attr_reader :sessions
11
+
12
+ private
13
+
14
+ # init connection
15
+ def init_session(s)
16
+ s.uid = `uuidgen`
17
+ s.server = self
18
+ @sessions << s
19
+ end
20
+
21
+ public
22
+
23
+ def initialize
24
+ @socket = nil
25
+ @sessions = []
26
+ end
27
+
28
+ # close existing session on client disconnect
29
+ def close_session(s)
30
+ @sessions.delete(s)
31
+ end
32
+
33
+ # start server execution
34
+ def start
35
+ config = DebugServer.config
36
+
37
+ system('clear')
38
+ puts "Starting debug server on #{config[:host]}:#{config[:port]}..."
39
+
40
+ begin
41
+ EventMachine::run do
42
+ EventMachine.epoll
43
+ @socket = EventMachine::start_server(config[:host], config[:port], Session) do |s|
44
+ init_session(s)
45
+ end
46
+ end
47
+ rescue Interrupt
48
+ stop
49
+ rescue RuntimeError => err
50
+ puts "Runtime error: #{err.message}"
51
+ stop
52
+ end
53
+ end
54
+
55
+ # stop server executions
56
+ def stop
57
+ puts "Exiting..."
58
+ exit(0)
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,17 @@
1
+ module DebugServer
2
+ class Session < EventMachine::Connection
3
+ include DebugServer::Parser
4
+ include DebugServer::Console
5
+
6
+ attr_accessor :uid, :server
7
+
8
+ def receive_data(buffer)
9
+ packets = parse_data(buffer)
10
+ packets.each { |p| process_output(p) }
11
+ end
12
+
13
+ def unbind
14
+ @server.close_session(self)
15
+ end
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: debugserver
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - Dan Sosedoff
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-07-01 00:00:00 -05:00
19
+ default_executable: debugserver
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: eventmachine
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 59
30
+ segments:
31
+ - 0
32
+ - 12
33
+ - 10
34
+ version: 0.12.10
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: json_pure
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 1
46
+ segments:
47
+ - 1
48
+ - 4
49
+ - 3
50
+ version: 1.4.3
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ description: Console server to provide debugging for web/any applications
54
+ email: dan.sosedoff@gmail.com
55
+ executables:
56
+ - debugserver
57
+ extensions: []
58
+
59
+ extra_rdoc_files: []
60
+
61
+ files:
62
+ - bin/debugserver
63
+ - lib/debugserver.rb
64
+ - lib/debugserver/common.rb
65
+ - lib/debugserver/parser.rb
66
+ - lib/debugserver/console.rb
67
+ - lib/debugserver/server.rb
68
+ - lib/debugserver/session.rb
69
+ - lib/debugserver/class_utils.rb
70
+ has_rdoc: true
71
+ homepage: http://sosedoff.com
72
+ licenses: []
73
+
74
+ post_install_message:
75
+ rdoc_options:
76
+ - --charset=UTF-8
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 3
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ requirements: []
98
+
99
+ rubyforge_project:
100
+ rubygems_version: 1.3.7
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: Console server to provide external debug log for applications over network
104
+ test_files: []
105
+