Class: ServerDirectoryCleanup

Inherits:
OpenStudio::Measure::ReportingMeasure
  • Object
show all
Defined in:
lib/measures/ServerDirectoryCleanup/measure.rb

Overview

start the measure

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.file_typesObject

file types that can be removed



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/measures/ServerDirectoryCleanup/measure.rb', line 23

def self.file_types
  # key is arg name value is string for run method
  file_types = {}
  file_types['sql'] = '*.sql'
  file_types['eso'] = '*.eso'
  file_types['audit'] = '*.audit'
  file_types['osm'] = '*.osm'
  file_types['idf'] = '*.idf'
  file_types['bnd'] = '*.bnd'
  file_types['eio'] = '*.eio'
  file_types['shd'] = '*.shd'
  file_types['mdd'] = '*.mdd'
  file_types['rdd'] = '*.rdd'
  file_types['csv'] = '*.csv'
  file_types['Sizing Run Directories'] = 'Sizing Run Directories'

  return file_types
end

Instance Method Details

#arguments(_model = nil) ⇒ Object

define the arguments that the user will input



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/measures/ServerDirectoryCleanup/measure.rb', line 43

def arguments(_model = nil)
  args = OpenStudio::Measure::OSArgumentVector.new

  # loop through file types and make arguments
  ServerDirectoryCleanup.file_types.each do |file_type, _|
    arg = OpenStudio::Measure::OSArgument.makeBoolArgument(file_type, true)
    arg.setDisplayName("Remove '#{file_type}' files from run directory")
    arg.setDefaultValue(true)
    args << arg
  end

  args
end

#descriptionObject



14
15
16
# File 'lib/measures/ServerDirectoryCleanup/measure.rb', line 14

def description
  'Clean up files in the run directory'
end

#modeler_descriptionObject



18
19
20
# File 'lib/measures/ServerDirectoryCleanup/measure.rb', line 18

def modeler_description
  'You can select which files to remove by the file types (eg: sql) as well as the sizing run directories'
end

#nameObject

define the name that a user will see, this method may be deprecated as the display name in PAT comes from the name field in measure.xml



10
11
12
# File 'lib/measures/ServerDirectoryCleanup/measure.rb', line 10

def name
  'Server Directory Cleanup'
end

#run(runner, user_arguments) ⇒ Object

define what happens when the measure is run



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/measures/ServerDirectoryCleanup/measure.rb', line 58

def run(runner, user_arguments)
  super(runner, user_arguments)

  # use the built-in error checking
  unless runner.validateUserArguments(arguments, user_arguments)
    false
  end

  # assign the user inputs to variables
  args = ServerDirectoryCleanup.file_types.map { |k, _| [k, runner.getBoolArgumentValue(k, user_arguments)] }.to_h
  initial_string = 'The following files were in the local run directory prior to the execution of this measure: '
  Dir.entries('./../').each do |f|
    initial_string << "#{f}, "
  end
  initial_string = "#{initial_string[0..(initial_string.length - 3)]}."
  runner.registerInitialCondition(initial_string)

  # TODO: - code to remove sizing runs is not functional yet
  # delete run directories
  ServerDirectoryCleanup.file_types.each do |k, v|
    next if !args[k]

    if v == 'Sizing Run Directories'

      Dir.glob('./../**/output').select { |e| File.directory? e }.each do |f|
        runner.registerInfo("Removing #{f} directory.")
        FileUtils.rm_f Dir.glob("#{f}/*")
        FileUtils.remove_dir(f, true)
      end
      # sometimes SizingRun seems to be used instead of output
      Dir.glob('./../**/SizingRun').select { |e| File.directory? e }.each do |f|
        runner.registerInfo("Removing #{f} directory.")
        FileUtils.rm_f Dir.glob("#{f}/*")
        FileUtils.remove_dir(f, true)
      end

    else
      Dir.glob("./../#{v}").each do |f|
        File.delete(f)
        runner.registerInfo("Deleted #{f} from the run directory.") if !File.exist?(f)
      end
    end
  end

  final_string = 'The following files were in the local run directory following to the execution of this measure: '
  Dir.entries('./..').each do |f|
    final_string << "#{f}, "
  end
  final_string = "#{final_string[0..(final_string.length - 3)]}."
  runner.registerFinalCondition(final_string)

  true
end