olsen 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- olsen (0.0.3)
4
+ olsen (0.0.5)
5
5
  sadie
6
6
 
7
7
  GEM
@@ -14,7 +14,7 @@ GEM
14
14
  deprecated (= 2.0.1)
15
15
  deprecated (2.0.1)
16
16
  mysql (2.8.1)
17
- sadie (0.0.34)
17
+ sadie (0.0.35)
18
18
  dbd-mysql
19
19
  dbi
20
20
  mysql
data/README CHANGED
@@ -1 +1,17 @@
1
- Olsen is a simple reporter. More later.
1
+ =Olsen
2
+ ==A simple reporter.
3
+
4
+ ===Overview
5
+ Olsen is a framework that wraps the Sadie gem and provides a facility for producing reports which make use of data managed in a Sadie-style primer chassis.
6
+
7
+ ===Usage
8
+ 1. create/choose a directory to put the olsen framework in (or use /var/olsen, the default...ensure writable)
9
+ 2. call olsen -init [ -framework-dir /my/dir ]
10
+ 3. define jobs in jobs folder and filters, outputs, and inbound data primers in primers folder
11
+ 4. call olsen -process <job>
12
+ 5. find output product in output folder
13
+ 6. Rejoice!
14
+
15
+ ===Todo
16
+ * enable a 'olsen -init -with-examples' that will create a functioning olsen framework with example ini files, sqlite databases and queries, pdf outputs, formatting filters, etc.
17
+ * provide docs on job and pdf ini-file format
data/bin/olsen CHANGED
@@ -1,14 +1,69 @@
1
1
  #!/usr/bin/env ruby
2
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
2
3
 
3
- # run report for each input file
4
- nomoreopts = false
5
- ARGV.each do |infile|
6
-
7
-
8
- puts "processing: #{infile}"
9
-
10
- Olsen.process infile
11
-
12
-
4
+ require 'olsen'
5
+
6
+ # define usage writer
7
+ def write_usage( msg=nil )
8
+ if defined? msg
9
+ puts "\n=== ERR: #{msg} ===\n\n"
10
+ end
11
+ usage_text = <<TXT
12
+
13
+ # to init framework with examples
14
+ olsen -init -framework-dir <dir> # defaults to /var/olsen
15
+
16
+ # to process jobs
17
+ olsen -process [-framework-dir <dir>] <job1> <job2> ... <jobn>
18
+
19
+ TXT
20
+ puts "USAGE:\n#{usage_text}"
21
+ end
22
+
23
+ # validate args
24
+ if ARGV.length < 1
25
+ write_usage "not enough arguments"
26
+ exit
13
27
  end
14
28
 
29
+ mainarg = ARGV.first
30
+ secarg = ARGV[1]
31
+ framework_dirpath = "/var/olsen"
32
+ restargs = ARGV[1..(ARGV.length-1)]
33
+ if secarg == "-framework-dir"
34
+ if ARGV.length < 3
35
+ write_usage "no framework dir given"
36
+ exit
37
+ end
38
+ framework_dirpath = ARGV[2]
39
+ if mainarg == "-process"
40
+ if ARGV.length < 4
41
+ write_usage "no jobs listed"
42
+ exit
43
+ end
44
+ restargs = ARGV[3..(ARGV.length-1)]
45
+ end
46
+ end
47
+
48
+ Olsen.setFrameworkDir framework_dirpath
49
+
50
+ if ARGV.length > 0
51
+ case mainarg
52
+ when "-process"
53
+ # process each input file
54
+ restargs.each do |infile|
55
+ puts "processing: #{infile}"
56
+ Olsen.process infile
57
+ end
58
+ when "-init"
59
+ if ! File.writable? framework_dirpath
60
+ write_usage "directory not writable (#{framework_dirpath})"
61
+ end
62
+ Olsen.initFramework
63
+ else
64
+ write_usage
65
+ exit
66
+ end
67
+ end
68
+
69
+
data/lib/olsen.rb CHANGED
@@ -12,7 +12,6 @@ def O( key, params=nil )
12
12
  if defined? params
13
13
  if params.respond_to? "has_key?"
14
14
  if params.has_key? :filter
15
- # puts "got filter!!!"
16
15
  filter = params[:filter]
17
16
  if filter.respond_to? "each"
18
17
  ret = Olsen::filter instance.get( key ), filter
@@ -24,7 +23,6 @@ def O( key, params=nil )
24
23
  end
25
24
  end
26
25
  end
27
- # puts "O(#{key}): NO PARAMS?"
28
26
  instance.get( key )
29
27
 
30
28
  end
@@ -33,8 +31,6 @@ class Olsen
33
31
 
34
32
  def self.filter( value, filters )
35
33
 
36
- # puts "filters: #{filters}"
37
-
38
34
  # validate filters
39
35
  defined? filters \
40
36
  or return value
@@ -43,13 +39,9 @@ class Olsen
43
39
 
44
40
  instance = Sadie::getCurrentSadieInstance
45
41
 
46
- #pp(instance)
47
-
48
42
  fhnd = "filter.#{filters[0]}"
49
43
  f = instance.get fhnd
50
44
 
51
- # puts "f(#{fhnd}): #{f}"
52
-
53
45
  if filters.length > 1
54
46
  rem = filters[1..(filters.length-1)]
55
47
  ret = f.call value
@@ -61,14 +53,24 @@ class Olsen
61
53
  end
62
54
  end
63
55
 
56
+ def self.initFramework
57
+ if ! defined? @@framework_dirpath
58
+ puts "framework dirpath not set...aborting."
59
+ return nil
60
+ end
61
+ puts "initializing olsen framework in #{@@framework_dirpath}"
62
+ [ "output", "jobs", "primers" ].each do |dir|
63
+ Dir.mkdir File.join( @@framework_dirpath, dir )
64
+ end
65
+ end
66
+
67
+ def self.setFrameworkDir( dirpath )
68
+ @@framework_dirpath = dirpath
69
+ end
70
+
64
71
  def self.registerFilter( name, &block )
65
72
  instance = Sadie::getCurrentSadieInstance
66
73
  instance.set "filter.#{name}", block
67
- # if ! defined? @@filters
68
- # @@filters = { name => block }
69
- # else
70
- # @@filters[name] = block
71
- # end
72
74
  end
73
75
 
74
76
  def self.initSadie( params )
@@ -99,10 +101,19 @@ class Olsen
99
101
  end
100
102
 
101
103
  # init sadie
102
- # puts "init storage!"
103
104
  storage = Sadie::getSadieInstance( sadieparams )
104
105
 
105
-
106
+ # add olsen plugin handlers
107
+ plugins_dirpath = File.join(
108
+ ENV['GEM_HOME'],
109
+ "gems/olsen-#{Olsen::VERSION}",
110
+ "lib/olsen/primer_plugins"
111
+ )
112
+ if ! File.exists? plugins_dirpath # for dev
113
+ plugins_dirpath = "lib/olsen/primer_plugins"
114
+ end
115
+ storage.addPrimerPluginsDirPath plugins_dirpath
116
+ storage.initializePrimers
106
117
  end
107
118
 
108
119
  def self.process( job, storage )
@@ -112,9 +123,16 @@ class Olsen
112
123
  return nil
113
124
  end
114
125
 
126
+ # turn files into hashes
115
127
  if ! job.respond_to? "each"
116
128
  if File.exists? job
117
129
  job = Sadie::iniFileToHash( job )
130
+ elsif defined? @@framework_dirpath
131
+ jobdirpath = File.join( @@framework_dirpath, "jobs" )
132
+ jobfile = File.join jobdirpath, "#{job}.job"
133
+ if File.exists? jobfile
134
+ job = Sadie::iniFileToHash( jobfile )
135
+ end
118
136
  else
119
137
  puts "job param was non-hash and was not a path to valid job file"
120
138
  return nil
@@ -126,29 +144,9 @@ class Olsen
126
144
  puts "job has no output definition"
127
145
  return nil
128
146
  end
129
-
130
- # sadieparams = {
131
- # "sadie.primer_plugins_dirpath" => "lib/olsen/primer_plugins",
132
- # "sadie.primers_dirpath" => "primers"
133
- # }
134
-
135
- # set keys from job
136
- # [ "sadie", "parameters","olsen" ].each do |ptype|
137
- # if job.has_key? ptype
138
- # job[ptype].each do |key,value|
139
- # if ptype.eql? "sadie"
140
- # sadieparams["sadie.#{key}"] = value
141
- # else
142
- # sadieparams["#{key}"] = value
143
- # end
144
- # end
145
- # end
146
- # end
147
-
148
-
149
-
150
-
147
+
151
148
  # call output triggers
149
+ storage = Sadie::getCurrentSadieInstance
152
150
  job["output"].each do |x,type|
153
151
  outputkey = "output.#{type}"
154
152
  puts "processing output trigger: #{outputkey}"
data/lib/olsen/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Olsen
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -0,0 +1,39 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
2
+ $:.unshift ENV["GEM_HOME"]
3
+
4
+ require "test/unit"
5
+ require "sadie"
6
+ require "olsen"
7
+ require "tmpdir"
8
+
9
+ class TestInitFramework < Test::Unit::TestCase
10
+ def test_simple
11
+ #ofdir = "test/olsen_framework_test"
12
+
13
+ Dir.mktmpdir("olsen_testdir") do | dir |
14
+
15
+ # create temp output and sessdirs
16
+ outputdir = File.join( dir, "output" )
17
+ Dir.mkdir outputdir
18
+ sessdir = File.join( dir, "session" )
19
+ Dir.mkdir sessdir
20
+
21
+ s = Olsen::initSadie( "sadie.primers_dirpath" => "#{ofdir}/primers",
22
+ "sadie.sessions_dirpath" => sessdir,
23
+ "olsen.output_dirpath" => outputdir )
24
+
25
+ # --------------- test pdf ---------------
26
+ # process some olsenry
27
+ output = nil
28
+ Olsen::process( File.join( ofdir, "jobs/outputtest_pdf.job" ),s ) do |sadie|
29
+
30
+
31
+ # test
32
+ output_path = sadie.get( "output.outputtest_pdf.pdf" )
33
+ output = File.exists? output_path
34
+ end
35
+ assert_equal( output, true )
36
+
37
+ end
38
+ end
39
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: olsen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-17 00:00:00.000000000Z
12
+ date: 2012-04-18 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sadie
16
- requirement: &13544120 !ruby/object:Gem::Requirement
16
+ requirement: &11535020 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *13544120
24
+ version_requirements: *11535020
25
25
  description: Olsen is a reporting tool intended to be used with Sadie.
26
26
  email:
27
27
  - fred@landmetrics.com
@@ -46,7 +46,6 @@ files:
46
46
  - lib/olsen/primer_plugins/Filter.plugin.rb
47
47
  - lib/olsen/primer_plugins/PDFINI.plugin.rb
48
48
  - lib/olsen/version.rb
49
- - olsen-0.0.2.gem
50
49
  - olsen.gemspec
51
50
  - test/olsen_framework_test/jobs/outputtest_filter.job
52
51
  - test/olsen_framework_test/jobs/outputtest_ltx.job
@@ -67,6 +66,7 @@ files:
67
66
  - test/olsen_framework_test/primers/output/outputtext_tex.tex.erb
68
67
  - test/olsen_framework_test/primers/testdata.ini
69
68
  - test/tc_framework_outputtest.rb
69
+ - test/tc_initframework.rb
70
70
  - test/tc_outputpdf.rb
71
71
  - test/tc_outputsimple.rb
72
72
  homepage: http://www.landmetrics.com/Olsen