Skip to content

Commit

Permalink
Add argument to specify whether the downloaded datapoint zips should …
Browse files Browse the repository at this point in the history
…be unzipped.
  • Loading branch information
shorowit committed Sep 9, 2017
1 parent 5349077 commit d85205e
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions scripts/complete_localResults
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ end
# @param server_api [::OpenStudio::Analysis::ServerApi] API to serve zips
# @param interval [::Fixnum] Percent interval to report progress to STDOUT
# @return [logical] Indicates if any errors were caught
def retrieve_dp_data(local_results_dir, server_api, interval=5, analysis_id=nil)
def retrieve_dp_data(local_results_dir, server_api, interval=5, analysis_id=nil, unzip=false)
# Verify localResults directory
unless File.basename(local_results_dir) == 'localResults'
fail "ERROR: input #{local_results_dir} does not point to localResults"
Expand All @@ -62,8 +62,13 @@ def retrieve_dp_data(local_results_dir, server_api, interval=5, analysis_id=nil)
ok, f = server_api.download_datapoint dp[:_id], local_results_dir
if ok
dest = File.join local_results_dir, dp[:_id]
unzip_archive f, dest
FileUtils.mv File.join(local_results_dir, 'data_point.zip'), dest
if unzip
unzip_archive f, dest
File.delete(File.join(local_results_dir, 'data_point.zip'))
else
Dir.mkdir dest
FileUtils.mv File.join(local_results_dir, 'data_point.zip'), dest
end
else
puts "ERROR: Failed to download data point #{dp[:_id]}"
dps_error_count += 1
Expand All @@ -89,7 +94,7 @@ options = {}
# -s --server_dns [string]
# -p --project_dir [string]
optparse = OptionParser.new do |opts|
opts.banner = 'Usage: complete_localResults [-s] <server_dns> [-p] <project_dir> -a <analysis_id> [-h]'
opts.banner = 'Usage: complete_localResults [-s] <server_dns> [-p] <project_dir> -a <analysis_id> [-u] [-h]'

options[:project_dir] = nil
opts.on('-p', '--project_dir <dir>', 'specified project DIRECTORY') do |dir|
Expand All @@ -106,6 +111,11 @@ optparse = OptionParser.new do |opts|
options[:a_id] = id
end

options[:unzip] = false
opts.on('-u', '--unzip', 'extract data_point.zip contents') do |zip|
options[:unzip] = true
end

opts.on_tail('-h', '--help', 'display help') do
puts opts
exit
Expand Down Expand Up @@ -137,7 +147,7 @@ end

# Retrieve the datapoints and indicate success
Zip.warn_invalid_date = false
failed_dps = retrieve_dp_data(local_results_dir, server_api, 1, options[:a_id])
failed_dps = retrieve_dp_data(local_results_dir, server_api, 1, options[:a_id], options[:unzip])
fail "ERROR: Retrieval failed #{failed_dps} times" if failed_dps != 0
puts 'SUCCESS: Exiting'
exit 0

0 comments on commit d85205e

Please sign in to comment.