puppet-ghostbuster 0.0.5 → 0.0.6

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: e640683fdc2081827655309a5b74b8789f64fc0b
4
- data.tar.gz: 35dc19ede6aead0efa888b524bf8cfa7e82f33a2
3
+ metadata.gz: 48db269b56e5bd75a9c1aa3349c578bf244957b3
4
+ data.tar.gz: caf14c62cef78d4f307302b5afc38d012f39824d
5
5
  SHA512:
6
- metadata.gz: f371c80c10c50346e92f7f26a4d6c34aa986fb43a261475c873d9c05bfa028e107188cb642935270850a6a2253ae78c82d383afb583649b9fc2a96f09e4fe362
7
- data.tar.gz: 5183186cf01b3c9bb5be41f3321113cd9b8df23d21139ac9295a11de7f8a245252616758cf56455af633b28777a1a3f39c13a773351ad0b68a20fca6f4c29c1a
6
+ metadata.gz: 0084173d38ed6fb21824f3ec750a70c9fe290a2f8a9c4d53bb45cbd9dbef64574d453f8dec6ef34ff9c85b900f04465dfed5cab9023b6771b507c8028d4d1ffe
7
+ data.tar.gz: ea9d82fd853ef6c0e20360729e700b3bf04d92dbdf4885217b5db56d9bb439f66c4b4ecc38dd255b87ecc0b649984df55e59b8ceae1b6f257c50887c1c016de9
@@ -1,3 +1,3 @@
1
1
  class PuppetGhostbuster
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
@@ -49,34 +49,69 @@ class PuppetGhostbuster
49
49
  )
50
50
  end
51
51
 
52
- def initialize
53
- Puppet.initialize_settings
52
+ def find_unused_classes
54
53
  Dir["./**/manifests/**/*.pp"].each do |file|
55
54
  if c = File.readlines(file).grep(/^class\s+([^\s\(\{]+)/){$1}[0]
56
55
  class_name = c.split('::').map(&:capitalize).join('::')
57
56
  count = self.class.used_classes.select { |klass| klass == class_name }.size
58
- puts "#{count} Class[#{class_name}]"
59
- elsif d = File.readlines(file).grep(/^define\s+([^\s\(\{]+)/){$1}[0]
57
+ puts "Class #{class_name} not used" if count == 0
58
+ end
59
+ end
60
+ end
61
+
62
+ def find_unused_defines
63
+ Dir["./**/manifests/**/*.pp"].each do |file|
64
+ if d = File.readlines(file).grep(/^define\s+([^\s\(\{]+)/){$1}[0]
60
65
  define_name = d.split('::').map(&:capitalize).join('::')
61
66
  count = self.class.client.request('resources', [:'=', 'type', define_name]).data.size
62
- puts "#{count} #{define_name}"
67
+ puts "Define #{define_name} not used" if count == 0
63
68
  end
64
69
  end
70
+ end
71
+
72
+ def find_unused_templates
65
73
  Dir['./**/templates/*'].each do |template|
66
74
  next unless File.file?(template)
67
75
  module_name, template_name = template.match(/.*\/([^\/]+)\/templates\/(.+)$/).captures
68
- found = false
76
+ count = 0
69
77
  Dir["./**/manifests/**/*.pp"].each do |manifest|
70
78
  if match = manifest.match(/.*\/([^\/]+)\/manifests\/.+$/)
71
79
  manifest_module_name = match.captures[0]
72
- found = File.readlines(manifest).grep(/["']\$\{module_name\}\/#{template_name}["']/).size > 0 if manifest_module_name == module_name
73
- break if found
80
+ count += File.readlines(manifest).grep(/["']\$\{module_name\}\/#{template_name}["']/).size if manifest_module_name == module_name
74
81
  end
75
- found = File.readlines(manifest).grep(/["']#{module_name}\/#{template_name}["']/).size > 0
76
- break if found
82
+ count += File.readlines(manifest).grep(/["']#{module_name}\/#{template_name}["']/).size
77
83
  end
78
- puts "#{template} not used" unless found
84
+ puts "Template #{template} not used" if count == 0
79
85
  end
80
86
  end
81
87
 
88
+ def find_unused_files
89
+ Dir['./**/files/*'].each do |file|
90
+ next unless File.file?(file)
91
+ module_name, file_name = file.match(/.*\/([^\/]+)\/files\/(.+)$/).captures
92
+ count = 0
93
+ Dir["."].each do |caller_file|
94
+ next unless File.file?(caller_file)
95
+ if caller_file =~ /\.pp$/
96
+ if match = manifest.match(/.*\/([^\/]+)\/manifests\/.+$/)
97
+ manifest_module_name = match.captures[0]
98
+ if manifest_module_name == module_name
99
+ count += File.readlines(caller_file).grep(/["']\$\{module_name\}\/#{file_name}["']/).size
100
+ end
101
+ end
102
+ end
103
+ count += File.readlines(caller_file).grep(/#{module_name}\/#{file_name}/).size
104
+ end
105
+ puts "File #{file} not used" if count == 0
106
+ end
107
+ end
108
+
109
+ def initialize
110
+ Puppet.initialize_settings
111
+ find_unused_classes
112
+ find_unused_defines
113
+ find_unused_templates
114
+ find_unused_files
115
+ end
116
+
82
117
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-ghostbuster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Camptocamp