evegem 0.1.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.
data/lib/eve/ci.rake ADDED
@@ -0,0 +1,68 @@
1
+ namespace :ci do
2
+
3
+ desc "Build the project"
4
+ task :build do
5
+ begin
6
+ # Rake::Task['ci:db:config'].invoke
7
+ Rake::Task['ci:local'].invoke
8
+ Rake::Task['ci:success'].invoke
9
+ rescue Exception => e
10
+ Rake::Task['ci:failure'].invoke
11
+ raise e
12
+ end
13
+ end
14
+
15
+ desc "Run CI from your local machine (will not propagte the success / failure message, or load the config file)"
16
+ task :local do
17
+ Rake::Task['ci:db:reset'].invoke
18
+ Rake::Task['ci:rspec'].invoke
19
+ end
20
+
21
+ desc 'Run Rspec'
22
+ task :rspec do
23
+ system 'mkdir -p ../public' unless File.exists?("../public")
24
+ Rake::Task['ci:rspec_run'].invoke
25
+ end
26
+
27
+ RSpec::Core::RakeTask.new(:rspec_run) do |t|
28
+ t.rspec_opts = ["--format", "html", "--out", "../public/rspec.html"]
29
+ t.fail_on_error = true
30
+ end
31
+
32
+ desc "The Build Succeeded, so tell our monitoring service"
33
+ task :success do
34
+ if File.exists?("/home/deployer/monitor/log")
35
+ system 'echo "Eve succeeded, http://cc.cenx.localnet" > /home/deployer/monitor/log/Eve.cc'
36
+ else
37
+ print "BUILD SUCCEEDED, but log directory (/home/deployer/monitor/log) does not exist"
38
+ end
39
+ end
40
+
41
+ desc "The Build failed, so tell our monitoring service"
42
+ task :failure do
43
+ if File.exists?("/home/deployer/monitor/log")
44
+ system "curl http://cc.cenx.localnet/eve > /home/deployer/monitor/log/Eve.cc"
45
+ else
46
+ raise "BUILD FAILED, but log directory (/home/deployer/monitor/log) does not exist"
47
+ end
48
+ end
49
+
50
+ namespace :db do
51
+
52
+ desc "Setup the correct database configuration files"
53
+ task :config do
54
+ copy_config('database','/cenx/eve/sensitive/database.yml',"#{File.dirname(__FILE__)}/../../config/database.yml")
55
+ end
56
+
57
+ desc "Setup the database"
58
+ task :reset do
59
+ system("ruby #{File.dirname(__FILE__)}/../../config/reset_db.rb")
60
+ end
61
+
62
+ def copy_config(type,source,dest)
63
+ abort "No #{type} file [#{source}], unable to continue CI build" unless File.exists? source
64
+ FileUtils.cp source, dest, :preserve => false
65
+ end
66
+
67
+ end
68
+ end
@@ -0,0 +1,67 @@
1
+
2
+ module Eve
3
+
4
+ class EventConnection < EM::Connection
5
+
6
+ cattr_accessor :data
7
+ attr_accessor :app, :server
8
+
9
+ def self.run(args)
10
+ server,port,appid = EventServer.handle_args(args).values
11
+ @@data = { :appid => appid }
12
+
13
+ EM.run do
14
+ EM.start_server(server, port, EventConnection)
15
+ puts "Started Eve (#{appid}) on #{server}:#{port}..."
16
+ end
17
+ end
18
+
19
+ def post_init
20
+ @server = EventServer.new(self,@@data)
21
+ @server.post_init
22
+ end
23
+
24
+ def receive_data(data)
25
+ @server.receive_data(data)
26
+ end
27
+
28
+ end
29
+
30
+ class EventServer
31
+
32
+ attr_accessor :connection, :appid
33
+
34
+ def initialize(connection,data)
35
+ @connection = connection
36
+ @appid = data[:appid]
37
+ end
38
+
39
+ def self.handle_args(args)
40
+ {
41
+ :server => Application.extract_arg("--server",args,"0.0.0.0"),
42
+ :port => Application.extract_arg("--port",args,"4848"),
43
+ :appid => Application.extract_arg("--id",args,"myeve")
44
+ }
45
+ end
46
+
47
+ def app
48
+ if @connection.app.nil?
49
+ @connection.app = Eve::Application.new(:display => { :event_machine => @connection }, :system_calls_display => { :filename => "./eve_server_calls.log" })
50
+ end
51
+ @connection.app
52
+ end
53
+
54
+ def post_init
55
+ app.cmd("appid #{@appid}")
56
+ end
57
+
58
+ def receive_data(data)
59
+ result = app.cmd(data)
60
+ @connection.close_connection if result[:status] == :exited
61
+ @connection.send_data("#{app.id}> ")
62
+ result
63
+ end
64
+
65
+ end
66
+
67
+ end
@@ -0,0 +1,77 @@
1
+ module Eve
2
+
3
+ class FileNotifierServer
4
+
5
+ attr_accessor :connection, :server, :port, :source, :appid, :callbacks, :inits
6
+
7
+ def initialize(connection,data)
8
+ @connection = connection
9
+ @server = data[:server]
10
+ @port = data[:port]
11
+ @source = data[:source]
12
+ @appid = data[:appid]
13
+ @callbacks = data[:callbacks] || []
14
+ @inits = data[:inits] || []
15
+ end
16
+
17
+ def self.handle_args(args)
18
+ {
19
+ :server => Application.extract_arg("--server",args,nil),
20
+ :port => Application.extract_arg("--port",args,nil),
21
+ :source => Application.extract_arg("--source",args,nil),
22
+ :appid => Application.extract_arg("--id",args,nil),
23
+ :callbacks => Application.extract_arg("--callback",args,[]),
24
+ :inits => Application.extract_arg("--init",args,[])
25
+ }
26
+ end
27
+
28
+ def app
29
+ if @connection.app.nil?
30
+ display = :stdio
31
+ @connection.app = Eve::Application.new(:display => display, :system_calls_display => { :filename => "./eve_system_calls.log" })
32
+ end
33
+ @connection.app
34
+ end
35
+
36
+ def post_init
37
+ if @server.nil?
38
+ app.cmd("appid #{@appid}")
39
+ else
40
+ app.cmd("event #{@server}:#{@port}")
41
+ end
42
+ @inits.each { |x| app.cmd(x) }
43
+ end
44
+
45
+ def file_modified
46
+ @callbacks.each { |cb| app.cmd(cb) }
47
+ end
48
+
49
+ end
50
+
51
+ class FileNotifierConnection < EventMachine::FileWatch
52
+
53
+ cattr_accessor :data
54
+
55
+ attr_accessor :app
56
+ attr_accessor :server
57
+
58
+ def post_init
59
+ @server = FileNotifierServer.new(self,@@data)
60
+ @server.post_init
61
+ end
62
+
63
+ def file_modified
64
+ @server.file_modified
65
+ end
66
+
67
+ def self.run(args)
68
+ @@data = FileNotifierServer.handle_args(args)
69
+ EM.kqueue = true if EM.kqueue? # file watching requires kqueue on OSX
70
+ EM.run {
71
+ EM.watch_file(@@data[:source], FileNotifierConnection)
72
+ }
73
+ end
74
+
75
+ end
76
+
77
+ end
data/lib/eve/io.rb ADDED
@@ -0,0 +1,25 @@
1
+ class IO
2
+ def self.write(filename,content)
3
+ File.open(filename, 'w') {|f| f.write(content) }
4
+ end
5
+ end
6
+
7
+ class String
8
+ def underscore
9
+ word = self.dup
10
+ word.gsub!(/::/, '/')
11
+ word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
12
+ word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
13
+ word.tr!("-", "_")
14
+ word.downcase!
15
+ word
16
+ end
17
+ end
18
+
19
+ def p?(filename)
20
+ File.exists?(filename)
21
+ end
22
+
23
+ def p(filename)
24
+ Pathname.new(filename).realpath.to_s
25
+ end
data/lib/eve/layout.rb ADDED
@@ -0,0 +1,22 @@
1
+ module Eve
2
+
3
+ class Layout
4
+
5
+ attr_accessor :columns
6
+
7
+ def initialize
8
+ @columns = []
9
+ end
10
+
11
+ def add_column(input)
12
+ return nil if input.nil?
13
+ parts = input.split(";")
14
+ return nil if parts.size != 3
15
+ entry = { :column_type => parts[0].downcase.to_sym, :filter => parts[1], :order => parts[2].to_i }
16
+ @columns << entry
17
+ entry
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,181 @@
1
+ module Eve
2
+
3
+ class Message
4
+
5
+ attr_accessor :app
6
+
7
+ def initialize(app)
8
+ @app = app
9
+ end
10
+
11
+ def print_version(appid,show_multiple_times = true)
12
+ if appid.nil?
13
+ print "eve, version #{Eve::VERSION}\n"
14
+ else
15
+ app_full_id = appid.to_s == $$.to_s ? appid : "#{appid} (#{$$})"
16
+ print "eve #{app_full_id}, version #{Eve::VERSION}\n"
17
+ end
18
+ end
19
+
20
+ def print_error(msg, error)
21
+ print "#{msg}\n"
22
+ print " #{error.message}\n"
23
+ print " " + error.backtrace.join("\n ") + "\n"
24
+ end
25
+
26
+ def print_system_call(cmd)
27
+ print "CALLING: #{cmd}\n", {} , "system_calls"
28
+ end
29
+
30
+ def print_exit
31
+ print "bye\n"
32
+ end
33
+
34
+ def print_unknown_cmd(cmd)
35
+ print "UNKNOWN CMD: #{cmd}\n"
36
+ end
37
+
38
+ def print_process_id(id)
39
+ print "Process Id: #{id}\n"
40
+ end
41
+
42
+ def print_ruby_call(call,answer)
43
+ print "#{call}: #{answer}\n"
44
+ end
45
+
46
+ def print_shell_mode
47
+ print "Entering shell mode, to exit this mode, type 'poll'\n"
48
+ end
49
+
50
+ def print_poll_details(in_secs, cmds)
51
+ output = Message.friendly_duration(in_secs)
52
+ if cmds.empty?
53
+ print "Poll will check every #{output}, but it has nothing to run.\n"
54
+ else
55
+ msg = "Poll will check every #{output}, and send the following events:\n"
56
+ cmds.each { |cmd| msg += " - #{cmd}\n" }
57
+ print msg
58
+ end
59
+ end
60
+
61
+ def print_poll_mode(id,in_secs)
62
+ output = Message.friendly_duration(in_secs)
63
+ print "Entering poll mode with checks every #{output}, to exit this mode, run 'eve --interrupt #{id}' from another terminal session\n"
64
+ end
65
+
66
+ def print_event_mode(where)
67
+ print "Messages will be routed to #{where}\n"
68
+ end
69
+
70
+ def print_app_interrupted(id)
71
+ print "Interrupted eve #{id}, should now be in shell mode\n"
72
+ end
73
+
74
+ def print_sleep(in_secs)
75
+ friendly = WatchMe::Timer.calculate_duration_to_s(in_secs)
76
+ seconds = "#{in_secs} seconds"
77
+ print friendly == seconds ? "Sleeping for #{friendly}\n" : "Sleeping for #{friendly} (#{seconds})\n"
78
+ end
79
+
80
+ def print_help(cmds,handler = nil)
81
+ msg = handler.nil? || handler == "" ? "Available commands are:\n" : "Available commands (#{handler}) are:\n"
82
+ msg += cmds.collect { |call,sub_calls| sub_calls.empty? ? " #{call}" : " #{call} [ #{sub_calls.join(" | ")} ]" }.join("\n")
83
+ msg += "\n"
84
+ print msg
85
+ end
86
+
87
+ def print_exported_commands(filename)
88
+ print "Exported all commands to #{filename} -- reload using 'import #{filename}'\n"
89
+ end
90
+
91
+ def print_importing_commands(filename)
92
+ print "Importing comamnds from #{filename}\n"
93
+ end
94
+
95
+ def print_importing_complete(filename,count)
96
+ case count
97
+ when 0
98
+ print "No commands found!\n"
99
+ when 1
100
+ print "Finished importing #{count} command (#{filename})\n"
101
+ else
102
+ print "Finished importing #{count} commands (#{filename})\n"
103
+ end
104
+ end
105
+
106
+ def print_cmd_error(cmd,e = nil)
107
+ msg = "An error occurred for '#{cmd}'"
108
+ e.nil? ? print("#{msg}\n") : print_error(msg,e)
109
+ end
110
+
111
+ def print_server_init
112
+ print "Connection Established\n"
113
+ end
114
+
115
+ def print_appid(appid)
116
+ print "Appid: #{appid}\n"
117
+ end
118
+
119
+ def print_unknown_handler(name)
120
+ print "Unknown handler Blah\n"
121
+ end
122
+
123
+ def print_registry_reloaded
124
+ print "Registry reloaded.\n"
125
+ end
126
+
127
+ def print_registry(registries)
128
+ if registries.empty?
129
+ print "Nothing registered.\n"
130
+ else
131
+ msg = "The following has been registered:\n"
132
+ registries.each do |classname,files|
133
+ msg += " - #{classname} (#{files.join(", ")})\n"
134
+ end
135
+ print msg
136
+ end
137
+ end
138
+
139
+ def print_registry_path(paths)
140
+ if paths.empty?
141
+ print "No paths have been provided.\n"
142
+ else
143
+ msg = "The following paths have been set:\n"
144
+ paths.each do |p|
145
+ msg += " -- #{p}\n"
146
+ end
147
+ print msg
148
+ end
149
+
150
+ end
151
+
152
+ def self.friendly_now(time = nil)
153
+ time = Time.now if time.nil?
154
+ time.strftime("%Y-%m-%d %H:%M:%S")
155
+ end
156
+
157
+ def self.friendly_duration(in_secs)
158
+ friendly = WatchMe::Timer.calculate_duration_to_s(in_secs)
159
+ in_secs_to_s = "#{in_secs} seconds"
160
+ output = friendly == in_secs_to_s ? friendly : "#{friendly} (#{in_secs} seconds)"
161
+ end
162
+
163
+ private
164
+
165
+ def last_accessed_to_s(input)
166
+ return "" if input == "" || input.nil?
167
+ " last accessed #{input}"
168
+ end
169
+
170
+ def print(msg, raw_options = {}, messenger_name = "console")
171
+ options = raw_options.clone
172
+ show_multiple_times = options.delete(:show_multiple_times)
173
+ show_multiple_times = true if show_multiple_times.nil?
174
+ as_string = msg
175
+ return if (!show_multiple_times && @app.console.was_printed?(as_string))
176
+ @app.send(messenger_name).print as_string, options
177
+ end
178
+
179
+ end
180
+
181
+ end