Skip to content

Commit

Permalink
Rename scripts_dir to launchers_dir. (#3922)
Browse files Browse the repository at this point in the history
Rename all things 'scripts' to 'launchers' including the folder holding the yaml files.
  • Loading branch information
euler-room authored Nov 1, 2024
1 parent d20e063 commit 78db912
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 80 deletions.
14 changes: 7 additions & 7 deletions apps/dashboard/app/controllers/launchers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# The controller for apps pages /dashboard/projects/:project_id/scripts
# The controller for apps pages /dashboard/projects/:project_id/launchers
class LaunchersController < ApplicationController

before_action :find_project
Expand All @@ -21,7 +21,7 @@ def new
@script = Launcher.new(project_dir: @project.directory)
end

# POST /dashboard/projects/:project_id/scripts
# POST /dashboard/projects/:project_id/launchers
def create
opts = { project_dir: @project.directory }.merge(create_script_params[:launcher])
@script = Launcher.new(opts)
Expand All @@ -36,12 +36,12 @@ def create
end
end

# GET /projects/:project_id/scripts/:id/edit
# GET /projects/:project_id/launchers/:id/edit
# edit
def edit
end

# DELETE /projects/:project_id/scripts/:id
# DELETE /projects/:project_id/launchers/:id
def destroy
if @script.destroy
redirect_to project_path(params[:project_id]), notice: I18n.t('dashboard.jobs_scripts_deleted')
Expand All @@ -50,8 +50,8 @@ def destroy
end
end

# POST /projects/:project_id/scripts/:id/save
# save the script after editing
# POST /projects/:project_id/launchers/:id/save
# save the launcher after editing
def save
@script.update(save_script_params[:launcher])

Expand All @@ -62,7 +62,7 @@ def save
end
end

# POST /projects/:project_id/scripts/:id/submit
# POST /projects/:project_id/launchers/:id/submit
# submit the job
def submit
opts = submit_script_params[:launcher].to_h.symbolize_keys
Expand Down
10 changes: 5 additions & 5 deletions apps/dashboard/app/models/launcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class ClusterNotFound < StandardError; end
attr_reader :title, :id, :created_at, :project_dir, :smart_attributes

class << self
def scripts_dir(project_dir)
Pathname.new("#{project_dir}/.ondemand/scripts")
def launchers_dir(project_dir)
Pathname.new("#{project_dir}/.ondemand/launchers")
end

def find(id, project_dir)
Expand All @@ -20,7 +20,7 @@ def find(id, project_dir)
end

def all(project_dir)
Dir.glob("#{scripts_dir(project_dir).to_s}/*/form.yml").map do |file|
Dir.glob("#{launchers_dir(project_dir).to_s}/*/form.yml").map do |file|
Launcher.from_yaml(file, project_dir)
end.compact.sort_by do |s|
s.created_at
Expand Down Expand Up @@ -226,7 +226,7 @@ def self.script_path(root_dir, script_id)
raise(StandardError, "#{script_id} is invalid. Does not match #{ID_REX.inspect}")
end

Pathname.new(File.join(Launcher.scripts_dir(root_dir), script_id.to_s))
Pathname.new(File.join(Launcher.launchers_dir(root_dir), script_id.to_s))
end

def default_script_path
Expand Down Expand Up @@ -293,7 +293,7 @@ def cache_file_exists?

def cached_values
@cached_values ||= begin
cache_file_path = OodAppkit.dataroot.join(Launcher.scripts_dir("#{project_dir}"), "#{id}_opts.json")
cache_file_path = OodAppkit.dataroot.join(Launcher.launchers_dir("#{project_dir}"), "#{id}_opts.json")
cache_file_content = File.read(cache_file_path) if cache_file_path.exist?

File.exist?(cache_file_path) ? JSON.parse(cache_file_content) : {}
Expand Down
4 changes: 2 additions & 2 deletions apps/dashboard/app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def sync_template
# that point to the _new_ project directory, not the template's directory.
# This creates them _and_ serializes them to yml in the new directory.
def save_new_launchers
dir = Launcher.scripts_dir(template)
dir = Launcher.launchers_dir(template)
Dir.glob("#{dir}/*/form.yml").map do |script_yml|
Launcher.from_yaml(script_yml, project_dataroot)
end.map do |script|
Expand All @@ -279,7 +279,7 @@ def save_new_launchers
def rsync_args
[
'rsync', '-rltp',
'--exclude', 'scripts/*',
'--exclude', 'launchers/*',
'--exclude', '.ondemand/job_log.yml',
"#{template}/", project_dataroot.to_s
]
Expand Down
16 changes: 8 additions & 8 deletions apps/dashboard/test/models/launcher_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def setup
target = Launcher.new({ project_dir: projects_path.to_s, id: '12345678', title: 'Test Script' })

assert target.save
assert Dir.entries("#{projects_path}/.ondemand/scripts").include?('12345678')
assert Dir.entries("#{projects_path}/.ondemand/launchers").include?('12345678')
end
end

Expand All @@ -36,10 +36,10 @@ def setup
target = Launcher.new({ project_dir: projects_path.to_s, id: '12345678', title: 'Test Script' })

assert target.save
assert Dir.entries("#{projects_path}/.ondemand/scripts").include?('12345678')
assert Dir.entries("#{projects_path}/.ondemand/launchers").include?('12345678')

assert target.destroy
assert_not Dir.entries("#{projects_path}/.ondemand/scripts").include?('12345678')
assert_not Dir.entries("#{projects_path}/.ondemand/launchers").include?('12345678')
end
end

Expand All @@ -61,14 +61,14 @@ def setup
OodAppkit.stubs(:dataroot).returns(projects_path)
script = Launcher.new({ project_dir: projects_path.to_s, id: '12345678', title: 'Test Script' })
assert script.save
assert Dir.entries("#{projects_path}/.ondemand/scripts").include?('12345678')
assert Dir.entries("#{projects_path}/.ondemand/launchers").include?('12345678')

target = Launcher.new({ project_dir: projects_path.to_s, id: '33333333', title: 'Not saved' })
assert_not Dir.entries("#{projects_path}/.ondemand/scripts").include?('33333333')
assert_not Dir.entries("#{projects_path}/.ondemand/launchers").include?('33333333')

assert target.destroy
assert Dir.entries("#{projects_path}/.ondemand/scripts").include?('12345678')
assert_not Dir.entries("#{projects_path}/.ondemand/scripts").include?('33333333')
assert Dir.entries("#{projects_path}/.ondemand/launchers").include?('12345678')
assert_not Dir.entries("#{projects_path}/.ondemand/launchers").include?('33333333')
end
end

Expand Down Expand Up @@ -154,7 +154,7 @@ def setup
refute(launcher.save)
assert(launcher.errors.size, 1)
assert_equal(launcher.errors.full_messages[0], "Id ID does not match #{Launcher::ID_REX.inspect}")
refute(Dir.exist?(Launcher.scripts_dir(tmp).to_s))
refute(Dir.exist?(Launcher.launchers_dir(tmp).to_s))
end
end
end
6 changes: 3 additions & 3 deletions apps/dashboard/test/models/projects_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ class ProjectsTest < ActiveSupport::TestCase
template_dir = File.join(tmp,'template')
job_log_path = "#{template_dir}/.ondemand/job_log.yml"
launcher_id = '50r4nd0m'
cache_json_path = "#{template_dir}/.ondemand/scripts/#{launcher_id}/cache.json"
cache_json_path = "#{template_dir}/.ondemand/launchers/#{launcher_id}/cache.json"

file_content = <<~HEREDOC
some multiline content
echo 'multiline content'
description: multiline content
HEREDOC
Pathname.new("#{template_dir}/.ondemand/scripts/#{launcher_id}").mkpath
Pathname.new("#{template_dir}/.ondemand/launchers/#{launcher_id}").mkpath
File.open(job_log_path, 'w') { |file| file.write(file_content) }
File.open(cache_json_path, 'w') { |file| file.write(file_content) }

Expand All @@ -143,7 +143,7 @@ class ProjectsTest < ActiveSupport::TestCase
project = create_project(projects_path, template: template_dir)

assert Dir.glob(cache_json_path).present? &&
Dir.glob("#{project.directory}/.ondemand/scripts/*/cache.json").empty?
Dir.glob("#{project.directory}/.ondemand/launchers/*/cache.json").empty?
assert Dir.glob(job_log_path).present? &&
Dir.glob("#{project.directory}/.ondemand/*").exclude?("#{project.directory}/.ondemand/job_log.yml")
end
Expand Down
Loading

0 comments on commit 78db912

Please sign in to comment.