forked from sequitur-g2p/sequitur-g2p
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtool.py
99 lines (85 loc) · 3.14 KB
/
tool.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
__author__ = 'Maximilian Bisani'
__version__ = '$LastChangedRevision: 1668 $'
__date__ = '$LastChangedDate: 2007-06-02 18:14:47 +0200 (Sat, 02 Jun 2007) $'
__copyright__ = 'Copyright (c) 2004-2005 RWTH Aachen University'
__license__ = """
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License Version 2 (June
1991) as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, you will find it at
http://www.gnu.org/licenses/gpl.html, or write to the Free Software
Foundation, Inc., 51 Franlin Street, Fifth Floor, Boston, MA 02110,
USA.
Should a provision of no. 9 and 10 of the GNU General Public License
be invalid or become invalid, a valid provision is deemed to have been
agreed upon which comes closest to what the parties intended
commercially. In any case guarantee/warranty shall be limited to gross
negligent actions or intended actions or fraudulent concealment.
"""
class UsageError(RuntimeError):
pass
def addOptions(optparser):
optparser.add_option(
'-p', '--profile',
help='Profile execution time and store result in FILE', metavar='FILE')
optparser.add_option(
'-R', '--resource-usage', action='store_true',
help='Report resource usage execution time')
optparser.add_option(
'-Y', '--psyco', action='store_true',
help='Use Psyco to speed up execution')
optparser.add_option(
'--tempdir',
help='store temporary files in PATH', metavar='PATH')
def run(main, options, args):
import sys
if options.tempdir:
import tempfile, os
if os.path.isdir(options.tempdir):
tempfile.tempdir = options.tempdir
else:
raise ValueError('path does not exist', options.tempdir)
if options.resource_usage:
import datetime, time
startTime = datetime.datetime.now()
startClock = time.clock()
try:
status = runMain(main, options, args)
except UsageError:
status = 1
print >> sys.stdout, "Try '%s --help'" % sys.argv[0]
if options.resource_usage:
stopTime = datetime.datetime.now()
stopClock = time.clock()
print >> sys.stderr, 'elapsed time: ', stopTime - startTime
print >> sys.stderr, 'processor time: ', datetime.timedelta(seconds=stopClock - startClock)
sys.exit(status)
def runMain(main, options, args):
if options.profile:
if True:
import hotshot
profile = hotshot.Profile(options.profile)
profile.runcall(main, options, args)
profile.close()
import hotshot.stats
stats = hotshot.stats.load(options.profile)
else:
import profile
profile.run('main(options, args)', options.profile)
import pstats
stats = pstats.Stats(options.profile)
stats.strip_dirs()
stats.sort_stats('time', 'calls')
stats.print_stats(20)
elif options.psyco:
import psyco
psyco.full()
status = main(options, args)
else:
status = main(options, args)
return status