Skip to content
This repository has been archived by the owner on Aug 18, 2022. It is now read-only.

(maint) Pay down tech debt #349

Merged
7 changes: 5 additions & 2 deletions build/dsc.rake
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,11 @@ eod
task :clean, [:module_path] do |t, args|
module_path = args[:module_path] || default_dsc_module_path
puts "Cleaning #{item_name}"
m = Dsc::Manager.new
m.target_module_path = module_path
m = Dsc::TypeCleaner.new(
module_path,
"lib/puppet/type",
"spec/unit/puppet/type",
)
msgs = m.clean_dsc_types
msgs.each{|m| puts "#{m}"}
msgs = m.clean_dsc_type_specs
Expand Down
1 change: 1 addition & 0 deletions build/dsc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
require "#{LIB_PATH}/dsc/resource"
require "#{LIB_PATH}/dsc/psmodule"
require "#{LIB_PATH}/dsc/manager"
require "#{LIB_PATH}/dsc/typecleaner"

module Dsc

Expand Down
26 changes: 0 additions & 26 deletions build/dsc/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,26 +241,12 @@ def document_types(markdown_file_path, dsc_types)
end
end

def clean_dsc_types
puppet_type_path = "#{@target_module_path}/#{@puppet_type_subpath}"
clean_folder(["#{puppet_type_path}/dsc_*.rb"])
end

def clean_dsc_type_specs
puppet_type_spec_path = "#{@target_module_path}/#{@puppet_type_spec_subpath}"
clean_folder(["#{puppet_type_spec_path}/dsc_*_spec.rb"])
end

# Mof's
def import_dmtf_mofs
Dsc::Import.download(@dmtf_cim_mof_zip_url, @dmtf_cim_mof_zip_path)
Dsc::Import.unzip(@dmtf_cim_mof_zip_path, @dmtf_mof_folder)
end

def clean_dmtf_mofs
clean_folder([@dmtf_mof_folder])
end

def format_type_value(type_value)
case
when type_value.class.name == 'Symbol'
Expand Down Expand Up @@ -308,17 +294,5 @@ def find_valid_files(directory)

private

def clean_folder(folders)
type_pathes = []
folders.each do |folder|
Dir.glob("#{folder}").each do |filepath|
pn = Pathname.new(filepath).expand_path.relative_path_from(@module_path)
type_pathes << "Remove - #{pn.to_s}"
FileUtils.rm_rf filepath
end
end
type_pathes
end

end
end
37 changes: 37 additions & 0 deletions build/dsc/typecleaner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module Dsc
class TypeCleaner
attr_accessor :target_module_path
attr_accessor :puppet_type_subpath
attr_accessor :puppet_type_spec_subpath
attr_accessor :module_path

def initialize(target_module_path, puppet_type_subpath, puppet_type_spec_subpath)
@target_module_path = target_module_path
@puppet_type_subpath = puppet_type_subpath
@puppet_type_spec_subpath = puppet_type_spec_subpath
end

def clean_dsc_types
puppet_type_path = "#{@target_module_path}/#{@puppet_type_subpath}"
clean_folder(["#{puppet_type_path}/dsc_*.rb"])
end

def clean_dsc_type_specs
puppet_type_spec_path = "#{@target_module_path}/#{@puppet_type_spec_subpath}"
clean_folder(["#{puppet_type_spec_path}/dsc_*_spec.rb"])
end

def clean_folder(folders)
type_pathes = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: typo. Won't stop a merge though

folders.each do |folder|
Dir.glob("#{folder}").each do |filepath|
pn = Pathname.new(filepath).expand_path.relative_path_from(@target_module_path)
type_pathes << "Remove - #{pn.to_s}"
FileUtils.rm_rf filepath
end
end
type_pathes
end

end
end