Code Duplication    Length = 29-29 lines in 2 locations

plumd/util.py 2 locations

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