Class: Twb::Analysis::DataSources::DataSourceFilesAnalyzer

Inherits:
Object
  • Object
show all
Includes:
TabTool
Defined in:
lib/twb/analysis/datasources/datasourcefilesanalyzer.rb

Constant Summary collapse

@@csvFileName =
'DataSourceFiles.csv'
@@csvFileHeader =
[ 'Record #',
  'Workbook',
  'Workbook Dir',
  'Data Source', 
  'File Name', 
  'File Dir',
  'File Exists?',
  'File Modified',
  'File Size'
]

Instance Attribute Summary collapse

Attributes included from TabTool

#alerts, #docDir, #docfiles, #funcdoc, #id, #licensed, #logfilename, #logger, #loglevel, #metrics, #properties, #ttdocdir, #type, #uuid

Instance Method Summary collapse

Methods included from TabTool

#addDocFile, #alert, #closeDocFiles, #config, #docFile, #docFileMaxNameLen, #docfilesdoc, #docfilesdocto_s, #emit, #emitCSV, #finis, #hasConfig, #init, #initCSV, #initDocDir, #initLogger, #license=, #licensed?, #loadConfig

Constructor Details

#initialize(**args) ⇒ DataSourceFilesAnalyzer

Returns a new instance of DataSourceFilesAnalyzer.


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/twb/analysis/datasources/datasourcefilesanalyzer.rb', line 41

def initialize(**args)
    emit "initialize DataSourceFilesAnalyzer args #{args}"
    @args      = args
    @recordDir = !@args.nil? && @args[:recordDir] == true
    @ttdocdir  = @args[:ttdocdir]
    @csvAdd    = @args[:csvMode] == :add
    @csvMode   = @csvAdd ? 'a' : 'w'
    init
    @funcdoc = {:class=>self.class, :blurb=>"Analyze Data Sources' Files", :description=>'Identifying the files accessed by Data Sources.',}
    @dataSourcesCount   = 0
    @recNum             = 0
    #--
    @csvFile   = initCSV(@@csvFileName, 'Data Sources and the Files they access.',                      @@csvFileHeader )
    #--
    @localEmit  = false
end

Instance Attribute Details

#filesCountObject (readonly)

Returns the value of attribute filesCount


27
28
29
# File 'lib/twb/analysis/datasources/datasourcefilesanalyzer.rb', line 27

def filesCount
  @filesCount
end

Instance Method Details

#processFiles(ds) ⇒ Object


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/twb/analysis/datasources/datasourcefilesanalyzer.rb', line 66

def processFiles ds
  dirFiles = Hash.new { |d,fs| d[fs] = Set.new }
  ds.node.xpath('.//connection[@filename]').each do |fnode|
      twbFileDir  = fnode['directory']
      twbFileName = fnode['filename']
      fqFileName  = twbFileDir.nil? ?  twbFileName : twbFileDir + '/' + twbFileName
      fileName = File.basename fqFileName
      fileDir  = File.dirname  fqFileName
      exists   = File.exist?   fqFileName
      modtime  = exists ? File.mtime(fqFileName) : nil
      size     = exists ? File.size(fqFileName)  : nil
      data = [@recNum+=1, @twbName, @twbDir, ds.uiname, fileName, fileDir, exists, modtime, size]
      @csvFile  << data
  end
end

#processTWB(twb) ⇒ Object


58
59
60
61
62
63
64
# File 'lib/twb/analysis/datasources/datasourcefilesanalyzer.rb', line 58

def processTWB twb
  @twbName = twb.name
  @twbDir  = twb.dir
  twb.datasources.each do |ds|
    processFiles ds
  end
end