-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from BBC-News/thor_cli
Enable thor cli
- Loading branch information
Showing
20 changed files
with
365 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,13 @@ | ||
#!/usr/bin/env ruby | ||
|
||
Signal.trap("INT") { exit 1 } | ||
|
||
# Split arguments by "--" if its there, we'll recombine them later | ||
argv = ARGV.dup | ||
argv_extra = [] | ||
if idx = argv.index("--") | ||
argv_extra = argv.slice(idx+1, argv.length-2) | ||
argv = argv.slice(0, idx) | ||
end | ||
|
||
# Find out if we're meant to be in debug mode | ||
if argv.include?('--debug') | ||
argv.delete('--debug') | ||
ENV['WRAITH_LOG'] = 'debug' | ||
end | ||
|
||
require 'log4r' | ||
require 'wraith' | ||
|
||
logger = Log4r::Logger.new('wraith::bin::wraith') | ||
logger.info("`wraith` started with: #{ARGV.inspect}") | ||
|
||
# stdout/stderr should not buffer output | ||
$stdout.sync = true | ||
$stderr.sync = true | ||
require 'rubygems' | ||
require 'bundler/setup' | ||
|
||
begin | ||
env = Wraith::Environment.new | ||
cli = env.cli(argv) | ||
|
||
# rescue Wraith::Error::WraithError => e | ||
rescue => e | ||
logger.error('Wraith could not start') | ||
logger.error(e.inspect) | ||
logger.error(e.message) | ||
require 'wraith/cli' | ||
Wraith::CLI.start | ||
rescue Interrupt => e | ||
puts "\nQuitting..." | ||
exit 1 | ||
rescue SystemExit => e | ||
exit e.status | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,6 @@ | ||
require 'log4r' | ||
|
||
if ENV['WRAITH_LOG'] && !ENV['WRAITH_LOG'].nil? | ||
require 'log4r/config' | ||
|
||
Log4r.define_levels(*Log4r::Log4rConfig::LogLevels) | ||
|
||
begin | ||
level = Log4r.const_get(ENV["WRAITH_LOG"].upcase) | ||
rescue NameError | ||
$stderr.puts "Invalid WRAITH_LOG: #{ENV['WRAITH_LOG']}" | ||
exit 1 | ||
end | ||
|
||
logger = Log4r::Logger.new('wraith') | ||
logger.outputters = Log4r::Outputter.stderr | ||
logger.level = level | ||
logger = nil | ||
end | ||
require "wraith/version" | ||
|
||
module Wraith | ||
autoload :Environment, 'wraith/environment' | ||
autoload :CLI, 'wraith/cli' | ||
autoload :Error, 'wraith/error' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,95 @@ | ||
require 'log4r' | ||
require 'thor' | ||
require 'wraith' | ||
require 'wraith/save_images' | ||
require 'wraith/crop' | ||
require 'wraith/spider' | ||
require 'wraith/folder' | ||
require 'wraith/thumbnails' | ||
require 'wraith/compare_images' | ||
require 'wraith/images' | ||
require 'wraith/gallery' | ||
|
||
class Wraith::CLI | ||
def initialize(args, env) | ||
@env = env | ||
class Wraith::CLI < Thor | ||
include Thor::Actions | ||
|
||
@logger = Log4r::Logger.new("wraith::cli") | ||
@logger.info("CLI: #{args.inspect}") | ||
attr_accessor :config_name | ||
|
||
def self.source_root | ||
File.expand_path('../../../templates/',__FILE__) | ||
end | ||
|
||
def start | ||
desc "setup", "creates config folder and default config" | ||
def setup | ||
template('configs/config.yaml', 'configs/config.yaml') | ||
template('javascript/snap.js', 'javascript/snap.js') | ||
template('assets/invalid.jpg', 'assets/invalid.jpg') | ||
end | ||
|
||
desc "reset_shots", "removes all the files in the shots folder" | ||
def reset_shots(config_name) | ||
reset = Wraith::FolderManager.new(config_name) | ||
reset.clear_shots_folder | ||
end | ||
|
||
protected | ||
desc "folders", "create folders for images" | ||
def setup_folders(config_name) | ||
create = Wraith::FolderManager.new(config_name) | ||
create.create_folders | ||
end | ||
|
||
attr_reader :env | ||
no_commands do | ||
def check_for_paths(config_name) | ||
spider = Wraith::Spidering.new(config_name) | ||
spider.check_for_paths | ||
end | ||
|
||
def check_images(config_name) | ||
image = Wraith::Images.new(config_name) | ||
image.files | ||
end | ||
end | ||
|
||
desc "save_images", "captures screenshots" | ||
def save_images(config_name) | ||
save_images = Wraith::SaveImages.new(config_name) | ||
save_images.save_images | ||
end | ||
|
||
desc "crop_images", "crops images to the same height" | ||
def crop_images(config_name) | ||
crop = Wraith::CropImages.new(config_name) | ||
crop.crop_images | ||
end | ||
|
||
desc "compare_images", "compares images to generate diffs" | ||
def compare_images(config_name) | ||
compare = Wraith::CompareImages.new(config_name) | ||
compare.compare_images | ||
end | ||
|
||
desc "generate_thumbnails", "create thumbnails for gallery" | ||
def generate_thumbnails(config_name) | ||
thumbs = Wraith::Thumbnails.new(config_name) | ||
thumbs.generate_thumbnails | ||
end | ||
|
||
desc "generate_gallery", "create page for viewing images" | ||
def generate_gallery(config_name) | ||
gallery = Wraith::GalleryGenerator.new(config_name) | ||
gallery.generate_gallery | ||
puts "Gallery generated" | ||
end | ||
|
||
desc "capture config_name", "A full Wraith job" | ||
def capture(config) | ||
reset_shots(config) | ||
setup_folders(config) | ||
check_for_paths(config) | ||
save_images(config) | ||
check_images(config) | ||
crop_images(config) | ||
compare_images(config) | ||
generate_thumbnails(config) | ||
generate_gallery(config) | ||
end | ||
end |
Oops, something went wrong.