tlog 0.0.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 +15 -0
- data/.gitignore +3 -0
- data/LICENSE +339 -0
- data/README.md +17 -0
- data/TODO +5 -0
- data/bin/tlog +22 -0
- data/lib/tlog/application.rb +81 -0
- data/lib/tlog/command/active.rb +45 -0
- data/lib/tlog/command/create.rb +32 -0
- data/lib/tlog/command/delete.rb +24 -0
- data/lib/tlog/command/display.rb +144 -0
- data/lib/tlog/command/init.rb +34 -0
- data/lib/tlog/command/start.rb +31 -0
- data/lib/tlog/command/stop.rb +25 -0
- data/lib/tlog/command/test.rb +32 -0
- data/lib/tlog/command.rb +14 -0
- data/lib/tlog/entity/active_log.rb +11 -0
- data/lib/tlog/entity/entry.rb +90 -0
- data/lib/tlog/entity/log.rb +102 -0
- data/lib/tlog/error.rb +6 -0
- data/lib/tlog/format/date_time.rb +7 -0
- data/lib/tlog/format/seconds.rb +13 -0
- data/lib/tlog/input.rb +10 -0
- data/lib/tlog/output.rb +29 -0
- data/lib/tlog/storage/disk.rb +277 -0
- data/lib/tlog/version.rb +3 -0
- data/lib/tlog.rb +47 -0
- data/tlog.gemspec +28 -0
- metadata +142 -0
@@ -0,0 +1,277 @@
|
|
1
|
+
|
2
|
+
class Tlog::Storage::Disk
|
3
|
+
|
4
|
+
attr_accessor :git
|
5
|
+
attr_accessor :tlog_dir
|
6
|
+
attr_accessor :tlog_working
|
7
|
+
attr_accessor :tlog_index
|
8
|
+
attr_accessor :working_dir
|
9
|
+
|
10
|
+
# Class methods 'create_repo' 'all_logs', also 'create' command
|
11
|
+
|
12
|
+
def initialize(git_dir)
|
13
|
+
@git = Git.open(find_repo(git_dir))
|
14
|
+
# Format class?
|
15
|
+
proj_path = @git.dir.path.downcase.gsub(/[^a-z0-9]+/i, '-')
|
16
|
+
|
17
|
+
@tlog_dir = '~/.tlog'
|
18
|
+
@tlog_working = File.expand_path(File.join(@tlog_dir, proj_path, 'working'))
|
19
|
+
@tlog_index = File.expand_path(File.join(@tlog_dir, proj_path, 'index'))
|
20
|
+
|
21
|
+
bs = git.lib.branches_all.map{|b| b.first}
|
22
|
+
|
23
|
+
unless(bs.include?('tlog') && File.directory?(@tlog_working))
|
24
|
+
init_tlog_branch(bs.include?('tlog'))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def create_log(log)
|
29
|
+
log.path = log_path(log.name)
|
30
|
+
if log.create
|
31
|
+
git.add
|
32
|
+
git.commit("Created log #{log.name}")
|
33
|
+
true
|
34
|
+
else
|
35
|
+
false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def delete_log(log)
|
40
|
+
log.path = log_path(log.name)
|
41
|
+
if log.delete
|
42
|
+
delete_current(log.name)
|
43
|
+
git.remove(log.path, {:recursive => "-r"})
|
44
|
+
git.commit("Deleted log #{log.name}")
|
45
|
+
true
|
46
|
+
else
|
47
|
+
false
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def require_log(log_name)
|
52
|
+
decode_log_path(Pathname.new(log_path(log_name)))
|
53
|
+
end
|
54
|
+
|
55
|
+
def start_log(log, entry_description)
|
56
|
+
entry_description = '(no description)' unless entry_description
|
57
|
+
if update_current(log.name, entry_description)
|
58
|
+
create_log(log) # Creates directory if it has not already been created
|
59
|
+
git.add
|
60
|
+
git.commit("Started log #{log.name}")
|
61
|
+
true
|
62
|
+
else
|
63
|
+
false
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def stop_log(log)
|
68
|
+
if Dir.exists?(current_path)
|
69
|
+
current_hash = {
|
70
|
+
:name => current_log_name,
|
71
|
+
:start_time => current_start_time,
|
72
|
+
:description => current_entry_description,
|
73
|
+
:owner => cur_entry_owner
|
74
|
+
}
|
75
|
+
delete_current(current_hash[:name])
|
76
|
+
log.add_entry(current_hash)
|
77
|
+
git.add
|
78
|
+
git.commit("Stopped log #{log.name}")
|
79
|
+
true
|
80
|
+
else
|
81
|
+
false
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def log_duration(log_name)
|
86
|
+
duration = 0
|
87
|
+
if current_log_name == log_name
|
88
|
+
duration += time_since_start
|
89
|
+
end
|
90
|
+
log_entries(log_name).each do |entry| # should just be able to do log.entries.each
|
91
|
+
duration += entry.length
|
92
|
+
end
|
93
|
+
duration
|
94
|
+
end
|
95
|
+
|
96
|
+
def find_repo(dir)
|
97
|
+
full = File.expand_path(dir)
|
98
|
+
ENV["GIT_WORKING_DIR"] || loop do
|
99
|
+
return full if File.directory?(File.join(full, ".git"))
|
100
|
+
raise "No Repo Found" if full == full=File.dirname(full)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def start_time_string
|
105
|
+
current_start_time
|
106
|
+
end
|
107
|
+
|
108
|
+
def time_since_start
|
109
|
+
if Dir.exists?(current_path)
|
110
|
+
difference = Time.now - Time.parse(current_start_time)
|
111
|
+
difference.to_i
|
112
|
+
else
|
113
|
+
nil
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def cur_start_time
|
118
|
+
Time.parse(current_start_time) if current_start_path
|
119
|
+
end
|
120
|
+
|
121
|
+
def cur_entry_owner
|
122
|
+
git.config["user.email"].split('@').first rescue ''
|
123
|
+
end
|
124
|
+
|
125
|
+
def cur_entry_description
|
126
|
+
current_entry_description
|
127
|
+
end
|
128
|
+
|
129
|
+
def current_log_name
|
130
|
+
name_contents = File.read(current_name_path) if File.exists?(current_name_path)
|
131
|
+
name_contents.strip if name_contents
|
132
|
+
end
|
133
|
+
|
134
|
+
def get_current_start_time
|
135
|
+
current_start_time
|
136
|
+
end
|
137
|
+
|
138
|
+
def all_log_dirs
|
139
|
+
Pathname.new(logs_path).children.select { |c| c.directory? }
|
140
|
+
end
|
141
|
+
|
142
|
+
# Code from 'ticgit', temporarily switches to tlog branch
|
143
|
+
def in_branch(branch_exists = true)
|
144
|
+
unless File.directory?(@tlog_working)
|
145
|
+
FileUtils.mkdir_p(@tlog_working)
|
146
|
+
end
|
147
|
+
|
148
|
+
old_current = git.lib.branch_current
|
149
|
+
begin
|
150
|
+
git.lib.change_head_branch('tlog')
|
151
|
+
git.with_index(@tlog_index) do
|
152
|
+
git.with_working(@tlog_working) do |wd|
|
153
|
+
git.lib.checkout('tlog') if branch_exists
|
154
|
+
yield wd
|
155
|
+
end
|
156
|
+
end
|
157
|
+
ensure
|
158
|
+
git.lib.change_head_branch(old_current)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
private
|
163
|
+
|
164
|
+
def decode_log_path(log_path)
|
165
|
+
if Dir.exists?(log_path)
|
166
|
+
log = Tlog::Entity::Log.new(log_path)
|
167
|
+
#log_storage.log_path = log_path # add this to the log class...i think task_store may not be neccessary
|
168
|
+
#lgolog.entries = log_storage.entries
|
169
|
+
end
|
170
|
+
return log
|
171
|
+
end
|
172
|
+
|
173
|
+
def init_tlog_branch(tlog_branch = false)
|
174
|
+
in_branch(tlog_branch) do
|
175
|
+
unless tlog_branch
|
176
|
+
git.add
|
177
|
+
git.commit('creating the tlog branch')
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
def update_current(log_name, entry_description)
|
183
|
+
unless Dir.exists?(current_path)
|
184
|
+
FileUtils.mkdir_p(current_path)
|
185
|
+
write_to_current(log_name, entry_description)
|
186
|
+
true
|
187
|
+
else
|
188
|
+
false
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def delete_current(log_name) # Change this method name or add one
|
193
|
+
if Dir.exists?(current_path)
|
194
|
+
if current_log_name == log_name
|
195
|
+
FileUtils.rm_rf(current_path)
|
196
|
+
git.remove(current_path, {:recursive => 'r'})
|
197
|
+
end
|
198
|
+
else
|
199
|
+
false
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
def write_to_current(log_name, entry_description)
|
204
|
+
# Create a current object, with a "read" method
|
205
|
+
File.open(current_name_path, 'w'){ |f| f.write(log_name)}
|
206
|
+
File.open(current_description_path, 'w'){ |f| f.write(entry_description)} if entry_description
|
207
|
+
File.open(current_start_path, 'w'){ |f| f.write(Time.now.to_s)}
|
208
|
+
end
|
209
|
+
|
210
|
+
def current_exists?
|
211
|
+
Dir.exists?(current_path)
|
212
|
+
end
|
213
|
+
|
214
|
+
def stop_current
|
215
|
+
if Dir.exists?(current_path)
|
216
|
+
create_log_entry(current_log_name, current_start_time, current_entry_description) # CURRENT Dictionary?!
|
217
|
+
true
|
218
|
+
else
|
219
|
+
false
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
#Eventually want to take this out and just create the entry on start
|
224
|
+
def current_start_time
|
225
|
+
read_file(current_start_path)
|
226
|
+
end
|
227
|
+
|
228
|
+
def current_entry_description
|
229
|
+
read_file(current_description_path)
|
230
|
+
end
|
231
|
+
|
232
|
+
def current_log_length
|
233
|
+
read_file(current_length_path)
|
234
|
+
end
|
235
|
+
|
236
|
+
def read_file(path)
|
237
|
+
if File.exists?(path)
|
238
|
+
contents = File.read(path)
|
239
|
+
contents.strip
|
240
|
+
else
|
241
|
+
nil
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
def log_path(log_name)
|
246
|
+
File.join(logs_path, log_name)
|
247
|
+
end
|
248
|
+
|
249
|
+
def goal_path(log_name)
|
250
|
+
File.join(log_path(log_name), 'GOAL')
|
251
|
+
end
|
252
|
+
|
253
|
+
def logs_path
|
254
|
+
File.expand_path(File.join('tasks'))
|
255
|
+
end
|
256
|
+
|
257
|
+
def current_path
|
258
|
+
File.expand_path(File.join('current'))
|
259
|
+
end
|
260
|
+
|
261
|
+
def current_name_path
|
262
|
+
File.join(current_path, 'NAME')
|
263
|
+
end
|
264
|
+
|
265
|
+
def current_start_path
|
266
|
+
File.join(current_path, 'START')
|
267
|
+
end
|
268
|
+
|
269
|
+
def current_length_path
|
270
|
+
File.join(current_path, 'LENGTH')
|
271
|
+
end
|
272
|
+
|
273
|
+
def current_description_path
|
274
|
+
File.join(current_path, 'DESCRIPTION')
|
275
|
+
end
|
276
|
+
|
277
|
+
end
|
data/lib/tlog/version.rb
ADDED
data/lib/tlog.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
|
2
|
+
module Tlog
|
3
|
+
Version = "0.0.0"
|
4
|
+
|
5
|
+
module Storage
|
6
|
+
end
|
7
|
+
|
8
|
+
module Error
|
9
|
+
end
|
10
|
+
|
11
|
+
module Format
|
12
|
+
end
|
13
|
+
|
14
|
+
module Entity
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
require "chronic_duration"
|
19
|
+
require 'fileutils'
|
20
|
+
require 'git'
|
21
|
+
require 'securerandom'
|
22
|
+
require 'pathname'
|
23
|
+
require 'time'
|
24
|
+
require 'chronic'
|
25
|
+
|
26
|
+
require 'tlog/command'
|
27
|
+
require 'tlog/command/init'
|
28
|
+
require 'tlog/command/start'
|
29
|
+
require 'tlog/command/stop'
|
30
|
+
require 'tlog/command/active'
|
31
|
+
require 'tlog/command/delete'
|
32
|
+
require 'tlog/command/display'
|
33
|
+
require 'tlog/command/create'
|
34
|
+
|
35
|
+
require 'tlog/storage/disk'
|
36
|
+
|
37
|
+
require 'tlog/format/seconds'
|
38
|
+
require 'tlog/format/date_time'
|
39
|
+
|
40
|
+
require 'tlog/entity/log'
|
41
|
+
require 'tlog/entity/active_log'
|
42
|
+
require 'tlog/entity/entry'
|
43
|
+
|
44
|
+
require 'tlog/error'
|
45
|
+
|
46
|
+
|
47
|
+
|
data/tlog.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
Gem::Specification.new do |spec|
|
3
|
+
|
4
|
+
spec.name = "tlog"
|
5
|
+
spec.version = "0.0.1"
|
6
|
+
spec.date = "2013-05-26"
|
7
|
+
|
8
|
+
spec.required_ruby_version = ">=1.9.3"
|
9
|
+
|
10
|
+
spec.summary = "CLI Project Time Logger"
|
11
|
+
spec.description = "tlog is a git-based command-line time logger that keeps track the time you've spend on different parts of a project"
|
12
|
+
spec.license = "GPL-2"
|
13
|
+
|
14
|
+
spec.add_dependency("commander", "~> 4.0")
|
15
|
+
spec.add_dependency("chronic_duration", "~> 0.10.2")
|
16
|
+
spec.add_dependency("fileutils", "~> 0.7")
|
17
|
+
spec.add_dependency("git", "~> 1.2.5")
|
18
|
+
spec.add_dependency("chronic", "~> 0.9.1")
|
19
|
+
|
20
|
+
spec.authors = ["Chris Wendel"]
|
21
|
+
spec.email = "chriwend@umich.edu"
|
22
|
+
|
23
|
+
spec.executables = "tlog"
|
24
|
+
|
25
|
+
spec.files = `git ls-files`.split("\n")
|
26
|
+
spec.require_path = "lib"
|
27
|
+
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tlog
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Wendel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-05-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: commander
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: chronic_duration
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.10.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.10.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: fileutils
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.7'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: git
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.2.5
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.2.5
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: chronic
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.9.1
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.9.1
|
83
|
+
description: tlog is a git-based command-line time logger that keeps track the time
|
84
|
+
you've spend on different parts of a project
|
85
|
+
email: chriwend@umich.edu
|
86
|
+
executables:
|
87
|
+
- tlog
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- .gitignore
|
92
|
+
- LICENSE
|
93
|
+
- README.md
|
94
|
+
- TODO
|
95
|
+
- bin/tlog
|
96
|
+
- lib/tlog.rb
|
97
|
+
- lib/tlog/application.rb
|
98
|
+
- lib/tlog/command.rb
|
99
|
+
- lib/tlog/command/active.rb
|
100
|
+
- lib/tlog/command/create.rb
|
101
|
+
- lib/tlog/command/delete.rb
|
102
|
+
- lib/tlog/command/display.rb
|
103
|
+
- lib/tlog/command/init.rb
|
104
|
+
- lib/tlog/command/start.rb
|
105
|
+
- lib/tlog/command/stop.rb
|
106
|
+
- lib/tlog/command/test.rb
|
107
|
+
- lib/tlog/entity/active_log.rb
|
108
|
+
- lib/tlog/entity/entry.rb
|
109
|
+
- lib/tlog/entity/log.rb
|
110
|
+
- lib/tlog/error.rb
|
111
|
+
- lib/tlog/format/date_time.rb
|
112
|
+
- lib/tlog/format/seconds.rb
|
113
|
+
- lib/tlog/input.rb
|
114
|
+
- lib/tlog/output.rb
|
115
|
+
- lib/tlog/storage/disk.rb
|
116
|
+
- lib/tlog/version.rb
|
117
|
+
- tlog.gemspec
|
118
|
+
homepage:
|
119
|
+
licenses:
|
120
|
+
- GPL-2
|
121
|
+
metadata: {}
|
122
|
+
post_install_message:
|
123
|
+
rdoc_options: []
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ! '>='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 1.9.3
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ! '>='
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
requirements: []
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 2.0.3
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: CLI Project Time Logger
|
142
|
+
test_files: []
|