Skip to content

Commit

Permalink
Merge pull request #94 from BBC-News/thor_cli
Browse files Browse the repository at this point in the history
Enable thor cli
  • Loading branch information
dblooman committed Feb 9, 2014
2 parents 10a88f7 + 625383d commit dd39c25
Show file tree
Hide file tree
Showing 20 changed files with 365 additions and 243 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ language: ruby
rvm:
- "1.9.2"
- "2.0.0"

script: "./bin/wraith capture config"

notifications:
email:
recipients:
Expand Down
67 changes: 0 additions & 67 deletions Gemfile.lock

This file was deleted.

46 changes: 32 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,15 @@ And then download the PhantomJS binary package from

Open terminal and run

git clone https://github.com/BBC-News/wraith
gem install wraith

You can then run the following inside the Wraith directory:
You can then run the following to create a template snap.js and config file:

bundle install

If you don't have bundler installed, install it :

gem install bundler

wraith setup

Alternatively you can download the install script via curl, this will not create a git repo though.
Alternatively you can clone the repo.

curl -fsSL https://raw.github.com/bbc-news/wraith/go/install | bash
git clone https://github.com/BBC-News/wraith
cd wraith
bundle install

Expand All @@ -91,7 +86,7 @@ browser:
# gecko: "slimerjs"

# If you want to have multiple snapping files, set the file name here
snap_file: "snap.js"
snap_file: "path/to/snap.js"

# Type the name of the directory that shots will be stored in
directory:
Expand Down Expand Up @@ -140,8 +135,30 @@ phantomjs_options: "--ignore-ssl-errors=true"
```
## Using Wraith
### Wraith Gem
You can type `wraith` into terminal to bring up the list of commands, but the one to start Wraith is

If you are new to ruby, rake and PhantomJS, [here is a great screencast](http://www.youtube.com/watch?v=gE_19L0l2q0) about how to use Wraith by [Kevin Lamping](https://twitter.com/klamping)
```sh
wraith capture config_name
```

This assumes that your snap.js and config.yaml are in the folders that were created on setup. There are other commands also available, these all expect a config_name to be passed as an option.

```sh
wraith capture config_name # A full Wraith job
wraith compare_images # compares images to generate diffs
wraith crop_images # crops images to the same height
wraith folders # create folders for images
wraith generate_gallery # create page for viewing images
wraith generate_thumbnails # create thumbnails for gallery
wraith reset_shots # removes all the files in the shots folder
wraith save_images # captures screenshots
wraith setup # creates config folder and default config
```

### Wraith Rake tasks

If you want to use the rake task instead of the gem, you can use the following.

There are two ways of using Wraith, the fastest is to simply type rake.

Expand All @@ -158,6 +175,7 @@ rake config[config_name]
On Windows before running the rake command you will need to make a small edit to the wraith.rb file.
Locate lines 60 and 70 and switch the commenting as described.

If you are new to ruby, rake and PhantomJS, [here is a great screencast](http://www.youtube.com/watch?v=gE_19L0l2q0) about how to use Wraith by [Kevin Lamping](https://twitter.com/klamping)

## Output

Expand Down Expand Up @@ -187,8 +205,8 @@ If you want to add functionality to this project, pull requests are welcome.

**Please raise any issues with this project as a GitHub issue.**

## Changelog - updated 24/01/14
New features include some refactoring and the start of additional cli work. We have removed the webdriver features for the time being, this will return in a more capable and fully feature state.
## Changelog - updated 2014-02-09
We have released Wraith as a Ruby Gem!! There is a new CLI to better interact with Wraith and it's commands.

## License

Expand Down
10 changes: 6 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require 'wraith/folder'
require 'wraith/thumbnails'
require 'wraith/compare_images'
require 'wraith/images'
require 'wraith/gallery'

@config = ('config')

Expand Down Expand Up @@ -47,12 +48,12 @@ task :save_images do
end

task :crop_images do
crop = Wraith::CropImages.new(@save_images.directory)
crop = Wraith::CropImages.new(@config)
crop.crop_images
end

task :check_images do
image = Wraith::Images.new(@save_images.directory)
image = Wraith::Images.new(@config)
image.files
end

Expand All @@ -62,7 +63,8 @@ task :generate_thumbnails do
end

task :generate_gallery do
sh "ruby lib/wraith/gallery.rb #{@save_images.directory}"
gallery = Wraith::GalleryGenerator.new(@config)
gallery.generate_gallery
end

task :grabber, [:yaml] do |t, custom|
Expand All @@ -73,4 +75,4 @@ end

task :grab => [:reset_shots_folder, :check_for_paths, :setup_folders, :save_images, :generate_thumbnails, :generate_gallery] do
puts 'Done!';
end
end
File renamed without changes
43 changes: 9 additions & 34 deletions bin/wraith
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
23 changes: 2 additions & 21 deletions lib/wraith.rb
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
95 changes: 86 additions & 9 deletions lib/wraith/cli.rb
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
Loading

0 comments on commit dd39c25

Please sign in to comment.