Gentoo Archives: gentoo-commits

From: Mike Frysinger <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/catalyst:master commit in: catalyst/
Date: Fri, 18 Dec 2015 01:53:37
Message-Id: 1450403602.f36f7adc0bdd0c60e78d0e4a3d366cac61568e3a.vapier@gentoo
1 commit: f36f7adc0bdd0c60e78d0e4a3d366cac61568e3a
2 Author: Mike Frysinger <vapier <AT> gentoo <DOT> org>
3 AuthorDate: Mon Nov 23 11:57:19 2015 +0000
4 Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org>
5 CommitDate: Fri Dec 18 01:53:22 2015 +0000
6 URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=f36f7adc
7
8 main: add a --trace option
9
10 This helps a lot with debugging as you can quickly get a transcript
11 of the python code paths that are taken by catalyst.
12
13 catalyst/main.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
14 1 file changed, 49 insertions(+)
15
16 diff --git a/catalyst/main.py b/catalyst/main.py
17 index f48293e..3550809 100644
18 --- a/catalyst/main.py
19 +++ b/catalyst/main.py
20 @@ -170,6 +170,11 @@ $ catalyst -f stage1-specfile.spec"""
21 dest='color', action='store_false',
22 help='never colorize output all the time (default: detect)')
23
24 + group = parser.add_argument_group('Developer options')
25 + group.add_argument('--trace',
26 + default=False, action='store_true',
27 + help='trace program output (akin to `sh -x`)')
28 +
29 group = parser.add_argument_group('Temporary file management')
30 group.add_argument('-a', '--clear-autoresume',
31 default=False, action='store_true',
32 @@ -203,10 +208,54 @@ $ catalyst -f stage1-specfile.spec"""
33 return parser
34
35
36 +def trace(func, *args, **kwargs):
37 + """Run |func| through the trace module (akin to `sh -x`)"""
38 + import trace
39 +
40 + # Ignore common system modules we use.
41 + ignoremods = set((
42 + 'argparse',
43 + 'genericpath', 'gettext',
44 + 'locale',
45 + 'os',
46 + 'posixpath',
47 + 're',
48 + 'sre_compile', 'sre_parse', 'sys',
49 + 'tempfile', 'threading',
50 + 'UserDict',
51 + ))
52 +
53 + # Ignore all the system modules.
54 + ignoredirs = set(sys.path)
55 + # But try to strip out the catalyst paths.
56 + try:
57 + ignoredirs.remove(os.path.dirname(os.path.dirname(
58 + os.path.realpath(__file__))))
59 + except KeyError:
60 + pass
61 +
62 + tracer = trace.Trace(
63 + count=False,
64 + trace=True,
65 + timing=True,
66 + ignoremods=ignoremods,
67 + ignoredirs=ignoredirs)
68 + return tracer.runfunc(func, *args, **kwargs)
69 +
70 +
71 def main(argv):
72 + """The main entry point for frontends to use"""
73 parser = get_parser()
74 opts = parser.parse_args(argv)
75
76 + if opts.trace:
77 + return trace(_main, parser, opts)
78 + else:
79 + return _main(parser, opts)
80 +
81 +
82 +def _main(parser, opts):
83 + """The "main" main function so we can trace/profile."""
84 # Initialize the logger before anything else.
85 log_level = opts.log_level
86 if log_level is None: