Skip to content

Commit

Permalink
set up a router style interface
Browse files Browse the repository at this point in the history
  • Loading branch information
stanleypliu committed Aug 3, 2020
1 parent 8f82921 commit be8c3f4
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions lib/tasks/staging_seeds.rake
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ namespace :comfy do
end
end

def main_task(local_list, remote_list, session)
remote_list.each do |object|
# There are files with non-ASCII characters (i.e. accented) in the CMS files
name = object.name.force_encoding('UTF-8')
paths = create_paths(name)

check_if_newer(local_list, name, object, paths[:remote_path], paths[:local_path], session) do
check_inside_folder(name, local_list, session) if object.attributes.directory?
end
end
end

task :staging_import => :environment do |_t|
require 'net/ssh'
require 'net/scp'
Expand All @@ -102,17 +114,28 @@ namespace :comfy do
# First get rid of any local top-level (i.e. which exist in the main
# directory of REMOTE) folders/files that don't exist remotely
compare_folders('*', LOCAL, REMOTE)

remote_list.each do |object|
# There are files with non-ASCII characters (i.e. accented) in the CMS files
name = object.name.force_encoding('UTF-8')
paths = create_paths(name)

check_if_newer(local_list, name, object, paths[:remote_path], paths[:local_path], session) do
check_inside_folder(name, local_list, session) if object.attributes.directory?
end

puts question = "What would you like to import? 'All/Files/Layouts' or 'Nothing' to quit"
valid_answers = ['All', 'Files', 'Layouts', 'Pages', 'Nothing']
answer = STDIN.gets.chomp.downcase.capitalise
until valid_answers.include?(answer)
puts question
answer = STDIN.gets.chomp.downcase.capitalise
end

local_list = Dir.glob('*', base: LOCAL)
remote_list = session.sftp.dir.glob(LOCAL, '*')

case answer
when 'All'
main_task(local_list, remote_list, session)
when 'Nothing'
abort('Goodbye')
else
remote_list.filter! { |f| f == answer.downcase }
main_task(local_list, remote_list, session)
end
end
# puts "Finished downloads, now replacing your local seed data..."

# Rake::Task["comfy:cms_seeds:import"].invoke('protected-planet', 'protectedplanet')
Expand All @@ -121,5 +144,4 @@ namespace :comfy do
end
end

desc ""
end

0 comments on commit be8c3f4

Please sign in to comment.