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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/nera/nera_simulator_layer_controller.rb', line 84
def remove_simulator( sim_name)
flag = true
sim_class = get_class_by_name( sim_name)
return nil unless sim_class
sim_id = (list.find do |rec| rec[:name] == sim_name end)[:id]
return nil unless sim_id
job_records = NERA::JobRecords.new( @db_folders.path_to_jobs_table )
job_records.transaction {
@sim_records.transaction {
found = job_records.list_all.find do |rec| rec[:simulator] == sim_name end
if found
flag = nil
return
end
f = @sim_records.destroy( sim_id)
raise "Couldn't destroy the record #{sim_id} in simulators table" unless f
path1 = @db_folders.path_to_parameter_layer( sim_class)
path2 = File.dirname( @db_folders.path_to_parameters_table( sim_class) )
path3 = File.join( @db_folders.path_to_simulator_layer, "Simulator_classes", "#{sim_name}.rb")
raise "Couldn't find #{path1}" unless File.directory?(path1)
raise "Couldn't find #{path2}" unless File.directory?(path2)
raise "Couldn't find #{path3}" unless File.exist?(path3)
base_path = Pathname.new( @db_folders.path_to_simulator_layer ).realpath
path1 = Pathname.new( path1).realpath.relative_path_from( base_path).to_s
path2 = Pathname.new( path2).realpath.relative_path_from( base_path).to_s
path3 = Pathname.new( path3).realpath.relative_path_from( base_path).to_s
Dir.chdir(base_path) {
tar_file = "#{sim_id}_#{sim_name}.tar"
cmd = "tar cf #{tar_file} #{path1} #{path2} #{path3}"
system cmd
raise "command \"#{cmd}\" failed." unless $? == 0
bz2_file = tar_file + '.bz2'
FileUtils.rm( bz2_file) if File.exist?( bz2_file )
cmd = "bzip2 #{tar_file}"
system cmd
raise "command \"#{cmd}\" failed." unless $? == 0
FileUtils.rm_r( path1)
FileUtils.rm_r( path2)
FileUtils.rm( path3)
}
NERA::Simulator.remove_simulator( sim_class)
@db_folders.logger.info(self.class.to_s) {
"removed the simulator (#{sim_class.to_s})"
}
}
}
return flag
end
|