fizx-skivvies 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Kyle Maxwell
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,7 @@
1
+ = skivvies
2
+
3
+ Description goes here.
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2009 Kyle Maxwell. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "skivvies"
8
+ gem.summary = %Q{TODO}
9
+ gem.email = "kyle@kylemaxwell.com"
10
+ gem.homepage = "http://github.com/fizx/skivvies"
11
+ gem.authors = ["Kyle Maxwell"]
12
+
13
+ gem.add_dependency("fizx-parsley-ruby", ["= 0.4.0"])
14
+ gem.add_dependency("fizx-rwget", ["= 0.4.0"])
15
+ gem.add_dependency("fastercsv", [">= 0.5.0"])
16
+ end
17
+
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+
35
+ task :default => :spec
36
+
37
+ require 'rake/rdoctask'
38
+ Rake::RDocTask.new do |rdoc|
39
+ if File.exist?('VERSION.yml')
40
+ config = YAML.load(File.read('VERSION.yml'))
41
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
42
+ else
43
+ version = ""
44
+ end
45
+
46
+ rdoc.rdoc_dir = 'rdoc'
47
+ rdoc.title = "skivvies #{version}"
48
+ rdoc.rdoc_files.include('README*')
49
+ rdoc.rdoc_files.include('lib/**/*.rb')
50
+ end
51
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/skivvies ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + "/../lib/skivvies"
3
+
4
+ parser = RWGetOptionParser.new do |opts|
5
+ opts.on("--parselet=JSON_FILE", "JSON_FILE must implement a parsley script") do |path|
6
+ parser.options[:parselets] ||= []
7
+ parser.options[:parselets] << path
8
+ parser.options[:store_class] ||= :ParseletCSVStore
9
+ end
10
+
11
+ opts.on("--store_path=PATH", "PATH will contain csv files of the crawl") do |path|
12
+ parser.options[:store_path] = path
13
+ end
14
+ end
15
+
16
+ parser.parse!
17
+
18
+ if parser.options[:seeds].empty?
19
+ puts parser.usage
20
+ puts " -h for options listing"
21
+ exit(1)
22
+ end
23
+
24
+ controller = RWGet::Controller.new(parser.options)
25
+ begin
26
+ controller.start
27
+ ensure
28
+ STDERR.puts "Closing..."
29
+ controller.close
30
+ end
@@ -0,0 +1,84 @@
1
+ require "rubygems"
2
+ require "parsley"
3
+ require "faster_csv"
4
+ require "fileutils"
5
+
6
+ class ParseletCSVStore
7
+ include FileUtils
8
+
9
+ SUFFIX = "skivvies.csv"
10
+ def initialize(options = {})
11
+ @options = options
12
+ @handles = {}
13
+ @path = options[:store_path] || "."
14
+ mkdir_p @path
15
+ @keys = Dir[File.join(@path, "*.#{SUFFIX}")].inject({}) do |memo, path|
16
+ max = 0
17
+ File.open(path, "r").each do |line|
18
+ id = line.to_i
19
+ max = id if id > max
20
+ end
21
+ memo[path] = max
22
+ memo
23
+ end
24
+ @parselets = (options[:parselets] || []).map do |path|
25
+ Parsley.new(File.read(path), options)
26
+ end
27
+ raise "no parselets provided" if @parselets.empty?
28
+ end
29
+
30
+ def put(key, tmpfile)
31
+ path = tmpfile.path
32
+ data = @parselets.map do |parselet|
33
+ parselet.parse(options.merge(:file => path))
34
+ end
35
+ visit(data, "root")
36
+ rescue => e
37
+ STDERR.puts e.message
38
+ STDERR.puts e.backtrace.join("\n")
39
+ end
40
+
41
+ def close
42
+ @handles.values.map{|h| h.close}
43
+ @handles = {}
44
+ end
45
+
46
+ private
47
+
48
+ def visit(data, key, base = nil, base_id = nil)
49
+ if data.is_a?(Array)
50
+ data.each do |entry|
51
+ visit entry, key
52
+ end
53
+ return
54
+ end
55
+
56
+ raise "WTF: #{data.inspect}" unless data.is_a?(Hash)
57
+
58
+ row = []
59
+
60
+ data.each do |k, v|
61
+ if v.is_a?(String)
62
+ row << v
63
+ elsif v.is_a?(Array) && v.first.is_a?(String)
64
+ row << v.join("|")
65
+ else
66
+ visit(v, k)
67
+ end
68
+ end
69
+
70
+ unless row.empty?
71
+ row.unshift(key)
72
+ row.unshift(@keys[key] += 1)
73
+ handle(key) << row
74
+ end
75
+ end
76
+
77
+ def handle(key)
78
+ @handles[key] ||= FasterCSV.open(File.join(@path, "#{key}.#{SUFFIX}"), "a")
79
+ end
80
+
81
+ def max(key)
82
+ @keys[key] || 0
83
+ end
84
+ end
data/lib/skivvies.rb ADDED
@@ -0,0 +1,3 @@
1
+ require "rubygems"
2
+ require "rwget"
3
+ require File.dirname(__FILE__) + "/parselet_csv_store"
@@ -0,0 +1,5 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Type do
4
+
5
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Skivvies" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec'
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ require 'skivvies'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fizx-skivvies
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kyle Maxwell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-17 00:00:00 -07:00
13
+ default_executable: skivvies
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: fizx-parsley-ruby
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - "="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.4.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: fizx-rwget
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.4.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: fastercsv
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.5.0
44
+ version:
45
+ description:
46
+ email: kyle@kylemaxwell.com
47
+ executables:
48
+ - skivvies
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - LICENSE
53
+ - README.rdoc
54
+ files:
55
+ - .document
56
+ - .gitignore
57
+ - LICENSE
58
+ - README.rdoc
59
+ - Rakefile
60
+ - VERSION
61
+ - bin/skivvies
62
+ - lib/parselet_csv_store.rb
63
+ - lib/skivvies.rb
64
+ - spec/parselet_csv_store_spec.rb
65
+ - spec/skivvies_spec.rb
66
+ - spec/spec_helper.rb
67
+ has_rdoc: true
68
+ homepage: http://github.com/fizx/skivvies
69
+ post_install_message:
70
+ rdoc_options:
71
+ - --charset=UTF-8
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ version:
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: "0"
85
+ version:
86
+ requirements: []
87
+
88
+ rubyforge_project:
89
+ rubygems_version: 1.2.0
90
+ signing_key:
91
+ specification_version: 2
92
+ summary: TODO
93
+ test_files:
94
+ - spec/parselet_csv_store_spec.rb
95
+ - spec/skivvies_spec.rb
96
+ - spec/spec_helper.rb