|
@@ 112-140 (lines=29) @@
|
| 109 |
|
return deque(['']) |
| 110 |
|
|
| 111 |
|
|
| 112 |
|
def get_file(fname): |
| 113 |
|
"""Return the file as a string - use on small files only. |
| 114 |
|
|
| 115 |
|
:param fname: Full pathname to a file. |
| 116 |
|
:type fname: str |
| 117 |
|
:rtype: dict |
| 118 |
|
""" |
| 119 |
|
if os.access(fname, os.R_OK): |
| 120 |
|
with open(fname, 'r') as fd: |
| 121 |
|
return fd.read() |
| 122 |
|
return '' |
| 123 |
|
|
| 124 |
|
|
| 125 |
|
class Interval(object): |
| 126 |
|
"""A simple helper class to ensure a loop occours every ltime seconds |
| 127 |
|
while optionally providing a means to interupt the loop with a |
| 128 |
|
:class:`threading.Event`. |
| 129 |
|
|
| 130 |
|
|
| 131 |
|
:param ltime: The target duration of a loop |
| 132 |
|
:type ltime: int or float |
| 133 |
|
:param evt: An event object that will cause the loop to complete early if |
| 134 |
|
the event is triggered while waiting. |
| 135 |
|
:type evt: threading.Event |
| 136 |
|
:raises: ValueError if the passed loop time is not an int or float or is < 0 |
| 137 |
|
|
| 138 |
|
|
| 139 |
|
As an example, use it like this to loop on an interval: |
| 140 |
|
|
| 141 |
|
:Example: |
| 142 |
|
|
| 143 |
|
>>> import threading |
|
@@ 81-109 (lines=29) @@
|
| 78 |
|
|
| 79 |
|
:param fname: Full pathname to a file. |
| 80 |
|
:type fname: str |
| 81 |
|
:param col: Column number to use as the map |
| 82 |
|
:type col: int |
| 83 |
|
:param skip: Skip this many lines of the file. |
| 84 |
|
:type skip: int |
| 85 |
|
:rtype: dict |
| 86 |
|
""" |
| 87 |
|
fdat = {} |
| 88 |
|
if os.access(fname, os.R_OK): |
| 89 |
|
with open(fname, 'r') as fd: |
| 90 |
|
dat = fd.read().split("\n") |
| 91 |
|
for line in dat[skip:]: |
| 92 |
|
vals = line.split() |
| 93 |
|
if len(vals) > col: |
| 94 |
|
map_val = vals.pop(col) |
| 95 |
|
fdat[map_val] = vals |
| 96 |
|
return fdat |
| 97 |
|
|
| 98 |
|
|
| 99 |
|
def get_file_list(fname): |
| 100 |
|
"""Return the file as a list - use on small files only. |
| 101 |
|
|
| 102 |
|
:param fname: Full pathname to a file. |
| 103 |
|
:type fname: str |
| 104 |
|
:rtype: dict |
| 105 |
|
""" |
| 106 |
|
if os.access(fname, os.R_OK): |
| 107 |
|
with open(fname, 'r') as fd: |
| 108 |
|
return deque(fd.read().strip().split("\n")) |
| 109 |
|
return deque(['']) |
| 110 |
|
|
| 111 |
|
|
| 112 |
|
def get_file(fname): |