OSDN Git Service

Modified: Upload, Command execution
[eos/zephyr.git] / cli / lib / option.rb
1 require 'csv'
2 require 'json'
3
4 module Option
5     def csv2hash(command_path)
6         #command_name = File.basename(command_path)
7         option_path = "#{command_path}/Config/OptionControlFile"
8
9         # option[0] = about -i, 
10         # option[1] = about -o, 
11         # option[3] = about -m, .... etc 
12         option = Array.new
13         index  = 0
14         begin
15             CSV.foreach(option_path) do |ref| 
16                 if ref[0] =~ /^#/ 
17                     next
18                 end
19
20                 # [{argIndex: ,argName: ,argType: ,initialValue: },{.,.}.,.{.,.}]
21                 optionNumber = ref[4].to_s.to_i
22
23                 if optionNumber != 0
24                     option[index]                     = Hash.new{|i|{}}
25                     option[index]["option"]           = ref[0].to_s
26                     option[index]["fullOption"]       = ref[1]
27                     option[index]["optionName"]       = ref[2]
28                     option[index]["optionProperties"] = ref[3].to_s == "Essential"
29                     option[index]["optionNumber"]     = ref[4].to_s.to_i
30
31
32                     option[index]["arg"]              = Array.new(option[index]["optionNumber"]){|i|{}} 
33
34                     option[index]["arg"].each_with_index do |arg,i|
35                         arg["argIndex"]      = ref[4*(i+1)+1].to_s
36                         arg["argName"]       = ref[4*(i+1)+2].to_s
37                         argType              = ref[4*(i+1)+3].to_s.split('::')  #argType{ inFile::mrcImage::ASCII } and so on
38                         arg["argType"]       = argType.shift                    #arg["argType"]   = inFile | outFile | appendFile ...
39                         arg["attribute"] = argType.empty? ? nil : argType       #arg["attribute"] = [ mrcImage,ASCII,... ]
40                         arg["initialValue"] = ref[4*(i+1)+4].to_s
41
42                         case arg["argType"]
43                         when "inFile","inFileList","inFileListNoOpen" then
44                             arg["formType"] = "select"
45                         when "outFile","outFileList","appendFile","appendFileList","Character","String","StringAll" then
46                             arg["formType"] = "text"
47                         when "Integer","Real" then
48                             arg["formType"] = "number"
49                         else 
50                             arg["formType"] = nil
51                         end
52
53                         if (arg["initialValue"] == "NULL"||
54                             arg["initialValue"] == "stdout") then
55                             arg["initialValue"] = ""
56                         end
57                     end
58                     index += 1
59                 end
60             end
61             #tag = nil
62             success = Hash.new
63             success[:option] = option
64             #success["tag"] = tag
65             return success
66         rescue => ex
67             return option_path,ex.class
68         end
69     end
70     module_function :csv2hash
71 end