| 286 | } |
| 287 | |
| 288 | boost::optional<BCLMeasure> MeasureManager::getMeasure(const openstudio::path& measureDirPath, bool force_reload) { |
| 289 | |
| 290 | const auto& measureDirPathStr = measureDirPath.string(); |
| 291 | |
| 292 | // check if measure exists on disk |
| 293 | if (!openstudio::filesystem::is_directory(measureDirPath)) { |
| 294 | fmt::print("Measure '{}' does not exist.\n", measureDirPathStr); |
| 295 | m_measures.erase(measureDirPath); |
| 296 | return boost::none; |
| 297 | } |
| 298 | if (!openstudio::filesystem::is_regular_file(measureDirPath / "measure.xml")) { |
| 299 | fmt::print("Measure directory '{}' exists but does not have a measure.xml.\n", measureDirPathStr); |
| 300 | m_measures.erase(measureDirPath); |
| 301 | return boost::none; |
| 302 | } |
| 303 | |
| 304 | BCLMeasureInfo* measureInfo_ = nullptr; |
| 305 | if (!force_reload) { |
| 306 | auto it = m_measures.find(measureDirPath); |
| 307 | if (it != m_measures.end()) { |
| 308 | measureInfo_ = &(it->second); |
| 309 | fmt::print("Using cached measure {}\n", measureDirPath.generic_string()); |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | if (!measureInfo_) { |
| 314 | m_measures.erase(measureDirPath); |
| 315 | |
| 316 | // load from disk |
| 317 | fmt::print("Attempting to load measure '{}'\n", measureDirPathStr); |
| 318 | |
| 319 | boost::optional<BCLMeasure> measure_ = openstudio::BCLMeasure::load(measureDirPath); |
| 320 | |
| 321 | if (!measure_) { |
| 322 | fmt::print("Failed to load measure '{}'\n", measureDirPathStr); |
| 323 | return boost::none; |
| 324 | } |
| 325 | fmt::print("Successfully loaded measure '{}'\n", measureDirPathStr); |
| 326 | auto [it, ok] = m_measures.insert({measureDirPath, BCLMeasureInfo{std::move(*measure_)}}); |
| 327 | measureInfo_ = &(it->second); |
| 328 | } |
| 329 | |
| 330 | auto& measure = measureInfo_->measure; |
| 331 | |
| 332 | // see if there are updates, want to make sure to perform both checks so do outside of conditional |
| 333 | bool file_updates = measure.checkForUpdatesFiles(); // checks if any files have been updated |
| 334 | bool xml_updates = measure.checkForUpdatesXML(); // only checks if xml as loaded has been changed since last save |
| 335 | |
| 336 | auto readmeInPath = measureDirPath / "README.md.erb"; |
| 337 | auto readmeOutPath = measureDirPath / "README.md"; |
| 338 | |
| 339 | const bool hasReadmeIn = openstudio::filesystem::is_regular_file(readmeInPath); |
| 340 | const bool hasReadmeOut = openstudio::filesystem::is_regular_file(readmeOutPath); |
| 341 | const bool readme_out_of_date = hasReadmeIn && !hasReadmeOut; |
| 342 | |
| 343 | // TODO: try catch like in measure_manager.rb? |
| 344 | bool missing_fields = measure.missingRequiredFields(); |
| 345 |
no test coverage detected