amqp-daemon-kit 0.1.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) hide show
  1. data/.gitignore +5 -0
  2. data/Configuration.txt +110 -0
  3. data/Deployment.txt +113 -0
  4. data/History.txt +131 -0
  5. data/Logging.txt +96 -0
  6. data/PostInstall.txt +6 -0
  7. data/README.rdoc +132 -0
  8. data/Rakefile +29 -0
  9. data/RuoteParticipants.txt +113 -0
  10. data/TODO.txt +27 -0
  11. data/bin/daemon-kit +18 -0
  12. data/config/website.yml +2 -0
  13. data/daemon-kit.gemspec +265 -0
  14. data/lib/daemon_kit.rb +60 -0
  15. data/lib/daemon_kit/abstract_logger.rb +249 -0
  16. data/lib/daemon_kit/application.rb +230 -0
  17. data/lib/daemon_kit/arguments.rb +165 -0
  18. data/lib/daemon_kit/commands/console.rb +38 -0
  19. data/lib/daemon_kit/commands/destroy.rb +10 -0
  20. data/lib/daemon_kit/commands/generate.rb +10 -0
  21. data/lib/daemon_kit/config.rb +113 -0
  22. data/lib/daemon_kit/console_daemon.rb +2 -0
  23. data/lib/daemon_kit/core_ext.rb +1 -0
  24. data/lib/daemon_kit/core_ext/configurable.rb +96 -0
  25. data/lib/daemon_kit/core_ext/string.rb +22 -0
  26. data/lib/daemon_kit/cron.rb +67 -0
  27. data/lib/daemon_kit/cucumber/world.rb +38 -0
  28. data/lib/daemon_kit/deployment/capistrano.rb +516 -0
  29. data/lib/daemon_kit/dk_amqp.rb +39 -0
  30. data/lib/daemon_kit/em.rb +43 -0
  31. data/lib/daemon_kit/error_handlers/base.rb +32 -0
  32. data/lib/daemon_kit/error_handlers/hoptoad.rb +180 -0
  33. data/lib/daemon_kit/exceptions.rb +15 -0
  34. data/lib/daemon_kit/generators.rb +67 -0
  35. data/lib/daemon_kit/generators/base.rb +60 -0
  36. data/lib/daemon_kit/initializer.rb +449 -0
  37. data/lib/daemon_kit/jabber.rb +171 -0
  38. data/lib/daemon_kit/nanite.rb +7 -0
  39. data/lib/daemon_kit/nanite/agent.rb +77 -0
  40. data/lib/daemon_kit/pid_file.rb +61 -0
  41. data/lib/daemon_kit/ruote_participants.rb +125 -0
  42. data/lib/daemon_kit/ruote_pseudo_participant.rb +68 -0
  43. data/lib/daemon_kit/ruote_workitem.rb +187 -0
  44. data/lib/daemon_kit/safety.rb +84 -0
  45. data/lib/daemon_kit/tasks.rb +2 -0
  46. data/lib/daemon_kit/tasks/environment.rake +11 -0
  47. data/lib/daemon_kit/tasks/framework.rake +123 -0
  48. data/lib/daemon_kit/tasks/god.rake +62 -0
  49. data/lib/daemon_kit/tasks/log.rake +8 -0
  50. data/lib/daemon_kit/tasks/monit.rake +29 -0
  51. data/lib/daemon_kit/vendor/thor-0.13.6/CHANGELOG.rdoc +89 -0
  52. data/lib/daemon_kit/vendor/thor-0.13.6/LICENSE +20 -0
  53. data/lib/daemon_kit/vendor/thor-0.13.6/README.rdoc +297 -0
  54. data/lib/daemon_kit/vendor/thor-0.13.6/Thorfile +69 -0
  55. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor.rb +244 -0
  56. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions.rb +296 -0
  57. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions/create_file.rb +103 -0
  58. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions/directory.rb +91 -0
  59. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions/empty_directory.rb +134 -0
  60. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions/file_manipulation.rb +223 -0
  61. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions/inject_into_file.rb +104 -0
  62. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/base.rb +540 -0
  63. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/core_ext/file_binary_read.rb +9 -0
  64. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/core_ext/hash_with_indifferent_access.rb +75 -0
  65. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/core_ext/ordered_hash.rb +100 -0
  66. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/error.rb +30 -0
  67. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/group.rb +271 -0
  68. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/invocation.rb +180 -0
  69. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/parser.rb +4 -0
  70. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/parser/argument.rb +67 -0
  71. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/parser/arguments.rb +150 -0
  72. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/parser/option.rb +128 -0
  73. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/parser/options.rb +169 -0
  74. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/rake_compat.rb +66 -0
  75. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/runner.rb +314 -0
  76. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/shell.rb +83 -0
  77. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/shell/basic.rb +239 -0
  78. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/shell/color.rb +108 -0
  79. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/task.rb +102 -0
  80. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/util.rb +224 -0
  81. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/version.rb +3 -0
  82. data/lib/daemon_kit/xmpp.rb +100 -0
  83. data/lib/generators/daemon_kit/amqp/USAGE +5 -0
  84. data/lib/generators/daemon_kit/amqp/amqp_generator.rb +24 -0
  85. data/lib/generators/daemon_kit/amqp/templates/config/amqp.yml +28 -0
  86. data/lib/generators/daemon_kit/amqp/templates/config/pre-daemonize/amqp.rb +7 -0
  87. data/lib/generators/daemon_kit/amqp/templates/libexec/%app_name%-daemon.rb +37 -0
  88. data/lib/generators/daemon_kit/app/USAGE +7 -0
  89. data/lib/generators/daemon_kit/app/app_generator.rb +140 -0
  90. data/lib/generators/daemon_kit/app/templates/Gemfile +12 -0
  91. data/lib/generators/daemon_kit/app/templates/README.tt +58 -0
  92. data/lib/generators/daemon_kit/app/templates/Rakefile +6 -0
  93. data/lib/generators/daemon_kit/app/templates/bin/daemon.tt +7 -0
  94. data/lib/generators/daemon_kit/app/templates/config/arguments.rb +12 -0
  95. data/lib/generators/daemon_kit/app/templates/config/boot.rb +70 -0
  96. data/lib/generators/daemon_kit/app/templates/config/environment.rb.tt +26 -0
  97. data/lib/generators/daemon_kit/app/templates/config/environments/development.rb +2 -0
  98. data/lib/generators/daemon_kit/app/templates/config/environments/production.rb +5 -0
  99. data/lib/generators/daemon_kit/app/templates/config/environments/test.rb +2 -0
  100. data/lib/generators/daemon_kit/app/templates/config/post-daemonize/readme +5 -0
  101. data/lib/generators/daemon_kit/app/templates/config/pre-daemonize/readme +12 -0
  102. data/lib/generators/daemon_kit/app/templates/lib/%app_name%.rb +2 -0
  103. data/lib/generators/daemon_kit/app/templates/libexec/%app_name%-daemon.rb +18 -0
  104. data/lib/generators/daemon_kit/app/templates/script/console +3 -0
  105. data/lib/generators/daemon_kit/app/templates/script/destroy +3 -0
  106. data/lib/generators/daemon_kit/app/templates/script/generate +3 -0
  107. data/lib/generators/daemon_kit/capistrano/capistrano_generator.rb +26 -0
  108. data/lib/generators/daemon_kit/capistrano/templates/Capfile +10 -0
  109. data/lib/generators/daemon_kit/capistrano/templates/USAGE +10 -0
  110. data/lib/generators/daemon_kit/capistrano/templates/config/deploy.rb.tt +67 -0
  111. data/lib/generators/daemon_kit/capistrano/templates/config/deploy/logrotate.erb +13 -0
  112. data/lib/generators/daemon_kit/capistrano/templates/config/deploy/production.rb.tt +6 -0
  113. data/lib/generators/daemon_kit/capistrano/templates/config/deploy/staging.rb.tt +6 -0
  114. data/lib/generators/daemon_kit/capistrano/templates/config/environments/staging.rb +0 -0
  115. data/lib/generators/daemon_kit/cron/USAGE +5 -0
  116. data/lib/generators/daemon_kit/cron/cron_generator.rb +24 -0
  117. data/lib/generators/daemon_kit/cron/templates/config/pre-daemonize/cron.rb +11 -0
  118. data/lib/generators/daemon_kit/cron/templates/libexec/%app_name%-daemon.rb +48 -0
  119. data/lib/generators/daemon_kit/cucumber/USAGE +11 -0
  120. data/lib/generators/daemon_kit/cucumber/cucumber_generator.rb +45 -0
  121. data/lib/generators/daemon_kit/cucumber/templates/config/environments/cucumber.rb +2 -0
  122. data/lib/generators/daemon_kit/cucumber/templates/features/step_definitions/.empty_directory +0 -0
  123. data/lib/generators/daemon_kit/cucumber/templates/features/support/env.rb +7 -0
  124. data/lib/generators/daemon_kit/cucumber/templates/script/cucumber +7 -0
  125. data/lib/generators/daemon_kit/cucumber/templates/tasks/cucumber.rake +13 -0
  126. data/lib/generators/daemon_kit/nanite_agent/USAGE +5 -0
  127. data/lib/generators/daemon_kit/nanite_agent/nanite_agent_generator.rb +29 -0
  128. data/lib/generators/daemon_kit/nanite_agent/templates/config/nanite.yml +35 -0
  129. data/lib/generators/daemon_kit/nanite_agent/templates/config/pre-daemonize/nanite_agent.rb +6 -0
  130. data/lib/generators/daemon_kit/nanite_agent/templates/lib/actors/sample.rb +11 -0
  131. data/lib/generators/daemon_kit/nanite_agent/templates/libexec/%app_name%-daemon.rb +31 -0
  132. data/lib/generators/daemon_kit/rspec/USAGE +5 -0
  133. data/lib/generators/daemon_kit/rspec/rspec_generator.rb +20 -0
  134. data/lib/generators/daemon_kit/rspec/templates/spec/%app_name%_spec.rb +11 -0
  135. data/lib/generators/daemon_kit/rspec/templates/spec/spec.opts +1 -0
  136. data/lib/generators/daemon_kit/rspec/templates/spec/spec_helper.rb +23 -0
  137. data/lib/generators/daemon_kit/rspec/templates/tasks/rspec.rake +21 -0
  138. data/lib/generators/daemon_kit/ruote/USAGE +5 -0
  139. data/lib/generators/daemon_kit/ruote/ruote_generator.rb +29 -0
  140. data/lib/generators/daemon_kit/ruote/templates/config/amqp.yml +30 -0
  141. data/lib/generators/daemon_kit/ruote/templates/config/pre-daemonize/ruote.rb +13 -0
  142. data/lib/generators/daemon_kit/ruote/templates/config/ruote.yml +23 -0
  143. data/lib/generators/daemon_kit/ruote/templates/lib/%app_name%.rb +4 -0
  144. data/lib/generators/daemon_kit/ruote/templates/lib/sample.rb +26 -0
  145. data/lib/generators/daemon_kit/ruote/templates/libexec/%app_name%-daemon.rb +33 -0
  146. data/lib/generators/daemon_kit/test_unit/USAGE +5 -0
  147. data/lib/generators/daemon_kit/test_unit/templates/tasks/test_unit.rake +7 -0
  148. data/lib/generators/daemon_kit/test_unit/templates/test/%app_name%_test.rb.tt +9 -0
  149. data/lib/generators/daemon_kit/test_unit/templates/test/test_helper.rb +6 -0
  150. data/lib/generators/daemon_kit/test_unit/test_unit_generator.rb +20 -0
  151. data/lib/generators/daemon_kit/xmpp/templates/config/pre-daemonize/xmpp.rb +6 -0
  152. data/lib/generators/daemon_kit/xmpp/templates/config/xmpp.yml +29 -0
  153. data/lib/generators/daemon_kit/xmpp/templates/libexec/%app_name%-daemon.rb +27 -0
  154. data/lib/generators/daemon_kit/xmpp/xmpp_generator.rb +24 -0
  155. data/script/console +10 -0
  156. data/script/destroy +14 -0
  157. data/script/generate +14 -0
  158. data/script/txt2html +71 -0
  159. data/spec/abstract_logger_spec.rb +126 -0
  160. data/spec/argument_spec.rb +70 -0
  161. data/spec/config_spec.rb +83 -0
  162. data/spec/configurable_spec.rb +56 -0
  163. data/spec/daemon_kit_spec.rb +7 -0
  164. data/spec/error_handlers_spec.rb +23 -0
  165. data/spec/fixtures/env.yml +15 -0
  166. data/spec/fixtures/noenv.yml +4 -0
  167. data/spec/initializer_spec.rb +26 -0
  168. data/spec/spec.opts +1 -0
  169. data/spec/spec_helper.rb +27 -0
  170. data/tasks/cucumber.rake +13 -0
  171. data/tasks/rspec.rake +20 -0
  172. data/tasks/tests.rake +6 -0
  173. data/templates/god/god.erb +69 -0
  174. data/templates/monit/monit.erb +14 -0
  175. data/test/test_amqp_generator.rb +48 -0
  176. data/test/test_cron_generator.rb +45 -0
  177. data/test/test_daemon-kit_generator.rb +84 -0
  178. data/test/test_daemon_kit_config.rb +28 -0
  179. data/test/test_deploy_capistrano_generator.rb +48 -0
  180. data/test/test_generator_helper.rb +29 -0
  181. data/test/test_helper.rb +7 -0
  182. data/test/test_nanite_agent_generator.rb +49 -0
  183. data/test/test_ruote_generator.rb +51 -0
  184. data/test/test_test_unit_generator.rb +46 -0
  185. metadata +302 -0
@@ -0,0 +1,13 @@
1
+ begin
2
+ require 'json'
3
+ rescue LoadError
4
+ $stderr.puts "Missing json gem. Please run 'bundle install'"
5
+ exit 1
6
+ end
7
+
8
+ begin
9
+ require 'amqp'
10
+ require 'mq'
11
+ rescue LoadError
12
+ $stderr.puts "Missing amqp gem. Please uncomment the amqp section in the Gemfile and run 'bundle install' if you wish to use the AMQP participant/listener pair in ruote"
13
+ end
@@ -0,0 +1,23 @@
1
+ # Sample configuration file for a remote participant daemon
2
+
3
+ # If your using the AMQP listener/participant pair in ruote, you only
4
+ # need to specify the names of the queues to subscribe to.
5
+
6
+ defaults: &defaults
7
+ amqp:
8
+ queues:
9
+ - work1
10
+ #- work2
11
+ #- work3
12
+
13
+ development:
14
+ <<: *defaults
15
+
16
+ test:
17
+ <<: *defaults
18
+
19
+ staging:
20
+ <<: *defaults
21
+
22
+ production:
23
+ <<: *defaults
@@ -0,0 +1,4 @@
1
+ # Your starting point for daemon specific classes. This directory is
2
+ # already included in your load path, so no need to specify it.
3
+
4
+ require 'sample'
@@ -0,0 +1,26 @@
1
+ require 'open-uri'
2
+
3
+ # Sample pseudo participant
4
+ #
5
+ # See http://gist.github.com/144861 for a test engine
6
+ class Sample < DaemonKit::RuotePseudoParticipant
7
+
8
+ on_exception :dammit
9
+
10
+ on_complete do |workitem|
11
+ workitem['success'] = true
12
+ end
13
+
14
+ def quote
15
+ workitem["quote"] = open("http://www.iheartquotes.com/api/v1/random").read
16
+ end
17
+
18
+ def err
19
+ raise ArgumentError, "Does not compute"
20
+ end
21
+
22
+ def dammit( exception )
23
+ workitem["error"] = exception.message
24
+ end
25
+
26
+ end
@@ -0,0 +1,33 @@
1
+ # Generated remote participant for the ruote workflow engine
2
+ # (http://openwferu.rubyforge.org)
3
+
4
+ # Do your post daemonization configuration here
5
+ # At minimum you need just the first line (without the block), or a lot
6
+ # of strange things might start happening...
7
+ DaemonKit::Application.running! do |config|
8
+ # Trap signals with blocks or procs
9
+ # config.trap( 'INT' ) do
10
+ # # do something clever
11
+ # end
12
+ # config.trap( 'TERM', Proc.new { puts 'Going down' } )
13
+ end
14
+
15
+ # IMPORTANT CONFIGURATION NOTE
16
+ #
17
+ # Please review and update 'config/amqp.yml' accordingly if you wish to use
18
+ # AMQP as a transport mechanism for workitems sent between ruote and this
19
+ # daemon.
20
+
21
+ # Configuration of the remote participant shell
22
+ DaemonKit::RuoteParticipants.configure do |config|
23
+ # Use AMQP as a workitem transport mechanism
24
+ config.use :amqp
25
+
26
+ # Register your classes as pseudo-participants, with work being delegated
27
+ # according to the 'command' parameter passed in the process definition
28
+ config.register Sample
29
+ end
30
+
31
+ DaemonKit::RuoteParticipants.run do
32
+ # Place any additional daemon-specific code in here...
33
+ end
@@ -0,0 +1,5 @@
1
+ Description:
2
+
3
+
4
+ Usage:
5
+
@@ -0,0 +1,7 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << "test"
5
+ t.test_files = FileList['test/*_test.rb']
6
+ t.verbose = true
7
+ end
@@ -0,0 +1,9 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class Test<%= app_name %> < Test::Unit::TestCase
4
+
5
+ def test_missing
6
+ assert false, "daemons should be tested"
7
+ end
8
+ end
9
+
@@ -0,0 +1,6 @@
1
+ DAEMON_ENV = 'test' unless defined?( DAEMON_ENV )
2
+
3
+ require 'test/unit'
4
+
5
+ require File.dirname(__FILE__) + '/../config/environment'
6
+ DaemonKit::Application.running!
@@ -0,0 +1,20 @@
1
+ module DaemonKit
2
+ module Generators
3
+ class TestUnitGenerator < Base
4
+
5
+ def create_tests
6
+ directory 'test'
7
+ end
8
+
9
+ def create_tasks
10
+ directory 'tasks'
11
+ end
12
+
13
+ protected
14
+
15
+ def self.source_root
16
+ File.expand_path( File.join( File.dirname(__FILE__), 'templates') )
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,6 @@
1
+ begin
2
+ require 'blather'
3
+ rescue LoadError
4
+ $stderr.puts "Missing blather gem. Please run 'bundle install'."
5
+ exit 1
6
+ end
@@ -0,0 +1,29 @@
1
+ # Jabber configuration file
2
+
3
+ # The configuration specifies the following keys:
4
+ # * jabber_id - Identidy (username) of the user
5
+ # * password - Password used to authenticate
6
+ # * resource - Multiple connections can be made with the same credentials and different resources
7
+ # * masters - Array of Jabber ID's whose messages will be processed
8
+ # * supporters - Additional 'buddies' to keep on roster, but messages won't be processed
9
+ # * enable_logging - Enable Blather logging (VERY VERBOSE)
10
+ # * require_master - Disable filtering of messages based on the sender being a 'master'
11
+
12
+ defaults: &defaults
13
+ jabber_id: dk@jabber
14
+ password: secret
15
+ resource: daemon_kit
16
+ enable_logging: false
17
+ masters:
18
+ - kenneth.kalmer@gmail.com
19
+ supporters:
20
+ - someone@gmail.com
21
+
22
+ development:
23
+ <<: *defaults
24
+
25
+ test:
26
+ <<: *defaults
27
+
28
+ production:
29
+ <<: *defaults
@@ -0,0 +1,27 @@
1
+ # Change this file to be a wrapper around your daemon code.
2
+
3
+ # Do your post daemonization configuration here
4
+ # At minimum you need just the first line (without the block), or a lot
5
+ # of strange things might start happening...
6
+ DaemonKit::Application.running! do |config|
7
+ # Trap signals with blocks or procs
8
+ # config.trap( 'INT' ) do
9
+ # # do something clever
10
+ # end
11
+ # config.trap( 'TERM', Proc.new { puts 'Going down' } )
12
+ end
13
+
14
+
15
+ DaemonKit::XMPP.run do
16
+ when_ready { DaemonKit.logger.info "Connected as #{jid}" }
17
+
18
+ # Auto approve subscription requests
19
+ subscription :request? do |s|
20
+ write_to_stream s.approve!
21
+ end
22
+
23
+ # Echo back what was said
24
+ message :chat?, :body do |m|
25
+ write_to_stream m.reply
26
+ end
27
+ end
@@ -0,0 +1,24 @@
1
+ module DaemonKit
2
+ module Generators
3
+ class XmppGenerator < Base
4
+
5
+ def update_gemfile
6
+ append_file 'Gemfile', "gem 'blather'\n"
7
+ end
8
+
9
+ def create_config
10
+ directory 'config'
11
+ end
12
+
13
+ def create_daemon
14
+ directory 'libexec'
15
+ end
16
+
17
+ protected
18
+
19
+ def self.source_root
20
+ File.expand_path( File.join( File.dirname(__FILE__), 'templates') )
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/daemon-kit.rb'}"
9
+ puts "Loading daemon-kit gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ load File.dirname(__FILE__) + "/../Rakefile"
4
+ require 'rubyforge'
5
+ require 'redcloth'
6
+ require 'syntax/convertors/html'
7
+ require 'erb'
8
+
9
+ download = "http://rubyforge.org/projects/#{$hoe.rubyforge_name}"
10
+ version = $hoe.version
11
+
12
+ def rubyforge_project_id
13
+ RubyForge.new.configure.autoconfig["group_ids"][$hoe.rubyforge_name]
14
+ end
15
+
16
+ class Fixnum
17
+ def ordinal
18
+ # teens
19
+ return 'th' if (10..19).include?(self % 100)
20
+ # others
21
+ case self % 10
22
+ when 1: return 'st'
23
+ when 2: return 'nd'
24
+ when 3: return 'rd'
25
+ else return 'th'
26
+ end
27
+ end
28
+ end
29
+
30
+ class Time
31
+ def pretty
32
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
33
+ end
34
+ end
35
+
36
+ def convert_syntax(syntax, source)
37
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
38
+ end
39
+
40
+ if ARGV.length >= 1
41
+ src, template = ARGV
42
+ template ||= File.join(File.dirname(__FILE__), '/../website/template.html.erb')
43
+ else
44
+ puts("Usage: #{File.split($0).last} source.txt [template.html.erb] > output.html")
45
+ exit!
46
+ end
47
+
48
+ template = ERB.new(File.open(template).read)
49
+
50
+ title = nil
51
+ body = nil
52
+ File.open(src) do |fsrc|
53
+ title_text = fsrc.readline
54
+ body_text_template = fsrc.read
55
+ body_text = ERB.new(body_text_template).result(binding)
56
+ syntax_items = []
57
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
58
+ ident = syntax_items.length
59
+ element, syntax, source = $1, $2, $3
60
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
61
+ "syntax-temp-#{ident}"
62
+ }
63
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
64
+ body = RedCloth.new(body_text).to_html
65
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
66
+ end
67
+ stat = File.stat(src)
68
+ created = stat.ctime
69
+ modified = stat.mtime
70
+
71
+ $stdout << template.result(binding)
@@ -0,0 +1,126 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe DaemonKit::AbstractLogger do
4
+
5
+ before(:each) do
6
+ @log_file = "#{DAEMON_ROOT}/log/spec.log"
7
+ @logger = DaemonKit::AbstractLogger.new( @log_file )
8
+ @logger.level = :debug
9
+ end
10
+
11
+ it "should have a log level" do
12
+ @logger.level.should == :debug
13
+ end
14
+
15
+ it "should have a backend logger" do
16
+ @logger.logger.should_not be_nil
17
+ end
18
+
19
+ it "should accept a different backend" do
20
+ l = Logger.new('/dev/null')
21
+ @logger.logger = l
22
+ @logger.logger.should == l
23
+ end
24
+
25
+ it "should be able to log to STDOUT as well" do
26
+ @logger.copy_to_stdout = true
27
+
28
+ STDOUT.expects(:puts).with(regexp_matches(/test/))
29
+
30
+ @logger.debug "test"
31
+ IO.readlines( @log_file ).last.should match(/test/)
32
+ end
33
+
34
+ it "should log debug level messages" do
35
+ @logger.debug( "Debug test" )
36
+
37
+ IO.readlines( @log_file ).last.should match(/\[DEBUG\].*Debug test/)
38
+ end
39
+
40
+ it "should log info level messages" do
41
+ @logger.info( "Info test" )
42
+
43
+ IO.readlines( @log_file ).last.should match(/\[INFO\].*Info test/)
44
+ end
45
+
46
+ it "should log warn level messages" do
47
+ @logger.warn( "Warn test" )
48
+
49
+ IO.readlines( @log_file ).last.should match(/\[WARN\].*Warn test/)
50
+ end
51
+
52
+ it "should log error level messages" do
53
+ @logger.error( "Err test" )
54
+
55
+ IO.readlines( @log_file ).last.should match(/\[ERROR\].*Err test/)
56
+ end
57
+
58
+ it "should log fatal level messages" do
59
+ @logger.fatal( "Fatal test" )
60
+
61
+ IO.readlines( @log_file ).last.should match(/\[FATAL\].*Fatal test/)
62
+ end
63
+
64
+ it "should log unknown level messages" do
65
+ @logger.unknown( "Unknown test" )
66
+
67
+ IO.readlines( @log_file ).last.should match(/\[ANY\].*Unknown test/)
68
+ end
69
+
70
+ it "should log the caller file and line number" do
71
+ f = File.basename(__FILE__)
72
+ l = __LINE__ + 2
73
+
74
+ @logger.info( "Caller test" )
75
+
76
+ IO.readlines( @log_file ).last.should match(/#{f}:#{l}:/)
77
+ end
78
+
79
+ it "should log exceptions with daemon traces" do
80
+ fake_trace = [
81
+ "/home/kenneth/daemon/libexec/daemon-daemon.rb:1:in `foo'",
82
+ "/usr/lib/ruby/gems/1.8/gems/daemon-kit-0.0.1/lib/daemon_kit/abstract_logger.rb:49: in `info'"
83
+ ]
84
+
85
+ e = RuntimeError.new( 'Test error' )
86
+ e.set_backtrace( fake_trace )
87
+
88
+ @logger.exception( e )
89
+
90
+ IO.readlines( @log_file ).last.should match(/EXCEPTION: Test error/)
91
+ end
92
+
93
+ it "should log exceptions without framework traces" do
94
+ fake_trace = [
95
+ "/home/kenneth/daemon/libexec/daemon-daemon.rb:1:in `foo'",
96
+ "/usr/lib/ruby/gems/1.8/gems/daemon-kit-0.0.1/lib/daemon_kit/abstract_logger.rb:49: in `info'"
97
+ ]
98
+
99
+ clean_trace = @logger.clean_trace( fake_trace )
100
+
101
+ clean_trace.should include("/home/kenneth/daemon/libexec/daemon-daemon.rb:1:in `foo'")
102
+ clean_trace.should_not include("/usr/lib/ruby/gems/1.8/gems/daemon-kit-0.0.1/lib/daemon_kit/abstract_logger.rb:49: in `info'")
103
+ end
104
+
105
+ it "should support reopening log files" do
106
+ @logger.close
107
+
108
+ FileUtils.rm( @log_file )
109
+
110
+ @logger.info( 'Reopen')
111
+ IO.readlines( @log_file ).last.should match(/Reopen/)
112
+ end
113
+
114
+ it "should support silencing" do
115
+ @logger.silence do |logger|
116
+ logger.info "This should never be logged"
117
+ end
118
+
119
+ @logger.info "This should be logged"
120
+
121
+ log = IO.readlines( @log_file )
122
+
123
+ log.detect { |l| l =~ /This should never be logged/ }.should be_nil
124
+ log.detect { |l| l =~ /This should be logged/ }.should_not be_nil
125
+ end
126
+ end