aptly-watcher 0.3.1 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4aad45eba38cd86eeed010e57bf5badec8173f82
4
- data.tar.gz: f9a3764bd2d38f9e0b3c7ea10329a1f152add3d6
3
+ metadata.gz: 559666bf483b86bfe158a4a8b658efe788bc1668
4
+ data.tar.gz: a3260100fbe61e3b5c6b4613cc4940aa96a20c60
5
5
  SHA512:
6
- metadata.gz: 11f8130fd522beb170524ced1a20100f1a05fd3f20d51bca24494ac8d3d14378f6fad608b55f6aec9c5896d98b18e7ba646f922df09ae3ab9b6339a44e618a55
7
- data.tar.gz: f7e3b07cdd5921dfba0dc6aa285370b7e20e8e8417d8549b626af89506edce75c5035633f494008f364b2f3313a15f72085f4665998666ed97636f67fa962df7
6
+ metadata.gz: f01dc300b5ebd7cd0c3b3b912497d1e58d6e96332a8a2d0919f2cf655f014ce590a5f38089413383f4814b705b030f7d53db873b4bb91a3a72f0690cf8a08e9f
7
+ data.tar.gz: 4447ce3cbe77c308f6807ccbd9a9ea45422111ff8d86a4e2a19cbd1e919f7ac186ee0d9179c7d884a9a1aa6d8cce602fe318267f8c350ff9a31ff0f209d19f3d
data/README.md CHANGED
@@ -26,15 +26,17 @@ First you need to create a config file as such (we parse tildes to `ENV['HOME']`
26
26
 
27
27
  ```yaml
28
28
  ---
29
- :distrib: myapp
30
- :repos:
29
+ :distrib: myapp # the distribution (or the name of your app)
30
+ :repos: # the repos to create and publish
31
31
  - stable
32
32
  - testing
33
- :log: ~/watcher.log # use '-' for STDOUT
34
- :conf: ~/aptly.conf
35
- :pidfile: ~/aptly-watcher.pid
36
- :incoming_dir: ~/incoming
37
- :user: aptly
33
+ :log: ~/watcher.log # use '-' for STDOUT, false to disable
34
+ :redis_log: aptly:watcher:log # the redis list to log into, set as false to disable
35
+ :conf: ~/aptly.conf # the location of the aptly conf file
36
+ :pidfile: ~/aptly-watcher.pid # the location of the aptly-watcher pidfile
37
+ :incoming_dir: ~/incoming # the base incoming directory
38
+ :user: aptly # the user to own the aptly directory after adding/publishing
39
+ :group: aptly # the group to own the aptly directory after adding/publishing
38
40
  ```
39
41
 
40
42
  Then you can run the watcher with the config file:
@@ -11,12 +11,22 @@ module Aptly
11
11
  class << self
12
12
 
13
13
  def redis
14
+ return nil if @config[:redis_log] == false
14
15
  @redis ||= Redis.new
15
16
  end
16
17
 
17
18
  def logger
18
19
  return @logger if @logger
19
- target = (@config[:log] == '-') ? STDOUT : @config[:log]
20
+
21
+ target = case @config[:log]
22
+ when '-'
23
+ STDOUT
24
+ when false
25
+ '/dev/null'
26
+ else
27
+ @config[:log]
28
+ end
29
+
20
30
  @logger ||= Logger.new target, 0, 1024000
21
31
  end
22
32
 
@@ -31,13 +41,21 @@ module Aptly
31
41
  end
32
42
  end
33
43
 
34
- # log into redis so we can pick it up in the DMS
35
44
  def log(level, message)
45
+ message.chomp.lines.each_with_index do |line, index| # multi line logging
46
+ line.chomp!
47
+ line = " #{line}" unless index.zero?
48
+ redis_log(level, line) if @config[:redis_log] != false
49
+ logger.send(level.to_sym, line) if @config[:log] != false
50
+ end
51
+ end
52
+
53
+ def redis_log(level, message)
54
+ return false if redis.nil?
36
55
  timestamp = Time.now.strftime('%Y-%m-%d %H:%M:%S')
37
56
  msg = "#{level[0].upcase}, [#{timestamp}] #{level.upcase} -- #{message}"
38
- redis.lpush("aptly:watcher:log", msg)
39
- redis.ltrim("aptly:watcher:log", 0, 99)
40
- logger.send(level.to_sym, message)
57
+ redis.lpush(@config[:redis_log], msg)
58
+ redis.ltrim(@config[:redis_log], 0, 99)
41
59
  end
42
60
 
43
61
  # run the watcher with the given config
@@ -54,8 +72,8 @@ module Aptly
54
72
  notifier.watch(repo_dir, :close_write) do |event|
55
73
  begin
56
74
  dispatcher.process(repo_dir, event, repo)
57
- log :info, "Successfully added #{event.name} to #{repo}"
58
- system "chown #{config[:user]}:#{config[:user]} #{config[:aptly]['rootDir']} -R"
75
+ log :info, "Successfully added #{event.name} to #{config[:distrib]}/#{repo}"
76
+ system "chown #{config[:user]}:#{config[:group]} #{config[:aptly]['rootDir']} -R"
59
77
  rescue StandardError => e
60
78
  e.message.lines.each {|line| log :error, line.chomp }
61
79
  end
@@ -10,19 +10,21 @@ module Aptly
10
10
  end
11
11
 
12
12
  def create
13
- repo_list = `aptly repo list --raw`
13
+ repo_list = `aptly repo list #{config} --raw`
14
14
 
15
15
  # create a repo for each component
16
16
  @components.each do |repo|
17
17
  next if repo_list.include? repo # avoid raising an error
18
18
  output = `aptly repo create #{distrib} #{config} #{component(repo)} #{repo} 2>&1`
19
19
  raise StandardError, "Failed to create repo #{repo}\n#{output}" unless $?.success?
20
+ Aptly::Watcher.log :info, "Created repo #{@name}/#{repo}"
20
21
  end
21
22
 
22
23
  # publish the repos for the first time (empty)
23
- unless `aptly publish list --raw`.include? @name # avoid raising an error
24
+ unless `aptly publish list #{config} --raw`.include? @name # avoid raising an error
24
25
  output = `aptly publish repo #{config} #{distrib} #{component(:all)} #{@components.join(' ')} 2>&1`
25
26
  raise StandardError, "Failed to publish #{@name} for the first time\n#{output}" unless $?.success?
27
+ Aptly::Watcher.log :info, "Published repos #{@components.join('/')} for #{@name}"
26
28
  end
27
29
  end
28
30
 
@@ -1,5 +1,5 @@
1
1
  module Aptly
2
2
  module Watcher
3
- VERSION = "0.3.1"
3
+ VERSION = "0.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aptly-watcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: '0.4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert McLeod