rbbt-util 5.5.49 → 5.5.50

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- M2MyZWMzOTc4ODRkYTkzZDg1MTY2ZDlhZGMzN2NkMWE5YTJiN2JiZQ==
4
+ NGM4ZjliYTA2Y2UxYzNiZWY2NWM0N2Q5ZTI3MTFhNGU2ODI2Nzk3ZQ==
5
5
  data.tar.gz: !binary |-
6
- YjhmN2VjNzljNDMzOTlkNzRiMmNhOWE1ZDM0YmI4ZWIxYTkwNzE4NQ==
6
+ NmI0MTM4MjRhYTM3NjJmMWRiN2NjOTg3NDNjYTYxYjhjN2IzNDRhOQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YTVkM2M1MjdkMzJjYmZlMmJiM2NlM2UwYzNjNDg2ZWQxMDkxZjRiMTEwMWZk
10
- Yjg5YWMxNGUzN2VlOGU4YmFlMDc5ZGZmZTdlOTRkMmI1NWI2NzQ4OTI0ODZm
11
- YWZmMzE1ODJmZWM4MTBlNWE0M2U4YWNkNzI0YWEyYWQ2ZmJmZjI=
9
+ NTc0MThjZDQ5ZTMyMjM0MjM2ZTFhMDZiYTg5YzU5ZDJmZGE1Y2ExNTZmZWU0
10
+ M2RkOWI3NTJkNmU3NWVkYzFiZDRiY2M2YTExMTg4MmQ1M2U4N2Y3YWRmN2U4
11
+ NDFiMjFiNzRhMmJmNzgwOTEyYzM2MDk2YjkxNzIxMTY5YjA0YmY=
12
12
  data.tar.gz: !binary |-
13
- OGI2OTYyYzRkZmE0Y2ZhMjY2OWFhZDAwNGU0MzVkOTk3MzQwNWY2YzY0ZGM0
14
- ZTAxNzEzNzkxODZhYjBiZmMzNDc0MjBmM2RhM2MwMTRlYjYwZDc3NmRkZDE1
15
- ODU0MjhiNmM0ZWRlMjc5Mzc4Y2FlMjU2NDczODU2N2Y5YmJlM2Y=
13
+ M2UyM2MyMmZjODBhZjU4N2MzNzA1MTcyMWZlYTEzYTU3MmVmNWRlZGY5ZmU1
14
+ MWU1MTIyMzNiNTQyMzBiNDc4OGZjNmE3NDZhNjk3YTk3MTU2ODNmMjY1NmRj
15
+ NTliMWJiOTBiZDRjYmQwZTg1NWEyZDM3NmZlMzUzZTQ3NzIwNTI=
data/lib/rbbt/resource.rb CHANGED
@@ -58,27 +58,34 @@ module Resource
58
58
  def get_from_server(path, final_path)
59
59
  url = File.join(remote_server, '/resource/', self.to_s, 'get_file')
60
60
  url << "?" << Misc.hash2GET_params(:file => path, :create => false)
61
+
61
62
  begin
62
- response = Net::HTTP.get_response(URI(url))
63
-
64
- case response
65
- when Net::HTTPSuccess then
66
- #Misc.sensiblewrite(final_path, response.body)
67
- Misc.sensiblewrite(final_path){ Net::HTTP.get_response(URI(url)).body }
68
- when Net::HTTPRedirection then
69
- location = response['location']
70
- Log.debug("Feching directory from: #{location}. Into: #{final_path}")
71
- FileUtils.mkdir_p final_path unless File.exists? final_path
72
- Misc.in_dir final_path do
73
- CMD.cmd('tar xvfz -', :in => Open.open(location))
74
- end
75
- else
76
- raise "Response not understood: #{response.inspect}"
63
+ Net::HTTP.get_response URI(url) do |response|
64
+ case response
65
+ when Net::HTTPSuccess, Net::HTTPOK
66
+
67
+ Misc.sensiblewrite(final_path) do |file|
68
+ response.read_body do |chunk|
69
+ file.write chunk
70
+ end
71
+ end
72
+
73
+ when Net::HTTPRedirection, Net::HTTPFound
74
+ location = response['location']
75
+ Log.debug("Feching directory from: #{location}. Into: #{final_path}")
76
+ FileUtils.mkdir_p final_path unless File.exists? final_path
77
+ Misc.in_dir final_path do
78
+ CMD.cmd('tar xvfz -', :in => Open.open(location))
79
+ end
80
+ else
81
+ exit
82
+ raise "Response not understood: #{response.inspect}"
83
+ end
77
84
  end
78
- return true
79
85
  rescue
80
86
  Log.warn "Could not retrieve (#{self.to_s}) #{ path } from #{ remote_server }"
81
87
  Log.error $!.message
88
+ Log.error $!.backtrace * "\n"
82
89
  FileUtils.rm_rf final_path if File.exists? final_path
83
90
  return false
84
91
  end
data/lib/rbbt/util/cmd.rb CHANGED
@@ -67,13 +67,12 @@ module CMD
67
67
  end
68
68
 
69
69
  def read(*args)
70
- data = original_read(*args)
70
+ data = original_read(*args) unless self.eof?
71
71
 
72
72
  self.close if self.eof?
73
73
 
74
74
  data
75
75
  end
76
-
77
76
  end
78
77
 
79
78
 
@@ -3,6 +3,9 @@ require 'net/smtp'
3
3
  require 'digest/md5'
4
4
  require 'narray'
5
5
  require 'cgi'
6
+ require 'zlib'
7
+ require 'rubygems/package'
8
+ require 'rbbt/util/tar'
6
9
 
7
10
  class Hash
8
11
  def chunked_values_at(keys, max = 5000)
@@ -1017,16 +1020,17 @@ end
1017
1020
  end
1018
1021
  end
1019
1022
 
1020
- def self.sensiblewrite(path, content = nil)
1023
+ def self.sensiblewrite(path, content = nil, &block)
1021
1024
  return if File.exists? path
1022
1025
  Misc.lock path + '.sensible_write' do
1023
1026
  if not File.exists? path
1024
1027
  begin
1025
- tmp_path = path + '.tmp'
1026
- content = yield if block_given?
1028
+ tmp_path = path + '.sensible_write'
1027
1029
  case
1030
+ when block_given?
1031
+ File.open(tmp_path, 'w', &block)
1028
1032
  when String === content
1029
- File.open(tmp_path, 'w') do |f| f.write content end
1033
+ File.open(tmp_path, 'w') do |f| f.write content end
1030
1034
  when (IO === content or StringIO === content)
1031
1035
  File.open(tmp_path, 'w') do |f|
1032
1036
  while l = content.gets; f.write l; end
@@ -0,0 +1,126 @@
1
+ require 'rubygems/package'
2
+ require 'zlib'
3
+ require 'fileutils'
4
+
5
+ # SOURCE: https://gist.github.com/sinisterchipmunk/1335041
6
+ # Adapted for Rbbt
7
+
8
+ module Misc
9
+ # Creates a tar file in memory recursively
10
+ # from the given path.
11
+ #
12
+ # Returns a StringIO whose underlying String
13
+ # is the contents of the tar file.
14
+ def self.tar(path, tarfile = nil)
15
+ tarfile ||= StringIO.new("")
16
+
17
+ Gem::Package::TarWriter.new(tarfile) do |tar|
18
+ Dir[File.join(path, "**/*")].each do |file|
19
+ mode = File.stat(file).mode
20
+ relative_file = file.sub /^#{Regexp::escape path}\/?/, ''
21
+
22
+ if File.directory?(file)
23
+ tar.mkdir relative_file, mode
24
+ else
25
+ tar.add_file relative_file, mode do |tf|
26
+ File.open(file, "rb") { |f| tf.write f.read }
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ tarfile.rewind
33
+
34
+ tarfile
35
+ end
36
+
37
+ def self.tarize(path, gz = nil)
38
+ gz ||= StringIO.new('wb')
39
+
40
+ tar = Misc.in_dir(path) do self.tar('.') end
41
+
42
+ tar.rewind
43
+
44
+ string = tar.string
45
+ ddd string.size
46
+
47
+ #chunk_size = 1024
48
+ #Zlib::GzipWriter.wrap(gz) do |writer|
49
+ # while chunk = tar.read(chunk_size) do
50
+ # writer.write chunk
51
+ # end
52
+ # writer.close
53
+ #end
54
+ z = Zlib::GzipWriter.new(gz)
55
+ z.write string
56
+ z.close
57
+
58
+ gz.reopen('read')
59
+ gz.rewind
60
+
61
+
62
+ gz
63
+ end
64
+
65
+ def self.tarize(path)
66
+ Misc.in_dir(path) do
67
+ CMD.cmd("tar cvfz - '.'", :pipe => true)
68
+ end
69
+ end
70
+
71
+ # gzips the underlying string in the given StringIO,
72
+ # returning a new StringIO representing the
73
+ # compressed file.
74
+ def self.gzip(tarfile)
75
+ gz = StringIO.new("")
76
+ z = Zlib::GzipWriter.new(gz)
77
+ z.write tarfile.string
78
+ z.close # this is necessary!
79
+
80
+ # z was closed to write the gzip footer, so
81
+ # now we need a new StringIO
82
+ StringIO.new gz.string
83
+ end
84
+
85
+ # un-gzips the given IO, returning the
86
+ # decompressed version as a StringIO
87
+ def ungzip(tarfile)
88
+ z = Zlib::GzipReader.new(tarfile)
89
+ unzipped = StringIO.new(z.read)
90
+ z.close
91
+ unzipped
92
+ end
93
+
94
+ # untars the given IO into the specified
95
+ # directory
96
+ def untar(io, destination)
97
+ Gem::Package::TarReader.new io do |tar|
98
+ tar.each do |tarfile|
99
+ destination_file = File.join destination, tarfile.full_name
100
+
101
+ if tarfile.directory?
102
+ FileUtils.mkdir_p destination_file
103
+ else
104
+ destination_directory = File.dirname(destination_file)
105
+ FileUtils.mkdir_p destination_directory unless File.directory?(destination_directory)
106
+ File.open destination_file, "wb" do |f|
107
+ f.print tarfile.read
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
114
+
115
+
116
+ ### Usage Example: ###
117
+ #
118
+ # include Util::Tar
119
+ #
120
+ # io = tar("./Desktop") # io is a TAR of files
121
+ # gz = gzip(io) # gz is a TGZ
122
+ #
123
+ # io = ungzip(gz) # io is a TAR
124
+ # untar(io, "./untarred") # files are untarred
125
+ #
126
+
data/share/unicorn.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  worker_processes 4
2
2
  timeout 30
3
+ preload_app true
3
4
 
4
5
  @app_path = Dir.pwd
5
6
  @port = "2887"
@@ -6,11 +6,11 @@ require 'rbbt/entity'
6
6
 
7
7
  class TestMisc < Test::Unit::TestCase
8
8
 
9
- def test_humanize
9
+ def _test_humanize
10
10
  assert_equal "mutation_enrichment", Misc.humanize("MutationEnrichment")
11
11
  end
12
12
 
13
- def test_fixutf8
13
+ def _test_fixutf8
14
14
  string = "abc\xffdef"
15
15
  string = string.force_encoding("UTF-8") if string.respond_to? :force_encoding
16
16
  assert(! string.valid_encoding?) if string.respond_to? :valid_encoding?
@@ -19,37 +19,37 @@ class TestMisc < Test::Unit::TestCase
19
19
  assert( Misc.fixutf8(string).valid_encoding) if string.respond_to? :valid_encoding
20
20
  end
21
21
 
22
- def test_colors_for
22
+ def _test_colors_for
23
23
  colors, used = Misc.colors_for([1,2,2,1,2,1,2,2,3,3,2,3,2])
24
24
  assert_equal Misc::COLOR_LIST[1], used[2]
25
25
  end
26
26
 
27
- def test_total_length
27
+ def _test_total_length
28
28
  ranges = [(0..100), (50..150), (120..160)]
29
29
  ranges = [(0..100), (50..150), (120..160), (51..70)]
30
30
  assert_equal 161, Misc.total_length(ranges)
31
31
  end
32
32
 
33
- def test_id_filename?
33
+ def _test_id_filename?
34
34
  TmpFile.with_file("") do |file|
35
35
  assert Misc.is_filename?(file)
36
36
  assert ! Misc.is_filename?("TEST STRING")
37
37
  end
38
38
  end
39
39
 
40
- def test_merge_sorted_arrays
40
+ def _test_merge_sorted_arrays
41
41
  assert_equal [1,2,3,4], Misc.merge_sorted_arrays([1,3], [2,4])
42
42
  end
43
43
 
44
- def test_intersect_sorted_arrays
44
+ def _test_intersect_sorted_arrays
45
45
  assert_equal [2,4], Misc.intersect_sorted_arrays([1,2,3,4], [2,4])
46
46
  end
47
47
 
48
- def test_sorted_array_matches
48
+ def _test_sorted_array_matches
49
49
  assert_equal [1,3], Misc.sorted_array_hits(%w(a b c d e), %w(b d))
50
50
  end
51
51
 
52
- def test_binary_include?
52
+ def _test_binary_include?
53
53
  a = %w(a b c d e).sort
54
54
  assert Misc.binary_include?(a, "a")
55
55
  assert(!Misc.binary_include?(a, "z"))
@@ -58,24 +58,24 @@ class TestMisc < Test::Unit::TestCase
58
58
  assert(Misc.binary_include?(a, "d"))
59
59
  end
60
60
 
61
- def test_process_to_hash
61
+ def _test_process_to_hash
62
62
  list = [1,2,3,4]
63
63
  assert_equal 4, Misc.process_to_hash(list){|l| l.collect{|e| e * 2}}[2]
64
64
  end
65
65
 
66
- # def test_pdf2text_example
66
+ # def _test_pdf2text_example
67
67
  # assert PDF2Text.pdf2text(datafile_test('example.pdf')).read =~ /An Example Paper/i
68
68
  # end
69
69
  #
70
- # def test_pdf2text_EPAR
70
+ # def _test_pdf2text_EPAR
71
71
  # assert PDF2Text.pdf2text("http://www.ema.europa.eu/docs/en_GB/document_library/EPAR_-_Scientific_Discussion/human/000402/WC500033103.pdf").read =~ /Tamiflu/i
72
72
  # end
73
73
  #
74
- # def test_pdf2text_wrong
74
+ # def _test_pdf2text_wrong
75
75
  # assert_raise CMD::CMDError do PDF2Text.pdf2text("http://www.ema.europa.eu/docs/en_GB#").read end
76
76
  # end
77
77
 
78
- def test_string2hash
78
+ def _test_string2hash
79
79
  assert(Misc.string2hash("--user-agent=firefox").include? "--user-agent")
80
80
  assert_equal(true, Misc.string2hash(":true")[:true])
81
81
  assert_equal(true, Misc.string2hash("true")["true"])
@@ -93,17 +93,17 @@ class TestMisc < Test::Unit::TestCase
93
93
  end
94
94
  end
95
95
 
96
- def test_named_array
96
+ def _test_named_array
97
97
  a = NamedArray.setup([1,2,3,4], %w(a b c d))
98
98
  assert_equal(1, a['a'])
99
99
  end
100
100
 
101
- # def test_path_relative_to
101
+ # def _test_path_relative_to
102
102
  # assert_equal "test/foo", Misc.path_relative_to('test/test/foo', 'test')
103
103
  # end
104
104
 
105
- # def test_chunk
106
- # test =<<-EOF
105
+ # def _test_chunk
106
+ # _test =<<-EOF
107
107
  #This is an example file. Entries are separated by Entry
108
108
  #-- Entry
109
109
  #1
@@ -118,7 +118,7 @@ class TestMisc < Test::Unit::TestCase
118
118
  # assert_equal "1\n2\n3", Misc.chunk(test, /^-- Entry/).first.strip
119
119
  # end
120
120
 
121
- def test_hash2string
121
+ def _test_hash2string
122
122
  hash = {}
123
123
  assert_equal hash, Misc.string2hash(Misc.hash2string(hash))
124
124
 
@@ -136,14 +136,14 @@ class TestMisc < Test::Unit::TestCase
136
136
 
137
137
  end
138
138
 
139
- def test_merge
139
+ def _test_merge
140
140
  a = [[1],[2]]
141
141
  a = NamedArray.setup a, %w(1 2)
142
142
  a.merge [3,4]
143
143
  assert_equal [1,3], a[0]
144
144
  end
145
145
 
146
- def test_indiferent_hash
146
+ def _test_indiferent_hash
147
147
  a = {:a => 1, "b" => 2}
148
148
  a.extend IndiferentHash
149
149
 
@@ -153,7 +153,7 @@ class TestMisc < Test::Unit::TestCase
153
153
  assert_equal 2, a[:b]
154
154
  end
155
155
 
156
- def test_lockfile
156
+ def _test_lockfile
157
157
 
158
158
  TmpFile.with_file do |tmpfile|
159
159
  pids = []
@@ -177,7 +177,7 @@ class TestMisc < Test::Unit::TestCase
177
177
  end
178
178
  end
179
179
 
180
- def test_positions2hash
180
+ def _test_positions2hash
181
181
  inputs = Misc.positional2hash([:one, :two, :three], 1, :two => 2, :four => 4)
182
182
  assert_equal 1, inputs[:one]
183
183
  assert_equal 2, inputs[:two]
@@ -185,7 +185,7 @@ class TestMisc < Test::Unit::TestCase
185
185
  assert_equal nil, inputs[:four]
186
186
  end
187
187
 
188
- def test_mean
188
+ def _test_mean
189
189
  assert_equal 2, Misc.mean([1,2,3])
190
190
  assert_equal 3, Misc.mean([1,2,3,4,5])
191
191
  end
@@ -194,32 +194,32 @@ class TestMisc < Test::Unit::TestCase
194
194
  assert_equal Math.sqrt(2), Misc.sd([1,3])
195
195
  end
196
196
 
197
- def test_align_small
197
+ def _test_align_small
198
198
  reference = "AABCDEBD"
199
199
  sequence = "ABCD"
200
200
  assert_equal '-ABCD---', Misc.fast_align(reference, sequence).last
201
201
  end
202
202
 
203
- def test_align_real
203
+ def _test_align_real
204
204
  reference = "SGNECNKAIDGNKDTFWHTFYGANGDPKPPPHTYTIDMKTTQNVNGLSMLPRQDGNQNGWIGRHEVYLSSDGTNW"
205
205
  sequence = "TYTIDMKTTQNVNGLSML"
206
206
  assert_equal "--------------------------------TYTIDMKTTQNVNGLSML-------------------------", Misc.fast_align(reference, sequence).last
207
207
  end
208
208
 
209
- def test_divide
209
+ def _test_divide
210
210
  assert_equal 2, Misc.divide(%w(1 2 3 4 5 6 7 8 9),2).length
211
211
  end
212
212
 
213
- def test_ordered_divide
213
+ def _test_ordered_divide
214
214
  assert_equal 5, Misc.ordered_divide(%w(1 2 3 4 5 6 7 8 9),2).length
215
215
  end
216
216
 
217
- def test_collapse_ranges
217
+ def _test_collapse_ranges
218
218
  ranges = [(0..100), (50..150), (51..61),(200..250), (300..324),(320..350)]
219
219
  assert_equal [(0..150),(200..250), (300..350)], Misc.collapse_ranges(ranges)
220
220
  end
221
221
 
222
- def test_humanize
222
+ def _test_humanize
223
223
  str1 = "test_string"
224
224
  str2 = "TEST_string"
225
225
  str3 = "test"
@@ -229,18 +229,28 @@ class TestMisc < Test::Unit::TestCase
229
229
  assert_equal "Test", Misc.humanize(str3)
230
230
  end
231
231
 
232
- def test_snake_case
232
+ def _test_snake_case
233
233
  str1 = "ACRONIMTest"
234
234
  str2 = "ACRONIM_test"
235
235
  assert_equal "ACRONIM_test", Misc.snake_case(str1)
236
236
  assert_equal "ACRONIM_test", Misc.snake_case(str2)
237
237
  end
238
238
 
239
- def test_correct_vcf_mutations
239
+ def _test_correct_vcf_mutations
240
240
  assert_equal [737407, ["-----", "-----G", "-----GTTAAT"]], Misc.correct_vcf_mutation(737406, "GTTAAT", "G,GG,GGTTAAT")
241
241
  end
242
242
 
243
- def test_fingerprint
243
+ def _test_fingerprint
244
244
  puts Misc.fingerprint({:a => 1})
245
245
  end
246
+
247
+ def test_tarize
248
+ path = File.expand_path('/home/mvazquezg/git/rbbt-util/lib')
249
+ stream = Misc.tarize(path)
250
+ TmpFile.with_file do |res|
251
+ Misc.in_dir(res) do
252
+ CMD.cmd("tar xvfz - ", :in => stream)
253
+ end
254
+ end
255
+ end
246
256
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbbt-util
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.5.49
4
+ version: 5.5.50
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
@@ -163,6 +163,7 @@ files:
163
163
  - lib/rbbt/util/semaphore.rb
164
164
  - lib/rbbt/util/simpleDSL.rb
165
165
  - lib/rbbt/util/simpleopt.rb
166
+ - lib/rbbt/util/tar.rb
166
167
  - lib/rbbt/util/task/job.rb
167
168
  - lib/rbbt/util/tmpfile.rb
168
169
  - lib/rbbt/workflow.rb