Module: TaskLoop::ProjTaskList

Included in:
List, Run
Defined in:
lib/taskloop/utils/proj_tasklist.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#proj_tasklist_mapObject (readonly)

Returns the value of attribute proj_tasklist_map.



4
5
6
# File 'lib/taskloop/utils/proj_tasklist.rb', line 4

def proj_tasklist_map
  @proj_tasklist_map
end

Instance Method Details

#clean_cache_file_if_neededObject



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/taskloop/utils/proj_tasklist.rb', line 121

def clean_cache_file_if_needed
  unless @proj_tasklist_map != nil
    return
  end

  @proj_tasklist_map.each do |proj, list|
    data_proj_dir = File.join(taskloop_data_dir, proj.sha1_8bit)
    files = Dir.entries(data_proj_dir)

    list.each do |task|
      files.delete(task.logfile_name)
      files.delete(task.timefile_name)
      files.delete(task.loopfile_name)
    end

    files.each do |file|
      path = File.join(data_proj_dir, file)
      if file != '.' && file != '..' && file != '.Taskfile.deploy' && file != '.description' && File.exists?(path)
        File.delete(path)
      end
    end
  end
end

#construct_proj_tasklist_mapObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/taskloop/utils/proj_tasklist.rb', line 31

def construct_proj_tasklist_map
  # load Taskfiles from ~/.taskloop/projlist
  taskloop_proj_list_dirs.each do |dir|
    deploy_file_path = File.join(taskloop_data_dir, dir.sha1_8bit,".Taskfile.deploy")
    unless File.exists?(deploy_file_path)
      puts "Warning: #{deploy_file_path} is not exist, taskloop will skip its execution.".ansi.yellow
      proj_tasklist_map[dir] = []
      next
    end
    eval_taskfile(deploy_file_path)
    proj_tasklist_map[dir] = TaskLoop::Task.tasklist
    TaskLoop::Task.tasklist = []
  end
end

#create_data_proj_description_if_neededObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/taskloop/utils/proj_tasklist.rb', line 18

def create_data_proj_description_if_needed
  taskloop_proj_list_dirs.each do |dir|
    # create ~/.taskloop/data/<proj_sha1-8bit>/.description
    data_proj_description_path = File.join(taskloop_data_dir, dir.sha1_8bit, ".description")
    unless File.exists?(data_proj_description_path)
      desc = File.new(data_proj_description_path, "w+")
      desc.puts dir
      desc.close
    end
  end
end

#create_data_proj_dir_if_neededObject



10
11
12
13
14
15
16
# File 'lib/taskloop/utils/proj_tasklist.rb', line 10

def create_data_proj_dir_if_needed
  taskloop_proj_list_dirs.each do |dir|
    # create ~/.tasklooop/data/<proj-sha1-8bit>/ dir
    data_proj_dir = File.join(taskloop_data_dir, dir.sha1_8bit)
    create_dir_if_needed(data_proj_dir)
  end
end

#eval_taskfile(path) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
# File 'lib/taskloop/utils/proj_tasklist.rb', line 109

def eval_taskfile(path)
  string = File.open(path, 'r:utf-8', &:read)
  if string.respond_to?(:encoding) && string.encoding.name != 'UTF-8'
    string.encode!('UTF-8')
  end
  eval(string)
rescue Exception => e
  message = "Invalid `#{path}` file: #{e.message}"
  # TODO: @baocq
  raise ArgumentError, "test"
end