def __init__(self, line, result, index): self.line = line self.index = index (file, num, matches) = result self.originalFile = file self.file = parse.prependDir(file) self.num = num # save a bunch of stuff so we can # pickle self.start = matches.start() self.end = min(matches.end(), len(line)) self.group = matches.group() # this is a bit weird but we need to strip # off the whitespace for the matches we got, # since matches like README are aggressive # about including whitespace. For most lines # this will be a no-op, but for lines like # "README " we will reset end to # earlier stringSubset = line[self.start:self.end] strippedSubset = stringSubset.strip() trailingWhitespace = (len(stringSubset) - len(strippedSubset)) self.end -= trailingWhitespace self.group = self.group[0:len(self.group) - trailingWhitespace] self.selected = False self.hovered = False
def testPrependDir(self): for testCase in prependDirTestCases: inFile = testCase['in'] result = parse.prependDir(inFile) self.assertEqual(testCase['out'], result) print 'Tested %d dir cases.' % len(prependDirTestCases)
def testPrependDir(self): for testCase in prependDirTestCases: inFile = testCase['in'] print 'Testing dir case\t', inFile result = parse.prependDir(inFile) self.assertEqual(testCase['out'], result)
def __init__(self, line, result, index): self.line = line self.index = index file, num, matches = result self.file = parse.prependDir(file) self.number = num # save a bunch of stuff so we can # pickle self.start = matches.start() end = min(matches.end(), len(line)) group = matches.group() # this is a bit weird but we need to strip # off the whitespace for the matches we got, # since matches like README are aggressive # about including whitespace. For most lines # this will be a no-op, but for lines like # "README " we will reset end to # earlier string_subset = line[self.start:end] stripped_subset = string_subset.strip() trailing_whitespace = len(string_subset) - len(stripped_subset) self.end = end - trailing_whitespace if trailing_whitespace: self.match = group[:-trailing_whitespace] else: self.match = group self.is_selected = False self.is_hovered = False
def testPrependDir(self): for testCase in prependDirTestCases: inFile = testCase['in'] result = parse.prependDir(inFile) expected = testCase['out'] if inFile[0:2] == '~/': expected = os.path.expanduser(expected) self.assertEqual(expected, result) print 'Tested %d dir cases.' % len(prependDirTestCases)
def testPrependDir(self): for testCase in prependDirTestCases: inFile = testCase['in'] result = parse.prependDir(inFile) expected = testCase['out'] if inFile[0:2] == '~/': expected = os.path.expanduser(expected) self.assertEqual(expected, result) print('Tested %d dir cases.' % len(prependDirTestCases))
def __init__(self, formattedLine, result, index, validateFileExists=False, allInput=False): self.controller = None self.formattedLine = formattedLine self.index = index self.allInput = allInput (path, num, matches) = result self.originalPath = path self.path = path if allInput else parse.prependDir( path, withFileInspection=validateFileExists) self.num = num line = str(self.formattedLine) # save a bunch of stuff so we can # pickle self.start = matches.start() self.end = min(matches.end(), len(line)) self.group = matches.group() # this is a bit weird but we need to strip # off the whitespace for the matches we got, # since matches like README are aggressive # about including whitespace. For most lines # this will be a no-op, but for lines like # "README " we will reset end to # earlier stringSubset = line[self.start:self.end] strippedSubset = stringSubset.strip() trailingWhitespace = (len(stringSubset) - len(strippedSubset)) self.end -= trailingWhitespace self.group = self.group[0:len(self.group) - trailingWhitespace] self.selected = False self.hovered = False self.isTruncated = False # precalculate the pre, post, and match strings (self.beforeText, unused) = self.formattedLine.breakat(self.start) (unused, self.afterText) = self.formattedLine.breakat(self.end) self.updateDecoratedMatch()
def __init__(self, formattedLine, result, index, validateFileExists=False, allInput=False): self.controller = None self.formattedLine = formattedLine self.index = index self.allInput = allInput (path, num, matches) = result self.originalPath = path self.path = path if allInput else parse.prependDir(path, withFileInspection=validateFileExists) self.num = num line = str(self.formattedLine) # save a bunch of stuff so we can # pickle self.start = matches.start() self.end = min(matches.end(), len(line)) self.group = matches.group() # this is a bit weird but we need to strip # off the whitespace for the matches we got, # since matches like README are aggressive # about including whitespace. For most lines # this will be a no-op, but for lines like # "README " we will reset end to # earlier stringSubset = line[self.start:self.end] strippedSubset = stringSubset.strip() trailingWhitespace = (len(stringSubset) - len(strippedSubset)) self.end -= trailingWhitespace self.group = self.group[0:len(self.group) - trailingWhitespace] self.selected = False self.hovered = False self.isTruncated = False # precalculate the pre, post, and match strings (self.beforeText, unused) = self.formattedLine.breakat(self.start) (unused, self.afterText) = self.formattedLine.breakat(self.end) self.updateDecoratedMatch()
import parse from formattedText import FormattedText PathMarker_buffer_file = os.path.expanduser('~/.PathMarker') open(PathMarker_buffer_file, 'a').close() theline = "" if __name__ == "__main__": if sys.argv[1] == "set": count = 0 f = open(PathMarker_buffer_file,"w") for name in sys.stdin.readlines(): formattedLine = FormattedText(name) result=parse.matchLine(str(formattedLine), allInput=False) if result: path = parse.prependDir(result[0], withFileInspection=False) count += 1 sys.stdout.write("%d\t%s" % (count, name)) f.write("%s\n" % path) else: sys.stdout.write("\t%s" % (name)) f.close if sys.argv[1] == "setall": count = 0 f = open(PathMarker_buffer_file,"w") for name in sys.stdin.readlines(): formattedLine = FormattedText(name) result=parse.matchLine(str(formattedLine), allInput=True) if result: path = parse.prependDir(result[0], withFileInspection=False)