timr 0.3.0 → 0.4.0

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.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.ackrc +9 -0
  3. data/.editorconfig +1 -0
  4. data/.env.example +7 -0
  5. data/.github/CONTRIBUTING.md +32 -0
  6. data/.github/ISSUE_TEMPLATE.md +13 -0
  7. data/.gitignore +8 -2
  8. data/.rdoc_options +21 -0
  9. data/.travis.yml +10 -7
  10. data/Gemfile +8 -0
  11. data/README.md +216 -3
  12. data/bin/.gitignore +2 -0
  13. data/bin/README.md +17 -0
  14. data/bin/build.sh +14 -0
  15. data/bin/build_api.sh +14 -0
  16. data/bin/build_coverage.sh +23 -0
  17. data/bin/build_info.sh +27 -0
  18. data/bin/build_man.sh +41 -0
  19. data/bin/clean.sh +14 -0
  20. data/bin/dev_setup.sh +19 -0
  21. data/bin/install.sh +49 -0
  22. data/bin/publish +38 -0
  23. data/bin/release.sh +35 -0
  24. data/bin/test.sh +19 -0
  25. data/bin/timr +20 -40
  26. data/bin/timr_bash_completion.sh +337 -0
  27. data/bin/uninstall.sh +24 -0
  28. data/lib/timr.rb +36 -8
  29. data/lib/timr/command/basic_command.rb +170 -0
  30. data/lib/timr/command/continue_command.rb +86 -0
  31. data/lib/timr/command/help_command.rb +137 -0
  32. data/lib/timr/command/log_command.rb +297 -0
  33. data/lib/timr/command/pause_command.rb +89 -0
  34. data/lib/timr/command/pop_command.rb +176 -0
  35. data/lib/timr/command/push_command.rb +141 -0
  36. data/lib/timr/command/report_command.rb +689 -0
  37. data/lib/timr/command/start_command.rb +172 -0
  38. data/lib/timr/command/status_command.rb +198 -0
  39. data/lib/timr/command/stop_command.rb +127 -0
  40. data/lib/timr/command/task_command.rb +318 -0
  41. data/lib/timr/command/track_command.rb +381 -0
  42. data/lib/timr/command/version_command.rb +18 -0
  43. data/lib/timr/duration.rb +159 -0
  44. data/lib/timr/exception/timr_error.rb +113 -0
  45. data/lib/timr/ext/time.rb +12 -0
  46. data/lib/timr/helper/datetime_helper.rb +128 -0
  47. data/lib/timr/helper/terminal_helper.rb +58 -0
  48. data/lib/timr/helper/translation_helper.rb +45 -0
  49. data/lib/timr/model/basic_model.rb +287 -0
  50. data/lib/timr/model/config.rb +48 -0
  51. data/lib/timr/model/foreign_id_db.rb +84 -0
  52. data/lib/timr/model/stack.rb +161 -0
  53. data/lib/timr/model/task.rb +1039 -0
  54. data/lib/timr/model/track.rb +589 -0
  55. data/lib/timr/progressbar.rb +41 -0
  56. data/lib/timr/simple_opt_parser.rb +230 -0
  57. data/lib/timr/status.rb +70 -0
  58. data/lib/timr/table.rb +88 -0
  59. data/lib/timr/timr.rb +500 -558
  60. data/lib/timr/version.rb +4 -15
  61. data/man/.gitignore +2 -0
  62. data/man/_footer +3 -0
  63. data/man/timr-continue.1 +48 -0
  64. data/man/timr-continue.1.ronn +39 -0
  65. data/man/timr-ftime.7 +77 -0
  66. data/man/timr-ftime.7.ronn +57 -0
  67. data/man/timr-log.1 +109 -0
  68. data/man/timr-log.1.ronn +87 -0
  69. data/man/timr-pause.1 +56 -0
  70. data/man/timr-pause.1.ronn +45 -0
  71. data/man/timr-pop.1 +66 -0
  72. data/man/timr-pop.1.ronn +53 -0
  73. data/man/timr-push.1 +25 -0
  74. data/man/timr-push.1.ronn +20 -0
  75. data/man/timr-report.1 +228 -0
  76. data/man/timr-report.1.ronn +193 -0
  77. data/man/timr-start.1 +100 -0
  78. data/man/timr-start.1.ronn +82 -0
  79. data/man/timr-status.1 +53 -0
  80. data/man/timr-status.1.ronn +42 -0
  81. data/man/timr-stop.1 +75 -0
  82. data/man/timr-stop.1.ronn +60 -0
  83. data/man/timr-task.1 +147 -0
  84. data/man/timr-task.1.ronn +115 -0
  85. data/man/timr-track.1 +109 -0
  86. data/man/timr-track.1.ronn +89 -0
  87. data/man/timr.1 +119 -0
  88. data/man/timr.1.ronn +68 -0
  89. data/timr.gemspec +18 -3
  90. data/timr.sublime-project +20 -1
  91. metadata +142 -23
  92. data/Makefile +0 -12
  93. data/Makefile.common +0 -56
  94. data/lib/timr/stack.rb +0 -81
  95. data/lib/timr/task.rb +0 -258
  96. data/lib/timr/track.rb +0 -167
  97. data/lib/timr/window.rb +0 -259
  98. data/lib/timr/window_help.rb +0 -41
  99. data/lib/timr/window_tasks.rb +0 -30
  100. data/lib/timr/window_test.rb +0 -20
  101. data/lib/timr/window_timeline.rb +0 -33
  102. data/tests/tc_stack.rb +0 -121
  103. data/tests/tc_task.rb +0 -190
  104. data/tests/tc_track.rb +0 -144
  105. data/tests/tc_window.rb +0 -428
  106. data/tests/ts_all.rb +0 -6
data/Makefile DELETED
@@ -1,12 +0,0 @@
1
-
2
- GEM_NAME = timr
3
- ALL_TARGETS_EXT = tmp
4
-
5
- include Makefile.common
6
-
7
- dev:
8
- RUBYOPT=-rbundler/setup ruby --debug ./bin/timr -d tmp/timr -c tmp/timr.conf
9
-
10
- .PHONY: test
11
- test:
12
- RUBYOPT=-w TZ=Europe/Vienna $(BUNDLER) exec ./tests/ts_all.rb
data/Makefile.common DELETED
@@ -1,56 +0,0 @@
1
-
2
- # Ruby Common Big
3
- # 2016-05-20
4
-
5
- MV = mv -nv
6
- RM = rm -rfd
7
- MKDIR = mkdir -p
8
- CHMOD = chmod
9
- BUNDLER = bundle
10
- BUNDLER_OPTIONS = --jobs=5 --retry=3
11
- GEMSPEC_FILE = $(GEM_NAME).gemspec
12
-
13
- .PHONY: all
14
- all: setup $(ALL_TARGETS_EXT)
15
-
16
- .PHONY: setup
17
- setup: .setup
18
-
19
- .setup:
20
- $(BUNDLER) install $(BUNDLER_OPTIONS)
21
- touch $@
22
-
23
- .PHONY: install
24
- install:
25
- gem_file=$$(gem build $(GEMSPEC_FILE) | grep 'File:' | tail -1 | awk '{ print $$2 }'); \
26
- sudo gem install $$gem_file; \
27
- $(RM) $$gem_file
28
-
29
- .PHONY: uninstall
30
- uninstall:
31
- sudo gem uninstall $(GEM_NAME)
32
-
33
- .PHONY: update
34
- update:
35
- $(BUNDLER) update
36
-
37
- .PHONY: clean
38
- clean:
39
- $(RM) .bundle .setup Gemfile.lock
40
-
41
- .PHONY: release
42
- release: | releases
43
- set -e; \
44
- gem_file=$$(gem build $(GEMSPEC_FILE) | grep 'File:' | tail -1 | awk '{ print $$2 }'); \
45
- dst="releases/$$gem_file"; \
46
- [ ! -f $$dst ]; \
47
- $(MV) $$gem_file releases; \
48
- gem push $$dst; \
49
- echo 'done'
50
-
51
- releases:
52
- $(MKDIR) $@
53
-
54
- tmp:
55
- $(MKDIR) $@
56
- $(CHMOD) u=rwx,go-rwx $@
data/lib/timr/stack.rb DELETED
@@ -1,81 +0,0 @@
1
-
2
- module TheFox
3
- module Timr
4
-
5
- class Stack
6
-
7
- def initialize
8
- @tasks = []
9
- @task = nil
10
- end
11
-
12
- def task
13
- @task
14
- end
15
-
16
- def has_task?
17
- !@task.nil?
18
- end
19
-
20
- def size
21
- @tasks.length
22
- end
23
-
24
- def tasks_texts
25
- @tasks.map{ |task|
26
- status = task.status
27
- status = '*' if task == @task
28
-
29
- task_name = task.to_s
30
- task_name = task.track.name if task.has_track?
31
-
32
- "#{status} #{task_name}"
33
- }
34
- end
35
-
36
- def pop
37
- old = @tasks.pop
38
- if !old.nil?
39
- old.stop
40
- @task = @tasks.last
41
- @task.start if !@task.nil?
42
- true
43
- else
44
- false
45
- end
46
- end
47
-
48
- def pop_all(new_task = nil, parent_track = nil)
49
- if @task == new_task
50
- @task.start(parent_track)
51
- else
52
- @tasks.each do |task|
53
- task.stop
54
- end
55
- @tasks = []
56
- @task = nil
57
-
58
- if !new_task.nil?
59
- push(new_task, parent_track)
60
- end
61
- true
62
- end
63
- end
64
-
65
- def push(task, parent_track = nil)
66
- if !@tasks.include?(task)
67
- @task.pause if has_task?
68
-
69
- @task = task
70
- @task.start(parent_track)
71
- @tasks << @task
72
- true
73
- else
74
- false
75
- end
76
- end
77
-
78
- end
79
-
80
- end
81
- end
data/lib/timr/task.rb DELETED
@@ -1,258 +0,0 @@
1
-
2
- require 'time'
3
- require 'yaml/store'
4
- require 'uuid'
5
-
6
- module TheFox
7
- module Timr
8
-
9
- class Task
10
-
11
- def initialize(path = nil)
12
- # Status
13
- # :running
14
- # :stop
15
- @status = :stop
16
- @changed = false
17
-
18
- @meta = {
19
- 'id' => UUID.new.generate,
20
- 'name' => nil,
21
- 'description' => nil,
22
- 'created' => Time.now.utc.strftime(TIME_FORMAT_FILE),
23
- 'modified' => Time.now.utc.strftime(TIME_FORMAT_FILE),
24
- }
25
- @track = nil
26
- @timeline = []
27
- @timeline_diff_total = nil
28
-
29
- @path = path
30
- if !@path.nil?
31
- load_from_file(@path)
32
- end
33
- end
34
-
35
- def load_from_file(path)
36
- content = YAML::load_file(path)
37
- @meta = content['meta']
38
- @timeline = content['timeline']
39
- .map{ |track_raw|
40
- Track.from_h(self, track_raw)
41
- }
42
- end
43
-
44
- def save_to_file(basepath)
45
- path = File.expand_path("task_#{@meta['id']}.yml", basepath)
46
-
47
- if @changed || !@track.nil?
48
- timeline_c = @timeline
49
- .map{ |track|
50
- h = track.to_h
51
- h['e'] = Time.now.utc.strftime(TIME_FORMAT_FILE) if !h.has_key?('e') || h['e'].nil?
52
- h
53
- }
54
-
55
- store = YAML::Store.new(path)
56
- store.transaction do
57
- store['meta'] = @meta
58
- store['timeline'] = timeline_c
59
- end
60
- @changed = false
61
- end
62
-
63
- path
64
- end
65
-
66
- def running?
67
- @status == :running
68
- end
69
-
70
- def paused?
71
- @status == :paused
72
- end
73
-
74
- def status
75
- case @status
76
- when :running
77
- ?>
78
- when :paused
79
- ?|
80
- when :stop
81
- ?.
82
- end
83
- end
84
-
85
- def changed
86
- @changed = true
87
- @meta['modified'] = Time.now.utc.strftime(TIME_FORMAT_FILE)
88
- end
89
-
90
- def id
91
- @meta['id']
92
- end
93
-
94
- def name
95
- @meta['name'].to_s
96
- end
97
-
98
- def name=(name)
99
- @changed = true
100
- @meta['name'] = name
101
- end
102
-
103
- def description
104
- @meta['description']
105
- end
106
-
107
- def description=(description)
108
- @changed = true
109
- @meta['description'] = description == '' ? nil : description
110
- end
111
-
112
- def track
113
- @track
114
- end
115
-
116
- def has_track?
117
- !@track.nil?
118
- end
119
-
120
- def timeline
121
- @timeline
122
- end
123
-
124
- def start(parent_track = nil)
125
- create_new_track = false
126
-
127
- if running?
128
- if !parent_track.nil?
129
- if @track.description != parent_track.description
130
- stop
131
- create_new_track = true
132
- end
133
- end
134
- elsif paused?
135
- parent_track = @track if parent_track.nil?
136
- create_new_track = true
137
- else
138
- create_new_track = true
139
- end
140
-
141
- if create_new_track
142
- @changed = true
143
-
144
- @track = Track.new
145
- if !parent_track.nil?
146
- @track.parent = parent_track
147
- @track.description = parent_track.description
148
- end
149
-
150
- @track.task = self
151
- @track.begin_time = Time.now
152
- @timeline << @track
153
- end
154
-
155
- @status = :running
156
-
157
- create_new_track
158
- end
159
-
160
- def pause
161
- if running? && !@track.nil?
162
- @status = :paused
163
- @changed = true
164
- @track.end_time = Time.now
165
- @timeline_diff_total = nil
166
- end
167
- end
168
-
169
- def stop
170
- if !@track.nil?
171
- if running?
172
- @changed = true
173
- @track.end_time = Time.now
174
- end
175
-
176
- @track = nil
177
- @timeline_diff_total = nil
178
- end
179
-
180
- @status = :stop
181
- end
182
-
183
- def toggle
184
- if running?
185
- pause
186
- else
187
- start
188
- end
189
- end
190
-
191
- def remove_track(track)
192
- @changed = true
193
- @timeline.delete(track)
194
- end
195
-
196
- def to_s
197
- name
198
- end
199
-
200
- def run_time_track(end_time = Time.now)
201
- hours = 0
202
- minutes = 0
203
- seconds = 0
204
-
205
- if running? && has_track?
206
- diff = (end_time - @track.begin_time).to_i.abs
207
- hours = diff / 3600
208
-
209
- diff -= hours * 3600
210
- minutes = diff / 60
211
-
212
- diff -= minutes * 60
213
- seconds = diff
214
- end
215
-
216
- [hours, minutes, seconds]
217
- end
218
-
219
- def run_time_total(end_time = Time.now)
220
- # Cache all other tracks.
221
- if @timeline_diff_total.nil?
222
- @timeline_diff_total = @timeline
223
- .select{ |track|
224
- if running?
225
- track != @track
226
- else
227
- true
228
- end
229
- }
230
- .map{ |track| track.diff }
231
- .inject(:+)
232
- end
233
-
234
- hours = 0
235
- minutes = 0
236
- seconds = 0
237
-
238
- track_diff = 0
239
- if running?
240
- track_diff = @track.diff(end_time)
241
- end
242
-
243
- diff = @timeline_diff_total.to_i + track_diff
244
- hours = diff / 3600
245
-
246
- diff -= hours * 3600
247
- minutes = diff / 60
248
-
249
- diff -= minutes * 60
250
- seconds = diff
251
-
252
- [hours, minutes, seconds]
253
- end
254
-
255
- end
256
-
257
- end
258
- end
data/lib/timr/track.rb DELETED
@@ -1,167 +0,0 @@
1
-
2
- require 'time'
3
- require 'uuid'
4
- require 'thefox-ext'
5
-
6
- module TheFox
7
- module Timr
8
-
9
- class Track
10
-
11
- def initialize
12
- @id = UUID.new.generate
13
- @parent = nil
14
- @parent_id = nil
15
- @task = nil
16
- @begin_time = nil
17
- @end_time = nil
18
- @description = nil
19
- end
20
-
21
- def id=(id)
22
- @id = id
23
- end
24
-
25
- def id
26
- @id
27
- end
28
-
29
- def parent=(parent)
30
- @parent = parent
31
- end
32
-
33
- def parent
34
- @parent
35
- end
36
-
37
- def parent_id=(parent_id)
38
- @parent_id = parent_id
39
- end
40
-
41
- def parent_id
42
- @parent_id
43
- end
44
-
45
- def task=(task)
46
- @task = task
47
- end
48
-
49
- def task
50
- @task
51
- end
52
-
53
- def begin_time=(begin_time)
54
- @begin_time = nil
55
- @begin_time = begin_time.utc if !begin_time.nil?
56
- end
57
-
58
- def begin_time
59
- if !@begin_time.nil?
60
- @begin_time.localtime
61
- else
62
- nil
63
- end
64
- end
65
-
66
- def end_time=(end_time)
67
- @end_time = nil
68
- @end_time = end_time.utc if !end_time.nil?
69
- end
70
-
71
- def end_time
72
- if !@end_time.nil?
73
- @end_time.localtime
74
- else
75
- nil
76
- end
77
- end
78
-
79
- def description=(description)
80
- @description = description == '' ? nil : description
81
- end
82
-
83
- def description
84
- @description
85
- end
86
-
87
- def diff(end_time = nil)
88
- end_time = @end_time if !@end_time.nil?
89
-
90
- if !@begin_time.nil? && !end_time.nil?
91
- (end_time - @begin_time).abs.to_i
92
- else
93
- 0
94
- end
95
- end
96
-
97
- def name
98
- name_s = ''
99
- if !@task.nil?
100
- name_s += @task.to_s
101
- end
102
- if !@description.nil? && @description.length > 0
103
- if name_s.length > 0
104
- name_s += ': '
105
- end
106
- name_s += @description
107
- end
108
- name_s
109
- end
110
-
111
- def to_h
112
- h = {
113
- 'id' => @id,
114
- #'p' => nil, # parent_id
115
- #'b' => nil, # begin time
116
- #'e' => nil, # end time
117
- #'d' => nil, # description
118
- }
119
- h['p'] = @parent.id if !@parent.nil?
120
- h['p'] = @parent_id if !@parent_id.nil?
121
-
122
- h['b'] = @begin_time.utc.strftime(TIME_FORMAT_FILE) if !@begin_time.nil?
123
- h['e'] = @end_time.utc.strftime(TIME_FORMAT_FILE) if !@end_time.nil?
124
-
125
- #h['d'] = @description if !@description.nil?
126
- d = description
127
- h['d'] = d if !d.nil?
128
-
129
- h
130
- end
131
-
132
- def to_s
133
- end_date = nil
134
- end_time_s = 'xx:xx'
135
- if !@end_time.nil?
136
- end_date = @end_time.localtime.to_date
137
- end_time_s = @end_time.localtime.strftime('%R')
138
- end
139
-
140
- begin_date_s = ''
141
- begin_date = @begin_time.localtime.to_date
142
- end_date_s = ''
143
- if (begin_date != end_date && !end_date.nil?) || !begin_date.today?
144
- begin_date_s = @begin_time.localtime.strftime('%F')
145
- end_date_s = @end_time.localtime.strftime('%F') if !@end_time.nil?
146
- end
147
-
148
- '%10s %5s - %5s %10s %s' % [
149
- begin_date_s, @begin_time.localtime.strftime('%R'), end_time_s, end_date_s, name]
150
- end
151
-
152
- def self.from_h(task = nil, h)
153
- t = Track.new
154
- t.task = task
155
- t.id = h['id'] if h.has_key?('id')
156
- t.parent_id = h['p'] if h.has_key?('p')
157
- t.begin_time = Time.parse(h['b']) if h.has_key?('b')
158
- t.end_time = Time.parse(h['e']) if h.has_key?('e')
159
- t.description = h['d'] if h.has_key?('d')
160
-
161
- t
162
- end
163
-
164
- end
165
-
166
- end
167
- end