allow a path to explicity given for py.lookup
--HG-- branch : trunk
This commit is contained in:
parent
6ddea4a1bc
commit
8af3ede092
|
@ -12,7 +12,6 @@ import py
|
||||||
from py.__.io.terminalwriter import ansi_print, terminal_width
|
from py.__.io.terminalwriter import ansi_print, terminal_width
|
||||||
import re
|
import re
|
||||||
|
|
||||||
curdir = py.path.local()
|
|
||||||
def rec(p):
|
def rec(p):
|
||||||
return p.check(dotfile=0)
|
return p.check(dotfile=0)
|
||||||
|
|
||||||
|
@ -35,12 +34,17 @@ def find_indexes(search_line, string):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
string = args[0]
|
if len(args) == 2:
|
||||||
|
search_dir, string = args
|
||||||
|
search_dir = py.path.local(search_dir)
|
||||||
|
else:
|
||||||
|
search_dir = py.path.local()
|
||||||
|
string = args[0]
|
||||||
if options.ignorecase:
|
if options.ignorecase:
|
||||||
string = string.lower()
|
string = string.lower()
|
||||||
for x in curdir.visit('*.py', rec):
|
for x in search_dir.visit('*.py', rec):
|
||||||
# match filename directly
|
# match filename directly
|
||||||
s = x.relto(curdir)
|
s = x.relto(search_dir)
|
||||||
if options.ignorecase:
|
if options.ignorecase:
|
||||||
s = s.lower()
|
s = s.lower()
|
||||||
if s.find(string) != -1:
|
if s.find(string) != -1:
|
||||||
|
@ -64,7 +68,7 @@ def main():
|
||||||
if not indexes:
|
if not indexes:
|
||||||
continue
|
continue
|
||||||
if not options.context:
|
if not options.context:
|
||||||
sys.stdout.write("%s:%d: " %(x.relto(curdir), i+1))
|
sys.stdout.write("%s:%d: " %(x.relto(search_dir), i+1))
|
||||||
last_index = 0
|
last_index = 0
|
||||||
for index in indexes:
|
for index in indexes:
|
||||||
sys.stdout.write(line[last_index: index])
|
sys.stdout.write(line[last_index: index])
|
||||||
|
@ -75,5 +79,5 @@ def main():
|
||||||
else:
|
else:
|
||||||
context = (options.context)/2
|
context = (options.context)/2
|
||||||
for count in range(max(0, i-context), min(len(lines) - 1, i+context+1)):
|
for count in range(max(0, i-context), min(len(lines) - 1, i+context+1)):
|
||||||
print("%s:%d: %s" %(x.relto(curdir), count+1, lines[count].rstrip()))
|
print("%s:%d: %s" %(x.relto(search_dir), count+1, lines[count].rstrip()))
|
||||||
print("-" * terminal_width)
|
print("-" * terminal_width)
|
||||||
|
|
|
@ -16,3 +16,13 @@ class TestPyLookup:
|
||||||
['*%s:*' %(p.basename)]
|
['*%s:*' %(p.basename)]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_with_explicit_path(self, testxbdir):
|
||||||
|
sub1 = testdir.mkdir("things")
|
||||||
|
sub2 = testdir.mkdir("foo")
|
||||||
|
sub1.join("pyfile.py").write("def stuff(): pass")
|
||||||
|
searched = sub2.join("other.py")
|
||||||
|
searched.write("stuff = x")
|
||||||
|
result = testdir.runpybin("py.lookup", sub2.basename, "stuff")
|
||||||
|
result.stdout.fnmatch_lines(
|
||||||
|
["%s:1: stuff = x" % (searched.basename,)]
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue