OSDN Git Service

Modified: Upload, Command execution
[eos/zephyr.git] / cli / lib / create-json-file.rb
1 EosHome           = ENV["EOS_HOME"]
2 EosSrc            = EosHome + "/src/Tools/"
3 JSONDirPath       = ENV["ZEPHYR_HOME"] + "/user-specific-files/OptionControlFile/"
4 CommandOptionPath = JSONDirPath + "commands/"
5 CommandListPath   = JSONDirPath + "command_list.json"
6 TagListPath       = JSONDirPath + "tag_list.json"
7 ErrorLogPath      = JSONDirPath + "error_log.json"
8
9 require ENV["ZEPHYR_HOME"] + "/cli/lib/option"
10 require "json"
11
12 error_logs    = Hash.new
13 command_lists = Array.new
14 class_names   = Dir.glob("#{EosSrc}*").sort
15 tag_list      = Array.new
16 tag_list.push("all")
17
18 if !(Dir.exist?(JSONDirPath))
19   Dir.mkdir(JSONDirPath, 0755)
20 end
21
22 if !(Dir.exist?(JSONDirPath + 'commands/'))
23   Dir.mkdir(JSONDirPath + 'commands/', 0755)
24 end
25
26 #For Debug
27 #count = 0
28
29 class_names.each do |class_path|
30   class_name = File.basename(class_path)
31
32   if (class_name == "Makefie" ||
33       class_name == "Makefile.orig" ||
34       class_name == "Config") then
35     next
36   end
37
38   command_names = Dir.glob("#{class_path}/*").sort
39
40   command_names.each do |command_path|
41     command_name = File.basename(command_path)
42     if (command_name=="Makefile"||
43         command_name=="Makefile.orig"||
44         command_name=="Config"
45       command_name == "Makefile.org"  ||
46         command_name == "q") then
47       next
48     end
49
50     #success Hash  {option->option ,tag->tag}
51     #error   Array [option_path,ex.class]
52     #タグがとれるようになったら、
53     #create_json_file.rbとoption.rbを書き換える
54     result = Option.csv2hash(command_path)
55     #tag    = result[:tag]
56
57     if result.class.to_s == "Hash"
58       # print "OK\n"
59       option = result[:option]
60       json_name = CommandOptionPath + "#{command_name}.json"
61       json = JSON.pretty_generate(option)
62
63       #write to ~/json/option/
64       open(json_name,"w") do |fh|
65         fh.write(json)
66       end
67
68       #prepare for ~/json/command_list.json
69       tmp = Hash.new
70       tmp[:name] = command_name
71       tmp[:tags]  = Array.new 
72       tmp[:tags].push("all")
73       tmp[:tags].push(class_name)
74       command_lists.push(tmp)
75
76       if !tag_list.include?(class_name)
77         tag_list.push(class_name)
78       end
79
80     elsif result.class.to_s == "Array"
81       error = Hash.new
82       error["path"]    = result[0]
83       error["error"]   = result[1]
84       error_logs[command_name] = error
85     else 
86       print "Unexpected Error Occured!\n"
87     end
88   end 
89   #break
90 end
91
92   #Write to ~/json/command_list.json
93 json = JSON.pretty_generate(command_lists)
94 open(CommandListPath,"w") do |fh|
95   fh.write(json)
96 end
97
98 #Write to ~/json/error_log.json
99 json = JSON.pretty_generate(error_logs)
100 open(ErrorLogPath,"w") do |fh|
101   fh.write(json)
102 end
103
104 ##write to ~/json/tag_list.json
105 json = JSON.pretty_generate(tag_list)
106 open(TagListPath,"w") do |fh|
107   fh.write(json)
108 end
109