tlog 0.2.0 → 0.2.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 +8 -8
- data/README.md +172 -30
- data/TODO +1 -0
- data/lib/tlog/application.rb +56 -56
- data/lib/tlog/command/active.rb +48 -48
- data/lib/tlog/command/checkout.rb +31 -31
- data/lib/tlog/command/create.rb +40 -40
- data/lib/tlog/command/delete.rb +21 -21
- data/lib/tlog/command/display.rb +195 -148
- data/lib/tlog/command/help.rb +33 -33
- data/lib/tlog/command/owner.rb +25 -25
- data/lib/tlog/command/points.rb +25 -25
- data/lib/tlog/command/pull.rb +18 -18
- data/lib/tlog/command/push.rb +18 -18
- data/lib/tlog/command/start.rb +35 -35
- data/lib/tlog/command/state.rb +25 -25
- data/lib/tlog/command/stop.rb +26 -26
- data/lib/tlog/command.rb +9 -8
- data/lib/tlog/command_suite.rb +29 -29
- data/lib/tlog/entity/active_log.rb +8 -8
- data/lib/tlog/entity/entry.rb +77 -77
- data/lib/tlog/entity/log.rb +161 -161
- data/lib/tlog/error.rb +3 -0
- data/lib/tlog/format/date_time.rb +4 -3
- data/lib/tlog/format/seconds.rb +10 -9
- data/lib/tlog/input.rb +6 -6
- data/lib/tlog/output.rb +28 -28
- data/lib/tlog/storage/disk.rb +326 -326
- data/lib/tlog.rb +1 -1
- metadata +2 -4
- data/lib/tlog/command/init.rb +0 -38
- data/lib/tlog/version.rb +0 -3
data/lib/tlog/entity/log.rb
CHANGED
@@ -1,165 +1,165 @@
|
|
1
1
|
|
2
2
|
class Tlog::Entity::Log
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
4
|
+
attr_accessor :name
|
5
|
+
attr_accessor :goal
|
6
|
+
attr_accessor :entries
|
7
|
+
attr_accessor :path
|
8
|
+
|
9
|
+
def initialize(log_path = nil)
|
10
|
+
@entries = []
|
11
|
+
if log_path
|
12
|
+
@name = log_path.basename.to_s
|
13
|
+
@path = log_path
|
14
|
+
@goal = goal_length
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def create(options)
|
19
|
+
unless Dir.exists?(@path)
|
20
|
+
# Default time log attribute values
|
21
|
+
state = 'open'
|
22
|
+
points = 0
|
23
|
+
owner = 'none'
|
24
|
+
|
25
|
+
FileUtils.mkdir_p(@path)
|
26
|
+
@goal = ChronicDuration.parse(options[:goal]) if options[:goal]
|
27
|
+
state = options[:state] if options[:state]
|
28
|
+
points = options[:points] if options[:points]
|
29
|
+
owner = options[:owner] if options[:owner]
|
30
|
+
write_log(state, points, owner)
|
31
|
+
true
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def goal_length
|
36
|
+
if File.exists?(goal_path)
|
37
|
+
contents = File.read(goal_path)
|
38
|
+
contents.strip
|
39
|
+
contents.to_i
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def entries
|
44
|
+
log_entries = []
|
45
|
+
hex_value = head_hex_value
|
46
|
+
return log_entries unless hex_value
|
47
|
+
begin
|
48
|
+
entry = Tlog::Entity::Entry.new(entry_path(hex_value), hex_value)
|
49
|
+
hex_value = entry.parent_hex
|
50
|
+
log_entries.push(entry)
|
51
|
+
end until hex_value == "none"
|
52
|
+
return log_entries
|
53
|
+
end
|
54
|
+
|
55
|
+
def duration
|
56
|
+
dur = 0
|
57
|
+
entries.each do |entry|
|
58
|
+
dur += entry.length
|
59
|
+
end
|
60
|
+
dur
|
61
|
+
end
|
62
|
+
|
63
|
+
def owner
|
64
|
+
read_file(owner_path) if File.exists?(owner_path)
|
65
|
+
end
|
66
|
+
|
67
|
+
def state
|
68
|
+
read_file(state_path) if File.exists?(state_path)
|
69
|
+
end
|
70
|
+
|
71
|
+
def points
|
72
|
+
read_file(points_path).to_i if File.exists?(points_path)
|
73
|
+
end
|
74
|
+
|
75
|
+
def update_state(state)
|
76
|
+
File.open(state_path, 'w'){|f| f.write(state)}
|
77
|
+
end
|
78
|
+
|
79
|
+
def update_points(points)
|
80
|
+
File.open(points_path, 'w'){|f| f.write(points)}
|
81
|
+
end
|
82
|
+
|
83
|
+
def update_owner(owner)
|
84
|
+
File.open(owner_path, 'w'){|f| f.write(owner)}
|
85
|
+
end
|
86
|
+
|
87
|
+
def add_entry(current)
|
88
|
+
entry_hex = generate_random_hex
|
89
|
+
new_entry = Tlog::Entity::Entry.new(entry_path(entry_hex), entry_hex)
|
90
|
+
head_hex_value ? parent_hex = head_hex_value : parent_hex = "none"
|
91
|
+
|
92
|
+
update_head(entry_hex)
|
93
|
+
new_entry.create(parent_hex, current)
|
94
|
+
update_goal(new_entry.length) if goal_length
|
95
|
+
end
|
96
|
+
|
97
|
+
def update_head(entry_hex)
|
98
|
+
File.open(head_path, 'w'){|f| f.write(entry_hex)}
|
99
|
+
end
|
100
|
+
|
101
|
+
def update_goal(entry_length)
|
102
|
+
new_length = goal_length - entry_length
|
103
|
+
File.open(goal_path, 'w'){|f| f.write(new_length)}
|
104
|
+
end
|
105
|
+
|
106
|
+
def delete
|
107
|
+
FileUtils.rm_rf(@path) if Dir.exists?(@path)
|
108
|
+
end
|
109
|
+
|
110
|
+
private
|
111
|
+
|
112
|
+
def write_log(state, points, owner)
|
113
|
+
File.open(points_path, 'w'){|f| f.write(points)}
|
114
|
+
File.open(state_path, 'w'){|f| f.write(state)}
|
115
|
+
File.open(owner_path, 'w'){|f| f.write(owner)}
|
116
|
+
File.open(hold_path, 'w+'){|f| f.write('hold')}
|
117
|
+
File.open(goal_path, 'w'){|f| f.write(@goal)} if @goal
|
118
|
+
end
|
119
|
+
|
120
|
+
def read_file(path)
|
121
|
+
if File.exists?(path)
|
122
|
+
contents = File.read(path)
|
123
|
+
contents.strip
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def head_hex_value
|
128
|
+
if File.exists?(head_path)
|
129
|
+
head_content = File.read(head_path)
|
130
|
+
head_content.strip if head_content
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def points_path
|
135
|
+
File.join(@path, 'POINTS')
|
136
|
+
end
|
137
|
+
|
138
|
+
def state_path
|
139
|
+
File.join(@path, 'STATE')
|
140
|
+
end
|
141
|
+
|
142
|
+
def owner_path
|
143
|
+
File.join(@path, 'OWNER')
|
144
|
+
end
|
145
|
+
|
146
|
+
def goal_path
|
147
|
+
File.join(@path, 'GOAL')
|
148
|
+
end
|
149
|
+
|
150
|
+
def hold_path
|
151
|
+
File.join(@path, '.HOLD')
|
152
|
+
end
|
153
|
+
|
154
|
+
def head_path
|
155
|
+
File.join(@path, 'HEAD')
|
156
|
+
end
|
157
|
+
|
158
|
+
def entry_path(hex)
|
159
|
+
File.join(@path, hex)
|
160
|
+
end
|
161
|
+
|
162
|
+
def generate_random_hex
|
163
|
+
SecureRandom.hex(13)
|
164
|
+
end
|
165
165
|
end
|
data/lib/tlog/error.rb
CHANGED
data/lib/tlog/format/seconds.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
|
+
|
1
2
|
class Tlog::Format::Seconds
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
def self.duration(total_seconds)
|
5
|
+
output = ""
|
6
|
+
total_seconds ||= 0
|
7
|
+
total_seconds = total_seconds.to_i
|
8
|
+
mm, ss = total_seconds.divmod(60)
|
9
|
+
hh, mm = mm.divmod(60)
|
10
|
+
output = "%2s:%02d:%02d" % [hh, mm, ss]
|
11
|
+
return output
|
12
|
+
end
|
12
13
|
|
13
14
|
end
|
data/lib/tlog/input.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
|
2
2
|
class Tlog::Input
|
3
|
-
|
4
|
-
|
3
|
+
attr_accessor :args
|
4
|
+
attr_accessor :options
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
def initialize(args=[])
|
7
|
+
@args = args
|
8
|
+
@options = {}
|
9
|
+
end
|
10
10
|
end
|
data/lib/tlog/output.rb
CHANGED
@@ -1,33 +1,33 @@
|
|
1
1
|
|
2
2
|
class Tlog::Output
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
4
|
+
attr_accessor :stdout
|
5
|
+
attr_accessor :stderr
|
6
|
+
|
7
|
+
def initialize(stdout,stderr)
|
8
|
+
@stdout = stdout
|
9
|
+
@stderr = stderr
|
10
|
+
end
|
11
|
+
|
12
|
+
def error(err)
|
13
|
+
@stderr.puts err
|
14
|
+
end
|
15
|
+
|
16
|
+
def line(out)
|
17
|
+
@stdout.puts out
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
def line_yellow(out)
|
22
|
+
@stdout.puts out.yellow
|
23
|
+
end
|
24
|
+
|
25
|
+
def line_red(out)
|
26
|
+
@stdout.puts out.red
|
27
|
+
end
|
28
|
+
|
29
|
+
def line_blue(out)
|
30
|
+
@stdout.puts out.blue
|
31
|
+
end
|
32
32
|
|
33
33
|
end
|