cinchize 0.1.0 → 0.2.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/VERSION +1 -1
- data/cinchize.gemspec +2 -2
- data/lib/cinchize.rb +95 -71
- metadata +3 -3
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.2.0
|
data/cinchize.gemspec
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = %q{cinchize}
|
|
8
|
-
s.version = "0.
|
|
8
|
+
s.version = "0.2.0"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["Victor Bergöö"]
|
|
12
|
-
s.date = %q{2010-
|
|
12
|
+
s.date = %q{2010-12-05}
|
|
13
13
|
s.default_executable = %q{cinchize}
|
|
14
14
|
s.description = %q{Create dynamic Cinch IRC-bots and daemonize them, without the need of writing any code}
|
|
15
15
|
s.email = %q{victor.bergoo@gmail.com}
|
data/lib/cinchize.rb
CHANGED
|
@@ -53,80 +53,16 @@ module Cinchize
|
|
|
53
53
|
o.parse!
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
when :status then
|
|
62
|
-
status(d_options[:dir], d_options[:app_name])
|
|
63
|
-
when :stop then
|
|
64
|
-
stop(d_options[:dir], d_options[:app_name])
|
|
65
|
-
when :restart then
|
|
66
|
-
stop(d_options[:dir], d_options[:app_name])
|
|
67
|
-
start(d_options, network, plugins, plugin_options)
|
|
68
|
-
else
|
|
69
|
-
puts "Error: no valid action supplied"
|
|
70
|
-
exit 1
|
|
71
|
-
end
|
|
56
|
+
daemon = Cinchize.new *config(options, ARGV.first)
|
|
57
|
+
daemon.send options[:action]
|
|
58
|
+
rescue NoMethodError => e
|
|
59
|
+
puts "Error: no such method"
|
|
60
|
+
exit 1
|
|
72
61
|
rescue ArgumentError => e
|
|
73
62
|
puts "Error: #{e}"
|
|
74
63
|
exit 1
|
|
75
64
|
end
|
|
76
|
-
|
|
77
|
-
def self.start d_options, network, plugins, plugin_options
|
|
78
|
-
puts "* starting #{d_options[:app_name].split('_').last}"
|
|
79
|
-
|
|
80
|
-
daemon = Daemons::ApplicationGroup.new(d_options[:app_name], {
|
|
81
|
-
:ontop => d_options[:ontop],
|
|
82
|
-
:dir => d_options[:dir],
|
|
83
|
-
:dir_mode => d_options[:dir_mode]
|
|
84
|
-
})
|
|
85
|
-
app = daemon.new_application :mode => :none, :log_output => d_options[:log_output]
|
|
86
|
-
app.start
|
|
87
|
-
|
|
88
|
-
loop do
|
|
89
|
-
bot = Cinch::Bot.new do
|
|
90
|
-
configure do |c|
|
|
91
|
-
network.keys.each { |key| c.send("#{key}=".to_sym, network[key]) }
|
|
92
|
-
|
|
93
|
-
c.plugins.plugins = plugins
|
|
94
|
-
c.plugins.options = plugin_options
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
65
|
|
|
98
|
-
bot.start
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
def self.stop dir, app_name
|
|
103
|
-
pidfile = Daemons::PidFile.new dir, app_name
|
|
104
|
-
unless pidfile.pid
|
|
105
|
-
puts "* #{app_name.split('_').last} is not running"
|
|
106
|
-
return
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
puts "* stopping #{app_name.split('_').last}"
|
|
110
|
-
|
|
111
|
-
Process.kill(9, pidfile.pid)
|
|
112
|
-
File.delete(pidfile.filename)
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
def self.status dir, app_name
|
|
116
|
-
pidfile = Daemons::PidFile.new dir, app_name
|
|
117
|
-
|
|
118
|
-
unless pidfile.pid
|
|
119
|
-
puts "* #{app_name.split('_').last} is not running"
|
|
120
|
-
return
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
if Process.kill(0, pidfile.pid) != 0
|
|
124
|
-
puts "* #{app_name.split('_').last} is running"
|
|
125
|
-
else
|
|
126
|
-
puts "* #{app_name.split('_').last} is not running"
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
|
|
130
66
|
def self.config options, network
|
|
131
67
|
config_file = options[:system] ? options[:system_config]: options[:local_config]
|
|
132
68
|
|
|
@@ -165,8 +101,8 @@ module Cinchize
|
|
|
165
101
|
raise ArgumentError.new "no plugins loaded" if plugins.size == 0
|
|
166
102
|
|
|
167
103
|
cfg["options"] ||= {}
|
|
168
|
-
dir_mode = cfg["options"]
|
|
169
|
-
|
|
104
|
+
dir_mode = cfg["options"].key?("dir_mode") ? cfg["options"]["dir_mode"] : "normal"
|
|
105
|
+
|
|
170
106
|
daemon_options = {
|
|
171
107
|
:dir_mode => dir_mode.to_sym,
|
|
172
108
|
:dir => cfg["options"]["dir"] || Dir.getwd,
|
|
@@ -177,6 +113,94 @@ module Cinchize
|
|
|
177
113
|
|
|
178
114
|
[daemon_options, ntw, plugins, plugin_options]
|
|
179
115
|
end
|
|
116
|
+
|
|
117
|
+
class Cinchize
|
|
118
|
+
attr_reader :options
|
|
119
|
+
|
|
120
|
+
def initialize options, network, plugins, plugin_options
|
|
121
|
+
@network = network
|
|
122
|
+
@plugins = plugins
|
|
123
|
+
@plugin_options = plugin_options
|
|
124
|
+
@options = options
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def app_name
|
|
128
|
+
options[:app_name]
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def dir
|
|
132
|
+
options[:dir]
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def clean_app_name
|
|
136
|
+
app_name.split('_').last
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def restart
|
|
140
|
+
stop
|
|
141
|
+
start
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def start
|
|
145
|
+
if running?
|
|
146
|
+
raise ArgumentError.new "#{clean_app_name} is already running"
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
puts "* starting #{clean_app_name}"
|
|
150
|
+
|
|
151
|
+
daemon = Daemons::ApplicationGroup.new(app_name, {
|
|
152
|
+
:ontop => options[:ontop],
|
|
153
|
+
:dir => dir,
|
|
154
|
+
:dir_mode => options[:dir_mode]
|
|
155
|
+
})
|
|
156
|
+
app = daemon.new_application :mode => :none, :log_output => options[:log_output]
|
|
157
|
+
app.start
|
|
158
|
+
|
|
159
|
+
network = @network
|
|
160
|
+
plugins = @plugins
|
|
161
|
+
plugin_options = @plugin_options
|
|
162
|
+
|
|
163
|
+
loop do
|
|
164
|
+
bot = Cinch::Bot.new do
|
|
165
|
+
configure do |c|
|
|
166
|
+
network.each_pair { |key, value| c.send("#{key}=".to_sym, value) }
|
|
167
|
+
|
|
168
|
+
c.plugins.plugins = plugins
|
|
169
|
+
c.plugins.options = plugin_options
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
bot.start
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
def stop
|
|
178
|
+
unless running?
|
|
179
|
+
puts "* #{clean_app_name} is not running"
|
|
180
|
+
return
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
pidfile = Daemons::PidFile.new dir, app_name
|
|
184
|
+
puts "* stopping #{clean_app_name}"
|
|
185
|
+
|
|
186
|
+
Process.kill(9, pidfile.pid)
|
|
187
|
+
File.delete(pidfile.filename)
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def status
|
|
191
|
+
if running?
|
|
192
|
+
puts "* #{clean_app_name} is running"
|
|
193
|
+
else
|
|
194
|
+
puts "* #{clean_app_name} is not running"
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def running?
|
|
199
|
+
pidfile = Daemons::PidFile.new dir, app_name
|
|
200
|
+
return false if pidfile.pid.nil?
|
|
201
|
+
return Process.kill(0, pidfile.pid) != 0
|
|
202
|
+
end
|
|
203
|
+
end
|
|
180
204
|
end
|
|
181
205
|
|
|
182
206
|
# We need to open up Daemons::Application#start_none so we can log the output
|
metadata
CHANGED
|
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
|
4
4
|
prerelease: false
|
|
5
5
|
segments:
|
|
6
6
|
- 0
|
|
7
|
-
-
|
|
7
|
+
- 2
|
|
8
8
|
- 0
|
|
9
|
-
version: 0.
|
|
9
|
+
version: 0.2.0
|
|
10
10
|
platform: ruby
|
|
11
11
|
authors:
|
|
12
12
|
- "Victor Berg\xC3\xB6\xC3\xB6"
|
|
@@ -14,7 +14,7 @@ autorequire:
|
|
|
14
14
|
bindir: bin
|
|
15
15
|
cert_chain: []
|
|
16
16
|
|
|
17
|
-
date: 2010-
|
|
17
|
+
date: 2010-12-05 00:00:00 +01:00
|
|
18
18
|
default_executable: cinchize
|
|
19
19
|
dependencies:
|
|
20
20
|
- !ruby/object:Gem::Dependency
|