@@ 112-140 (lines=29) @@ | ||
109 | fdat[map_val] = vals |
|
110 | return fdat |
|
111 | ||
112 | ||
113 | def get_file_list(fname): |
|
114 | """Return the file as a list - use on small files only. |
|
115 | ||
116 | :param fname: Full pathname to a file. |
|
117 | :type fname: str |
|
118 | :rtype: dict |
|
119 | """ |
|
120 | if os.access(fname, os.R_OK): |
|
121 | with open(fname, 'r') as filed: |
|
122 | return deque(filed.read().strip().split("\n")) |
|
123 | return deque(['']) |
|
124 | ||
125 | ||
126 | def get_file(fname): |
|
127 | """Return the file as a string - use on small files only. |
|
128 | ||
129 | :param fname: Full pathname to a file. |
|
130 | :type fname: str |
|
131 | :rtype: dict |
|
132 | """ |
|
133 | if os.access(fname, os.R_OK): |
|
134 | with open(fname, 'r') as filed: |
|
135 | return filed.read() |
|
136 | return '' |
|
137 | ||
138 | ||
139 | class Interval(object): |
|
140 | """An interruptible time Interval for use with with statements. |
|
141 | ||
142 | Provides a means to interupt the interval with a :class:`threading.Event`. |
|
143 | ||
@@ 81-109 (lines=29) @@ | ||
78 | fdat[map_val] = deque(vals) |
|
79 | return fdat |
|
80 | ||
81 | ||
82 | def get_file_map_list(fname, col, skip): |
|
83 | """Return a dict representation of a file - use on small files only. |
|
84 | ||
85 | eg. file contents of: |
|
86 | ||
87 | 8 1 sda1 284 166 2673 1724 58 18 9056 369 0 1122 2091 |
|
88 | ||
89 | with a call of col=2, skip=0 returns: |
|
90 | ||
91 | {"sda1": [8, 1, 284, 166, 2673, 1724, 58, 18, 9056, 369, 0, 1122, 2091]} |
|
92 | ||
93 | :param fname: Full pathname to a file. |
|
94 | :type fname: str |
|
95 | :param col: Column number to use as the map |
|
96 | :type col: int |
|
97 | :param skip: Skip this many lines of the file. |
|
98 | :type skip: int |
|
99 | :rtype: dict |
|
100 | """ |
|
101 | fdat = {} |
|
102 | if os.access(fname, os.R_OK): |
|
103 | with open(fname, 'r') as filed: |
|
104 | dat = filed.read().split("\n") |
|
105 | for line in dat[skip:]: |
|
106 | vals = line.split() |
|
107 | if len(vals) > col: |
|
108 | map_val = vals.pop(col) |
|
109 | fdat[map_val] = vals |
|
110 | return fdat |
|
111 | ||
112 |