You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
users have to start the program not by scanner.py like described, but by
jython searchdir.py . term
In searchdir.py you have to call a static method on ScanResults: scanner.ScanResults.scan(), not an object one, and exit() was not working, had to use sys.exit()
#from scanner import ScanResults
import search.scanner as scanner
import sys
help = """
Usage: search.py directory terms...
"""
args = sys.argv
if args == None or len(args) < 2:
print help
sys.exit()
dir = args[1]
terms = args[2:]
scan = scanner.ScanResults.scan(dir, terms)
scan.display()
Accordingly you have to add the @staticmethod annotation to ScanResults.scan
from search.walker import DirectoryWalker
from javax.swing import JFrame, JTable, WindowConstants
class ScanResults(object):
def __init__(self):
self.results = []
def add(self, file, line):
self.results.append((file, line))
def display(self):
colnames = ['file', 'line']
table = JTable(self.results, colnames)
frame = JFrame("%i Results" % len(self.results))
frame.getContentPane().add(table)
frame.size = 400, 300
frame.defaultCloseOperation = WindowConstants.EXIT_ON_CLOSE
frame.visible = True
@staticmethod
def scan(dir, terms):
results = ScanResults()
for filename in DirectoryWalker(dir):
for line in open(filename):
for term in terms:
if term in line:
results.add(filename,line)
return results
Activity
jeff5 commentedon Apr 16, 2020
This is another section that is quite different in the paper book. In this case, we have not yet fixed the on-line version under issue #14.
heywiki commentedon Apr 16, 2020
Thank you. I forked the version to keep the rationale for my example repo at https://github.com/heywiki/jython-book-examples for now