Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update oss.rb #681

Merged
merged 4 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions server/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ gem 'rubyzip', '~> 2.3.0'
gem 'tzinfo-data', '~>1.2021.1'

# database modules

gem 'mongoid', '7.2.1'
#gem 'mongoid-paperclip'
# forked gem is neccessary as mongoid-paperclip relies on mimemagic which now requires freedesktop.org.xml at run time"
Expand Down Expand Up @@ -58,7 +57,8 @@ gem 'sass', '~> 3.7.4'
gem 'sass-rails', '~> 6.0.0'
gem 'sprockets-rails', '~> 3.2.2'
gem 'uglifier', '~> 4.2.0'

# mail => 2.8.0 has startup failures with rails 6.1.x series
gem 'mail', '= 2.7.1'
# don't try to install sassc 2.
gem 'roo', '~> 2.8.3'
gem 'sassc', '~> 2.4.0'
Expand Down
5 changes: 3 additions & 2 deletions server/app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ class AdminController < ApplicationController
def index
require 'rubygems'
@gems = Gem::Specification.all.map { |g| [g.name, g.version.to_s] }.sort
Rails.logger.debug "oscli version command: #{Utility::Oss.oscli_cmd} openstudio_version"
#use split.first to remove the --bundle stuff, see why below
Rails.logger.debug "oscli version command: #{Utility::Oss.oscli_cmd_no_bundle_args(Rails.logger)} openstudio_version"
# syntax to explicitly unset a bunch of env vars is very different for windows
# Use the default shell to query for OpenStudio version. Not neccessary to unset these.
#unset_vars = Gem.win_platform? || ENV['OS'] == 'Windows_NT' ? 'set ' + Utility::Oss::ENV_VARS_TO_UNSET_FOR_OSCLI.join('= && set ') : 'unset ' + Utility::Oss::ENV_VARS_TO_UNSET_FOR_OSCLI.join(' && unset ')
oscli_cmd = "#{Utility::Oss.oscli_cmd} openstudio_version"
oscli_cmd = "#{Utility::Oss.oscli_cmd_no_bundle_args(Rails.logger)} openstudio_version"
oscli_cmd = "call #{oscli_cmd}" if Gem.win_platform? || ENV['OS'] == 'Windows_NT'
Rails.logger.debug "oscli_cmd: #{oscli_cmd}"
version = `#{oscli_cmd}` #this will not work with --bundle args since user is 'nobody' and cannot create a tmpdir from $HOME
Expand Down
20 changes: 17 additions & 3 deletions server/app/lib/utility/oss.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ def self.oscli_cmd(logger = Rails.logger)

raise 'OPENSTUDIO_EXE_PATH not set' unless ENV['OPENSTUDIO_EXE_PATH']
raise "Unable to find file specified in OPENSTUDIO_EXE_PATH: `#{ENV['OPENSTUDIO_EXE_PATH']}`" unless File.exist?(ENV['OPENSTUDIO_EXE_PATH'])

logger.info "Found ENV['OPENSTUDIO_EXE_PATH']"
# set cmd from ENV variable
cmd = ENV['OPENSTUDIO_EXE_PATH']
cmd = ENV['OPENSTUDIO_EXE_PATH'] + oscli_bundle
logger.info "Returning Oscli cmd: #{cmd}"
cmd
rescue Exception => e
logger.warn "Error finding Oscli: #{e}"
cmd = Gem.win_platform? || ENV['OS'] == 'Windows_NT' ? 'openstudio.exe' : `which openstudio`.strip
Expand All @@ -32,9 +34,21 @@ def self.oscli_cmd(logger = Rails.logger)
else
logger.error 'Unable to find Oscli.'
end
logger.info "Returning Oscli cmd: #{cmd + oscli_bundle}"
logger.info "RESCUE: Returning Oscli cmd: #{cmd + oscli_bundle}"
cmd + oscli_bundle
end

def self.oscli_cmd_no_bundle_args(logger = Rails.logger)
# determine if an explicit oscli path has been set via the meta-cli option, warn if not

raise 'OPENSTUDIO_EXE_PATH not set' unless ENV['OPENSTUDIO_EXE_PATH']
raise "Unable to find file specified in OPENSTUDIO_EXE_PATH: `#{ENV['OPENSTUDIO_EXE_PATH']}`" unless File.exist?(ENV['OPENSTUDIO_EXE_PATH'])
logger.info "Found ENV['OPENSTUDIO_EXE_PATH'] in oscli_cmd_no_bundle_args"
# set cmd from ENV variable
cmd = ENV['OPENSTUDIO_EXE_PATH']
logger.info "Returning Oscli cmd: #{cmd}"
cmd
end

# use bundle option only if we have a path to openstudio gemfile.
# if BUNDLE_PATH is not set (ie Docker), we must add these options
Expand Down