puppet-ghostbuster 0.0.5 → 0.0.6
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 +4 -4
- data/lib/puppet-ghostbuster/version.rb +1 -1
- data/lib/puppet-ghostbuster.rb +46 -11
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48db269b56e5bd75a9c1aa3349c578bf244957b3
|
4
|
+
data.tar.gz: caf14c62cef78d4f307302b5afc38d012f39824d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0084173d38ed6fb21824f3ec750a70c9fe290a2f8a9c4d53bb45cbd9dbef64574d453f8dec6ef34ff9c85b900f04465dfed5cab9023b6771b507c8028d4d1ffe
|
7
|
+
data.tar.gz: ea9d82fd853ef6c0e20360729e700b3bf04d92dbdf4885217b5db56d9bb439f66c4b4ecc38dd255b87ecc0b649984df55e59b8ceae1b6f257c50887c1c016de9
|
data/lib/puppet-ghostbuster.rb
CHANGED
@@ -49,34 +49,69 @@ class PuppetGhostbuster
|
|
49
49
|
)
|
50
50
|
end
|
51
51
|
|
52
|
-
def
|
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 "
|
59
|
-
|
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 "
|
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
|
-
|
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
|
-
|
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
|
-
|
76
|
-
break if found
|
82
|
+
count += File.readlines(manifest).grep(/["']#{module_name}\/#{template_name}["']/).size
|
77
83
|
end
|
78
|
-
puts "#{template} not used"
|
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
|