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