Permalink
Browse files

Get rid of unused --trace flag.

I haven't used this in over a year.
  • Loading branch information...
Andy Chu
Andy Chu committed Sep 3, 2018
1 parent b6d6791 commit 395ebb043f3950c830349476a9ffec0458c0c9c4
Showing with 6 additions and 79 deletions.
  1. +2 −10 bin/oil.py
  2. +1 −44 core/util.py
  3. +3 −25 core/util_test.py
View
@@ -114,8 +114,7 @@ def OshMain(argv0, argv, login_shell):
spec.LongFlag('--debug-spans') # For oshc translate
spec.LongFlag('--parse-and-print-arena') # Invariant for translation
spec.LongFlag('--print-status')
spec.LongFlag('--trace', ['cmd-parse', 'word-parse', 'lexer']) # NOTE: can only trace one now
spec.LongFlag('--hijack-shebang')
spec.LongFlag('--hijack-shebang') # TODO:
# For benchmarks/*.sh
spec.LongFlag('--parser-mem-dump', args.Str)
@@ -138,16 +137,9 @@ def OshMain(argv0, argv, login_shell):
_ShowVersion()
return 0
# TODO: This should be in interactive mode only?
builtin.RegisterSigIntHandler()
trace_state = util.TraceState()
if 'cmd-parse' == opts.trace:
util.WrapMethods(cmd_parse.CommandParser, trace_state)
if 'word-parse' == opts.trace:
util.WrapMethods(word_parse.WordParser, trace_state)
if 'lexer' == opts.trace:
util.WrapMethods(lexer.Lexer, trace_state)
if opt_index == len(argv):
dollar0 = argv0
else:
View
@@ -14,6 +14,7 @@
import os
import pwd # TODO: Move this dependency to Oil?
import sys
import zipimport # NOT the zipfile module.
if not os.getenv('_OVM_DEPS'):
import inspect
@@ -149,48 +150,6 @@ def GetHomeDir():
return e.pw_dir
# Mutate the class after defining it:
#
# http://stackoverflow.com/questions/3467526/attaching-a-decorator-to-all-functions-within-a-class
# Other more complicated ways:
#
# http://code.activestate.com/recipes/366254-generic-proxy-object-with-beforeafter-method-hooks/
# http://stackoverflow.com/questions/3467526/attaching-a-decorator-to-all-functions-within-a-class
def TracedFunc(func, cls_name, state):
def traced(*args, **kwargs):
name_str = '%s.%s' % (cls_name, func.__name__)
print(state.indent + '>', name_str) #, args[1:] #, kwargs
state.Push()
ret = func(*args, **kwargs)
state.Pop()
print(state.indent + '<', name_str, ret)
return ret
return traced
def WrapMethods(cls, state):
for name, func in inspect.getmembers(cls):
# NOTE: This doesn't work in python 3? Types module is different
if isinstance(func, types.UnboundMethodType):
setattr(cls, name, TracedFunc(func, cls.__name__, state))
class TraceState(object):
def __init__(self):
self.indent = ''
self.num_spaces = 4
def Push(self):
self.indent += self.num_spaces * ' '
def Pop(self):
self.indent = self.indent[:-self.num_spaces]
class _FileResourceLoader(object):
"""Open resources relative to argv[0]."""
@@ -202,8 +161,6 @@ def open(self, rel_path):
return open(os.path.join(self.root_dir, rel_path))
import zipimport # NOT the zipfile module.
class _ZipResourceLoader(object):
"""Open resources INSIDE argv[0] as a zip file."""
View
@@ -14,32 +14,10 @@
from core import util # module under test
class _Parser(object):
"""Test class for tracing."""
class UtilTest(unittest.TestCase):
def __init__(self, lexer):
self.lexer = lexer
def ParseTrailer(self, node):
return 'trailer'
def ParseCommandTerm(self, node):
return 'term'
def ParseCommandList(self, node):
self.ParseCommandTerm(node)
return self.ParseTrailer(node)
class TraceTest(unittest.TestCase):
def testWrapMethods(self):
state = util.TraceState()
# TODO: Fix UnboundMethodType error
return
util.WrapMethods(_Parser, state)
p = _Parser('lexer')
print(p.ParseCommandList({}))
def testFoo(self):
pass
if __name__ == '__main__':

0 comments on commit 395ebb0

Please sign in to comment.