Class: Lolcommits::Lolsrv
- Inherits:
-
Plugin
- Object
- Plugin
- Lolcommits::Lolsrv
show all
- Defined in:
- lib/lolcommits/plugins/lolsrv.rb
Instance Attribute Summary
Attributes inherited from Plugin
#options, #runner
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Plugin
#configuration, #configure_options!, #debug, #execute, #is_enabled?, #puts, #valid_configuration?
Constructor Details
#initialize(runner) ⇒ Lolsrv
Returns a new instance of Lolsrv.
9
10
11
12
13
14
15
|
# File 'lib/lolcommits/plugins/lolsrv.rb', line 9
def initialize(runner)
super
self.options << 'server'
if self.runner
@logger = Logger.new(File.new(self.runner.config.loldir + "/lolsrv.log", "a+"))
end
end
|
Class Method Details
.name ⇒ Object
68
69
70
|
# File 'lib/lolcommits/plugins/lolsrv.rb', line 68
def self.name
"lolsrv"
end
|
Instance Method Details
#get_existing_lols ⇒ Object
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/lolcommits/plugins/lolsrv.rb', line 38
def get_existing_lols
begin
lols = JSON.parse(
RestClient.get(configuration['server'] + "/lols"))
lols.map { |lol| lol["sha"] }
rescue => e
log_error(e, "ERROR: existing lols could not be retrieved #{e.class} - #{e.message}")
return nil
end
end
|
22
23
24
|
# File 'lib/lolcommits/plugins/lolsrv.rb', line 22
def is_configured?
!configuration["enabled"].nil? && configuration["server"]
end
|
#log_error(e, message) ⇒ Object
62
63
64
65
66
|
# File 'lib/lolcommits/plugins/lolsrv.rb', line 62
def log_error(e, message)
debug message
@logger.info message
@logger.info e.backtrace
end
|
#run ⇒ Object
17
18
19
20
|
# File 'lib/lolcommits/plugins/lolsrv.rb', line 17
def run
return unless valid_configuration?
fork { sync() }
end
|
#sync ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/lolcommits/plugins/lolsrv.rb', line 26
def sync
existing = get_existing_lols
unless existing.nil?
Dir[self.runner.config.loldir + "/*.{jpg,gif}"].each do |item|
sha = File.basename(item, ".*")
unless existing.include?(sha) || sha == "tmp_snapshot"
upload(item, sha)
end
end
end
end
|
#upload(file, sha) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/lolcommits/plugins/lolsrv.rb', line 49
def upload(file, sha)
begin
RestClient.post(
configuration["server"] + "/uplol",
:lol => File.new(file),
:sha => sha
)
rescue => e
log_error(e,"ERROR: Upload of lol #{sha} FAILED #{e.class} - #{e.message}")
return
end
end
|