lolcommits 0.17.2 → 0.18.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.
- checksums.yaml +4 -4
- data/.rubocop.yml +309 -9
- data/README.md +14 -26
- data/bin/lolcommits +2 -12
- data/lib/core_ext/mercurial-ruby/changed_file.rb +1 -3
- data/lib/core_ext/mercurial-ruby/command.rb +2 -4
- data/lib/core_ext/mercurial-ruby/config_file.rb +0 -2
- data/lib/core_ext/mercurial-ruby/repository.rb +0 -2
- data/lib/core_ext/mercurial-ruby/shell.rb +1 -3
- data/lib/lolcommits/animated_gif.rb +12 -7
- data/lib/lolcommits/backends/git_info.rb +6 -8
- data/lib/lolcommits/backends/installation_git.rb +8 -10
- data/lib/lolcommits/backends/installation_mercurial.rb +8 -10
- data/lib/lolcommits/backends/mercurial_info.rb +9 -11
- data/lib/lolcommits/capturer/capture_cygwin.rb +0 -2
- data/lib/lolcommits/capturer/capture_fake.rb +2 -4
- data/lib/lolcommits/capturer/capture_linux.rb +4 -6
- data/lib/lolcommits/capturer/capture_linux_video.rb +1 -3
- data/lib/lolcommits/capturer/capture_mac.rb +2 -4
- data/lib/lolcommits/capturer/capture_mac_video.rb +1 -3
- data/lib/lolcommits/capturer/capture_windows.rb +2 -4
- data/lib/lolcommits/capturer/capture_windows_video.rb +5 -7
- data/lib/lolcommits/capturer.rb +9 -12
- data/lib/lolcommits/cli/fatals.rb +11 -16
- data/lib/lolcommits/cli/launcher.rb +1 -3
- data/lib/lolcommits/cli/process_runner.rb +2 -4
- data/lib/lolcommits/cli/timelapse_gif.rb +11 -11
- data/lib/lolcommits/cli.rb +6 -6
- data/lib/lolcommits/configuration.rb +32 -36
- data/lib/lolcommits/gem_plugin.rb +5 -7
- data/lib/lolcommits/installation.rb +5 -7
- data/lib/lolcommits/platform.rb +14 -18
- data/lib/lolcommits/plugin/base.rb +4 -8
- data/lib/lolcommits/plugin/configuration_helper.rb +4 -6
- data/lib/lolcommits/plugin_manager.rb +1 -3
- data/lib/lolcommits/runner.rb +21 -24
- data/lib/lolcommits/test_helpers/fake_io.rb +0 -2
- data/lib/lolcommits/test_helpers/git_repo.rb +3 -5
- data/lib/lolcommits/vcs_info.rb +2 -4
- data/lib/lolcommits/version.rb +1 -3
- data/lib/lolcommits.rb +26 -30
- metadata +42 -83
- data/.gitattributes +0 -1
- data/.github/workflows/build.yml +0 -64
- data/.github/workflows/push_gem.yml +0 -25
- data/.gitignore +0 -15
- data/.rubocop_todo.yml +0 -97
- data/.travis.yml +0 -45
- data/CHANGELOG.md +0 -637
- data/CODE_OF_CONDUCT.md +0 -73
- data/CONTRIBUTING.md +0 -44
- data/Gemfile +0 -4
- data/PULL_REQUEST_TEMPLATE.md +0 -16
- data/Rakefile +0 -53
- data/bin/console +0 -12
- data/features/bugs.feature +0 -52
- data/features/lolcommits.feature +0 -376
- data/features/step_definitions/lolcommits_steps.rb +0 -238
- data/features/support/env.rb +0 -56
- data/features/support/path_helpers.rb +0 -38
- data/lolcommits.gemspec +0 -62
- data/test/assets/test_image.jpg +0 -0
- data/test/assets/test_video.mp4 +0 -0
- data/test/images/test_image.jpg +0 -0
- data/test/permissions_test.rb +0 -19
- data/test/test_helper.rb +0 -4
@@ -1,17 +1,15 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Lolcommits
|
4
2
|
#
|
5
3
|
# Methods to handle enabling and disabling of lolcommits
|
6
4
|
#
|
7
5
|
class InstallationMercurial
|
8
|
-
HOOK_SECTION =
|
9
|
-
HOOK_OPERATIONS = %w
|
6
|
+
HOOK_SECTION = "hooks"
|
7
|
+
HOOK_OPERATIONS = %w[commit record crecord].freeze
|
10
8
|
|
11
9
|
#
|
12
10
|
# IF --ENABLE, DO ENABLE
|
13
11
|
#
|
14
|
-
def self.do_enable(capture_args =
|
12
|
+
def self.do_enable(capture_args = "")
|
15
13
|
if lolcommits_hook_exists?
|
16
14
|
# clear away any existing lolcommits hook
|
17
15
|
remove_existing_hook!
|
@@ -39,9 +37,9 @@ module Lolcommits
|
|
39
37
|
end
|
40
38
|
end
|
41
39
|
|
42
|
-
def self.hook_script(capture_args =
|
43
|
-
ruby_path = Lolcommits::Platform.command_which(
|
44
|
-
imagick_path = Lolcommits::Platform.command_which(
|
40
|
+
def self.hook_script(capture_args = "")
|
41
|
+
ruby_path = Lolcommits::Platform.command_which("ruby", only_path: true)
|
42
|
+
imagick_path = Lolcommits::Platform.command_which("identify", only_path: true)
|
45
43
|
capture_cmd = "if [ \"$LOLCOMMITS_CAPTURE_DISABLED\" != \"true\" ]; then lolcommits --capture #{capture_args}; fi"
|
46
44
|
exports = "LANG=\"#{ENV.fetch('LANG', nil)}\" && PATH=\"$PATH:#{ruby_path}:#{imagick_path}\""
|
47
45
|
|
@@ -53,13 +51,13 @@ module Lolcommits
|
|
53
51
|
end
|
54
52
|
|
55
53
|
def self.repository
|
56
|
-
Mercurial::Repository.open(
|
54
|
+
Mercurial::Repository.open(".")
|
57
55
|
end
|
58
56
|
|
59
57
|
# does a mercurial hook exist with lolcommits commands?
|
60
58
|
def self.lolcommits_hook_exists?
|
61
59
|
config = repository.config
|
62
|
-
config.exists? && config.setting_exists?(HOOK_SECTION,
|
60
|
+
config.exists? && config.setting_exists?(HOOK_SECTION, "post-crecord.lolcommits")
|
63
61
|
end
|
64
62
|
|
65
63
|
# can we load the hgrc?
|
@@ -1,26 +1,24 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Lolcommits
|
4
2
|
class MercurialInfo
|
5
|
-
def self.repo_root?(path =
|
6
|
-
File.directory?(File.join(path,
|
3
|
+
def self.repo_root?(path = ".")
|
4
|
+
File.directory?(File.join(path, ".hg"))
|
7
5
|
end
|
8
6
|
|
9
|
-
def self.local_name(path =
|
7
|
+
def self.local_name(path = ".")
|
10
8
|
File.basename(File.dirname(Mercurial::Repository.open(path).dothg_path))
|
11
9
|
end
|
12
10
|
|
13
11
|
def initialize
|
14
12
|
# mercurial sets HG_RESULT for post- hooks
|
15
|
-
if ENV.key?(
|
16
|
-
debug
|
13
|
+
if ENV.key?("HG_RESULT") && ENV["HG_RESULT"] != "0"
|
14
|
+
debug "Aborting lolcommits hook from failed operation"
|
17
15
|
exit 1
|
18
16
|
end
|
19
17
|
|
20
18
|
Mercurial.configure do |conf|
|
21
|
-
conf.hg_binary_path =
|
19
|
+
conf.hg_binary_path = "hg"
|
22
20
|
end
|
23
|
-
debug
|
21
|
+
debug "parsed the following values from commit:"
|
24
22
|
debug "\t#{message}"
|
25
23
|
debug "\t#{sha}"
|
26
24
|
debug "\t#{repo_internal_path}"
|
@@ -37,7 +35,7 @@ module Lolcommits
|
|
37
35
|
|
38
36
|
def message
|
39
37
|
@message ||= begin
|
40
|
-
message = last_commit.message ||
|
38
|
+
message = last_commit.message || ""
|
41
39
|
message.split("\n").first
|
42
40
|
end
|
43
41
|
end
|
@@ -76,7 +74,7 @@ module Lolcommits
|
|
76
74
|
super("#{self.class}: #{message}")
|
77
75
|
end
|
78
76
|
|
79
|
-
def repository(path =
|
77
|
+
def repository(path = ".")
|
80
78
|
@repository ||= Mercurial::Repository.open(path)
|
81
79
|
end
|
82
80
|
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Lolcommits
|
4
2
|
class CaptureFake < Capturer
|
5
3
|
def capture
|
@@ -9,8 +7,8 @@ module Lolcommits
|
|
9
7
|
private
|
10
8
|
|
11
9
|
def test_file
|
12
|
-
filename = capture_duration.zero? ?
|
13
|
-
File.join(Configuration::LOLCOMMITS_ROOT,
|
10
|
+
filename = capture_duration.zero? ? "test_image.jpg" : "test_video.mp4"
|
11
|
+
File.join(Configuration::LOLCOMMITS_ROOT, "test", "assets", filename)
|
14
12
|
end
|
15
13
|
end
|
16
14
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Lolcommits
|
4
2
|
class CaptureLinux < Capturer
|
5
3
|
MPLAYER_FPS = 25
|
@@ -15,13 +13,13 @@ module Lolcommits
|
|
15
13
|
# multiply the set value (in seconds) by 25
|
16
14
|
frames = delay.to_i * MPLAYER_FPS
|
17
15
|
|
18
|
-
debug
|
16
|
+
debug "calling out to mplayer to capture image"
|
19
17
|
# mplayer's output is ugly and useless, let's throw it away
|
20
18
|
_stdin, stdout, _stderr = Open3.popen3("mplayer -vo jpeg:outdir=#{tmpdir} #{capture_device_string} -frames #{frames} -fps #{MPLAYER_FPS} tv://")
|
21
19
|
# looks like we still need to read the output for something to happen
|
22
20
|
stdout.read
|
23
21
|
|
24
|
-
debug
|
22
|
+
debug "calling out to mplayer to capture image"
|
25
23
|
|
26
24
|
# get last frame from tmpdir (regardless of fps)
|
27
25
|
all_frames = Dir.glob("#{tmpdir}/*.jpg").sort_by do |f|
|
@@ -29,10 +27,10 @@ module Lolcommits
|
|
29
27
|
end
|
30
28
|
|
31
29
|
if all_frames.empty?
|
32
|
-
debug
|
30
|
+
debug "failed to capture any image"
|
33
31
|
else
|
34
32
|
FileUtils.mv(all_frames.last, capture_path)
|
35
|
-
debug
|
33
|
+
debug "cleaning up"
|
36
34
|
end
|
37
35
|
|
38
36
|
FileUtils.rm_rf(tmpdir)
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Lolcommits
|
4
2
|
class CaptureLinuxVideo < Capturer
|
5
3
|
def capture
|
@@ -9,7 +7,7 @@ module Lolcommits
|
|
9
7
|
private
|
10
8
|
|
11
9
|
def capture_device_string
|
12
|
-
capture_device || Dir.glob(
|
10
|
+
capture_device || Dir.glob("/dev/video*").first
|
13
11
|
end
|
14
12
|
end
|
15
13
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Lolcommits
|
4
2
|
class CaptureMac < Capturer
|
5
3
|
def capture
|
@@ -9,11 +7,11 @@ module Lolcommits
|
|
9
7
|
private
|
10
8
|
|
11
9
|
def capture_device_string
|
12
|
-
capture_device.nil? ?
|
10
|
+
capture_device.nil? ? "" : "-d \"#{capture_device}\""
|
13
11
|
end
|
14
12
|
|
15
13
|
def executable_path
|
16
|
-
File.join(Configuration::LOLCOMMITS_ROOT,
|
14
|
+
File.join(Configuration::LOLCOMMITS_ROOT, "vendor", "ext", "imagesnap", "imagesnap")
|
17
15
|
end
|
18
16
|
end
|
19
17
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Lolcommits
|
4
2
|
class CaptureMacVideo < Capturer
|
5
3
|
def capture
|
@@ -17,7 +15,7 @@ module Lolcommits
|
|
17
15
|
end
|
18
16
|
|
19
17
|
def executable_path
|
20
|
-
File.join(Configuration::LOLCOMMITS_ROOT,
|
18
|
+
File.join(Configuration::LOLCOMMITS_ROOT, "vendor", "ext", "videosnap", "videosnap")
|
21
19
|
end
|
22
20
|
end
|
23
21
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Lolcommits
|
4
2
|
class CaptureWindows < Capturer
|
5
3
|
def capture
|
@@ -17,12 +15,12 @@ module Lolcommits
|
|
17
15
|
" /delay #{capture_delay * 1000}"
|
18
16
|
else
|
19
17
|
# DirectShow takes a while to show, default to 3 sec delay
|
20
|
-
|
18
|
+
" /delay 3000"
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
24
22
|
def executable_path
|
25
|
-
File.join(Configuration::LOLCOMMITS_ROOT,
|
23
|
+
File.join(Configuration::LOLCOMMITS_ROOT, "vendor", "ext", "CommandCam", "CommandCam.exe")
|
26
24
|
end
|
27
25
|
end
|
28
26
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Lolcommits
|
4
2
|
class CaptureWindowsVideo < Capturer
|
5
3
|
def capture
|
@@ -15,24 +13,24 @@ module Lolcommits
|
|
15
13
|
end
|
16
14
|
|
17
15
|
def ffpmeg_list_devices_cmd
|
18
|
-
|
16
|
+
"ffmpeg -list_devices true -f dshow -i dummy 2>&1"
|
19
17
|
end
|
20
18
|
|
21
19
|
# inspired by this code from @rdp http://tinyurl.com/y7t276bh
|
22
20
|
def device_names
|
23
21
|
@device_names ||= begin
|
24
22
|
names = []
|
25
|
-
cmd_output =
|
23
|
+
cmd_output = ""
|
26
24
|
count = 0
|
27
|
-
while cmd_output.empty? || !cmd_output.split(
|
25
|
+
while cmd_output.empty? || !cmd_output.split("DirectShow")[2]
|
28
26
|
cmd_output = system_call(ffpmeg_list_devices_cmd, capture_output: true)
|
29
27
|
count += 1
|
30
|
-
raise
|
28
|
+
raise "failed to find a video capture device with ffmpeg -list_devices" if count == 5
|
31
29
|
|
32
30
|
sleep 0.1
|
33
31
|
end
|
34
32
|
cmd_output.gsub!("\r\n", "\n")
|
35
|
-
video = cmd_output.split(
|
33
|
+
video = cmd_output.split("DirectShow")[1]
|
36
34
|
|
37
35
|
video.lines.map do |line|
|
38
36
|
names << Regexp.last_match(1) if line =~ /"(.+)"\n/
|
data/lib/lolcommits/capturer.rb
CHANGED
@@ -1,9 +1,6 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Lolcommits
|
4
2
|
class Capturer
|
5
|
-
attr_accessor :capture_device, :capture_delay, :capture_duration,
|
6
|
-
:capture_path
|
3
|
+
attr_accessor :capture_device, :capture_delay, :capture_duration, :capture_path
|
7
4
|
|
8
5
|
def initialize(attributes = {})
|
9
6
|
attributes.each do |attr, val|
|
@@ -22,11 +19,11 @@ module Lolcommits
|
|
22
19
|
end
|
23
20
|
end
|
24
21
|
|
25
|
-
require
|
26
|
-
require
|
27
|
-
require
|
28
|
-
require
|
29
|
-
require
|
30
|
-
require
|
31
|
-
require
|
32
|
-
require
|
22
|
+
require "lolcommits/capturer/capture_mac"
|
23
|
+
require "lolcommits/capturer/capture_mac_video"
|
24
|
+
require "lolcommits/capturer/capture_linux"
|
25
|
+
require "lolcommits/capturer/capture_linux_video"
|
26
|
+
require "lolcommits/capturer/capture_windows"
|
27
|
+
require "lolcommits/capturer/capture_windows_video"
|
28
|
+
require "lolcommits/capturer/capture_cygwin"
|
29
|
+
require "lolcommits/capturer/capture_fake"
|
@@ -1,7 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'lolcommits/platform'
|
4
|
-
require 'optparse_plus'
|
1
|
+
require "lolcommits/platform"
|
2
|
+
require "optparse_plus"
|
5
3
|
|
6
4
|
module Lolcommits
|
7
5
|
module CLI
|
@@ -16,15 +14,14 @@ module Lolcommits
|
|
16
14
|
def self.die_on_fatal_platform_conditions!
|
17
15
|
# make sure the capture binaries are in a good state
|
18
16
|
if Platform.platform_mac?
|
19
|
-
%w
|
20
|
-
next if File.executable? File.join(Configuration::LOLCOMMITS_ROOT,
|
17
|
+
%w[imagesnap videosnap].each do |executable|
|
18
|
+
next if File.executable? File.join(Configuration::LOLCOMMITS_ROOT, "vendor", "ext", executable, executable)
|
21
19
|
|
22
|
-
fatal "Couldn't properly execute #{executable} for some reason, "
|
23
|
-
'please file a bug?!'
|
20
|
+
fatal "Couldn't properly execute #{executable} for some reason, " + "please file a bug?!"
|
24
21
|
exit 1
|
25
22
|
end
|
26
23
|
elsif Platform.platform_linux?
|
27
|
-
unless Platform.command_which(
|
24
|
+
unless Platform.command_which("mplayer")
|
28
25
|
fatal "Couldn't find mplayer in your PATH!"
|
29
26
|
exit 1
|
30
27
|
end
|
@@ -32,16 +29,14 @@ module Lolcommits
|
|
32
29
|
|
33
30
|
# make sure imagemagick is around and good to go
|
34
31
|
unless Platform.valid_imagemagick_installed?
|
35
|
-
fatal
|
36
|
-
'(or version is too old)'
|
32
|
+
fatal "FATAL: ImageMagick does not appear to be properly installed!(or version is too old)"
|
37
33
|
exit 1
|
38
34
|
end
|
39
35
|
|
40
36
|
# check for a error condition with git config affecting ruby-git
|
41
37
|
return unless Platform.git_config_color_always?
|
42
38
|
|
43
|
-
fatal
|
44
|
-
"cannot be set to 'always'."
|
39
|
+
fatal "Due to a bug in the ruby-git library, git config for color.ui " + "cannot be set to 'always'."
|
45
40
|
fatal "Try setting it to 'auto' instead!"
|
46
41
|
exit 1
|
47
42
|
end
|
@@ -52,15 +47,15 @@ module Lolcommits
|
|
52
47
|
def self.die_if_no_valid_ffmpeg_installed!
|
53
48
|
return if Platform.valid_ffmpeg_installed?
|
54
49
|
|
55
|
-
fatal
|
50
|
+
fatal "FATAL: ffmpeg does not appear to be properly installed!"
|
56
51
|
exit 1
|
57
52
|
end
|
58
53
|
|
59
54
|
# If we are not in a git repo, we can't do git related things!
|
60
55
|
# Die with an informative error message in that case.
|
61
56
|
def self.die_if_not_vcs_repo!
|
62
|
-
debug
|
63
|
-
current = File.expand_path(
|
57
|
+
debug "Checking for valid VCS repo"
|
58
|
+
current = File.expand_path(".")
|
64
59
|
parent = File.dirname(current)
|
65
60
|
while current != parent
|
66
61
|
return if VCSInfo.repo_root?(current)
|
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'fileutils'
|
1
|
+
require "fileutils"
|
4
2
|
|
5
3
|
module Lolcommits
|
6
4
|
module CLI
|
@@ -43,7 +41,7 @@ module Lolcommits
|
|
43
41
|
end
|
44
42
|
|
45
43
|
def pid_file
|
46
|
-
File.join(@configuration.loldir,
|
44
|
+
File.join(@configuration.loldir, "lolcommits.pid")
|
47
45
|
end
|
48
46
|
end
|
49
47
|
end
|
@@ -1,7 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'lolcommits/cli/fatals'
|
4
|
-
require 'mini_magick'
|
1
|
+
require "lolcommits/cli/fatals"
|
2
|
+
require "mini_magick"
|
5
3
|
|
6
4
|
module Lolcommits
|
7
5
|
module CLI
|
@@ -16,7 +14,7 @@ module Lolcommits
|
|
16
14
|
# param args [String] the arg passed to the gif command on CLI (optional)
|
17
15
|
def run(args = nil)
|
18
16
|
case args
|
19
|
-
when
|
17
|
+
when "today"
|
20
18
|
lolimages = jpg_images_today
|
21
19
|
filename = Date.today.to_s
|
22
20
|
else
|
@@ -25,20 +23,22 @@ module Lolcommits
|
|
25
23
|
end
|
26
24
|
|
27
25
|
if lolimages.empty?
|
28
|
-
warn
|
26
|
+
warn "No lolcommits have been captured for this time yet."
|
29
27
|
exit 1
|
30
28
|
end
|
31
29
|
|
32
|
-
puts
|
30
|
+
puts "*** Generating animated timelapse gif."
|
31
|
+
|
32
|
+
gif_path = File.join(timelapses_dir_path, "#{filename}.gif")
|
33
33
|
|
34
34
|
MiniMagick.convert do |convert|
|
35
35
|
convert.delay 50
|
36
36
|
convert.loop 0
|
37
37
|
lolimages.each { |image| convert << image }
|
38
|
-
convert <<
|
38
|
+
convert << gif_path
|
39
39
|
end
|
40
40
|
|
41
|
-
puts "*** Done, generated at #{
|
41
|
+
puts "*** Done, generated at #{gif_path}"
|
42
42
|
end
|
43
43
|
|
44
44
|
private
|
@@ -46,7 +46,7 @@ module Lolcommits
|
|
46
46
|
attr_accessor :loldir
|
47
47
|
|
48
48
|
def jpg_images
|
49
|
-
Dir.glob(File.join(loldir,
|
49
|
+
Dir.glob(File.join(loldir, "*.jpg")).sort_by { |f| File.mtime(f) }
|
50
50
|
end
|
51
51
|
|
52
52
|
def jpg_images_today
|
@@ -54,7 +54,7 @@ module Lolcommits
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def timelapses_dir_path
|
57
|
-
dir = File.join(loldir,
|
57
|
+
dir = File.join(loldir, "timelapses")
|
58
58
|
FileUtils.mkdir_p(dir)
|
59
59
|
dir
|
60
60
|
end
|
data/lib/lolcommits/cli.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
1
|
+
require "optparse"
|
2
|
+
require "optparse_plus"
|
3
|
+
require "lolcommits/cli/fatals"
|
4
|
+
require "lolcommits/cli/launcher"
|
5
|
+
require "lolcommits/cli/process_runner"
|
6
|
+
require "lolcommits/cli/timelapse_gif"
|
@@ -1,24 +1,41 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Lolcommits
|
4
2
|
class Configuration
|
5
|
-
LOLCOMMITS_BASE = ENV[
|
6
|
-
LOLCOMMITS_ROOT = File.join(File.dirname(__FILE__),
|
3
|
+
LOLCOMMITS_BASE = ENV["LOLCOMMITS_DIR"] || File.join(Dir.home, ".lolcommits")
|
4
|
+
LOLCOMMITS_ROOT = File.join(File.dirname(__FILE__), "../..")
|
7
5
|
|
8
6
|
attr_accessor :plugin_manager
|
9
7
|
attr_writer :loldir
|
10
8
|
|
9
|
+
def self.loldir_for(basename)
|
10
|
+
loldir = File.join(LOLCOMMITS_BASE, basename)
|
11
|
+
|
12
|
+
if File.directory? loldir
|
13
|
+
begin
|
14
|
+
# ensure 755 permissions for loldir
|
15
|
+
File.chmod(0o755, loldir)
|
16
|
+
rescue Errno::EPERM
|
17
|
+
# abort if permissions cannot be met
|
18
|
+
puts "FATAL: directory '#{loldir}' should be present and writeable by user '#{ENV.fetch('USER', nil)}'"
|
19
|
+
puts "Try changing the directory permissions to 755"
|
20
|
+
exit 1
|
21
|
+
end
|
22
|
+
else
|
23
|
+
FileUtils.mkdir_p loldir
|
24
|
+
end
|
25
|
+
loldir
|
26
|
+
end
|
27
|
+
|
11
28
|
def initialize(plugin_manager, test_mode: false)
|
12
29
|
@plugin_manager = plugin_manager
|
13
|
-
@loldir = Configuration.loldir_for(
|
30
|
+
@loldir = Configuration.loldir_for("test") if test_mode
|
14
31
|
end
|
15
32
|
|
16
33
|
def yaml
|
17
34
|
@yaml ||= if File.exist?(configuration_file)
|
18
|
-
YAML.safe_load(File.open(configuration_file), permitted_classes: [Symbol]) || Hash.new({})
|
19
|
-
|
35
|
+
YAML.safe_load(File.open(configuration_file), permitted_classes: [ Symbol ]) || Hash.new({})
|
36
|
+
else
|
20
37
|
Hash.new({})
|
21
|
-
|
38
|
+
end
|
22
39
|
end
|
23
40
|
|
24
41
|
def configuration_file
|
@@ -30,11 +47,11 @@ module Lolcommits
|
|
30
47
|
|
31
48
|
basename ||= if VCSInfo.repo_root?
|
32
49
|
VCSInfo.local_name
|
33
|
-
|
50
|
+
else
|
34
51
|
File.basename(Dir.getwd)
|
35
|
-
|
36
|
-
basename.sub!(/^\./,
|
37
|
-
basename.sub!(/ /,
|
52
|
+
end
|
53
|
+
basename.sub!(/^\./, "dot")
|
54
|
+
basename.sub!(/ /, "-")
|
38
55
|
@loldir = Configuration.loldir_for(basename)
|
39
56
|
end
|
40
57
|
|
@@ -42,7 +59,7 @@ module Lolcommits
|
|
42
59
|
File.join loldir, "#{sha}.#{ext}"
|
43
60
|
end
|
44
61
|
|
45
|
-
def capture_path(ext =
|
62
|
+
def capture_path(ext = "jpg")
|
46
63
|
File.join loldir, "raw_capture.#{ext}"
|
47
64
|
end
|
48
65
|
|
@@ -68,7 +85,7 @@ module Lolcommits
|
|
68
85
|
|
69
86
|
def ask_for_plugin_name
|
70
87
|
list_plugins
|
71
|
-
print
|
88
|
+
print "Name of plugin to configure: "
|
72
89
|
gets.strip
|
73
90
|
end
|
74
91
|
|
@@ -94,7 +111,7 @@ module Lolcommits
|
|
94
111
|
ensure
|
95
112
|
if plugin
|
96
113
|
# clean away legacy enabled key, later we can remove this
|
97
|
-
plugin_config.delete(
|
114
|
+
plugin_config.delete("enabled")
|
98
115
|
# save plugin config (if we have anything in the hash)
|
99
116
|
save(plugin.name, plugin_config) unless plugin_config.empty?
|
100
117
|
|
@@ -114,26 +131,5 @@ module Lolcommits
|
|
114
131
|
def to_s
|
115
132
|
yaml.to_yaml.to_s
|
116
133
|
end
|
117
|
-
|
118
|
-
# class methods
|
119
|
-
|
120
|
-
def self.loldir_for(basename)
|
121
|
-
loldir = File.join(LOLCOMMITS_BASE, basename)
|
122
|
-
|
123
|
-
if File.directory? loldir
|
124
|
-
begin
|
125
|
-
# ensure 755 permissions for loldir
|
126
|
-
File.chmod(0o755, loldir)
|
127
|
-
rescue Errno::EPERM
|
128
|
-
# abort if permissions cannot be met
|
129
|
-
puts "FATAL: directory '#{loldir}' should be present and writeable by user '#{ENV.fetch('USER', nil)}'"
|
130
|
-
puts 'Try changing the directory permissions to 755'
|
131
|
-
exit 1
|
132
|
-
end
|
133
|
-
else
|
134
|
-
FileUtils.mkdir_p loldir
|
135
|
-
end
|
136
|
-
loldir
|
137
|
-
end
|
138
134
|
end
|
139
135
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Lolcommits
|
4
2
|
class GemPlugin
|
5
3
|
attr_accessor :gem_spec, :required
|
@@ -51,22 +49,22 @@ module Lolcommits
|
|
51
49
|
end
|
52
50
|
|
53
51
|
def name
|
54
|
-
gem_name.split(
|
52
|
+
gem_name.split("-", 2).last
|
55
53
|
end
|
56
54
|
|
57
55
|
private
|
58
56
|
|
59
57
|
def gem_path
|
60
|
-
gem_name.tr(
|
58
|
+
gem_name.tr("-", "/")
|
61
59
|
end
|
62
60
|
|
63
61
|
def plugin_klass_name
|
64
62
|
# convert gem paths to plugin classes e.g.
|
65
63
|
# lolcommits/loltext --> Lolcommits::Plugin::Loltext
|
66
64
|
# lolcommits/term_output --> Lolcommits::Plugin::TermOutput
|
67
|
-
gem_path.split(
|
68
|
-
c.split(
|
69
|
-
end.join(
|
65
|
+
gem_path.split("/").insert(1, "plugin").collect do |c|
|
66
|
+
c.split("_").collect(&:capitalize).join
|
67
|
+
end.join("::")
|
70
68
|
end
|
71
69
|
end
|
72
70
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Lolcommits
|
4
2
|
#
|
5
3
|
# Methods to handle enabling and disabling of lolcommits
|
@@ -23,9 +21,9 @@ module Lolcommits
|
|
23
21
|
capture_args = extract_capture_args(options)
|
24
22
|
path = backend.do_enable(capture_args)
|
25
23
|
|
26
|
-
info
|
24
|
+
info "installed lolcommit hook to:"
|
27
25
|
info " -> #{File.expand_path(path)}"
|
28
|
-
info
|
26
|
+
info "(to remove later, you can use: lolcommits --disable)"
|
29
27
|
# we dont symlink, but rather install a small stub that calls the one from path
|
30
28
|
# that way, as gem version changes, script updates even if new file thus breaking symlink
|
31
29
|
end
|
@@ -43,14 +41,14 @@ module Lolcommits
|
|
43
41
|
# @return [String]
|
44
42
|
def self.extract_capture_args(options)
|
45
43
|
options.map do |k, v|
|
46
|
-
next unless %w
|
44
|
+
next unless %w[device animate delay stealth fork].include?(k)
|
47
45
|
|
48
|
-
if k ==
|
46
|
+
if k == "device"
|
49
47
|
"--device '#{v}'"
|
50
48
|
else
|
51
49
|
"--#{k}#{v == true ? '' : " #{v}"}"
|
52
50
|
end
|
53
|
-
end.compact.join(
|
51
|
+
end.compact.join(" ")
|
54
52
|
end
|
55
53
|
end
|
56
54
|
end
|