Report attacking by "."

This commit is contained in:
Takafumi Arakaki
2013-05-22 23:31:42 +02:00
parent 2dee71ff4b
commit 8bf5f9d539

33
sith.py
View File

@@ -11,6 +11,11 @@ import random
import sys import sys
import traceback import traceback
try:
from itertools import izip as zip
except ImportError:
pass
import jedi import jedi
@@ -105,6 +110,31 @@ class MixinLoader(object):
self.load_record(record) self.load_record(record)
class AttackReporter(object):
def __init__(self):
self.tries = 0
self.errors = 0
def __iter__(self):
return self
def __next__(self):
self.tries += 1
sys.stderr.write('.')
sys.stderr.flush()
return self.tries
next = __next__
def error(self):
self.errors += 1
sys.stderr.write('\n')
sys.stderr.flush()
print('{0}th error is encountered after {1} tries.'
.format(self.errors, self.tries))
class RandomAtaccker(MixinPrinter, BaseAttacker): class RandomAtaccker(MixinPrinter, BaseAttacker):
operations = [ operations = [
@@ -122,13 +152,16 @@ class RandomAtaccker(MixinPrinter, BaseAttacker):
def do_run(self, record, rootpath, maxtries): def do_run(self, record, rootpath, maxtries):
finder = SourceFinder(rootpath) finder = SourceFinder(rootpath)
reporter = AttackReporter()
for (operation, args) in self.generate_attacks(maxtries, finder): for (operation, args) in self.generate_attacks(maxtries, finder):
reporter.next()
try: try:
self.attack(operation, *args) self.attack(operation, *args)
except jedi.NotFoundError: except jedi.NotFoundError:
pass pass
except Exception: except Exception:
self.add_record(sys.exc_info(), operation, args) self.add_record(sys.exc_info(), operation, args)
reporter.error()
self.print_record() self.print_record()
raise raise
self.save_record(record) self.save_record(record)