Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 15f27fb

Browse files
committed
Adapt to modern times...
1 parent 1d97417 commit 15f27fb

2 files changed

Lines changed: 27 additions & 25 deletions

File tree

Tools/scripts/objgraph.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/local/python
1+
#!/usr/local/bin/python
22

33
# objgraph
44
#
@@ -21,9 +21,9 @@
2121

2222
import sys
2323
import string
24-
import path
24+
import os
2525
import getopt
26-
import regexp
26+
import regex
2727

2828
# Types of symbols.
2929
#
@@ -33,7 +33,7 @@
3333

3434
# Regular expression to parse "nm -o" output.
3535
#
36-
matcher = regexp.compile('(.*):\t?........ (.) (.*)$')
36+
matcher = regex.compile('\(.*\):\t?........ \(.\) \(.*\)$')
3737

3838
# Store "item" in "dict" under "key".
3939
# The dictionary maps keys to lists of items.
@@ -66,12 +66,13 @@ def flat(list):
6666
#
6767
def readinput(file):
6868
while 1:
69-
s = file.readline(200) # Arbitrary, but reasonable limit
69+
s = file.readline()
7070
if not s:
7171
break
72-
# If you get an exception on this line,
72+
# If you get any output from this line,
7373
# it is probably caused by an unexpected input line:
74-
(ra, rb), (r1a, r1b), (r2a, r2b), (r3a, r3b) = matcher.exec(s)
74+
if matcher.search(s) < 0: s; continue # Shouldn't happen
75+
(ra, rb), (r1a, r1b), (r2a, r2b), (r3a, r3b) = matcher.regs[:4]
7576
fn, name, type = s[r1a:r1b], s[r3a:r3b], s[r2a:r2b]
7677
if type in definitions:
7778
store(def2file, name, fn)
@@ -160,7 +161,8 @@ def main():
160161
optlist, args = getopt.getopt(sys.argv[1:], 'cdu')
161162
except getopt.error:
162163
sys.stdout = sys.stderr
163-
print 'Usage:', path.basename(sys.argv[0]), '[-cdu] [file] ...'
164+
print 'Usage:', os.path.basename(sys.argv[0]),
165+
print '[-cdu] [file] ...'
164166
print '-c: print callers per objectfile'
165167
print '-d: print callees per objectfile'
166168
print '-u: print usage of undefined symbols'

Tools/scripts/pdeps.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /usr/local/python
1+
#! /usr/local/bin/python
22

33
# pdeps
44
#
@@ -21,8 +21,8 @@
2121

2222

2323
import sys
24-
import regexp
25-
import path
24+
import regex
25+
import os
2626
import string
2727

2828

@@ -58,15 +58,15 @@ def main():
5858

5959
# Compiled regular expressions to search for import statements
6060
#
61-
m_import = regexp.compile('^[ \t]*from[ \t]+([^ \t]+)[ \t]+')
62-
m_from = regexp.compile('^[ \t]*import[ \t]+([^#]+)')
61+
m_import = regex.compile('^[ \t]*from[ \t]+\([^ \t]+\)[ \t]+')
62+
m_from = regex.compile('^[ \t]*import[ \t]+\([^#]+\)')
6363

6464

6565
# Collect data from one file
6666
#
6767
def process(filename, table):
6868
fp = open(filename, 'r')
69-
mod = path.basename(filename)
69+
mod = os.path.basename(filename)
7070
if mod[-3:] == '.py':
7171
mod = mod[:-3]
7272
table[mod] = list = []
@@ -77,17 +77,17 @@ def process(filename, table):
7777
nextline = fp.readline()
7878
if not nextline: break
7979
line = line[:-1] + nextline
80-
result = m_import.exec(line)
81-
if not result:
82-
result = m_from.exec(line)
83-
if result:
84-
(a, b), (a1, b1) = result
85-
words = string.splitfields(line[a1:b1], ',')
86-
# print '#', line, words
87-
for word in words:
88-
word = string.strip(word)
89-
if word not in list:
90-
list.append(word)
80+
if m_import.match(line) >= 0:
81+
(a, b), (a1, b1) = m_import.regs[:2]
82+
elif m_from.match(line) >= 0:
83+
(a, b), (a1, b1) = m_from.regs[:2]
84+
else: continue
85+
words = string.splitfields(line[a1:b1], ',')
86+
# print '#', line, words
87+
for word in words:
88+
word = string.strip(word)
89+
if word not in list:
90+
list.append(word)
9191

9292

9393
# Compute closure (this is in fact totally general)

0 commit comments

Comments
 (0)