rscript 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bcf43718d97e71fe37bee3a62f1770d1a55254e59d892462f879864faf653688
4
- data.tar.gz: ff8a1cf984cc885b90d119a47b9354185df2b16081f7547feb8b5e2ab1bb1fc2
3
+ metadata.gz: 8aec962ed289a675c59189eb2bd7d5c8c28cbdb0e6c35e2fa127f9c7336f181d
4
+ data.tar.gz: acda35d707dc3d0162b889f4920354de05f3d4621c2f5c8fc04a613bab57b5f2
5
5
  SHA512:
6
- metadata.gz: fc56fc7b376efeeabf272a0f85d4512daf274b2203d1ede851abc05e37685e895e9bacf8b0a5b66741b6646f2b5ea45e4e880887af785aeaa585781ab964597b
7
- data.tar.gz: 2d70b5ede964d1516e90c0a22887ccf714cf6bb7cccdd678b93ff2d07a9df767879397eaf4c2d172dbabeb2c81dc78c73de27064cfcbc80950d6e163160b2fc8
6
+ metadata.gz: 3432b133427da64d0e5efc87df4907751fe0e906e2bf711e2037fb6fc2d0d5e35a2400ee0e25421b2bc56d06275706b9bbf0ef9070049c823d16a7af1a6c68ea
7
+ data.tar.gz: 74b615fe0c30f3828fde0f1fb5625f468fa6405ed510ccdc8571893dc9b63d1444d8cbe349cfc555023c26915c1c33081d1e8105f104368fb88a4d4fbce3f8e8
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/rscript.rb CHANGED
@@ -48,37 +48,144 @@ require 'hashcache'
48
48
  require 'rexle'
49
49
 
50
50
 
51
- class RScriptBase
51
+ class RScript < RScriptBase
52
+
53
+ def initialize(log: nil, pkg_src: '', cache: 5, debug: false, type: 'job')
54
+
55
+ puts 'inside RScript' if @debug
56
+ @log = log
57
+ @cache = cache
58
+ @rsf_cache = HashCache.new({cache: cache}) if cache and cache > 0
59
+ @jobname = type
60
+ super(debug: debug)
61
+
62
+ end
52
63
 
53
- def initialize(debug: false)
54
- @debug = debug
64
+ def jobs(package)
65
+ a = read_rsfdoc([package])
66
+ a.map(&:first).uniq
55
67
  end
56
68
 
57
- def read(doc)
58
- doc.root.xpath('//script').map {|s| run_script(s)}.join(';')
69
+ def read(raw_args=[])
70
+
71
+ puts 'inside read' if @debug
72
+ args = raw_args.clone
73
+ @log.info 'RScript/read: args: ' + args.inspect if @log
74
+
75
+ threads = []
76
+
77
+ if args.to_s[/\/\/#{@jobname}:/] then
78
+ ajob = ''
79
+ args.each_index do |i|
80
+ if args[i].to_s[/\/\/#{@jobname}:/] then
81
+ ajob = $'; args[i] = nil
82
+ end
83
+ end
84
+
85
+ args.compact!
86
+ puts 'before read_rsfdoc' if @debug
87
+ a = read_rsfdoc(args)
88
+ job = a.assoc(ajob.to_sym)
89
+ out, attr = job.last[:code], job.last[:attributes]
90
+
91
+ raise "job not found" unless out.length > 0
92
+ out
93
+
94
+ else
95
+ out = read_rsfdoc(args).map {|x| x.last[:code]}.join("\n")
96
+ end
97
+
98
+ @log.info 'RScript/read: code: ' + out.inspect if @log
99
+
100
+ [out, args, attr]
59
101
  end
102
+
103
+ def reset()
104
+ @rsf_cache.reset
105
+ end
106
+
107
+ # note: run() was copied from the development file rscript-wrapper.rb
108
+ def run(raw_args, params={}, rws=self)
109
+
110
+ @log.info 'RScript/run: raw_args: ' + raw_args.inspect if @log
111
+ puts 'raw_args: ' + raw_args.inspect if @debug
112
+
113
+ if params and params[:splat] then
114
+ params.each do |k,v|
115
+ params.delete k unless k == :splat or k == :package or k == :job or k == :captures
116
+ end
117
+ end
118
+
119
+ if params and params[:splat] and params[:splat].length > 0 then
120
+ h = params[:splat].first[1..-1].split('&').inject({}) do |r,x|
121
+ k, v = x.split('=')
122
+ v ? r.merge(k[/\w+$/].to_sym => v) : r
123
+ end
124
+ params.merge! h
125
+ end
126
+
127
+ code2, args, attr = self.read raw_args.clone
128
+ puts 'code2 : ' + code2.inspect if @debug
129
+ @log.info 'RScript/run: code2: ' + code2 if @log
130
+
131
+ begin
132
+
133
+ r = eval code2
134
+
135
+ params = {}
136
+
137
+ return r
138
+
139
+ rescue Exception => e
140
+ params = {}
141
+ err_label = e.message.to_s + " :: \n" + e.backtrace.join("\n")
142
+ @log.debug 'rscrcript/error: ' + err_label
143
+ return err_label
144
+ end
145
+
146
+ end
60
147
 
61
- protected
148
+ private
62
149
 
63
- def read_script(script)
64
- puts 'inside read_script' if @debug
65
- out_buffer = ''
150
+ def build_a(rsfile)
66
151
 
67
- src = script.attributes[:src]
152
+ buffer = read_sourcecode(rsfile)
153
+ puts 'buffer: ' + buffer.inspect if @debug
154
+
155
+ doc = Rexle.new(buffer)
156
+ puts 'after Rexle' if @debug
157
+
158
+ doc.root.xpath("//#{@jobname}").inject([]) do |r,x|
159
+ puts 'x: ' + x.inspect if @debug
160
+ codeblock = x.xpath('//script')\
161
+ .map {|s| read_script(s)}.join("\n")
162
+ r << [x.attributes[:id].to_sym, {attributes: x.attributes,
163
+ code: codeblock}]
164
+ end
165
+
166
+ end
167
+
168
+ def read_rsfdoc(args=[])
169
+
170
+ puts 'args: ' + args.inspect if @debug
171
+ rsfile = args[0]; args.shift
172
+
173
+ $rsfile = rsfile[/[^\/]+(?=\.rsf)/]
174
+
175
+ a = @cache ? @rsf_cache.read(rsfile) { build_a(rsfile) } : build_a(rsfile)
176
+ puts 'read_rsfdoc a: ' + a.inspect if @debug
68
177
 
69
- out_buffer = if src then
70
- read_sourcecode(script.attributes[:src].to_s)
71
- else
72
- script.texts.join("\n")
73
- end
178
+ @url_base = rsfile[/\w+:\/\/[^\/]+/]
74
179
 
75
- out_buffer
76
- end
77
-
78
- def read_sourcecode(rsf)
79
- puts 'inside read_sourcecode' if @debug
80
- buffer, _ = RXFHelper.read rsf, auto: false
81
- return buffer
82
- end
180
+ return a
181
+
182
+ end
83
183
 
84
184
  end
185
+
186
+ if __FILE__ == $0 then
187
+ raw_args = ARGV
188
+ rs = RScript.new()
189
+ code, args = rs.read(raw_args)
190
+ puts eval(code).join("\n")
191
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rscript
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file