/usr/lib/python3/dist-packages/ginga/misc/LineHistory.py is in python3-ginga 2.6.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | #
# LineHistory.py -- class implementing a text line based history
#
# This is open-source software licensed under a BSD license.
# Please see the file LICENSE.txt for details.
#
class LineHistory(object):
def __init__(self, numlines=1000):
super(LineHistory, self).__init__()
self.history = []
self.histidx = 0
self.histlimit = numlines
def set_limit(self, numlines):
self.histlimit = numlines
def get_history(self):
return self.history
def set_history(self, lines):
self.history = list(lines)
def append(self, text):
self.history.append(text)
i = self.histlimit - len(self.history)
if i < 0:
self.history = self.history[abs(i):]
self.histidx = len(self.history)
def prev(self):
i = self.histidx - 1
if i >= 0:
self.histidx = i
return self.history[i]
raise ValueError("At beginning")
def next(self):
i = self.histidx + 1
if i < len(self.history):
self.histidx = i
return self.history[i]
raise ValueError("At end")
def save(self, path):
with open(path, 'w') as out_f:
out_f.write('\n'.join(self.history))
def load(self, path):
with open(path, 'r') as in_f:
buf = in_f.read()
self.history = buf.split('\n')
#END
|