first commit
[bl_monitoring.git] / tools / archiving_extraction / archi_utils.py
blob52e2f97f89993de36392c129c301fabbf89435ee
1 #!/usr/bin/env python
3 import sys, os, time
6 ##############################################
7 def sort_by_archiModes( attrs_archiModes_dict ):
10 attrs_archiModes = []
11 for a in attrs_archiModes_dict.keys():
12 attrs_archiModes.append([a] + attrs_archiModes_dict[a])
14 ac_byModes = [] # ac as archiving configuration
16 "Initialization"
17 attrs = [ attrs_archiModes[0][0] ]
18 ac_byModes.append([ attrs_archiModes[0][1:], attrs ] )
21 for i in range (1, len(attrs_archiModes)):
23 attr_archiMode_i = attrs_archiModes[i]
25 curr_attr = attr_archiMode_i[0]
26 curr_mode = attr_archiMode_i[1:]
27 seen_mode = 0
29 j = 0
30 while j in range (len(ac_byModes)) and not seen_mode:
32 if curr_mode == ac_byModes[j][0]:
33 seen_mode = 1
34 ac_byModes[j][1].append(curr_attr)
35 j = j +1
37 if not seen_mode:
38 attrs = [curr_attr]
39 ac_byModes.append([curr_mode, attrs])
41 #print ac_byModes # debug
42 return ac_byModes
45 ##############################################
46 ##def sort_by_archiModes( attrs_archiModes ):
49 ## ac_byModes = [] # ac as archiving configuration
51 ## "Initialization"
52 ## attrs = [ attrs_archiModes[0][0] ]
53 ## ac_byModes.append([ attrs_archiModes[0][1:], attrs ] )
56 ## for i in range (1, len(attrs_archiModes)):
58 ## attr_archiMode_i = attrs_archiModes[i]
60 ## curr_attr = attr_archiMode_i[0]
61 ## curr_mode = attr_archiMode_i[1:]
62 ## seen_mode = 0
64 ## j = 0
65 ## while j in range (len(ac_byModes)) and not seen_mode:
67 ## if curr_mode == ac_byModes[j][0]:
68 ## seen_mode = 1
69 ## ac_byModes[j][1].append(curr_attr)
70 ## j = j +1
72 ## if not seen_mode:
73 ## attrs = [curr_attr]
74 ## ac_byModes.append([curr_mode, attrs])
76 ## #print ac_byModes # debug
77 ## return ac_byModes
85 #################################################
86 def ac_byModes_fromDevFiles( devAC_filenames ):
89 splitted_lines = []
90 for f in range (len(devAC_filenames)):
92 f_lines = open(devAC_filenames[f]).readlines()
94 "The 1st line is supposed to contain the device name"
95 "Removing '\n' at the end of the string"
96 dev_name = f_lines[0].split()[0]
98 for i in range (1, len(f_lines)):
99 splitted_f_line = f_lines[i].split()
101 "Skipping the empty lines"
102 if( len(splitted_f_line) != 0 and f_lines[i][0] != "#"):
103 "Full attr name = device name + attr name"
104 splitted_f_line[0] = dev_name + '/' + splitted_f_line[0]
105 splitted_lines.append(splitted_f_line)
108 return splitted_lines
112 ############################
113 if __name__ == '__main__':
115 if len(sys.argv) != 2:
116 print "File name expected"
117 sys.exit(0)
119 #print ac_byModes_fromDevList(sys.argv[1])
120 filenames = []
121 filenames.append(sys.argv[1])
122 print ac_byModes_fromDevFiles(filenames)