-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzyp_hist.js
265 lines (218 loc) · 9.33 KB
/
zyp_hist.js
1
2
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
function myFunction(){
var input = document.getElementById("myFile");
var file = input.files[0];
var reader = new FileReader();
reader.onload = function(){
//把文件内容保存到filecontent变量
var filecontent = reader.result;
//输出文件内容到<code>标签中
// document.getElementById("fileContent").innerHTML = filecontent;
onReadFileContent(filecontent);
};
reader.readAsText(file);
}
let installed_list = new Set();
let removed_list = new Set();
function set_installed(p) {
installed_list.add(p);
removed_list.delete(p);
}
function set_removed(p) {
installed_list.delete(p);
removed_list.add(p);
}
let obj_gByTime = {}; // 创建对象obj_gByTime
function onReadFileContent(filecontent) {
let lines_arr = filecontent.split('\n');
lines_arr = lines_arr.filter(function(line_t) {
return ! line_t.startsWith("#");
});
//对于每一行,都按"|"分割
let lines_cols_arr = [] ;
for (let i = 0; i < lines_arr.length; i++) {
var tmp_arr = lines_arr[i].split('|') ;
if ( tmp_arr.length <2)
continue;
lines_cols_arr.push(tmp_arr);
}
let start_time;
// 按顺序遍历每一行,按照第一列(时间)内容
lines_cols_arr.forEach(function(line) {
// console.log(line);
// 如果遇到第二列是 install / remove 之外的,就更新时间
const time = line[0].trim();
const action = line[1].trim();
if ( ! ['install', 'remove'].includes(action) ) {
// console.log(action, "new time", time);
start_time = time;
}
// console.log(line);
/*把lines里的各行分类到obj_gByTime里,键名为时间,键值为对象
* 键值这个对象内容为'action':第二列内容,'c3':第3列内容, 'c4':第4列内容, 'c6':第6列内容, 'c7':第7列内容*/
let lineObj = {
'action': action.trim(),
'c3': line[2]?.trim(),
'c4': line[3]?.trim(),
'c6': line[5]?.trim(),
'c7': line[6]?.trim()
};
// console.log(time, lineObj);
if (! Object.keys(obj_gByTime).includes(start_time) ) {
// console.log("haha");
obj_gByTime [start_time] = [];
}
obj_gByTime[start_time] .push (lineObj); // 键名为时间
});
// 删掉不包含install或remove的时间(一般都是radd或rremove)
for (time of Object.keys(obj_gByTime) ) {
if (! obj_gByTime [time].some(obj => obj.action === 'install' || obj.action === 'remove') ) {
delete obj_gByTime [time];
}
}
for (time of Object.keys(obj_gByTime) ) {
const session = obj_gByTime [time];
var command;
var arr_command;
var program;
var onSystemInstall = false;
var session_install_list = { auto: [], manu: [], unsure: [], };
var session_remove_list = [];
if (session[0] ['action'] == 'command' ) {
command = session[0]['c4'];
arr_command = command.replaceAll("'", "").split(' ');
if (session[0]['c3'] == "root@install")
onSystemInstall = true;
//判断program
if ( (new RegExp("\\bzypper\\b")).test( command.split(' ')[0] ) ) {
program = "zypper";
} else {
if ( (new RegExp("\\bsw_single\\b")).test( command ) )
program = "yast_sw_single";
else if ( (new RegExp("\\bOneClickInstallWorker\\b")).test( command ) )
program = "OneClickInstallWorker";
else
program = "system_installation";
}
}
// 开始遍历这个session中的每个包操作
for (let i=1; i<session.length; ++i) {
const line = session [i];
const action = line['action'];
if (action == 'install') {
const p = line['c3'];
set_installed(p);
var install_type;
// 判断install_type
if (line['c6'] == "root@install"
|| (new RegExp("^[0-9]+:ruby\.ruby") ).test( line['c6'] )
) {
install_type = 'manu';
} else {
if (program == 'zypper') {
var zypperAction;
for (var j=1; j<arr_command.length; j++) {
const arg = arr_command[j];
if (arg.startsWith('-') ) {
continue;
}else {
if ( ['in', 'install'].includes(arg) )
zypperAction = 'install';
break;
}
}
if (zypperAction=='install') {
if (line['c6'].startsWith("root@"))
install_type='manu';
else
install_type='auto';
}else{
install_type='auto';
}
}else if (program == 'yast_sw_single') {
if (! line['c6'])
install_type='auto';
else
install_type='unsure';
}else if (program == 'system_installation') {
if (!install_type)
install_type = 'auto';
}
}
session_install_list[install_type].push(p);
}
if (action == 'remove') {
const p = line['c3']
set_removed(p);
session_remove_list.push(p);
}
}
session['program'] = program;
session['command'] = command;
for (let type of Object.keys(session_install_list)) {
var type_list = session_install_list[type];
type_list = type_list.sort();
}
session['session_install_list'] = session_install_list;
session['session_remove_list'] = session_remove_list.sort();
}
for (time of Object.keys(obj_gByTime) ) {
const session = obj_gByTime [time];
const program = session['program'];
const command = session['command'];
const session_install_list = session['session_install_list'];
const session_remove_list = session['session_remove_list'];
var html_manu = list_to_html(session_install_list['manu'] );
var html_auto = list_to_html( session_install_list['auto']) ;
var html_unsure = list_to_html( session_install_list['unsure']);
var html_remove = list_to_html( session_remove_list);
$$("#div_tables_cont").appendChild(htmlStr2dom(`
<div>
<hr>
<details>
<summary><b><code>${time} | ${program=="zypper"? command.replaceAll("'", "") : program}</code></b></summary>
<div>
<table>
<tr>
<th class="col_manu">User Install</th>
<th class="col_unsure">Install ?</th>
<th class="col_auto">Auto Install</th>
<th class="col_remove">Remove</th>
</tr>
<tr>
<td class="td_install col_manu">
<div><code>${html_manu}</code></div>
</td>
<td class="td_install col_unsure">
<div><code>${html_unsure}</code></div>
</td>
<td class="td_install col_auto">
<div><code>${html_auto}</code></div>
</td>
<td class="td_remove col_remove">
<div><code>${html_remove}</code></div>
</td>
</tr>
</table>
</div>
</details>
</div>
`))
}
// var output = JSON.stringify(obj_gByTime,null, 4);
// document.getElementById("fileContent").textContent = output;
Array.from( document.getElementsByTagName('details') ) .forEach( function (ele) {
ele.open = true;
});
}
function list_to_html(list) {
var html='';
for ( var ele of list) {
var p_status_class='';
if ( installed_list.has(ele) )
p_status_class=' p_installed';
else if (removed_list.has(ele))
p_status_class=' p_removed';
html += `<span class="span_p${p_status_class}">${ele}</span> \n`;
}
return html;
}