/usr/share/pyshared/seascope/view/CodemarkView.py is in seascope 0.8-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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | #!/usr/bin/env python
# Copyright (c) 2012 Anthony Liu
# All rights reserved.
#
# License: BSD
import sys
from array import *
class CodemarkManager():
def __init__(self, parent=None):
self.haystack = []
def check(self, filename, line):
if self.haystack.count((filename, line)):
return 1
return 0
def append(self, filename, line):
if self.check(filename, line) == 0:
self.haystack.append((filename, line))
return self.haystack.index((filename, line))
def delete(self, filename, line):
if self.haystack.count((filename, line)) == 0:
return -1
else:
self.haystack.remove((filename, line))
return 0
def delete_index(self, index):
if self.count() <= index:
return -1
elif index < 0:
return -1
else:
self.haystack.pop(index)
return 0
def count(self):
return len(self.haystack)
def get(self, index):
if self.count() <= index:
return (None, None)
elif index < 0:
return (None, None)
else:
(filename, line) = self.haystack.pop(index)
self.haystack.insert(index, (filename, line))
return (filename, line)
def clear(self):
del self.haystack[:]
def codemarks(self):
return self.haystack
def dump(self):
for i in range(len(self.haystack)):
print >> sys.stderr, "cm index ", i, " ", self.haystack[i]
#############################################################################
#
# Basic unit test
#
#############################################################################
if __name__ == '__main__':
cm = CodemarkManager()
#
# case 1, basic add, delete
#
print >> sys.stderr, "Initial empty"
print >> sys.stderr, "cm has ", cm.count(), "items (0)"
cm.append("file1", 100)
cm.append("file2", 200)
cm.append("file3", 300)
print >> sys.stderr, "cm has " , cm.count(), "items (3) "
cm.delete("file1", 100)
print >> sys.stderr, "cm has " , cm.count(), "items (2)"
cm.delete("file2", 100) # not existed
print >> sys.stderr, "cm has " , cm.count(), "items (2)"
cm.delete_index(1)
print >> sys.stderr, "cm has " , cm.count(), "items (1)"
#
# case 2, dump
#
for i in range(cm.count()):
(f, l) = cm.get(i)
print >> sys.stderr, f, " (#", l, ")"
#
# case 3, duplicate
#
index = cm.append("file4", 400)
print >> sys.stderr, "index for file4 #400 is " , index
index = cm.append("file4", 400)
print >> sys.stderr, "index for file4 #400 is " , index, " (again)"
print >> sys.stderr, "cm has " , cm.count(), "items (2) "
#
# case 4, dump for eye examine
#
print >> sys.stderr, "cm dump for final check"
cm.dump()
|