bjornno-ruby-batch 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +0 -0
- data/LICENSE +22 -0
- data/README.rdoc +48 -0
- data/Rakefile +162 -0
- data/lib/ruby-batch.rb +72 -0
- data/ruby-batch.gemspec +38 -0
- data/test/printfile_test.rb +17 -0
- data/test/test_helper.rb +3 -0
- metadata +66 -0
data/ChangeLog
ADDED
File without changes
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2008 Bj�rn Nordlund
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
= ruby-batch
|
2
|
+
|
3
|
+
* FIX (url)
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
FIX (describe your package)
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* FIX (list of features or problems)
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
FIX (code sample of usage)
|
16
|
+
|
17
|
+
== REQUIREMENTS:
|
18
|
+
|
19
|
+
* FIX (list of requirements)
|
20
|
+
|
21
|
+
== INSTALL:
|
22
|
+
|
23
|
+
* FIX (sudo gem install, anything else)
|
24
|
+
|
25
|
+
== LICENSE:
|
26
|
+
|
27
|
+
(The MIT License)
|
28
|
+
|
29
|
+
Copyright (c) 2008 FIXME full name
|
30
|
+
|
31
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
32
|
+
a copy of this software and associated documentation files (the
|
33
|
+
'Software'), to deal in the Software without restriction, including
|
34
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
35
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
36
|
+
permit persons to whom the Software is furnished to do so, subject to
|
37
|
+
the following conditions:
|
38
|
+
|
39
|
+
The above copyright notice and this permission notice shall be
|
40
|
+
included in all copies or substantial portions of the Software.
|
41
|
+
|
42
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
43
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
44
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
45
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
46
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
47
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
48
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/clean'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
task :default => :test
|
6
|
+
|
7
|
+
# SPECS ===============================================================
|
8
|
+
|
9
|
+
desc 'Run specs with story style output'
|
10
|
+
task :spec do
|
11
|
+
sh 'specrb --specdox -Ilib:test test/*_test.rb'
|
12
|
+
end
|
13
|
+
|
14
|
+
desc 'Run specs with unit test style output'
|
15
|
+
task :test => FileList['test/*_test.rb'] do |t|
|
16
|
+
suite = t.prerequisites.map{|f| "-r#{f.chomp('.rb')}"}.join(' ')
|
17
|
+
sh "ruby -Ilib:test #{suite} -e ''", :verbose => false
|
18
|
+
end
|
19
|
+
|
20
|
+
# PACKAGING ============================================================
|
21
|
+
|
22
|
+
# Load the gemspec using the same limitations as github
|
23
|
+
def spec
|
24
|
+
@spec ||=
|
25
|
+
begin
|
26
|
+
require 'rubygems/specification'
|
27
|
+
data = File.read('ruby-batch.gemspec')
|
28
|
+
spec = nil
|
29
|
+
Thread.new { spec = eval("$SAFE = 3\n#{data}") }.join
|
30
|
+
spec
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def package(ext='')
|
35
|
+
"dist/ruby-batch-#{spec.version}" + ext
|
36
|
+
end
|
37
|
+
|
38
|
+
desc 'Build packages'
|
39
|
+
task :package => %w[.gem .tar.gz].map {|e| package(e)}
|
40
|
+
|
41
|
+
desc 'Build and install as local gem'
|
42
|
+
task :install => package('.gem') do
|
43
|
+
sh "gem install #{package('.gem')}"
|
44
|
+
end
|
45
|
+
|
46
|
+
directory 'dist/'
|
47
|
+
|
48
|
+
file package('.gem') => %w[dist/ ruby-batch.gemspec] + spec.files do |f|
|
49
|
+
sh "gem build ruby-batch.gemspec"
|
50
|
+
mv File.basename(f.name), f.name
|
51
|
+
end
|
52
|
+
|
53
|
+
file package('.tar.gz') => %w[dist/] + spec.files do |f|
|
54
|
+
sh "git archive --format=tar HEAD | gzip > #{f.name}"
|
55
|
+
end
|
56
|
+
|
57
|
+
# Rubyforge Release / Publish Tasks ==================================
|
58
|
+
|
59
|
+
desc 'Publish website to rubyforge'
|
60
|
+
task 'publish:doc' => 'doc/api/index.html' do
|
61
|
+
sh 'scp -rp doc/* rubyforge.org:/var/www/gforge-projects/ruby-batch/'
|
62
|
+
end
|
63
|
+
|
64
|
+
task 'publish:gem' => [package('.gem'), package('.tar.gz')] do |t|
|
65
|
+
sh <<-end
|
66
|
+
rubyforge add_release ruby-batch ruby-batch #{spec.version} #{package('.gem')} &&
|
67
|
+
rubyforge add_file ruby-batch ruby-batch #{spec.version} #{package('.tar.gz')}
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Website ============================================================
|
72
|
+
# Building docs requires HAML and the hanna gem:
|
73
|
+
# gem install mislav-hanna --source=http://gems.github.com
|
74
|
+
|
75
|
+
task 'doc' => ['doc:api','doc:site']
|
76
|
+
|
77
|
+
desc 'Generate Hanna RDoc under doc/api'
|
78
|
+
task 'doc:api' => ['doc/api/index.html']
|
79
|
+
|
80
|
+
file 'doc/api/index.html' => FileList['lib/**/*.rb','README.rdoc'] do |f|
|
81
|
+
rb_files = f.prerequisites
|
82
|
+
sh((<<-end).gsub(/\s+/, ' '))
|
83
|
+
hanna --charset utf8 \
|
84
|
+
--fmt html \
|
85
|
+
--inline-source \
|
86
|
+
--line-numbers \
|
87
|
+
--main README.rdoc \
|
88
|
+
--op doc/api \
|
89
|
+
--title 'Ruby-batch API Documentation' \
|
90
|
+
#{rb_files.join(' ')}
|
91
|
+
end
|
92
|
+
end
|
93
|
+
CLEAN.include 'doc/api'
|
94
|
+
|
95
|
+
def rdoc_to_html(file_name)
|
96
|
+
require 'rdoc/markup/to_html'
|
97
|
+
rdoc = RDoc::Markup::ToHtml.new
|
98
|
+
rdoc.convert(File.read(file_name))
|
99
|
+
end
|
100
|
+
|
101
|
+
def haml(locals={})
|
102
|
+
require 'haml'
|
103
|
+
template = File.read('doc/template.haml')
|
104
|
+
haml = Haml::Engine.new(template, :format => :html4, :attr_wrapper => '"')
|
105
|
+
haml.render(Object.new, locals)
|
106
|
+
end
|
107
|
+
|
108
|
+
desc 'Build website HTML and stuff'
|
109
|
+
task 'doc:site' => ['doc/index.html', 'doc/book.html']
|
110
|
+
|
111
|
+
file 'doc/index.html' => %w[README.rdoc doc/template.haml] do |file|
|
112
|
+
File.open(file.name, 'w') do |file|
|
113
|
+
file << haml(:title => 'Ruby Batch', :content => rdoc_to_html('README.rdoc'))
|
114
|
+
end
|
115
|
+
end
|
116
|
+
CLEAN.include 'doc/index.html'
|
117
|
+
|
118
|
+
file 'doc/book.html' => ['book/output/ruby-batch-book.html'] do |file|
|
119
|
+
File.open(file.name, 'w') do |file|
|
120
|
+
book_content = File.read('book/output/ruby-batch-book.html')
|
121
|
+
file << haml(:title => 'Ruby Batch Book', :content => book_content)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
CLEAN.include 'doc/book.html'
|
125
|
+
|
126
|
+
file 'book/output/ruby-batch-book.html' => FileList['book/**'] do |f|
|
127
|
+
unless File.directory?('book')
|
128
|
+
sh 'git clone git://github.com/cschneid/ruby-batch-book.git book'
|
129
|
+
end
|
130
|
+
sh((<<-SH).strip.gsub(/\s+/, ' '))
|
131
|
+
cd book &&
|
132
|
+
git fetch origin &&
|
133
|
+
git rebase origin/master &&
|
134
|
+
thor book:build
|
135
|
+
SH
|
136
|
+
end
|
137
|
+
CLEAN.include 'book/output/ruby-batch-book.html'
|
138
|
+
|
139
|
+
desc 'Build the Ruby Batch book'
|
140
|
+
task 'doc:book' => ['book/output/ruby-batch-book.html']
|
141
|
+
|
142
|
+
# Gemspec Helpers ====================================================
|
143
|
+
|
144
|
+
file 'ruby-batch.gemspec' => FileList['{lib,test,images}/**','Rakefile'] do |f|
|
145
|
+
# read spec file and split out manifest section
|
146
|
+
spec = File.read(f.name)
|
147
|
+
parts = spec.split(" # = MANIFEST =\n")
|
148
|
+
fail 'bad spec' if parts.length != 3
|
149
|
+
# determine file list from git ls-files
|
150
|
+
files = `git ls-files`.
|
151
|
+
split("\n").
|
152
|
+
sort.
|
153
|
+
reject{ |file| file =~ /^\./ }.
|
154
|
+
reject { |file| file =~ /^doc/ }.
|
155
|
+
map{ |file| " #{file}" }.
|
156
|
+
join("\n")
|
157
|
+
# piece file back together and write...
|
158
|
+
parts[1] = " s.files = %w[\n#{files}\n ]\n"
|
159
|
+
spec = parts.join(" # = MANIFEST =\n")
|
160
|
+
File.open(f.name, 'w') { |io| io.write(spec) }
|
161
|
+
puts "updated #{f.name}"
|
162
|
+
end
|
data/lib/ruby-batch.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'sequel'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'ftools'
|
5
|
+
|
6
|
+
module Filescanner
|
7
|
+
|
8
|
+
def moveFile(fromfilename, fromdir, tofilename, todir)
|
9
|
+
|
10
|
+
if File.exist? fromdir+'/'+fromfilename
|
11
|
+
if !File.exist? todir
|
12
|
+
FileUtils.mkdir(todir)
|
13
|
+
end
|
14
|
+
puts 'moving file: ' + fromfilename
|
15
|
+
FileUtils.mv(fromdir+'/'+fromfilename, todir+tofilename)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
def startProcess(path, file)
|
21
|
+
moveFile(file, path, file, path + '/processing/')
|
22
|
+
file = File.open(path + '/processing/' + file, "r")
|
23
|
+
end
|
24
|
+
|
25
|
+
def endProcess(path, file)
|
26
|
+
moveFile(file, path + '/processing/', file +'-'+rand(999999).to_s.center(6, rand(9).to_s), path + '/processed/')
|
27
|
+
end
|
28
|
+
|
29
|
+
def filescan(path, regexp, &block)
|
30
|
+
if !File.exist? path
|
31
|
+
FileUtils.mkdir_p(path)
|
32
|
+
end
|
33
|
+
while true
|
34
|
+
Dir.foreach(path) do |filename|
|
35
|
+
if (File.fnmatch(regexp, filename)) #File.directory?(file) &&
|
36
|
+
file = startProcess(path,filename)
|
37
|
+
if file != nil
|
38
|
+
#DB.transaction do
|
39
|
+
yield block [file]
|
40
|
+
#end
|
41
|
+
file.close
|
42
|
+
end
|
43
|
+
endProcess(path, filename)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
sleep 5
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
module Dbscanner
|
53
|
+
def dbscan(db, queue, &block)
|
54
|
+
while true
|
55
|
+
db.transaction do
|
56
|
+
workset = db[:work_item].where(:processing_state => 0).where(:work_queue_id => queue)
|
57
|
+
work = workset.first
|
58
|
+
if work != nil
|
59
|
+
yield block [work]
|
60
|
+
workset.filter(:id => work[:id]).update(:processing_state => 3)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
sleep 10
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
include Filescanner
|
69
|
+
include Dbscanner
|
70
|
+
|
71
|
+
|
72
|
+
|
data/ruby-batch.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.specification_version = 2 if s.respond_to? :specification_version=
|
3
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
4
|
+
|
5
|
+
s.name = 'ruby-batch'
|
6
|
+
s.version = '0.1.1'
|
7
|
+
s.date = "2008-11-23"
|
8
|
+
|
9
|
+
s.description = "Simple batch frameork DSL"
|
10
|
+
s.summary = "Simple batch frameork DSL"
|
11
|
+
|
12
|
+
s.authors = ["Bj�rn Nordlund"]
|
13
|
+
|
14
|
+
# = MANIFEST =
|
15
|
+
s.files = %w[
|
16
|
+
ChangeLog
|
17
|
+
LICENSE
|
18
|
+
README.rdoc
|
19
|
+
Rakefile
|
20
|
+
|
21
|
+
lib/ruby-batch.rb
|
22
|
+
ruby-batch.gemspec
|
23
|
+
test/printfile_test.rb
|
24
|
+
test/test_helper.rb
|
25
|
+
]
|
26
|
+
# = MANIFEST =
|
27
|
+
|
28
|
+
s.test_files = s.files.select {|path| path =~ /^test\/.*_test.rb/}
|
29
|
+
|
30
|
+
s.extra_rdoc_files = %w[README.rdoc LICENSE]
|
31
|
+
|
32
|
+
s.has_rdoc = true
|
33
|
+
s.homepage = "http://ruby-batch.rubyforge.org"
|
34
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Ruby Batch", "--main", "README.rdoc"]
|
35
|
+
s.require_paths = %w[lib]
|
36
|
+
s.rubyforge_project = 'ruby-batch'
|
37
|
+
s.rubygems_version = '1.1.1'
|
38
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
filescan '/data/from_host/bjorn', 'bjorn*' do
|
4
|
+
|file|
|
5
|
+
if file != nil
|
6
|
+
puts '---------------'
|
7
|
+
puts 'reading file'
|
8
|
+
while line = file.gets
|
9
|
+
if (line != nil)
|
10
|
+
puts line
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
puts 'finished reading file'
|
15
|
+
puts '---------------'
|
16
|
+
|
17
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bjornno-ruby-batch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "Bj\xEF\xBF\xBDrn Nordlund"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-11-23 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Simple batch frameork DSL
|
17
|
+
email:
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
- LICENSE
|
25
|
+
files:
|
26
|
+
- ChangeLog
|
27
|
+
- LICENSE
|
28
|
+
- README.rdoc
|
29
|
+
- Rakefile
|
30
|
+
- lib/ruby-batch.rb
|
31
|
+
- ruby-batch.gemspec
|
32
|
+
- test/printfile_test.rb
|
33
|
+
- test/test_helper.rb
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: http://ruby-batch.rubyforge.org
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options:
|
38
|
+
- --line-numbers
|
39
|
+
- --inline-source
|
40
|
+
- --title
|
41
|
+
- Ruby Batch
|
42
|
+
- --main
|
43
|
+
- README.rdoc
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
requirements: []
|
59
|
+
|
60
|
+
rubyforge_project: ruby-batch
|
61
|
+
rubygems_version: 1.2.0
|
62
|
+
signing_key:
|
63
|
+
specification_version: 2
|
64
|
+
summary: Simple batch frameork DSL
|
65
|
+
test_files:
|
66
|
+
- test/printfile_test.rb
|