pristine 0.0.1 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2889f95571ad2f6239fa667f0ed081b50acec970
4
- data.tar.gz: 2a76345d192a025c5e21e5267c3dfb8c0c47602c
3
+ metadata.gz: 0eb20ebacf82b1dd7daf7bd2c0e50ab11aa03981
4
+ data.tar.gz: 119cbe33b15d18bb6c0b33688ea11f30a58d4900
5
5
  SHA512:
6
- metadata.gz: 6b90553687cb391ab642fca0e01ae2b8af1bb72f0f05249959120f25f448c95fbda8912571fd4de61c6243819d0ad49e507aae555b9179acfaa7628a76c08b1d
7
- data.tar.gz: b1b934659dd6f7776392f7bf3dc1dc90e1cf6e64bcd7451ad343bdc16c71f91282e5e78040d20dbe62e3581fd06f246d7b8516db1102f6018b53c3bb8b58b293
6
+ metadata.gz: 82c10c9cc9844f159342c4f4900f70c5c699e3bfeb90618d3816d9c2d7759fbab2e600b7374abd97a5b57995e296b0cd92fb396414636dc8b0f05ea3dc5093ee
7
+ data.tar.gz: f9576653c5505a01924903d6dbac8ac048ce0a6b7a7e2b4aadbb5b38186f339e6b754de4dbf6a5db3e9abacb7513aee5b1a980ca962b68087badef87b1480440
data/README.md CHANGED
@@ -2,9 +2,25 @@
2
2
 
3
3
  Watches if any file managed by Puppet was modified.
4
4
 
5
+ # Usage
6
+
7
+ ```
8
+ $ ./bin/pristine -h
9
+ Usage: pristine [options]
10
+ --config FILE Config file
11
+ -l, --log FILE Log output
12
+ -f, --files Files list to watch
13
+ -h, --help Show this message
14
+ --version Show version
5
15
  ```
16
+
17
+ # Example
18
+
19
+
20
+ ```
21
+ $ git clone https://github.com/carlasouza/pristine.git; cd pristine
6
22
  $ ./example/create_example_files.sh
7
- $ ./bin/pristine example.config
23
+ $ ./bin/pristine -c config.yaml
8
24
  W, [2016-04-17T19:18:34.376080 #29074] WARN -- : /foo/bar does not exist.
9
25
  I, [2016-04-17T19:18:34.376153 #29074] INFO -- : /tmp/pristine/example/ watcher created.
10
26
  I, [2016-04-17T19:18:34.376190 #29074] INFO -- : /tmp/pristine/example/a watcher created.
@@ -22,6 +38,8 @@ I, [2016-04-17T19:19:28.959390 #29074] INFO -- : /tmp/pristine/example/a/c - [:
22
38
 
23
39
  # TODO
24
40
 
41
+ * Arguments sanity check
42
+
25
43
  * Check if `puppet` is installed
26
44
 
27
45
  * Filter out concats from resources file
@@ -30,10 +48,10 @@ I, [2016-04-17T19:19:28.959390 #29074] INFO -- : /tmp/pristine/example/a/c - [:
30
48
 
31
49
  If directory, monitor recursevly
32
50
 
33
-
34
51
  * Add `:access` to files that contain passwords
35
52
 
36
- * Add a watcher to the `file_list` file
53
+ * Add a watcher to the `file_list` file and then reload itself upon modification
54
+
37
55
 
38
56
 
39
57
  # Copyright
@@ -7,8 +7,5 @@ end
7
7
  require 'pristine/config'
8
8
  require 'pristine/daemon'
9
9
 
10
- config_file = ARGV.first
11
- abort('No configuration file specified') if config_file.nil?
12
-
13
- Pristine::Config.load config_file
10
+ Pristine::Config.load ARGV
14
11
  Pristine::Daemon.run
@@ -0,0 +1,10 @@
1
+ require 'optparse'
2
+
3
+ module Pristine
4
+ class CLI
5
+ def self.read(args = ARGV)
6
+
7
+ end
8
+ end
9
+ end
10
+
@@ -1,25 +1,66 @@
1
- require 'parseconfig'
1
+ require 'yaml'
2
+ require 'optparse'
3
+ require 'ostruct'
4
+ require 'pristine/version'
2
5
 
3
6
  module Pristine
4
7
  class Config
5
8
 
9
+ DEFAULT_LOG = STDOUT
10
+ DEFAULT_FLAGS = :modify #Lets watch IN_MODIFY events for now
6
11
  DEFAULT_FILES_LIST = '/var/lib/puppet/state/resources.txt'
7
12
 
8
- def self.load(config_file)
9
- @config ||= ParseConfig.new(config_file)
13
+ def self.load(args)
14
+ @config = OpenStruct.new
15
+
16
+ parser = OptionParser.new do |opts|
17
+ opts.on_head('--config FILE', 'Config file') do |path|
18
+ @config[:config_file] = path
19
+ @config = OpenStruct.new(Hash[YAML::load(open(path)).map { |k, v| [k.to_sym, v] }])
20
+ end
21
+
22
+ # TODO
23
+ # opts.on('-F', '--foreground', 'Run on foreground') do |v|
24
+ # @config[:foreground] = v
25
+ # end
26
+
27
+ opts.on('-l', '--log FILE', 'Log output') do |v|
28
+ @config[:log] = v
29
+ end
30
+
31
+ # TODO
32
+ # opts.on('-f', '--flags x,y,z', Array, 'Systemcalls to watch') do |v|
33
+ # @config[:config_file] = v
34
+ # end
35
+
36
+ opts.on('-f', '--files FILE', 'Files list to watch') do |v|
37
+ @config[:files_list] = v
38
+ end
39
+
40
+ opts.on_tail("-h", "--help", "Show this message") do
41
+ puts opts
42
+ exit
43
+ end
44
+
45
+ opts.on_tail("--version", "Show version") do
46
+ puts Pristine::VERSION
47
+ exit
48
+ end
49
+ end
50
+ parser.parse(args)
51
+ parser.load(config.config_file) unless config.config_file.nil?
52
+
53
+ set_defaults
10
54
  end
11
55
 
12
56
  def self.config
13
57
  @config
14
58
  end
15
59
 
16
- def self.flags
17
- :modify #Lets watch IN_MODIFY events for now
18
- end
19
-
60
+ # Specific for Puppet's resource.txt file
20
61
  def self.files_list
21
62
  list = []
22
- File.open(config.params['files_list'] || DEFAULT_FILES_LIST, 'r') do |f|
63
+ File.open(@config.files_list, 'r') do |f|
23
64
  f.each_line do |line|
24
65
  if line.match(/^file/)
25
66
  list << line.split('[')[1].split(']').first
@@ -33,6 +74,12 @@ module Pristine
33
74
  @config.send method
34
75
  end
35
76
 
77
+ private
78
+ def self.set_defaults
79
+ @config.log ||= DEFAULT_LOG
80
+ @config.flags ||= DEFAULT_FLAGS
81
+ @config.files_list ||= DEFAULT_FILES_LIST
82
+ end
36
83
 
37
84
  end
38
85
  end
@@ -26,8 +26,10 @@ module Pristine
26
26
 
27
27
  def self.run
28
28
  set_target_files(Config.files_list)
29
-
30
29
  notifier.run
30
+ rescue Interrupt
31
+ notifier.stop
32
+ Log.info 'Stopped all watchers. Exiting.'
31
33
  end
32
34
 
33
35
  end
@@ -15,7 +15,7 @@ module Pristine
15
15
  private
16
16
 
17
17
  def self.log
18
- @@log ||= Logger.new(Pristine::Config.params['log'] || STDOUT, 'weekly')
18
+ @@log ||= Logger.new(Pristine::Config.log, 'weekly')
19
19
  @@log
20
20
  end
21
21
 
@@ -1,3 +1,3 @@
1
1
  module Pristine
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pristine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carla Souza
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-18 00:00:00.000000000 Z
11
+ date: 2016-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rb-inotify
@@ -24,26 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.9.7
27
- - !ruby/object:Gem::Dependency
28
- name: parseconfig
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1.0'
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: 1.0.8
37
- type: :runtime
38
- prerelease: false
39
- version_requirements: !ruby/object:Gem::Requirement
40
- requirements:
41
- - - "~>"
42
- - !ruby/object:Gem::Version
43
- version: '1.0'
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: 1.0.8
47
27
  description: Watches if any file managed by Puppet was modified.
48
28
  email:
49
29
  - contact@carlasouza.com
@@ -56,6 +36,7 @@ files:
56
36
  - README.md
57
37
  - bin/pristine
58
38
  - lib/pristine.rb
39
+ - lib/pristine/cli.rb
59
40
  - lib/pristine/collector.rb
60
41
  - lib/pristine/config.rb
61
42
  - lib/pristine/daemon.rb