rbbt-util 5.33.11 → 5.33.12

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: e5c26a161d8529f19d32ace8b5565042b4baa6fef3d69580f46aadc523e8cc51
4
- data.tar.gz: 8ee1305d3a66a55273474da60e84cec3385391ad99c8c87e764fd72eaaf29285
3
+ metadata.gz: 729b93bb0b82b05a03eb9cdf99728b4793ecd002ab06a92c08dc899341d26810
4
+ data.tar.gz: 568b263ae5bbc16e18383bd0fc5fb42054d2954b674bb1df97f80280ade9e7b2
5
5
  SHA512:
6
- metadata.gz: 6b9ddf9ff821584ef21f7c30be381965ea9a8cf1cce7e9913cc11c118fa1d31211fe321d72c5d8daabcb14aac5b20df45c527fefa1d142c7a08633c3818b79dd
7
- data.tar.gz: c0ab742b23fe87fd7f52bfdfe75690a02566547a34a484912c74766cff70c83634434d5a67a9e665bfdffb28be143afdb20028356befe045e19b14bcc83a21ff
6
+ metadata.gz: 1c56e3f171523bb412b391899b93ba88d80038a2a201ed4573897c3039526fbf1f05d2a2bcb81b837d6cb9ad31672c7c5a67572d7baa3789c10f3fc3929db274
7
+ data.tar.gz: b178ecce6c10f7933bdafd3cf495e3a185d6f0005b5111ed6b86f79f70b9608d613c837d7141c6ca42bf4504d352f46102d2ac628bc19d6e9a2001dbcc081284
@@ -0,0 +1,79 @@
1
+ module Misc
2
+ PUSHBULLET_KEY=begin
3
+ if ENV["PUSHBULLET_KEY"]
4
+ ENV["PUSHBULLET_KEY"]
5
+ else
6
+ config_api = File.join(ENV['HOME'], 'config/apps/pushbullet/apikey')
7
+ if File.exist? config_api
8
+ File.read(config_api).strip
9
+ else
10
+ nil
11
+ end
12
+ end
13
+ end
14
+
15
+ def self.notify(description, event='notification', key = nil)
16
+ if PUSHBULLET_KEY.nil? and key.nil?
17
+ Log.warn "Could not notify, no PUSHBULLET_KEY"
18
+ return
19
+ end
20
+
21
+ Thread.new do
22
+ application = 'rbbt'
23
+ event ||= 'notification'
24
+ key ||= PUSHBULLET_KEY
25
+ `curl -s --header "Authorization: Bearer #{key}" -X POST https://api.pushbullet.com/v2/pushes --header 'Content-Type: application/json' --data-binary '{"type": "note", "title": "#{event}", "body": "#{description}"}'`
26
+ end
27
+ end
28
+
29
+ def self.send_email_old(from, to, subject, message, options = {})
30
+ IndiferentHash.setup(options)
31
+ options = Misc.add_defaults options, :from_alias => nil, :to_alias => nil, :server => 'localhost', :port => 25, :user => nil, :pass => nil, :auth => :login
32
+
33
+ server, port, user, pass, from_alias, to_alias, auth = Misc.process_options options, :server, :port, :user, :pass, :from_alias, :to_alias, :auth
34
+
35
+ msg = <<-END_OF_MESSAGE
36
+ From: #{from_alias} <#{from}>
37
+ To: #{to_alias} <#{to}>
38
+ Subject: #{subject}
39
+
40
+ #{message}
41
+ END_OF_MESSAGE
42
+
43
+ Net::SMTP.start(server, port, server, user, pass, auth) do |smtp|
44
+ smtp.send_message msg, from, to
45
+ end
46
+ end
47
+
48
+ def self.send_email(from, to, subject, message, options = {})
49
+ require 'mail'
50
+
51
+ IndiferentHash.setup(options)
52
+ options = Misc.add_defaults options, :from_alias => nil, :to_alias => nil, :server => 'localhost', :port => 25, :user => nil, :pass => nil, :auth => :login, :files => []
53
+
54
+ server, port, user, pass, from_alias, to_alias, auth, files = Misc.process_options options, :server, :port, :user, :pass, :from_alias, :to_alias, :auth, :files
55
+
56
+ files = [] if files.nil?
57
+ files = [files] unless Array === files
58
+
59
+ Mail.defaults do
60
+ delivery_method :smtp, address: server, port: port, user_name: user, password: pass
61
+ end
62
+
63
+ mail = Mail.deliver do
64
+ from "#{from_alias} <#{from}>"
65
+ to "#{to_alias} <#{to}>"
66
+ subject subject
67
+
68
+ text_part do
69
+ body message
70
+ end
71
+
72
+ files.each do |file|
73
+ file = file.find if Path === file
74
+ file = file.path if Step === file
75
+ end
76
+ end
77
+ end
78
+
79
+ end
@@ -385,32 +385,6 @@ def self.add_libdir(dir=nil)
385
385
  `ps -o rss -p #{pid || $$}`.strip.split.last.to_i
386
386
  end
387
387
 
388
- PUSHBULLET_KEY=begin
389
- if ENV["PUSHBULLET_KEY"]
390
- ENV["PUSHBULLET_KEY"]
391
- else
392
- config_api = File.join(ENV['HOME'], 'config/apps/pushbullet/apikey')
393
- if File.exist? config_api
394
- File.read(config_api).strip
395
- else
396
- nil
397
- end
398
- end
399
- end
400
-
401
- def self.notify(description, event='notification', key = nil)
402
- if PUSHBULLET_KEY.nil? and key.nil?
403
- Log.warn "Could not notify, no PUSHBULLET_KEY"
404
- return
405
- end
406
-
407
- Thread.new do
408
- application = 'rbbt'
409
- event ||= 'notification'
410
- key ||= PUSHBULLET_KEY
411
- `curl -s --header "Authorization: Bearer #{key}" -X POST https://api.pushbullet.com/v2/pushes --header 'Content-Type: application/json' --data-binary '{"type": "note", "title": "#{event}", "body": "#{description}"}'`
412
- end
413
- end
414
388
 
415
389
  def self.unzip_in_dir(file, dir)
416
390
  raise "Target is not a directory: #{file}" if File.exist?(dir) and not File.directory?(dir)
@@ -16,25 +16,6 @@ module Misc
16
16
  end
17
17
  end
18
18
 
19
- def self.send_email(from, to, subject, message, options = {})
20
- IndiferentHash.setup(options)
21
- options = Misc.add_defaults options, :from_alias => nil, :to_alias => nil, :server => 'localhost', :port => 25, :user => nil, :pass => nil, :auth => :login
22
-
23
- server, port, user, pass, from_alias, to_alias, auth = Misc.process_options options, :server, :port, :user, :pass, :from_alias, :to_alias, :auth
24
-
25
- msg = <<-END_OF_MESSAGE
26
- From: #{from_alias} <#{from}>
27
- To: #{to_alias} <#{to}>
28
- Subject: #{subject}
29
-
30
- #{message}
31
- END_OF_MESSAGE
32
-
33
- Net::SMTP.start(server, port, server, user, pass, auth) do |smtp|
34
- smtp.send_message msg, from, to
35
- end
36
- end
37
-
38
19
  def self.env_add(var, value, sep = ":", prepend = true)
39
20
  ENV[var] ||= ""
40
21
  return if ENV[var] =~ /(#{sep}|^)#{Regexp.quote value}(#{sep}|$)/
@@ -20,6 +20,7 @@ require 'rbbt/util/misc/options'
20
20
  require 'rbbt/util/misc/system'
21
21
  require 'rbbt/util/misc/objects'
22
22
  require 'rbbt/util/misc/manipulation'
23
+ require 'rbbt/util/misc/communication'
23
24
 
24
25
  require 'to_regexp'
25
26
 
@@ -678,7 +678,14 @@ module Open
678
678
  if Open.exists? notification_file
679
679
  key = Open.read(notification_file).strip
680
680
  key = nil if key.empty?
681
- Misc.notify("Wrote " << file, nil, key)
681
+ if key.include?("@")
682
+ to = from = key
683
+ subject = "Wrote " << file
684
+ message = "Content attached"
685
+ Misc.send_email(from, to, subject, message, :files => [file])
686
+ else
687
+ Misc.notify("Wrote " << file, nil, key)
688
+ end
682
689
  Open.rm notification_file
683
690
  end
684
691
  rescue
@@ -0,0 +1,11 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), '../../..', 'test_helper.rb')
2
+ require 'rbbt/util/misc/communication'
3
+
4
+ class TestCommunication < Test::Unit::TestCase
5
+ def test_send_email
6
+ to = from = 'mvazque2@localhost'
7
+ subject = message = "Test"
8
+ iii Misc.send_email(to, from, subject, message)
9
+ end
10
+ end
11
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbbt-util
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.33.11
4
+ version: 5.33.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-05 00:00:00.000000000 Z
11
+ date: 2022-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -292,6 +292,7 @@ files:
292
292
  - lib/rbbt/util/misc.rb
293
293
  - lib/rbbt/util/misc/annotated_module.rb
294
294
  - lib/rbbt/util/misc/bgzf.rb
295
+ - lib/rbbt/util/misc/communication.rb
295
296
  - lib/rbbt/util/misc/concurrent_stream.rb
296
297
  - lib/rbbt/util/misc/development.rb
297
298
  - lib/rbbt/util/misc/exceptions.rb
@@ -531,6 +532,7 @@ files:
531
532
  - test/rbbt/util/concurrency/test_threads.rb
532
533
  - test/rbbt/util/log/test_progress.rb
533
534
  - test/rbbt/util/misc/test_bgzf.rb
535
+ - test/rbbt/util/misc/test_communication.rb
534
536
  - test/rbbt/util/misc/test_development.rb
535
537
  - test/rbbt/util/misc/test_format.rb
536
538
  - test/rbbt/util/misc/test_lock.rb
@@ -611,6 +613,7 @@ test_files:
611
613
  - test/rbbt/util/misc/test_omics.rb
612
614
  - test/rbbt/util/misc/test_pipes.rb
613
615
  - test/rbbt/util/misc/test_format.rb
616
+ - test/rbbt/util/misc/test_communication.rb
614
617
  - test/rbbt/util/misc/test_lock.rb
615
618
  - test/rbbt/util/misc/test_multipart_payload.rb
616
619
  - test/rbbt/util/misc/test_bgzf.rb