Class: Lolcommits::Lolsrv
- Inherits:
-
Plugin
- Object
- Plugin
- Lolcommits::Lolsrv
show all
- Defined in:
- lib/lolcommits/plugins/lolsrv.rb
Constant Summary
collapse
- SERVER =
'server'
Instance Attribute Summary
Attributes inherited from Plugin
#default, #name, #options, #runner
Instance Method Summary
collapse
Methods inherited from Plugin
#configuration, #execute, #is_enabled?, #plugdebug
Constructor Details
#initialize(runner) ⇒ Lolsrv
Returns a new instance of Lolsrv.
12
13
14
15
16
17
18
|
# File 'lib/lolcommits/plugins/lolsrv.rb', line 12
def initialize(runner)
super
self.name = 'lolsrv'
self.default = false
self.options << SERVER
end
|
Instance Method Details
#get_existing_lols ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/lolcommits/plugins/lolsrv.rb', line 49
def get_existing_lols
begin
lols = JSON.parse(
RestClient.get(configuration[SERVER] + '/commits'))
lols["commits"].map { |lol| lol["sha"] }
rescue => error
@logger.info "Existing commits could not be retrieved with Error " + error.message
@logger.info error.backtrace
return nil
end
end
|
#run ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/lolcommits/plugins/lolsrv.rb', line 20
def run
log_file = File.new(self.runner.config.loldir + "/lolsrv.log", "a+")
@logger = Logger.new(log_file)
if configuration[SERVER].nil?
puts "Missing server configuration. Use lolcommits --config -p lolsrv"
return
end
fork do
sync()
end
end
|
#sync ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/lolcommits/plugins/lolsrv.rb', line 35
def sync
existing = get_existing_lols
unless existing.nil? || existing == []
Dir.glob(self.runner.config.loldir + "/*.jpg") do |item|
next if item == '.' or item == '..'
sha = File.basename(item, '.*')
unless existing.include?(sha) || sha == 'tmp_snapshot'
upload(item, sha)
end
end
end
end
|
#upload(file, sha) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/lolcommits/plugins/lolsrv.rb', line 61
def upload(file, sha)
begin
RestClient.post(
configuration[SERVER] + '/upload',
:lol => File.new(file),
:sha => sha)
rescue => error
@logger.info "Upload of LOL "+ sha + " failed with Error " + error.message
return
end
end
|