lolcommits 0.4.0 → 0.4.1pre1

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/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ 0.4.1 (in development)
2
+ * add lolsrv plugin
3
+ * restructure logging slightly to use Methadone::CLILogging in most places
4
+ * add a bunch of debugging output, viewable via --debug flag
5
+
1
6
  0.4.0 (13 January 2013)
2
7
  * Switch the main ImageMagick wrapper from RMagick to mini_magick
3
8
  - fix for RMagick not working with ImageMagick 6.8+ and generally
data/bin/lolcommits CHANGED
@@ -11,6 +11,9 @@ include Lolcommits
11
11
  require "launchy"
12
12
  require "choice"
13
13
 
14
+ require 'methadone'
15
+ include Methadone::CLILogging
16
+
14
17
  #
15
18
  # CHECK FOR FURTHER DEPENDENCIES
16
19
  #
@@ -23,26 +26,27 @@ end
23
26
 
24
27
  if Configuration.is_mac?
25
28
  unless File.executable? File.join(Configuration::LOLCOMMITS_ROOT, "vendor", "ext", "imagesnap", "imagesnap")
26
- puts "Couldn't properly execute imagesnap for some reason, please file a bug?!"
29
+ fatal "Couldn't properly execute imagesnap for some reason, please file a bug?!"
27
30
  exit 1
28
31
  end
29
32
  elsif Configuration.is_linux?
30
33
  if not command?('mplayer')
31
- puts "Couldn't find mplayer in your PATH!"
34
+ fatal "Couldn't find mplayer in your PATH!"
32
35
  exit 1
33
36
  end
34
37
  end
35
38
  unless File.readable? File.join(Configuration::LOLCOMMITS_ROOT, "vendor", "fonts", "Impact.ttf")
36
- puts "Couldn't properly read Impact font from gem package, please file a bug?!"
39
+ fatal "Couldn't properly read Impact font from gem package, please file a bug?!"
37
40
  exit 1
38
41
  end
39
42
 
40
43
  def die_if_not_git_repo!
41
44
  begin
45
+ debug "Checking for valid git repo"
42
46
  g=Git.open('.')
43
47
  rescue ArgumentError
44
48
  # ruby-git throws an argument error if path isnt for a valid git repo...
45
- puts "Erm? Can't do that since we're not in a valid git repository!"
49
+ fatal "Erm? Can't do that since we're not in a valid git repository!"
46
50
  exit 1
47
51
  end
48
52
  end
@@ -65,7 +69,7 @@ HOOK_DIR = File.join ".git", "hooks"
65
69
  #
66
70
  def do_enable
67
71
  if not File.directory?(".git")
68
- puts "You don't appear to be in the base directory of a git project."
72
+ fatal "You don't appear to be in the base directory of a git project."
69
73
  exit 1
70
74
  end
71
75
 
@@ -75,7 +79,7 @@ def do_enable
75
79
  end
76
80
 
77
81
  if File.exists? HOOK_PATH
78
- puts "A post-commit hook already exists for this project."
82
+ fatal "A post-commit hook already exists for this project."
79
83
  #TODO: disambiguate between OUR post-commit hook and something else
80
84
  exit 1
81
85
  end
@@ -83,9 +87,9 @@ def do_enable
83
87
  doc = "#!/bin/sh\nlolcommits --capture\n"
84
88
  File.open(HOOK_PATH, 'w') {|f| f.write(doc) }
85
89
  FileUtils.chmod 0755, HOOK_PATH
86
- puts "installed lolcommmit hook as:"
87
- puts " -> #{File.expand_path(HOOK_PATH)}"
88
- puts "(to remove later, you can use: lolcommits --disable)"
90
+ info "installed lolcommmit hook as:"
91
+ info " -> #{File.expand_path(HOOK_PATH)}"
92
+ info "(to remove later, you can use: lolcommits --disable)"
89
93
  # we dont symlink, but rather install a small stub that calls the one from path
90
94
  # that way, as gem version changes, script updates even if new file thus breaking symlink
91
95
  end
@@ -97,9 +101,9 @@ def do_disable
97
101
  if File.exists? HOOK_PATH
98
102
  #TODO: check if hook file has been modified before removing
99
103
  FileUtils.rm HOOK_PATH
100
- puts "removed #{HOOK_PATH}"
104
+ info "removed #{HOOK_PATH}"
101
105
  else
102
- puts "lolcommits is not enabled for this directory, so there is nothing to uninstall."
106
+ info "lolcommits is not enabled for this directory, so there is nothing to uninstall."
103
107
  end
104
108
  end
105
109
 
@@ -119,7 +123,7 @@ def do_capture
119
123
  capture_device = Choice.choices[:device] || ENV['LOLCOMMITS_DEVICE'] || nil
120
124
 
121
125
  if Choice.choices[:test]
122
- puts "*** Capturing in test mode."
126
+ info "*** Capturing in test mode."
123
127
  runner = Lolcommits::Runner.new(:capture_delay => capture_delay,
124
128
  :capture_device => capture_device,
125
129
  :message => Choice.choices[:msg],
@@ -146,7 +150,7 @@ def do_last
146
150
  die_if_not_git_repo!
147
151
  lolimage = configuration.most_recent
148
152
  if lolimage.nil?
149
- puts "No lolcommits have been captured for this repository yet."
153
+ warn "No lolcommits have been captured for this repository yet."
150
154
  exit 1
151
155
  end
152
156
  Launchy.open lolimage
@@ -242,6 +246,19 @@ Choice.options do
242
246
  long "--device=DEVICE"
243
247
  desc "the device name used to take the snapshot (only mac)"
244
248
  end
249
+
250
+ option :debug do
251
+ long "--debug"
252
+ desc "Output debugging information"
253
+ end
254
+
255
+ end
256
+
257
+ # Set debug level if needed
258
+ debug_mode = Choice.choices[:debug] || ENV['LOLCOMMITS_DEBUG'] || nil
259
+ if debug_mode
260
+ logger.level = Logger::DEBUG
261
+ debug "Outputting at DEBUG verbosity"
245
262
  end
246
263
 
247
264
  #
@@ -22,3 +22,15 @@ Feature: Plugins Work
22
22
  When I do a git commit
23
23
  Then the output should contain "*** Preserving this moment in history."
24
24
  And there should be exactly 1 jpg in "../.lolcommits/loltext"
25
+
26
+ Scenario: lolsrv integration works
27
+ Given I am in a git repository named "lolsrv" with lolcommits enabled
28
+ When I run `lolcommits --config` and wait for output
29
+ And I enter "lolsrv" for "Plugin Name"
30
+ And I enter "true" for "enabled"
31
+ And I enter "http://localhost" for "server"
32
+ Then I should be presented "Successfully Configured"
33
+ When I do a git commit
34
+ Then the output should contain "*** Preserving this moment in history."
35
+ And there should be exactly 1 jpg in "../.lolcommits/lolsrv"
36
+
data/lib/lolcommits.rb CHANGED
@@ -8,6 +8,7 @@ require 'open3'
8
8
  require 'active_support/inflector'
9
9
  require 'active_support/concern'
10
10
  require 'active_support/callbacks'
11
+ require 'methadone'
11
12
 
12
13
  require 'lolcommits/version'
13
14
  require 'lolcommits/configuration'
@@ -24,6 +25,7 @@ require 'lolcommits/plugins/tranzlate'
24
25
  require 'lolcommits/plugins/statsd'
25
26
  require 'lolcommits/plugins/lol_twitter'
26
27
  require 'lolcommits/plugins/uploldz'
28
+ require 'lolcommits/plugins/lolsrv'
27
29
 
28
30
  # require runner after all the plugins have been required
29
31
  require 'lolcommits/runner'
@@ -1,16 +1,25 @@
1
1
  module Lolcommits
2
2
  class CaptureLinux < Capturer
3
3
  def capture
4
+ debug "LinuxCapturer: making tmp directory"
4
5
  tmpdir = Dir.mktmpdir
6
+
5
7
  # There's no way to give a capture delay in mplayer, but a number of frame
6
8
  # I've found that 6 is a good value for me.
7
9
  frames = if capture_delay != 0 then capture_delay else 6 end
8
10
 
11
+ debug "LinuxCapturer: calling out to mplayer to capture image"
9
12
  # mplayer's output is ugly and useless, let's throw it away
10
13
  _, r, _ = Open3.popen3("mplayer -vo jpeg:outdir=#{tmpdir} -frames #{frames} tv://")
11
14
  # looks like we still need to read the output for something to happen
12
15
  r.read
16
+
17
+ # the below SHOULD tell FileUtils actions to post their output if we are in debug mode
18
+ include FileUtils::Verbose if logger.level == 0
19
+
20
+ debug "LinuxCapturer: calling out to mplayer to capture image"
13
21
  FileUtils.mv(tmpdir + "/%08d.jpg" % frames, snapshot_location)
22
+ debug "LinuxCapturer: cleaning up"
14
23
  FileUtils.rm_rf( tmpdir )
15
24
  end
16
25
 
@@ -5,7 +5,9 @@ module Lolcommits
5
5
  end
6
6
 
7
7
  def capture
8
- system("#{imagesnap_bin} -q \"#{snapshot_location}\" -w #{capture_delay} #{capture_device_string}")
8
+ call_str = "#{imagesnap_bin} -q \"#{snapshot_location}\" -w #{capture_delay} #{capture_device_string}"
9
+ debug "Capturer: making system call for #{call_str}"
10
+ system(call_str)
9
11
  end
10
12
 
11
13
  private
@@ -1,10 +1,13 @@
1
1
  module Lolcommits
2
2
  class Capturer
3
+ include Methadone::CLILogging
3
4
  attr_accessor :capture_device, :capture_delay, :snapshot_location
5
+
4
6
  def initialize(attributes = Hash.new)
5
7
  attributes.each do |attr, val|
6
8
  self.send("#{attr}=", val)
7
9
  end
10
+ debug "Capturer: initializing new instance " + self.to_s
8
11
  end
9
12
  end
10
13
  end
@@ -1,5 +1,6 @@
1
1
  module Lolcommits
2
2
  class Plugin
3
+ include Methadone::CLILogging
3
4
  attr_accessor :default, :name, :runner, :options
4
5
 
5
6
  def configuration
@@ -11,6 +12,8 @@ module Lolcommits
11
12
  def initialize(runner)
12
13
  self.runner = runner
13
14
  self.options = ['enabled']
15
+
16
+ plugdebug "Initializing"
14
17
  end
15
18
 
16
19
  def is_enabled?
@@ -22,8 +25,16 @@ module Lolcommits
22
25
 
23
26
  def execute
24
27
  if is_enabled?
28
+ plugdebug "I am enabled, about to run"
25
29
  run
30
+ else
31
+ plugdebug "Disabled, doing nothing for execution"
26
32
  end
27
33
  end
34
+
35
+ # uniform debug logging output for plugins
36
+ def plugdebug(msg)
37
+ debug("Plugin: #{self.class.to_s}: " + msg)
38
+ end
28
39
  end
29
40
  end
@@ -0,0 +1,73 @@
1
+ require "rest_client"
2
+ require "pp"
3
+ require "json"
4
+ require "logger"
5
+
6
+ module Lolcommits
7
+
8
+ class Lolsrv < Plugin
9
+
10
+ SERVER = 'server'
11
+
12
+ def initialize(runner)
13
+ super
14
+ self.name = 'lolsrv'
15
+ self.default = false
16
+ self.options << SERVER
17
+
18
+ end
19
+
20
+ def run
21
+
22
+ log_file = File.new(self.runner.config.loldir + "/lolsrv.log", "a+")
23
+ @logger = Logger.new(log_file)
24
+
25
+ if configuration[SERVER].nil?
26
+ puts "Missing server configuration. Use lolcommits --config -p lolsrv"
27
+ return
28
+ end
29
+
30
+ fork do
31
+ sync()
32
+ end
33
+ end
34
+
35
+ def sync
36
+ existing = get_existing_lols
37
+ unless existing.nil?
38
+ Dir.glob(self.runner.config.loldir + "/*.jpg") do |item|
39
+ next if item == '.' or item == '..'
40
+ # do work on real items
41
+ sha = File.basename(item, '.*')
42
+ unless existing.include?(sha) || sha == 'tmp_snapshot'
43
+ upload(item, sha)
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ def get_existing_lols
50
+ begin
51
+ lols = JSON.parse(
52
+ RestClient.get(configuration[SERVER] + '/lols'))
53
+ lols.map { |lol| lol["sha"] }
54
+ rescue => error
55
+ @logger.info "Existing lols could not be retrieved with Error " + error.message
56
+ @logger.info error.backtrace
57
+ return nil
58
+ end
59
+ end
60
+
61
+ def upload(file, sha)
62
+ begin
63
+ RestClient.post(
64
+ configuration[SERVER] + '/uplol',
65
+ :lol => File.new(file),
66
+ :sha => sha)
67
+ rescue => error
68
+ @logger.info "Upload of LOL "+ sha + " failed with Error " + error.message
69
+ return
70
+ end
71
+ end
72
+ end
73
+ end
@@ -16,6 +16,7 @@ module Lolcommits
16
16
  def mm_run
17
17
  font_location = File.join(Configuration::LOLCOMMITS_ROOT, "vendor", "fonts", "Impact.ttf")
18
18
 
19
+ plugdebug "Annotating image via MiniMagick"
19
20
  image = MiniMagick::Image.open(self.runner.main_image)
20
21
  image.combine_options do |c|
21
22
  c.gravity 'SouthWest'
@@ -38,6 +39,7 @@ module Lolcommits
38
39
  c.annotate '0', self.runner.sha
39
40
  end
40
41
 
42
+ plugdebug "Writing changed file to #{self.runner.main_image}"
41
43
  image.write self.runner.main_image
42
44
  end
43
45
 
@@ -10,7 +10,9 @@ module Lolcommits
10
10
  end
11
11
 
12
12
  def run
13
+ plugdebug "Commit message before: #{self.runner.message}"
13
14
  self.runner.message = self.runner.message.tranzlate
15
+ plugdebug "Commit message after: #{self.runner.message}"
14
16
  end
15
17
  end
16
18
  end
@@ -4,7 +4,8 @@ module Lolcommits
4
4
  class Runner
5
5
  attr_accessor :capture_delay, :capture_device, :message, :sha,
6
6
  :snapshot_loc, :main_image, :repo, :config, :repo_internal_path
7
-
7
+
8
+ include Methadone::CLILogging
8
9
  include ActiveSupport::Callbacks
9
10
  define_callbacks :run
10
11
  set_callback :run, :before, :execute_lolcommits_tranzlate
@@ -12,6 +13,7 @@ module Lolcommits
12
13
  # Executed Last
13
14
  set_callback :run, :after, :cleanup!
14
15
  set_callback :run, :after, :execute_lolcommits_uploldz
16
+ set_callback :run, :after, :execute_lolcommits_lolsrv
15
17
  set_callback :run, :after, :execute_lolcommits_lol_twitter
16
18
  set_callback :run, :after, :execute_lolcommits_stats_d
17
19
  set_callback :run, :after, :execute_lolcommits_dot_com
@@ -51,15 +53,18 @@ module Lolcommits
51
53
 
52
54
  protected
53
55
  def die_if_rebasing!
56
+ debug "Runner: Making sure user isn't rebasing"
54
57
  if not self.repo_internal_path.nil?
55
58
  mergeclue = File.join self.repo_internal_path, "rebase-merge"
56
59
  if File.directory? mergeclue
60
+ debug "Runner: Rebase detected, silently exiting!"
57
61
  exit 0
58
62
  end
59
63
  end
60
64
  end
61
65
 
62
66
  def resize_snapshot!
67
+ debug "Runner: resizing snapshot"
63
68
  image = MiniMagick::Image.open(self.snapshot_loc)
64
69
  if (image[:width] > 640 || image[:height] > 480)
65
70
  #this is ghetto resize-to-fill
@@ -68,12 +73,15 @@ module Lolcommits
68
73
  c.gravity 'center'
69
74
  c.extent '640x480'
70
75
  end
76
+ debug "Runner: writing resized image to #{self.snapshot_loc}"
71
77
  image.write self.snapshot_loc
72
78
  end
79
+ debug "Runner: copying resized image to #{self.main_image}"
73
80
  FileUtils.cp(self.snapshot_loc, self.main_image)
74
81
  end
75
82
 
76
83
  def cleanup!
84
+ debug "Runner: running cleanup"
77
85
  #clean up the captured image
78
86
  FileUtils.rm(self.snapshot_loc)
79
87
  end
@@ -1,3 +1,3 @@
1
1
  module Lolcommits
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1pre1"
3
3
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lolcommits
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
5
- prerelease:
4
+ version: 0.4.1pre1
5
+ prerelease: 5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Matthew Rothenberg
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-13 00:00:00.000000000 Z
12
+ date: 2013-01-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mini_magick
@@ -303,6 +303,7 @@ files:
303
303
  - lib/lolcommits/plugin.rb
304
304
  - lib/lolcommits/plugins/dot_com.rb
305
305
  - lib/lolcommits/plugins/lol_twitter.rb
306
+ - lib/lolcommits/plugins/lolsrv.rb
306
307
  - lib/lolcommits/plugins/loltext.rb
307
308
  - lib/lolcommits/plugins/statsd.rb
308
309
  - lib/lolcommits/plugins/tranzlate.rb
@@ -334,16 +335,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
334
335
  version: '0'
335
336
  segments:
336
337
  - 0
337
- hash: 3878014605033370511
338
+ hash: -2108041142645643516
338
339
  required_rubygems_version: !ruby/object:Gem::Requirement
339
340
  none: false
340
341
  requirements:
341
- - - ! '>='
342
+ - - ! '>'
342
343
  - !ruby/object:Gem::Version
343
- version: '0'
344
- segments:
345
- - 0
346
- hash: 3878014605033370511
344
+ version: 1.3.1
347
345
  requirements: []
348
346
  rubyforge_project: lolcommits
349
347
  rubygems_version: 1.8.24