<commit_before>= RightScraper

== DESCRIPTION

=== Synopsis

RightScraper provides a simple interface to download and keep repositories up-to-date 
using various protocols.

The supported protocols include:
- *git*: RightScraper will clone then pull repos from git
- *SVN*: RightScraper will checkout then update SVN repositories
- *tarballs*: Includes uncompressed (.tar), gzip (.tgz, .gzip) and bzip (.bzip, .bzip2) tar files.

The scraper first inspects the local directory to see if the repo has already been scraped
and if so runs some basic checks before it tries to update it. Incremental updates are not
supported with tar files.

=== Rationale

The idea is to have many repos that need to be downloaded/kept up-to-date in a central
place. Point the scraper to this central place and it will take care of creating unique
local directories for each remote repository and keep that mapping to download changes
incrementally upon request.

== USAGE

=== Simple Example

 require 'rubygems'
 require 'right_scraper'

 scraper = RightScale::Scraper.new('/tmp')
 scraper.scrape(:type => :git, :url => 'git://github.com/rightscale/right_scraper.git')

== INSTALLATION

RightScraper can be installed by entering the following at the command prompt:

 gem install right_scraper

== DEPENDENCIES

RightScraper relies on the following tools:
- git
- svn
- curl

== TESTING

Install the following RubyGems required for testing:
- rspec

The build can be tested using the RSpec gem.

 rake spec

== CODE OVERVIEW

The main interface to right_scraper is RightScale::Scraper.  If
you're interested in digging in deeper, there are several major moving
parts to be aware of.

=== Repositories, Scrapers and Cookbooks

A RightScale::Repository completely defines how to access a specific
repository (including revision information as appropriate).
Repository definitions are in <tt>lib/right_scraper/repositories</tt> and
should inherit from RightScale::Repository.

Scrapers are subclasses of RightScale::Scrapers::ScraperBase, and can
scan a repository and return a number of RightScale::Cookbook
instances.  Scrapers live in <tt>lib/right_scraper/scrapers</tt>.
Scrapers should never be instantiated directly, only through
repositories.  Scrapers implement a stream-type interface like +IO+
streams and +Dir+ instances.

Cookbooks, gotten from scrapers, are instances of
RightScale::Cookbook.  Cookbooks can be converted to and from URL-type
syntaxes with RightScale::Cookbook#to_url and
RightScale::Cookbook::from_url, with the caveat that it is not at
present possible to perfectly reconstruct the repository a cookbook
uses from the cookbook URL.

=== Scraper Hooks

There are two interesting classes of scraper hooks; builders, which
scan a tree on the filesystem, and scanners, which handle
filesystem-like structures in memory.  Both these are needed because a
scraper is allowed to operate in a streaming fashion (and indeed
RightScale::Scrapers::Download does), meaning that there is never an
actual filesysteme tree.  Builders can be specified in the
<tt>:builders</tt> argument and scanners can be specified in the
<tt>:scanners</tt> argument to RightScale::Scrapers::ScraperBase#new.

== LICENSE

<b>RightScraper</b>

Copyright:: Copyright (c) 2010 RightScale, Inc. 

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
<commit_msg>Add some documentation of the callback interface.<commit_after>= RightScraper

== DESCRIPTION

=== Synopsis

RightScraper provides a simple interface to download and keep repositories up-to-date 
using various protocols.

The supported protocols include:
- *git*: RightScraper will clone then pull repos from git
- *SVN*: RightScraper will checkout then update SVN repositories
- *tarballs*: Includes uncompressed (.tar), gzip (.tgz, .gzip) and bzip (.bzip, .bzip2) tar files.

The scraper first inspects the local directory to see if the repo has already been scraped
and if so runs some basic checks before it tries to update it. Incremental updates are not
supported with tar files.

=== Rationale

The idea is to have many repos that need to be downloaded/kept up-to-date in a central
place. Point the scraper to this central place and it will take care of creating unique
local directories for each remote repository and keep that mapping to download changes
incrementally upon request.

== USAGE

=== Simple Example

 require 'rubygems'
 require 'right_scraper'

 scraper = RightScale::Scraper.new('/tmp')
 scraper.scrape(:type => :git, :url => 'git://github.com/rightscale/right_scraper.git')

=== More complex example

 require 'rubygems'
 require 'right_scraper'

 url = 'git://github.com/rightscale/right_scraper.git'
 scraper = RightScale::Scraper.new('/tmp')
 scraper.scrape(:type => :git, :url => url) do |phase, op, info, exception|
   ...
 end

Here the block will be called several times during the scraping
process.  The arguments are as follows:

+phase+:: One of <tt>:begin</tt>, <tt>:commit</tt> or <tt>:abort</tt>.
          <tt>:begin</tt> means that the operation is beginning,
          <tt>:commit</tt> means that the operation has completed
          successfully, and <tt>:abort</tt> means that the operation
          has triggered an error and is being aborted.
+op+:: Symbol representing the operation being performed.  The only
       operation guaranteed to be signalled is <tt>:scraping</tt>,
       which is begun at the start of the +scrape+ call and completed
       at the end, but version control systems typically trigger
       operations like <tt>:checkout</tt> or <tt>:cloning</tt>.
+info+:: Optional English language information, typically clarifying
         the repository being cloned or other data +op+ is presumed to
         be operating on.
+exception+:: Non-nil only in an abort phase, this is the exception
              that triggered the abort.

== INSTALLATION

RightScraper can be installed by entering the following at the command prompt:

 gem install right_scraper

== DEPENDENCIES

RightScraper relies on the following tools:
- git
- svn
- curl

== TESTING

Install the following RubyGems required for testing:
- rspec

The build can be tested using the RSpec gem.

 rake spec

== CODE OVERVIEW

The main interface to right_scraper is RightScale::Scraper.  If
you're interested in digging in deeper, there are several major moving
parts to be aware of.

=== Repositories, Scrapers and Cookbooks

A RightScale::Repository completely defines how to access a specific
repository (including revision information as appropriate).
Repository definitions are in <tt>lib/right_scraper/repositories</tt> and
should inherit from RightScale::Repository.

Scrapers are subclasses of RightScale::Scrapers::ScraperBase, and can
scan a repository and return a number of RightScale::Cookbook
instances.  Scrapers live in <tt>lib/right_scraper/scrapers</tt>.
Scrapers should never be instantiated directly, only through
repositories.  Scrapers implement a stream-type interface like +IO+
streams and +Dir+ instances.

Cookbooks, gotten from scrapers, are instances of
RightScale::Cookbook.  Cookbooks can be converted to and from URL-type
syntaxes with RightScale::Cookbook#to_url and
RightScale::Cookbook::from_url, with the caveat that it is not at
present possible to perfectly reconstruct the repository a cookbook
uses from the cookbook URL.

=== Scraper Hooks

There are two interesting classes of scraper hooks; builders, which
scan a tree on the filesystem, and scanners, which handle
filesystem-like structures in memory.  Both these are needed because a
scraper is allowed to operate in a streaming fashion (and indeed
RightScale::Scrapers::Download does), meaning that there is never an
actual filesysteme tree.  Builders can be specified in the
<tt>:builders</tt> argument and scanners can be specified in the
<tt>:scanners</tt> argument to RightScale::Scrapers::ScraperBase#new.

== LICENSE

<b>RightScraper</b>

Copyright:: Copyright (c) 2010 RightScale, Inc. 

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

{'fraction_non_alphanumeric': 0.06372499748718465, 'fraction_numerical': 0.001005126143330988, 'mean_word_length': 4.734870317002882, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3333918', 'n_tokens_mistral': 2722, 'n_tokens_neox': 2599, 'n_words': 1316}