Begin refactoring

master3.3
Mike Hiretsky 10 years ago
parent 06ada512d9
commit 8a0da9cb89

@ -13,6 +13,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import traceback
from functools import wraps
from itertools import tee
@ -175,3 +177,27 @@ def debug(prefix="DEBUG {name}({args},{kw})={ret}"):
return ret
return wrapper
return debug_decor
def short_traceback(e1, e2, e3):
"""
Return short traceback
"""
frame = e3
for i in apply(traceback.format_exception, (e1, e2, e3)):
print i,
while frame.tb_next:
frame = frame.tb_next
module, part = os.path.split(frame.tb_frame.f_code.co_filename)
if part.endswith('.py'):
part = part[:-3]
fallback_mod = part
modname = [part]
while module != '/' and not module.endswith('site-packages'):
module, part = os.path.split(module)
modname.insert(0, part)
if module.endswith('site-packages'):
modname = ".".join(modname)
else:
modname = fallback_mod
return "%s:%s(%s:%s)" % (e1.__name__, str(e2), modname, frame.tb_lineno)

Loading…
Cancel
Save