class FMPVC::DDR
Attributes
base_dir_ddr[R]
base_dir_text_path[R]
content[R]
creation_date[R]
creation_time[R]
fmp_files[R]
fmpa_version[R]
reports[R]
type[R]
xml_files[R]
Public Class Methods
new(summary_directory, summary_filename = FMPVC.configuration.ddr_filename)
click to toggle source
# File lib/fmpvc/DDR.rb, line 13 def initialize(summary_directory, summary_filename = FMPVC.configuration.ddr_filename) @summary_filename = summary_filename @base_dir_ddr = File.expand_path(summary_directory) ; raise(RuntimeError, "Error: can't find the DDR directory, #{@base_dir_ddr}") unless File.readable?(@base_dir_ddr) summary_file_path = "#{@base_dir_ddr}/#{summary_filename}" ; raise(RuntimeError, "Error: can't find the DDR Summary.xml file, #{summary_file_path}") unless File.readable?(summary_file_path) @base_dir_text_path = @base_dir_ddr.gsub(%r{#{FMPVC.configuration.ddr_dirname}}, FMPVC.configuration.text_dirname) @summary_text_path = "#{@base_dir_text_path}/#{summary_filename.gsub(%r{\.xml}, '.txt')}" @content = IO.read(summary_file_path) @reports = Array.new self.parse end
Public Instance Methods
element2yaml(xml_element)
click to toggle source
# File lib/fmpvc/DDR.rb, line 98 def element2yaml(xml_element) return '' unless FMPVC.configuration.yaml element_xml = xml_element.to_xml({:encoding => 'UTF-8'}) # REMEMBER: the encoding element_hash = Hash.from_xml(element_xml) element_yaml = element_hash.to_yaml end
parse()
click to toggle source
# File lib/fmpvc/DDR.rb, line 27 def parse post_notification('Summary', 'Parsing') summary = Nokogiri::XML(@content) attrs = summary.xpath("//FMPReport").first # "there can be only one" @type = attrs["type"] ; raise RuntimeError, "Incorrect file type: not a DDR Summary.xml file!" unless @type == "Summary" @fmpa_version = attrs["version"] @creation_time = attrs["creationTime"] @creation_date = attrs["creationDate"] @summary_yaml = element2yaml(summary) fmp_reports = summary.xpath("//FMPReport/File") @reports = fmp_reports.map do |a_report| { :name => a_report['name'], :link => a_report['link'], :path => a_report['path'], :attrs => Hash[ a_report.xpath("./*").map {|v| [v.name, v['count']]} ] } end @xml_files = fmp_reports.collect {|node| node['link']} @fmp_files = fmp_reports.collect {|node| node['name']} end
post_notification(object, verb = 'Updating')
click to toggle source
# File lib/fmpvc/DDR.rb, line 58 def post_notification(object, verb = 'Updating') $stdout.puts [verb, object].join(" ") unless FMPVC.configuration.quiet end
process_reports()
click to toggle source
# File lib/fmpvc/DDR.rb, line 50 def process_reports @reports.each do |r| # $stdout.puts post_notification(r[:link].gsub(%r{\./+},''), 'Processing') r[:report] = FMPReport.new(r[:link], self) end end
stringer(n, str = " ")
click to toggle source
# File lib/fmpvc/DDR.rb, line 62 def stringer(n, str = " ") n.times.map {str}.join end
write_reports()
click to toggle source
# File lib/fmpvc/DDR.rb, line 93 def write_reports self.process_reports if @reports.first[:report].nil? @reports.each { |r| r[:report].write_all_objects } end
write_summary()
click to toggle source
# File lib/fmpvc/DDR.rb, line 66 def write_summary post_notification('Summary file', 'Writing') FileUtils.mkdir(@base_dir_text_path) unless File.directory?(@base_dir_text_path) summary_format = "%25s %-512s\n" # report_params = ["BaseTables", "Tables", "Relationships", "Privileges", "ExtendedPrivileges", "FileAccess", "Layouts", "Scripts", "ValueLists", "CustomFunctions", "FileReferences", "CustomMenuSets", "CustomMenus"] report_params = @reports.first[:attrs].keys # better to get the keys dynamically than a fixed list params_label = report_params.map {|p| "%-2s" + stringer(p.length) }.join() report_format = "%25s " + params_label header = stringer(25 - "Report".length) + "Report" + " " + report_params.join(' ') separator = header.gsub(%r{\w}, '-') File.open(@summary_text_path, 'w') do |f| f.write format(summary_format, "Summary file:", @summary_filename) f.write format(summary_format, "Summary path:", @base_dir_ddr) f.write format(summary_format, "FileMaker Pro version:", @fmpa_version) f.write format(summary_format, "Creation Date:", @creation_date) f.write format(summary_format, "Creation Time:", @creation_time) f.puts f.puts header f.puts separator @reports.each do |r| f.puts format(report_format, r[:name] + ' ', *report_params.map { |p| r[:attrs][p] }) end f.puts f.puts @summary_yaml end end