Skip to content

Commit

Permalink
moved router into a separate method
Browse files Browse the repository at this point in the history
  • Loading branch information
stanleypliu committed Aug 11, 2020
1 parent c874f1c commit 0f56eac
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
9 changes: 5 additions & 4 deletions lib/modules/sync_seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ def check_if_newer(parent_folder, local_item, remote_item, remote_path, local_pa
downloaded
end

def compare_folders(wildcard, local, remote, base)
puts "Checking to see what files need to be deleted from #{base}"
def compare_folders(wildcard, local, remote)
puts "Checking to see what files need to be deleted from #{local}"

remote_list = @session.sftp.dir.glob(remote, wildcard).map do |f|
f.name.force_encoding('UTF-8')
end

local_list = Dir.glob(wildcard, base: local)

files_for_deletion(local_list, remote_list, base)
files_for_deletion(local_list, remote_list, local)
end

def check_inside_folder(folder, local_list)
Expand Down Expand Up @@ -120,7 +120,8 @@ def main_task(local_list, remote_list)
end
end

def commence_import(answer)
# Piggybacks on existing Comfy modules
def commence_comfy_import(answer)
logger = ComfortableMexicanSofa.logger
ComfortableMexicanSofa.logger = Logger.new(STDOUT)

Expand Down
37 changes: 19 additions & 18 deletions lib/tasks/staging_seeds.rake
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,25 @@ namespace :comfy do
PP_STAGING = 'new-web.pp-staging.linode.protectedplanet.net'.freeze
PP_USER = 'wcmc'.freeze

desc "Import CMS Seed data from staging. Can be run with arguments (<destination>, files/pages/layouts/all) or can accept user input if no argument is supplied"
task :staging_import, %i[to folder] => [:environment] do |_t, args|

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

# Fast-tracked unhappy path
abort('Goodbye') if answer == 'Nothing'
else
to = File.join(ComfortableMexicanSofa.config.seeds_path, args[:to])
answer = args[:folder].downcase.capitalize!
def user_input
puts question = "What would you like to import? 'All/Files/Layouts/Pages' or 'Nothing' to quit"
valid_answers = ['All', 'Files', 'Layouts', 'Pages', 'Nothing']
answer = STDIN.gets.chomp.downcase.capitalize
until valid_answers.include?(answer)
puts question
end

# Fast-tracked unhappy path
abort('Goodbye') if answer == 'Nothing'

{ answer: answer, destination: File.join(ComfortableMexicanSofa.config.seeds_path, 'protected-planet') }
end

desc "Import CMS Seed data from staging. Can be run with arguments [<destination>, files/pages/layouts/all] or can accept user input if no argument is supplied"
task :staging_import, %i[to folder] => [:environment] do |_t, args|
to = args[:to].nil? ? user_input[:destination] : File.join(ComfortableMexicanSofa.config.seeds_path, args[:to])
answer = args[:answer].nil? ? user_input[:answer] : args[:folder].downcase.capitalize!

puts "Importing CMS Seed data from Staging Folder to #{to} ..."

new_session = SyncSeeds.new(PP_STAGING, PP_USER)
Expand All @@ -32,7 +33,7 @@ namespace :comfy do
new_session.start_session do |session|
# 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
new_session.compare_folders('*', to, FROM, to)
new_session.compare_folders('*', to, FROM)

local_list = new_session.list_local_files(to)
remote_list = new_session.list_remote_files(FROM)
Expand All @@ -52,7 +53,7 @@ namespace :comfy do

puts "Finished downloads, now replacing your local seed data with your selection..."

new_session.commence_import(answer)
# new_session.commence_comfy_import(answer)
end
end

Expand Down

0 comments on commit 0f56eac

Please sign in to comment.