lib/morph-cli.rb in morph-cli-0.2.4 vs lib/morph-cli.rb in morph-cli-0.2.5

- old
+ new

@@ -1,13 +1,23 @@ require "morph-cli/version" require 'yaml' require 'find' +require 'filesize' module MorphCLI def self.execute(directory, development, env_config) - puts "Uploading and running..." - file = MorphCLI.create_tar(directory, MorphCLI.all_paths(directory)) + all_paths = MorphCLI.all_paths(directory) + + if !all_paths.find{ |file| /scraper\.[\S]+$/ =~ file } + $stderr.puts "Can't find scraper to upload. Expected to find a file called scraper.rb, scraper.php, scraper.py, scraper.pl, scraper.js, etc to upload" + exit(1) + end + + size = MorphCLI.get_dir_size(directory, all_paths) + puts "Uploading #{size}..." + + file = MorphCLI.create_tar(directory, all_paths) buffer = "" block = Proc.new do |http_response| if http_response.code == "200" http_response.read_body do |line| before, match, after = line.rpartition("\n") @@ -98,9 +108,17 @@ ensure tar.close end end File.new('/tmp/out', 'r') + end + + def self.get_dir_size(directory, paths) + size = 0 + in_directory(directory) do + paths.each { |entry| size += File.size(entry) } + end + Filesize.from("#{size} B").pretty end # Relative paths to all the files in the given directory (recursive) # (except for anything below a directory starting with ".") def self.all_paths(directory)