syc-task 0.4.2 → 1.0.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.
- checksums.yaml +5 -13
- data/README.rdoc +9 -2
- data/bin/console_timer +1 -1
- data/bin/syctask +5 -5
- data/lib/syctask/environment.rb +157 -151
- data/lib/syctask/scanner.rb +1 -1
- data/lib/syctask/schedule.rb +126 -118
- data/lib/syctask/settings.rb +6 -4
- data/lib/syctask/statistics.rb +1 -1
- data/lib/syctask/task.rb +91 -82
- data/lib/syctask/task_planner.rb +4 -4
- data/lib/syctask/task_scheduler.rb +3 -3
- data/lib/syctask/task_service.rb +10 -9
- data/lib/syctask/task_tracker.rb +10 -6
- data/lib/syctask/version.rb +2 -2
- data/lib/syctime/time_util.rb +32 -33
- data/lib/sycutil/console_timer.rb +5 -9
- metadata +112 -83
data/lib/syctask/environment.rb
CHANGED
@@ -1,43 +1,42 @@
|
|
1
1
|
require 'find'
|
2
2
|
|
3
3
|
module Syctask
|
4
|
-
|
5
4
|
# System directory of syctask
|
6
5
|
SYC_DIR = File.join(ENV['HOME'], '.syc/syctask') # expand_path('~/.syc/syctask')
|
7
6
|
# ID file where the last issued ID is saved
|
8
|
-
ID = SYC_DIR +
|
7
|
+
ID = SYC_DIR + '/id'
|
9
8
|
# File that contains all issued IDs
|
10
|
-
IDS = SYC_DIR +
|
9
|
+
IDS = SYC_DIR + '/ids'
|
11
10
|
# File with tags
|
12
|
-
TAGS = SYC_DIR +
|
11
|
+
TAGS = SYC_DIR + '/tags'
|
13
12
|
# File with the general purpose tasks
|
14
|
-
DEFAULT_TASKS = SYC_DIR +
|
13
|
+
DEFAULT_TASKS = SYC_DIR + '/default_tasks'
|
15
14
|
# File that holds the default task directory
|
16
|
-
DEFAULT_TASKS_DIR = SYC_DIR +
|
15
|
+
DEFAULT_TASKS_DIR = SYC_DIR + '/default_tasks_dir'
|
17
16
|
# Log file that logs all activities of syctask like creation of tasks
|
18
|
-
TASKS_LOG = SYC_DIR +
|
17
|
+
TASKS_LOG = SYC_DIR + '/tasks.log'
|
19
18
|
# File that holds the tracked task
|
20
|
-
TRACKED_TASK = SYC_DIR +
|
19
|
+
TRACKED_TASK = SYC_DIR + '/tracked_tasks'
|
21
20
|
# If files are re-indexed during re-indexing these tasks are save here
|
22
|
-
RIDX_LOG = SYC_DIR +
|
23
|
-
|
21
|
+
RIDX_LOG = SYC_DIR + '/reindex.log'
|
22
|
+
|
24
23
|
# Reads the default task directory from the DEFAULT_TASKS_DIR file if it
|
25
|
-
# exists. If it exist but doesn't contain a valid directory ~/.tasks is
|
24
|
+
# exists. If it exist but doesn't contain a valid directory ~/.tasks is
|
26
25
|
# returned as default tasks directory
|
27
|
-
dir = File.read(DEFAULT_TASKS_DIR) if File.
|
26
|
+
dir = File.read(DEFAULT_TASKS_DIR) if File.exist? DEFAULT_TASKS_DIR
|
28
27
|
# User specified default working directory
|
29
|
-
work_dir = dir if
|
28
|
+
work_dir = dir if !dir.nil? and !dir.empty? and File.exist? dir
|
30
29
|
# Set eather user defined work directory or default
|
31
30
|
WORK_DIR = work_dir.nil? ? File.join(ENV['HOME'], '.tasks') : work_dir
|
32
31
|
|
33
32
|
# Logs a task regarding create, update, done, delete
|
34
33
|
def log_task(type, task)
|
35
34
|
File.open(TASKS_LOG, 'a') do |file|
|
36
|
-
log_entry = "#{type
|
35
|
+
log_entry = "#{type};"
|
37
36
|
log_entry += "#{task.id};#{task.dir};"
|
38
37
|
log_entry += "#{task.title.gsub(';', '\'semicolon\'')};"
|
39
38
|
log_entry += "#{Time.now};"
|
40
|
-
log_entry += "#{Time.now}"
|
39
|
+
log_entry += "#{Time.now}"
|
41
40
|
file.puts log_entry
|
42
41
|
end
|
43
42
|
end
|
@@ -60,13 +59,14 @@ module Syctask
|
|
60
59
|
entry = "#{type};-1;;work;#{begins};#{ends}\n"
|
61
60
|
logs = File.read(TASKS_LOG)
|
62
61
|
return if logs.scan(entry)[0]
|
63
|
-
|
64
|
-
|
62
|
+
|
63
|
+
time_pat = "#{today.strftime('%Y-%m-%d')} \\d{2}:\\d{2}:\\d{2} [+-]\\d{4}"
|
64
|
+
pattern = /#{type};-1;;work;#{time_pat};#{time_pat}\n/
|
65
65
|
log = logs.scan(pattern)[0]
|
66
66
|
if log and logs.sub!(log, entry)
|
67
67
|
File.write(TASKS_LOG, logs)
|
68
68
|
else
|
69
|
-
File.open(TASKS_LOG, 'a') {|f| f.puts entry}
|
69
|
+
File.open(TASKS_LOG, 'a') { |f| f.puts entry }
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
@@ -74,13 +74,13 @@ module Syctask
|
|
74
74
|
def log_meetings(type, busy_time, meetings)
|
75
75
|
today = Time.now
|
76
76
|
logs = File.read(TASKS_LOG)
|
77
|
-
time_pat = "#{today.strftime(
|
78
|
-
pattern =
|
79
|
-
logs.gsub!(pattern,
|
80
|
-
busy_time.each_with_index do |busy,i|
|
81
|
-
begins = Time.local(today.year,today.mon,today.day,busy[0],busy[1],0)
|
82
|
-
ends = Time.local(today.year,today.mon,today.day,busy[2],busy[3],0)
|
83
|
-
meeting = meetings[i]
|
77
|
+
time_pat = "#{today.strftime('%Y-%m-%d')} \\d{2}:\\d{2}:\\d{2} [+-]\\d{4}"
|
78
|
+
pattern = /#{type};-2;;.*?;#{time_pat};#{time_pat}\n/
|
79
|
+
logs.gsub!(pattern, '')
|
80
|
+
busy_time.each_with_index do |busy, i|
|
81
|
+
begins = Time.local(today.year, today.mon, today.day, busy[0], busy[1], 0)
|
82
|
+
ends = Time.local(today.year, today.mon, today.day, busy[2], busy[3], 0)
|
83
|
+
meeting = meetings[i] || "Meeting #{i}"
|
84
84
|
logs << "#{type};-2;;#{meeting};#{begins};#{ends}\n"
|
85
85
|
end
|
86
86
|
File.write(TASKS_LOG, logs)
|
@@ -89,37 +89,39 @@ module Syctask
|
|
89
89
|
# Checks whether all files are available that are needed for syctask's
|
90
90
|
# operation
|
91
91
|
def check_environment
|
92
|
-
FileUtils.mkdir_p WORK_DIR unless File.
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
# Restore ARGV content
|
111
|
-
args.each {|arg| ARGV << arg} unless args.empty?
|
112
|
-
when 2
|
113
|
-
puts "o.k. - don't do nothing"
|
114
|
-
exit -1
|
92
|
+
FileUtils.mkdir_p WORK_DIR unless File.exist? WORK_DIR
|
93
|
+
return if viable?
|
94
|
+
|
95
|
+
recover, whitelisted_dirs, blacklisted_dirs = initialize_or_recover_system
|
96
|
+
case recover
|
97
|
+
when 0
|
98
|
+
FileUtils.mkdir_p SYC_DIR unless File.exist? SYC_DIR
|
99
|
+
File.write(ID, '0')
|
100
|
+
when 1
|
101
|
+
# Backup ARGV content
|
102
|
+
args = []
|
103
|
+
ARGV.each { |arg| args << arg } unless ARGV.empty?
|
104
|
+
ARGV.clear
|
105
|
+
reindex_tasks(whitelisted_dirs, blacklisted_dirs)
|
106
|
+
puts 'Successfully recovered syc-task'
|
107
|
+
if File.exist? RIDX_LOG
|
108
|
+
puts "-> A log file of re-indexed tasks can be found at\n" +
|
109
|
+
"#{RIDX_LOG}"
|
115
110
|
end
|
111
|
+
print 'Press any key to continue '
|
112
|
+
gets
|
113
|
+
# Restore ARGV content
|
114
|
+
args.each { |arg| ARGV << arg } unless args.empty?
|
115
|
+
when 2
|
116
|
+
puts "o.k. - don't do nothing"
|
117
|
+
exit(-1)
|
116
118
|
end
|
117
119
|
end
|
118
120
|
|
119
121
|
# Checks if system files are available that are needed for running syc-task.
|
120
122
|
# Returns true if neccessary system files are available, otherwise false.
|
121
123
|
def viable?
|
122
|
-
File.
|
124
|
+
File.exist? SYC_DIR and File.exist? ID
|
123
125
|
end
|
124
126
|
|
125
127
|
# Asks the user whether this is a fresh install because of missing system
|
@@ -127,7 +129,7 @@ module Syctask
|
|
127
129
|
# to a version > 0.0.7 or the user accidentally has deleted the system files.
|
128
130
|
# If it is a fresh install the system files are created. Otherwise the user
|
129
131
|
# can select to search for task files and recover the system.
|
130
|
-
#
|
132
|
+
#
|
131
133
|
# intialize_or_recover_system #=> recover, whitelisted_dirs, blacklisted_dirs
|
132
134
|
# recover = 0 just creates the system files as it is fresh install
|
133
135
|
# recover = 1 recover task files
|
@@ -138,47 +140,47 @@ module Syctask
|
|
138
140
|
whitelisted_dirs = []
|
139
141
|
blacklisted_dirs = []
|
140
142
|
|
141
|
-
puts
|
142
|
-
|
143
|
+
puts 'This seems to be a fresh install because there are no system files ' +
|
144
|
+
'available.'
|
143
145
|
puts "* If this is a fresh install just hit 'y'. "
|
144
146
|
puts "* Otherwise hit 'n' to go to the recovery step."
|
145
|
-
print
|
147
|
+
print 'Is this a fresh install (y/n)? '
|
146
148
|
answer = gets.chomp
|
147
|
-
if answer.downcase ==
|
149
|
+
if answer.downcase == 'y'
|
148
150
|
[0, nil, nil]
|
149
151
|
else
|
150
152
|
puts
|
151
|
-
puts
|
152
|
-
"due to a changed\nfile structure. For changes in version "+
|
153
|
-
|
154
|
-
puts
|
155
|
-
puts
|
153
|
+
puts 'If you have upgraded from version 0.0.7 or below than this is ' +
|
154
|
+
"due to a changed\nfile structure. For changes in version " +
|
155
|
+
'greater 0.0.7 see'
|
156
|
+
puts '--> https://rubygems.org/gems/syc-task'
|
157
|
+
puts 'Or you have accidentially deleted system files. In both cases ' +
|
156
158
|
"re-indexing\nwill recover syc-task."
|
157
|
-
print
|
159
|
+
print 'Do you want to recover syc-task (y/n)? '
|
158
160
|
answer = gets.chomp
|
159
|
-
if answer.downcase ==
|
161
|
+
if answer.downcase == 'y'
|
160
162
|
puts
|
161
|
-
puts
|
163
|
+
puts 'If you know where your task files are located then you can ' +
|
162
164
|
"specify the\ndirectories. Search starts in your home directory."
|
163
|
-
print
|
165
|
+
print 'Do you want to specify the directories (y/n)? '
|
164
166
|
answer = gets.chomp
|
165
|
-
if answer.downcase ==
|
166
|
-
puts
|
167
|
+
if answer.downcase == 'y'
|
168
|
+
puts 'Please enter directories, e.g. ~/.my-tasks ~/work-tasks'
|
167
169
|
whitelisted_dirs = gets.chomp.split(/\s+/)
|
168
|
-
|
170
|
+
.map { |f| File.expand_path(f) }
|
169
171
|
else
|
170
|
-
puts "You don't want to select task directories. It is adviced to "+
|
171
|
-
"exclude mounted \ndirectories as this might take very long to "+
|
172
|
-
|
172
|
+
puts "You don't want to select task directories. It is adviced to " +
|
173
|
+
"exclude mounted \ndirectories as this might take very long to " +
|
174
|
+
'search all directories for task files. Also if it is no ' +
|
173
175
|
"stable connection\n the recovery process might be aborted"
|
174
|
-
print
|
175
|
-
if answer.downcase ==
|
176
|
-
puts
|
176
|
+
print 'Do you want to exclude directories (y/n)? '
|
177
|
+
if answer.downcase == 'y'
|
178
|
+
puts 'Please enter directories, e.g. ~/mount ~/.no-tasks'
|
177
179
|
blacklisted_dirs = gets.chomp.split(/\s+/)
|
178
|
-
|
180
|
+
.map { |f| File.expand_path(f) }
|
179
181
|
else
|
180
|
-
|
181
|
-
puts "Searching directories and all sub-directories starting in\n"+
|
182
|
+
[ENV['HOME']]
|
183
|
+
puts "Searching directories and all sub-directories starting in\n" +
|
182
184
|
"#{ENV['HOME']}"
|
183
185
|
end
|
184
186
|
end
|
@@ -202,41 +204,43 @@ module Syctask
|
|
202
204
|
# * Copy all system files planned_tasks, time_schedule, tasks.log, id to the
|
203
205
|
# SYC_DIR directory if not already in the SYC_DIR directory. This should
|
204
206
|
# only be if upgrading from version 0.0.7 and below.
|
205
|
-
def reindex_tasks(dirs, excluded) #root)
|
206
|
-
FileUtils.mkdir_p SYC_DIR unless File.
|
207
|
+
def reindex_tasks(dirs, excluded) # root)
|
208
|
+
FileUtils.mkdir_p SYC_DIR unless File.exist? SYC_DIR
|
207
209
|
new_id = {}
|
208
210
|
to_be_renamed = {}
|
209
|
-
puts
|
211
|
+
puts '-> Collect task files...'
|
210
212
|
task_files = task_files(dirs, excluded)
|
211
|
-
puts
|
213
|
+
puts '-> Restore ID counter...'
|
212
214
|
initialize_id(task_files)
|
213
|
-
print
|
214
|
-
collect_by_id(task_files).each do |
|
215
|
+
print '-> Start re-indexing now...'
|
216
|
+
collect_by_id(task_files).each do |_id, files|
|
215
217
|
next if files.size < 2
|
216
|
-
|
218
|
+
|
219
|
+
files.each_with_index do |file, i|
|
217
220
|
next if i == 0 # need to re-index only second and following tasks
|
221
|
+
|
218
222
|
result = reindex_task(file)
|
219
223
|
# associate old id to new id and dir name
|
220
224
|
if new_id[result[:old_id]].nil?
|
221
|
-
new_id[result[:old_id]] = {result[:dirname] => result[:new_id]}
|
225
|
+
new_id[result[:old_id]] = { result[:dirname] => result[:new_id] }
|
222
226
|
else
|
223
227
|
new_id[result[:old_id]][result[:dirname]] = result[:new_id]
|
224
|
-
end
|
228
|
+
end
|
225
229
|
# assign tmp_file to new_file for later renaming
|
226
230
|
to_be_renamed[result[:tmp_file]] = result[:new_file]
|
227
231
|
# document the re-indexing of tasks
|
228
|
-
log_reindexing(result[:old_id], result[:new_id], result[:new_file])
|
232
|
+
log_reindexing(result[:old_id], result[:new_id], result[:new_file])
|
229
233
|
end
|
230
|
-
end
|
231
|
-
to_be_renamed.each {|old_name,new_name| File.rename(old_name, new_name)}
|
234
|
+
end
|
235
|
+
to_be_renamed.each { |old_name, new_name| File.rename(old_name, new_name) }
|
232
236
|
puts
|
233
|
-
puts
|
237
|
+
puts '-> Update task log file'
|
234
238
|
update_tasks_log(dirs, excluded, new_id)
|
235
|
-
puts
|
239
|
+
puts '-> Update planned tasks files'
|
236
240
|
update_planned_tasks(dirs, excluded, new_id)
|
237
|
-
puts
|
241
|
+
puts '-> Move schedule files...'
|
238
242
|
move_time_schedule_files(dirs, excluded)
|
239
|
-
puts
|
243
|
+
puts '-> Update tracked task file...'
|
240
244
|
update_tracked_task(dirs, excluded)
|
241
245
|
end
|
242
246
|
|
@@ -247,7 +251,7 @@ module Syctask
|
|
247
251
|
# After all tasks are re-indexed the tmp_file_names have to be renamed to the
|
248
252
|
# new_file_names. The renaming is in the responsibility of the calling method.
|
249
253
|
def reindex_task(file)
|
250
|
-
print
|
254
|
+
print '.'
|
251
255
|
task = File.read(file)
|
252
256
|
old_id = task.scan(/(?<=^id: )\d+$/)[0]
|
253
257
|
new_id = next_id.to_s
|
@@ -257,31 +261,32 @@ module Syctask
|
|
257
261
|
tmp_file = "#{new_file}_"
|
258
262
|
File.write(tmp_file, task)
|
259
263
|
File.delete(file)
|
260
|
-
{old_id: old_id,
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
264
|
+
{ old_id: old_id,
|
265
|
+
new_id: new_id,
|
266
|
+
tmp_file: tmp_file,
|
267
|
+
new_file: new_file,
|
268
|
+
dirname: dirname }
|
265
269
|
end
|
266
270
|
|
267
271
|
# Determines the greatest task ID out of the provided tasks and saves it to
|
268
272
|
# the ID file
|
269
273
|
def initialize_id(tasks)
|
270
|
-
pattern = %r{(
|
271
|
-
tasks.sort_by! {|t| t.scan(pattern)[0].to_i}
|
272
|
-
save_id(tasks[tasks.size-1].scan(pattern)[0].to_i)
|
274
|
+
pattern = %r{(?<=/)\d+(?=\.task)}
|
275
|
+
tasks.sort_by! { |t| t.scan(pattern)[0].to_i }
|
276
|
+
save_id(tasks[tasks.size - 1].scan(pattern)[0].to_i)
|
273
277
|
end
|
274
278
|
|
275
279
|
# Saves the ids to ids file
|
276
280
|
def save_ids(id, file)
|
277
281
|
entry = "#{id},#{file}"
|
278
|
-
return if File.
|
279
|
-
|
282
|
+
return if File.exist? IDS and !File.read(IDS).scan(entry).empty?
|
283
|
+
|
284
|
+
File.open(IDS, 'a') { |f| f.puts entry }
|
280
285
|
end
|
281
286
|
|
282
287
|
# Save the id to the ID file. Returns the id when save was successful
|
283
288
|
def save_id(id)
|
284
|
-
File.write(ID,id)
|
289
|
+
File.write(ID, id)
|
285
290
|
id
|
286
291
|
end
|
287
292
|
|
@@ -295,30 +300,33 @@ module Syctask
|
|
295
300
|
# Logs if a task is re-indexed
|
296
301
|
def log_reindexing(old_id, new_id, file)
|
297
302
|
entry = "#{old_id},#{new_id},#{file}"
|
298
|
-
return if File.
|
299
|
-
|
300
|
-
|
303
|
+
return if File.exist? RIDX_LOG and !File.read(RIDX_LOG)
|
304
|
+
.scan(entry).empty?
|
305
|
+
|
306
|
+
File.open(RIDX_LOG, 'a') { |f| f.puts entry }
|
301
307
|
end
|
302
308
|
|
303
309
|
# Updates the tasks.log file if tasks are re-indexed with the task's new ids
|
304
|
-
def update_tasks_log(dirs, excluded=[], new_ids)
|
310
|
+
def update_tasks_log(dirs, excluded = [], new_ids)
|
305
311
|
tasks_log_files(dirs, excluded).each do |file|
|
306
312
|
logs = File.readlines(file)
|
307
|
-
logs.each_with_index do |log,i|
|
313
|
+
logs.each_with_index do |log, i|
|
308
314
|
type = log.scan(/^.*?(?=;)/)[0]
|
309
|
-
logs[i] = log.sub!(
|
315
|
+
logs[i] = log.sub!('-', ';') if log.scan(/(?<=^#{type};)\d+-/)[0]
|
310
316
|
old_id = log.scan(/(?<=^#{type};)\d+(?=;)/)[0]
|
311
317
|
next unless new_ids[old_id]
|
318
|
+
|
312
319
|
task_dir = log.scan(/(?<=^#{type};#{old_id};).*?(?=;)/)[0]
|
313
320
|
next unless new_ids[old_id][task_dir]
|
314
|
-
|
321
|
+
|
322
|
+
logs[i] = log.sub("#{old_id};#{task_dir}",
|
315
323
|
"#{new_ids[old_id][task_dir]};#{task_dir}")
|
316
324
|
end
|
317
325
|
if file == TASKS_LOG
|
318
326
|
File.write(TASKS_LOG, logs.join)
|
319
327
|
else
|
320
|
-
#TODO only append a line if it is not already available in TASKS_LOG
|
321
|
-
File.open(TASKS_LOG, 'a') {|f| f.puts logs.join}
|
328
|
+
# TODO: only append a line if it is not already available in TASKS_LOG
|
329
|
+
File.open(TASKS_LOG, 'a') { |f| f.puts logs.join }
|
322
330
|
FileUtils.rm file
|
323
331
|
end
|
324
332
|
end
|
@@ -333,11 +341,12 @@ module Syctask
|
|
333
341
|
def update_planned_tasks(dirs, excluded, new_ids)
|
334
342
|
planned_tasks_files(dirs, excluded).each do |file|
|
335
343
|
tasks = File.readlines(file)
|
336
|
-
tasks.each_with_index do |task,i|
|
344
|
+
tasks.each_with_index do |task, i|
|
337
345
|
task_dir, old_id = task.chomp.split(',')
|
338
346
|
next unless new_ids[old_id]
|
339
347
|
next unless new_ids[old_id][task_dir]
|
340
|
-
|
348
|
+
|
349
|
+
tasks[i] = "#{task_dir},#{new_ids[old_id][task_dir]}"
|
341
350
|
end
|
342
351
|
File.write("#{SYC_DIR}/#{File.basename(file)}", tasks.join("\n"))
|
343
352
|
end
|
@@ -347,12 +356,14 @@ module Syctask
|
|
347
356
|
def update_tracked_task(dirs, excluded)
|
348
357
|
@tracked = get_files(dirs, excluded, /tracked_tasks/) if @tracked.nil?
|
349
358
|
return if @tracked.empty?
|
359
|
+
|
350
360
|
task = File.read(@tracked[0])
|
351
|
-
if File.
|
361
|
+
if File.exist? RIDX_LOG
|
352
362
|
old_id = task.scan(/(?<=id: )\d+$/)
|
353
363
|
old_dir = task.scan(/(?<=dir: ).*$/)
|
354
364
|
return if old_id.empty? or old_dir.empty?
|
355
|
-
|
365
|
+
|
366
|
+
pattern = %r{(?<=#{old_id[0]},)\d+(?=,#{old_dir[0]}/\d+\.task)}
|
356
367
|
new_id = File.read(RIDX_LOG).scan(pattern)
|
357
368
|
task.gsub!("id: #{old_id}", "id: #{new_id}")
|
358
369
|
end
|
@@ -364,7 +375,7 @@ module Syctask
|
|
364
375
|
def collect_by_id(tasks)
|
365
376
|
extract = {}
|
366
377
|
tasks.each do |task|
|
367
|
-
id = task.scan(
|
378
|
+
id = task.scan(%r{(?<=/)\d+(?=\.task$)})[0]
|
368
379
|
extract[id].nil? ? extract[id] = [task] : extract[id] << task
|
369
380
|
end
|
370
381
|
extract
|
@@ -372,39 +383,38 @@ module Syctask
|
|
372
383
|
|
373
384
|
# Retrieves all task files in and below the provided dir. Returns an array of
|
374
385
|
# task files
|
375
|
-
def task_files(dirs, excluded=[])
|
386
|
+
def task_files(dirs, excluded = [])
|
376
387
|
get_files(dirs, excluded, /\d+\.task$/)
|
377
388
|
end
|
378
389
|
|
379
390
|
# Retrieves all planned task files in and below the given directory
|
380
|
-
def planned_tasks_files(dirs, excluded=[])
|
381
|
-
pattern =
|
391
|
+
def planned_tasks_files(dirs, excluded = [])
|
392
|
+
pattern = /\d{4}-\d{2}-\d{2}_planned_tasks/
|
382
393
|
get_files(dirs, excluded, pattern)
|
383
394
|
end
|
384
395
|
|
385
396
|
# Retrieves all schedule files in and below the given directory
|
386
|
-
def time_schedule_files(dirs, excluded=[])
|
387
|
-
pattern =
|
397
|
+
def time_schedule_files(dirs, excluded = [])
|
398
|
+
pattern = /\d{4}-\d{2}-\d{2}_time_schedule/
|
388
399
|
get_files(dirs, excluded, pattern)
|
389
400
|
end
|
390
401
|
|
391
402
|
# Retrieves als tasks.log files in and below the given directory
|
392
|
-
def tasks_log_files(dirs, excluded=[])
|
403
|
+
def tasks_log_files(dirs, excluded = [])
|
393
404
|
get_files(dirs, excluded, /tasks\.log/)
|
394
405
|
end
|
395
406
|
|
396
407
|
# Retrieves all files that meet the pattern in and below the given directory
|
397
|
-
def get_files(included, excluded=[], pattern)
|
408
|
+
def get_files(included, excluded = [], pattern)
|
398
409
|
files = []
|
399
410
|
Find.find(*included) do |path|
|
400
411
|
if FileTest.directory?(path)
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
files << File.expand_path(path) if File.basename(path) =~ pattern
|
412
|
+
next unless excluded.include?(path)
|
413
|
+
|
414
|
+
Find.prune
|
415
|
+
|
416
|
+
elsif File.basename(path) =~ pattern
|
417
|
+
files << File.expand_path(path)
|
408
418
|
end
|
409
419
|
end
|
410
420
|
files
|
@@ -412,9 +422,9 @@ module Syctask
|
|
412
422
|
|
413
423
|
# Retrieve all directories that contain tasks
|
414
424
|
def get_task_dirs(dir)
|
415
|
-
original_dir = File.expand_path(
|
425
|
+
original_dir = File.expand_path('.')
|
416
426
|
Dir.chdir(dir)
|
417
|
-
dirs = Dir.glob(
|
427
|
+
dirs = Dir.glob('**/*.task', File::FNM_DOTMATCH).map do |f|
|
418
428
|
File.dirname(File.expand_path(f))
|
419
429
|
end
|
420
430
|
Dir.chdir(original_dir)
|
@@ -424,10 +434,10 @@ module Syctask
|
|
424
434
|
# Retrieves all directories that contain tasks and the count of contained
|
425
435
|
# tasks in and below the provided directory
|
426
436
|
def get_task_dirs_and_count(dir)
|
427
|
-
original_dir = File.expand_path(
|
437
|
+
original_dir = File.expand_path('.')
|
428
438
|
Dir.chdir(dir)
|
429
439
|
dirs_and_count = Hash.new(0)
|
430
|
-
Dir.glob(
|
440
|
+
Dir.glob('**/*.task', File::FNM_DOTMATCH).each do |f|
|
431
441
|
dirname = File.dirname(File.expand_path(f))
|
432
442
|
dirs_and_count[dirname] += 1
|
433
443
|
end
|
@@ -438,41 +448,37 @@ module Syctask
|
|
438
448
|
# Moves the tasks.log file to the system directory if not there. Should only
|
439
449
|
# be if upgrading from version 0.0.7 and below
|
440
450
|
def move_task_log_file(dirs, excluded)
|
441
|
-
if @tasks_log_files.nil?
|
442
|
-
@tasks_log_files = tasks_log_files(dirs, excluded)
|
443
|
-
end
|
451
|
+
@tasks_log_files = tasks_log_files(dirs, excluded) if @tasks_log_files.nil?
|
444
452
|
@tasks_log_files.each do |f|
|
445
453
|
next if f == TASKS_LOG
|
454
|
+
|
446
455
|
tasks_log = File.read(f)
|
447
|
-
File.open(TASKS_LOG, 'a') {|t| t.puts tasks_log}
|
448
|
-
FileUtils.mv(f, "#{f}_#{Time.now.strftime(
|
456
|
+
File.open(TASKS_LOG, 'a') { |t| t.puts tasks_log }
|
457
|
+
FileUtils.mv(f, "#{f}_#{Time.now.strftime('%y%m%d')}")
|
449
458
|
end
|
450
459
|
end
|
451
460
|
|
452
|
-
# Moves the planned tasks file to the system directory if not there. Should
|
461
|
+
# Moves the planned tasks file to the system directory if not there. Should
|
453
462
|
# only be if upgrading from version 0.0.7 and below
|
454
463
|
def move_planned_tasks_files(dirs, excluded)
|
455
|
-
if @planned_tasks_files.nil?
|
456
|
-
@planned_tasks_files = planned_tasks_files(dirs, excluded)
|
457
|
-
end
|
464
|
+
@planned_tasks_files = planned_tasks_files(dirs, excluded) if @planned_tasks_files.nil?
|
458
465
|
@planned_tasks_files.each do |file|
|
459
466
|
to_file = "#{SYC_DIR}/#{File.basename(file)}"
|
460
467
|
next if file == to_file
|
468
|
+
|
461
469
|
FileUtils.mv file, to_file
|
462
470
|
end
|
463
471
|
end
|
464
472
|
|
465
|
-
# Moves the schedule file to the system directory if not there. Should
|
473
|
+
# Moves the schedule file to the system directory if not there. Should
|
466
474
|
# only be if upgrading from version 0.0.7 and below
|
467
475
|
def move_time_schedule_files(dirs, excluded)
|
468
|
-
if @time_schedule_files.nil?
|
469
|
-
@time_schedule_files = time_schedule_files(dirs, excluded)
|
470
|
-
end
|
476
|
+
@time_schedule_files = time_schedule_files(dirs, excluded) if @time_schedule_files.nil?
|
471
477
|
@time_schedule_files.each do |file|
|
472
|
-
to_file = "#{SYC_DIR}/#{File.basename(file)}"
|
478
|
+
to_file = "#{SYC_DIR}/#{File.basename(file)}"
|
473
479
|
next if file == to_file
|
480
|
+
|
474
481
|
FileUtils.mv file, to_file
|
475
|
-
end
|
482
|
+
end
|
476
483
|
end
|
477
|
-
|
478
484
|
end
|
data/lib/syctask/scanner.rb
CHANGED
@@ -40,7 +40,7 @@ module Syctask
|
|
40
40
|
# It checks if 'content' is a file and if it exists scans the file otherwise
|
41
41
|
# it asumes the content to be text and scans accordingly.
|
42
42
|
def scan(content)
|
43
|
-
if File.
|
43
|
+
if File.exist? content
|
44
44
|
scan_file(content)
|
45
45
|
else
|
46
46
|
scan_text(content)
|