summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorJohannes Gijsbers <jlg@dds.nl>2005-01-09 01:58:02 (GMT)
committerJohannes Gijsbers <jlg@dds.nl>2005-01-09 01:58:02 (GMT)
commit2abe785fee0839a51c83d6f2285e6ed8ade89c3a (patch)
treeccec900a75e436a3b7bbc3cc955b5bbcfd976979 /Lib
parent97613ad02dd925c65b6bb17e605ba1b0b966a2ed (diff)
downloadcpython-2abe785fee0839a51c83d6f2285e6ed8ade89c3a.zip
cpython-2abe785fee0839a51c83d6f2285e6ed8ade89c3a.tar.gz
cpython-2abe785fee0839a51c83d6f2285e6ed8ade89c3a.tar.bz2
Move code in __name__ == '__main__' block into main() function, rewrite code so
there's no need to subclass OptionParser.
Diffstat (limited to 'Lib')
-rwxr-xr-xLib/profile.py30
1 files changed, 14 insertions, 16 deletions
diff --git a/Lib/profile.py b/Lib/profile.py
index 00a0ae9..9d7e284 100755
--- a/Lib/profile.py
+++ b/Lib/profile.py
@@ -583,31 +583,29 @@ class Profile:
def Stats(*args):
print 'Report generating functions are in the "pstats" module\a'
-
-# When invoked as main program, invoke the profiler on a script
-if __name__ == '__main__':
+def main():
usage = "profile.py [-o output_file_path] [-s sort] scriptfile [arg] ..."
- if not sys.argv[1:]:
- print "Usage: ", usage
- sys.exit(2)
-
- class ProfileParser(OptionParser):
- def __init__(self, usage):
- OptionParser.__init__(self)
- self.usage = usage
-
- parser = ProfileParser(usage)
+ parser = OptionParser(usage=usage)
parser.allow_interspersed_args = False
parser.add_option('-o', '--outfile', dest="outfile",
help="Save stats to <outfile>", default=None)
parser.add_option('-s', '--sort', dest="sort",
help="Sort order when printing to stdout, based on pstats.Stats class", default=-1)
-
+
+ if not sys.argv[1:]:
+ parser.print_usage()
+ sys.exit(2)
+
(options, args) = parser.parse_args()
sys.argv[:] = args
-
+
if (len(sys.argv) > 0):
sys.path.insert(0, os.path.dirname(sys.argv[0]))
run('execfile(%r)' % (sys.argv[0],), options.outfile, options.sort)
else:
- print "Usage: ", usage
+ parser.print_usage()
+ return parser
+
+# When invoked as main program, invoke the profiler on a script
+if __name__ == '__main__':
+ main()