gwtf 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/gwtf.rb +23 -6
- data/lib/gwtf/commands/list_command.rb +1 -12
- data/lib/gwtf/commands/new_command.rb +2 -1
- data/lib/gwtf/commands/notify_command.rb +63 -0
- data/lib/gwtf/commands/remind_command.rb +4 -5
- data/lib/gwtf/item.rb +8 -4
- data/lib/gwtf/items.rb +37 -0
- data/lib/gwtf/notifier/email.rb +18 -14
- data/lib/gwtf/version.rb +1 -1
- metadata +6 -5
data/lib/gwtf.rb
CHANGED
@@ -4,6 +4,7 @@ module Gwtf
|
|
4
4
|
require 'gwtf/item'
|
5
5
|
require 'gwtf/version'
|
6
6
|
require 'gwtf/notifier/base'
|
7
|
+
require 'gwtf/notifier/email'
|
7
8
|
require 'json'
|
8
9
|
require 'yaml'
|
9
10
|
require 'fileutils'
|
@@ -12,6 +13,12 @@ module Gwtf
|
|
12
13
|
require 'time'
|
13
14
|
require 'readline'
|
14
15
|
|
16
|
+
@@color = true
|
17
|
+
|
18
|
+
def self.color=(value)
|
19
|
+
@@color = value
|
20
|
+
end
|
21
|
+
|
15
22
|
def self.each_command
|
16
23
|
commands_dir = File.join(File.dirname(__FILE__), "gwtf", "commands")
|
17
24
|
Dir.entries(commands_dir).grep(/_command.rb$/).sort.each do |command|
|
@@ -28,12 +35,22 @@ module Gwtf
|
|
28
35
|
end.compact.sort
|
29
36
|
end
|
30
37
|
|
31
|
-
def self.
|
38
|
+
def self.protocol_for_address(address)
|
32
39
|
uri = URI.parse(address)
|
33
40
|
|
34
41
|
case uri.scheme
|
35
42
|
when nil, "email"
|
36
|
-
|
43
|
+
return "email"
|
44
|
+
else
|
45
|
+
return uri.scheme
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.notifier_for_address(address)
|
50
|
+
protocol = protocol_for_address(address)
|
51
|
+
|
52
|
+
case protocol_for_address(address)
|
53
|
+
when "email"
|
37
54
|
return Notifier::Email
|
38
55
|
when "boxcar"
|
39
56
|
gem 'boxcar_api', '>= 1.2.0'
|
@@ -42,7 +59,7 @@ module Gwtf
|
|
42
59
|
|
43
60
|
return Notifier::Boxcar
|
44
61
|
else
|
45
|
-
raise "Do not know how to handle addresses of type #{
|
62
|
+
raise "Do not know how to handle addresses of type #{protocol} for #{address}"
|
46
63
|
end
|
47
64
|
end
|
48
65
|
|
@@ -58,7 +75,7 @@ module Gwtf
|
|
58
75
|
end
|
59
76
|
|
60
77
|
def self.green(msg)
|
61
|
-
if STDOUT.tty?
|
78
|
+
if STDOUT.tty? && @@color
|
62
79
|
"[1m[32m%s[0m" % [ msg ]
|
63
80
|
else
|
64
81
|
msg
|
@@ -66,7 +83,7 @@ module Gwtf
|
|
66
83
|
end
|
67
84
|
|
68
85
|
def self.yellow(msg)
|
69
|
-
if STDOUT.tty?
|
86
|
+
if STDOUT.tty? && @@color
|
70
87
|
"[1m[33m%s[0m" % [ msg ]
|
71
88
|
else
|
72
89
|
msg
|
@@ -74,7 +91,7 @@ module Gwtf
|
|
74
91
|
end
|
75
92
|
|
76
93
|
def self.red(msg)
|
77
|
-
if STDOUT.tty?
|
94
|
+
if STDOUT.tty? && @@color
|
78
95
|
"[1m[31m%s[0m" % [ msg ]
|
79
96
|
else
|
80
97
|
msg
|
@@ -55,18 +55,7 @@ command [:list, :ls, :l] do |c|
|
|
55
55
|
end
|
56
56
|
|
57
57
|
elsif options[:overview]
|
58
|
-
Gwtf.
|
59
|
-
next if project == "reminders"
|
60
|
-
|
61
|
-
items = Gwtf::Items.new(File.join(global_options[:data], project), project)
|
62
|
-
|
63
|
-
if items.item_ids.size > 0
|
64
|
-
if text = items.list_text(options[:all], true)
|
65
|
-
puts text
|
66
|
-
puts
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
58
|
+
puts Gwtf::Items.overview_text(global_options[:data], options[:all])
|
70
59
|
|
71
60
|
else
|
72
61
|
puts
|
@@ -48,7 +48,6 @@ command [:new, :add, :n, :a, :c] do |c|
|
|
48
48
|
item.subject = subject
|
49
49
|
item.description = description if description
|
50
50
|
item.due_date = options[:due] if options[:due]
|
51
|
-
item.save
|
52
51
|
|
53
52
|
if options[:remind]
|
54
53
|
STDOUT.sync
|
@@ -58,6 +57,8 @@ command [:new, :add, :n, :a, :c] do |c|
|
|
58
57
|
item.schedule_reminer(options[:remind], options[:recipient], options[:done], options[:ifopen])
|
59
58
|
end
|
60
59
|
|
60
|
+
item.save
|
61
|
+
|
61
62
|
puts item.to_s
|
62
63
|
end
|
63
64
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
desc 'Tool to send various kinds of notification'
|
2
|
+
|
3
|
+
command [:notify] do |c|
|
4
|
+
c.desc 'Email address to send to'
|
5
|
+
c.default_value Etc.getlogin
|
6
|
+
c.flag [:recipient, :r]
|
7
|
+
|
8
|
+
c.desc 'Send a reminder about an item'
|
9
|
+
c.default_value false
|
10
|
+
c.flag [:remind]
|
11
|
+
|
12
|
+
c.desc 'Send a overview list of all projects with items'
|
13
|
+
c.default_value false
|
14
|
+
c.switch [:overview]
|
15
|
+
|
16
|
+
c.desc 'Send a list of any due or overdue items'
|
17
|
+
c.default_value false
|
18
|
+
c.switch [:due]
|
19
|
+
|
20
|
+
c.desc 'When notifying about a specific item, close it after notify'
|
21
|
+
c.default_value false
|
22
|
+
c.switch [:done]
|
23
|
+
|
24
|
+
c.desc 'Only notify about an open item'
|
25
|
+
c.default_value false
|
26
|
+
c.switch [:ifopen]
|
27
|
+
|
28
|
+
c.action do |global_options,options,args|
|
29
|
+
if options[:remind]
|
30
|
+
raise "Need an item ID to remind" unless options[:remind] =~ /^(.+)$/
|
31
|
+
|
32
|
+
item = @items.load_item(options[:remind])
|
33
|
+
|
34
|
+
unless options[:ifopen] && item.closed?
|
35
|
+
item.send_reminder(options[:recipient], options[:done])
|
36
|
+
end
|
37
|
+
|
38
|
+
elsif options[:overview]
|
39
|
+
overview_text = Gwtf::Items.overview_text(global_options[:data])
|
40
|
+
|
41
|
+
unless overview_text == ""
|
42
|
+
options[:recipient].split(",").each do |r|
|
43
|
+
next unless Gwtf.protocol_for_address(r) == "email"
|
44
|
+
|
45
|
+
Gwtf::Notifier::Email.send_email(overview_text, "Summary of Tasks", r)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
elsif options[:due]
|
50
|
+
Gwtf.color = false
|
51
|
+
|
52
|
+
due_text = Gwtf::Items.due_text(global_options[:data])
|
53
|
+
|
54
|
+
unless due_text == ""
|
55
|
+
options[:recipient].split(",").each do |r|
|
56
|
+
next unless Gwtf.protocol_for_address(r) == "email"
|
57
|
+
|
58
|
+
Gwtf::Notifier::Email.send_email(due_text, "Due and Overdue Tasks", r)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -33,12 +33,12 @@ command [:remind, :rem] do |c|
|
|
33
33
|
c.action do |global_options,options,args|
|
34
34
|
raise "Please supply an item ID to remind about" if args.empty?
|
35
35
|
|
36
|
-
STDOUT.sync
|
36
|
+
STDOUT.sync = true
|
37
37
|
|
38
38
|
unless options[:send]
|
39
39
|
if args.first =~ /^\d+$/ # got an item id, schedule a reminder
|
40
40
|
unless options[:at]
|
41
|
-
raise "Please specify a valid at(1) time specification with --at after the item id" unless args.size
|
41
|
+
raise "Please specify a valid at(1) time specification with --at after the item id" unless args.size >= 2
|
42
42
|
options[:at] = args[1..-1].join(" ")
|
43
43
|
end
|
44
44
|
|
@@ -67,12 +67,11 @@ command [:remind, :rem] do |c|
|
|
67
67
|
puts reminder.to_s
|
68
68
|
end
|
69
69
|
else
|
70
|
+
# This is deprecated use 'gwtf email --remind 10' instead
|
70
71
|
item = @items.load_item(args.first)
|
71
72
|
|
72
73
|
unless options[:ifopen] && item.closed?
|
73
|
-
options[:recipient]
|
74
|
-
item.send_reminder(recipient.strip, options[:done], Gwtf.notifier_for_address(recipient.strip))
|
75
|
-
end
|
74
|
+
item.send_reminder(options[:recipient], options[:done])
|
76
75
|
end
|
77
76
|
end
|
78
77
|
end
|
data/lib/gwtf/item.rb
CHANGED
@@ -186,20 +186,24 @@ module Gwtf
|
|
186
186
|
end
|
187
187
|
|
188
188
|
def schedule_reminer(timespec, recipient, done=false, ifopen=false)
|
189
|
-
command_args = ["--
|
189
|
+
command_args = ["--remind"]
|
190
190
|
command_args << "--recipient=%s" % [ recipient ]
|
191
191
|
command_args << "--done" if done
|
192
192
|
command_args << "--ifopen" if ifopen
|
193
193
|
|
194
|
-
command = "echo gwtf --project='%s'
|
194
|
+
command = "echo gwtf --project='%s' email %s %s | at %s 2>&1" % [ @project, command_args.join(" "), item_id, timespec]
|
195
195
|
out = %x[#{command}]
|
196
196
|
|
197
|
+
raise "Failed to add at(1) job: %s" % [ out ] unless $? == 0
|
198
|
+
|
197
199
|
puts out
|
198
200
|
out
|
199
201
|
end
|
200
202
|
|
201
|
-
def send_reminder(recipient, mark_as_done
|
202
|
-
|
203
|
+
def send_reminder(recipient, mark_as_done)
|
204
|
+
recipient.split(",").each do |r|
|
205
|
+
Gwtf.notifier_for_address(r.strip).new(self, r.strip).notify
|
206
|
+
end
|
203
207
|
|
204
208
|
if mark_as_done
|
205
209
|
record_work("Closing item as part of scheduled reminder")
|
data/lib/gwtf/items.rb
CHANGED
@@ -20,6 +20,43 @@ module Gwtf
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
# overview text of open (or all) items in all projects
|
24
|
+
def self.overview_text(datadir, all=false)
|
25
|
+
overview = StringIO.new
|
26
|
+
|
27
|
+
Gwtf.projects(datadir).each do |project|
|
28
|
+
next if project == "reminders"
|
29
|
+
|
30
|
+
items = Gwtf::Items.new(File.join(datadir, project), project)
|
31
|
+
|
32
|
+
if items.item_ids.size > 0
|
33
|
+
if text = items.list_text(all, true)
|
34
|
+
overview.puts text
|
35
|
+
overview.puts
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
overview.string
|
41
|
+
end
|
42
|
+
|
43
|
+
# overview text of all due items in all projects
|
44
|
+
def self.due_text(datadir)
|
45
|
+
overview = StringIO.new
|
46
|
+
|
47
|
+
Gwtf.projects(datadir).each do |project|
|
48
|
+
next if project == "reminders"
|
49
|
+
|
50
|
+
items = Gwtf::Items.new(File.join(datadir, project), project)
|
51
|
+
|
52
|
+
items.each_item do |item|
|
53
|
+
overview.puts "%s: %s" % [ project, item.to_s ] if item.due?
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
overview.string
|
58
|
+
end
|
59
|
+
|
23
60
|
def initialize(data_dir, project)
|
24
61
|
raise "Data directory #{data_dir} does not exist" unless File.directory?(data_dir)
|
25
62
|
|
data/lib/gwtf/notifier/email.rb
CHANGED
@@ -1,23 +1,27 @@
|
|
1
1
|
module Gwtf
|
2
2
|
module Notifier
|
3
3
|
class Email<Base
|
4
|
-
def
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
def self.send_email(body, subject, recipient)
|
5
|
+
tmp = Tempfile.new("gwtf")
|
6
|
+
tmp.write(body)
|
7
|
+
tmp.rewind
|
8
|
+
|
9
|
+
subject.gsub!("'", "\'")
|
10
|
+
recipient.gsub!("'", "\'")
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
12
|
+
system("cat #{tmp.path} | mail -s '#{subject}' '#{recipient}'")
|
13
|
+
ensure
|
14
|
+
tmp.close!
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
def notify
|
18
|
+
if item.project == "default"
|
19
|
+
subject = "Reminder for item %s" % [ item.item_id ]
|
20
|
+
else
|
21
|
+
subject = "Reminder for item %s in %s project" % [ item.item_id, item.project ]
|
20
22
|
end
|
23
|
+
|
24
|
+
Email.send_email(item.summary, subject, recipient)
|
21
25
|
end
|
22
26
|
end
|
23
27
|
end
|
data/lib/gwtf/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gwtf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 7
|
9
|
+
- 0
|
10
|
+
version: 0.7.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- R.I.Pienaar
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-04-
|
18
|
+
date: 2012-04-11 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- lib/gwtf/commands/show_command.rb
|
107
107
|
- lib/gwtf/commands/open_command.rb
|
108
108
|
- lib/gwtf/commands/shell_command.rb
|
109
|
+
- lib/gwtf/commands/notify_command.rb
|
109
110
|
- lib/gwtf/commands/done_command.rb
|
110
111
|
- lib/gwtf/commands/log_command.rb
|
111
112
|
- lib/gwtf/commands/edit_command.rb
|