Skip to content

Commit 391b5bb

Browse files
committed
Update stg-prof and stg-dbg to same style as stg
All three scripts once again have consistent structure. Signed-off-by: Peter Grayson <[email protected]>
1 parent 690f37a commit 391b5bb

File tree

2 files changed

+41
-35
lines changed

2 files changed

+41
-35
lines changed

stg-dbg

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,12 @@
22
# -*- coding: utf-8 -*-
33
# -*- python-mode -*-
44
"""Run stg with the pdb debugger."""
5+
from __future__ import (absolute_import, division, print_function,
6+
unicode_literals)
57
import os
68
import pdb
79
import sys
810

9-
# Try to detect where it is run from and set prefix and the search path.
10-
# It is assumed that the user installed StGIT using the --prefix= option
11-
prefix, bin = os.path.split(sys.path[0])
12-
13-
if bin == 'bin' and prefix != sys.prefix:
14-
sys.prefix = prefix
15-
sys.exec_prefix = prefix
16-
17-
major, minor = sys.version_info[0:2]
18-
local_path = [os.path.join(prefix, 'lib', 'python'),
19-
os.path.join(prefix, 'lib', 'python%s.%s' % (major, minor)),
20-
os.path.join(prefix, 'lib', 'python%s.%s' % (major, minor),
21-
'site-packages')]
22-
sys.path = local_path + sys.path
23-
24-
from stgit.main import main
25-
2611
__copyright__ = """
2712
Copyright (C) 2005, Catalin Marinas <[email protected]>
2813
@@ -40,4 +25,22 @@ along with this program; if not, see http://www.gnu.org/licenses/.
4025
"""
4126

4227
if __name__ == '__main__':
28+
# Try to detect where it is run from and set prefix and the search path.
29+
# It is assumed that the user installed StGIT using the --prefix= option
30+
prefix, bin = os.path.split(sys.path[0])
31+
32+
if bin == 'bin' and prefix != sys.prefix:
33+
sys.prefix = prefix
34+
sys.exec_prefix = prefix
35+
36+
major, minor = sys.version_info[0:2]
37+
local_path = [
38+
os.path.join(prefix, 'lib', 'python'),
39+
os.path.join(prefix, 'lib', 'python%s.%s' % (major, minor)),
40+
os.path.join(prefix, 'lib', 'python%s.%s' % (major, minor),
41+
'site-packages')]
42+
sys.path = local_path + sys.path
43+
44+
from stgit.main import main # noqa
45+
4346
pdb.run('main()')

stg-prof

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,6 @@ import pstats
1010
import sys
1111
import time
1212

13-
# Try to detect where it is run from and set prefix and the search path.
14-
# It is assumed that the user installed StGIT using the --prefix= option
15-
prefix, bin = os.path.split(sys.path[0])
16-
17-
if bin == 'bin' and prefix != sys.prefix:
18-
sys.prefix = prefix
19-
sys.exec_prefix = prefix
20-
21-
major, minor = sys.version_info[0:2]
22-
local_path = [os.path.join(prefix, 'lib', 'python'),
23-
os.path.join(prefix, 'lib', 'python%s.%s' % (major, minor)),
24-
os.path.join(prefix, 'lib', 'python%s.%s' % (major, minor),
25-
'site-packages')]
26-
sys.path = local_path + sys.path
27-
28-
from stgit.main import main
29-
3013
__copyright__ = """
3114
Copyright (C) 2005, Catalin Marinas <[email protected]>
3215
@@ -44,7 +27,26 @@ along with this program; if not, see http://www.gnu.org/licenses/.
4427
"""
4528

4629
if __name__ == '__main__':
30+
# Try to detect where it is run from and set prefix and the search path.
31+
# It is assumed that the user installed StGIT using the --prefix= option
32+
prefix, bin = os.path.split(sys.path[0])
33+
34+
if bin == 'bin' and prefix != sys.prefix:
35+
sys.prefix = prefix
36+
sys.exec_prefix = prefix
37+
38+
major, minor = sys.version_info[0:2]
39+
local_path = [
40+
os.path.join(prefix, 'lib', 'python'),
41+
os.path.join(prefix, 'lib', 'python%s.%s' % (major, minor)),
42+
os.path.join(prefix, 'lib', 'python%s.%s' % (major, minor),
43+
'site-packages')]
44+
sys.path = local_path + sys.path
45+
46+
from stgit.main import main # noqa
47+
4748
start_time = time.time()
49+
4850
def timer():
4951
return time.time() - start_time
5052

@@ -53,4 +55,5 @@ if __name__ == '__main__':
5355
prof.run('main()')
5456
except SystemExit:
5557
pass
56-
pstats.Stats(prof).strip_dirs().sort_stats(-1).print_stats().print_callees()
58+
stats = pstats.Stats(prof)
59+
stats.strip_dirs().sort_stats(-1).print_stats().print_callees()

0 commit comments

Comments
 (0)