summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-01-17 08:48:39 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-01-17 08:48:39 (GMT)
commit70c4378dbcfdcbeef6fb3aa348f32ed862fe8eb7 (patch)
treecf47b67db3753288cfd9fa2adc45e7c5cd2f8741 /Tools
parenta88854059309667092000da55d4d5a5804267e9f (diff)
downloadcpython-70c4378dbcfdcbeef6fb3aa348f32ed862fe8eb7.zip
cpython-70c4378dbcfdcbeef6fb3aa348f32ed862fe8eb7.tar.gz
cpython-70c4378dbcfdcbeef6fb3aa348f32ed862fe8eb7.tar.bz2
Whitespace normalization.
Diffstat (limited to 'Tools')
-rw-r--r--Tools/idle/CallTipWindow.py4
-rw-r--r--Tools/idle/CallTips.py6
-rw-r--r--Tools/idle/ClassBrowser.py2
-rw-r--r--Tools/idle/Debugger.py8
-rw-r--r--Tools/idle/Delegator.py1
-rw-r--r--Tools/idle/FileList.py12
-rw-r--r--Tools/idle/FormatParagraph.py4
-rw-r--r--Tools/idle/IdleConf.py27
-rw-r--r--Tools/idle/IdleHistory.py1
-rw-r--r--Tools/idle/MultiScrolledLists.py26
-rw-r--r--Tools/idle/MultiStatusBar.py48
-rw-r--r--Tools/idle/OutputWindow.py8
-rw-r--r--Tools/idle/ParenMatch.py13
-rw-r--r--Tools/idle/PathBrowser.py2
-rw-r--r--Tools/idle/PyShell.py2
-rw-r--r--Tools/idle/RemoteInterp.py11
-rw-r--r--Tools/idle/ScriptBinding.py4
-rw-r--r--Tools/idle/ScrolledList.py2
-rw-r--r--Tools/idle/Separator.py16
-rw-r--r--Tools/idle/StackViewer.py2
-rw-r--r--Tools/idle/ToolTip.py2
-rw-r--r--Tools/idle/WindowList.py2
-rwxr-xr-xTools/scripts/byteyears.py52
-rwxr-xr-xTools/scripts/checkpyc.py102
-rwxr-xr-xTools/scripts/classfix.py262
-rwxr-xr-xTools/scripts/copytime.py28
-rwxr-xr-xTools/scripts/dutree.py90
-rwxr-xr-xTools/scripts/findlinksto.py52
-rwxr-xr-xTools/scripts/fixcid.py426
-rwxr-xr-xTools/scripts/fixheader.py74
-rwxr-xr-xTools/scripts/fixps.py40
-rwxr-xr-xTools/scripts/ftpmirror.py668
-rw-r--r--Tools/scripts/gencodec.py8
-rwxr-xr-xTools/scripts/h2py.py200
-rwxr-xr-xTools/scripts/ifdef.py146
-rwxr-xr-xTools/scripts/linktree.py112
-rwxr-xr-xTools/scripts/lll.py20
-rwxr-xr-xTools/scripts/logmerge.py2
-rwxr-xr-xTools/scripts/mailerdaemon.py2
-rwxr-xr-xTools/scripts/methfix.py238
-rwxr-xr-xTools/scripts/mkreal.py84
-rwxr-xr-xTools/scripts/nm2def.py2
-rwxr-xr-xTools/scripts/objgraph.py256
-rwxr-xr-xTools/scripts/parseentities.py3
-rwxr-xr-xTools/scripts/pathfix.py202
-rwxr-xr-xTools/scripts/pdeps.py194
-rwxr-xr-xTools/scripts/pindent.py760
-rwxr-xr-xTools/scripts/ptags.py2
-rw-r--r--Tools/scripts/redemo.py306
-rwxr-xr-xTools/scripts/suff.py32
-rwxr-xr-xTools/scripts/sum5.py120
-rwxr-xr-xTools/scripts/texi2html.py6
-rw-r--r--Tools/scripts/trace.py10
-rwxr-xr-xTools/scripts/treesync.py4
-rwxr-xr-xTools/scripts/which.py64
-rwxr-xr-xTools/scripts/xxci.py146
56 files changed, 2455 insertions, 2461 deletions
diff --git a/Tools/idle/CallTipWindow.py b/Tools/idle/CallTipWindow.py
index cbeab8c..d253fa5 100644
--- a/Tools/idle/CallTipWindow.py
+++ b/Tools/idle/CallTipWindow.py
@@ -28,7 +28,7 @@ class CallTip:
background="#ffffe0", relief=SOLID, borderwidth=1,
font = self.widget['font'])
label.pack()
-
+
def hidetip(self):
tw = self.tipwindow
self.tipwindow = None
@@ -53,7 +53,7 @@ class container: # Conceptually an editor_window
text.event_add("<<calltip-hide>>", ")")
text.bind("<<calltip-show>>", self.calltip_show)
text.bind("<<calltip-hide>>", self.calltip_hide)
-
+
text.focus_set()
# root.mainloop() # not in idle
diff --git a/Tools/idle/CallTips.py b/Tools/idle/CallTips.py
index 04eccde..7c5f41c 100644
--- a/Tools/idle/CallTips.py
+++ b/Tools/idle/CallTips.py
@@ -45,7 +45,7 @@ class CallTips:
if self.calltip:
self.calltip.hidetip()
self.calltip = None
-
+
def paren_open_event(self, event):
self._remove_calltip_window()
arg_text = get_arg_text(self.get_object_at_cursor())
@@ -91,9 +91,9 @@ class CallTips:
namespace = sys.modules.copy()
namespace.update(__main__.__dict__)
try:
- return eval(word, namespace)
+ return eval(word, namespace)
except:
- pass
+ pass
return None # Can't find an object.
def _find_constructor(class_ob):
diff --git a/Tools/idle/ClassBrowser.py b/Tools/idle/ClassBrowser.py
index f440164..19f3b7e 100644
--- a/Tools/idle/ClassBrowser.py
+++ b/Tools/idle/ClassBrowser.py
@@ -92,7 +92,7 @@ class ModuleBrowserTreeItem(TreeItem):
def IsExpandable(self):
return os.path.normcase(self.file[-3:]) == ".py"
-
+
def listclasses(self):
dir, file = os.path.split(self.file)
name, ext = os.path.splitext(file)
diff --git a/Tools/idle/Debugger.py b/Tools/idle/Debugger.py
index 267d39f..e4591ff 100644
--- a/Tools/idle/Debugger.py
+++ b/Tools/idle/Debugger.py
@@ -17,7 +17,7 @@ class Debugger(bdb.Bdb):
bdb.Bdb.__init__(self)
self.pyshell = pyshell
self.make_gui()
-
+
def canonic(self, filename):
# Canonicalize filename -- called by Bdb
return os.path.normcase(os.path.abspath(filename))
@@ -299,10 +299,10 @@ class Debugger(bdb.Bdb):
import linecache # Import as late as possible
line = linecache.getline(filename, lineno)
if not line:
- return 'That line does not exist!'
+ return 'That line does not exist!'
if not self.breaks.has_key(filename):
- self.breaks[filename] = []
+ self.breaks[filename] = []
list = self.breaks[filename]
if not lineno in list:
- list.append(lineno)
+ list.append(lineno)
bp = bdb.Breakpoint(filename, lineno, temporary, cond)
diff --git a/Tools/idle/Delegator.py b/Tools/idle/Delegator.py
index 3665247..6125591 100644
--- a/Tools/idle/Delegator.py
+++ b/Tools/idle/Delegator.py
@@ -1,4 +1,3 @@
-
class Delegator:
# The cache is only used to be able to change delegates!
diff --git a/Tools/idle/FileList.py b/Tools/idle/FileList.py
index 0791157..db862a1 100644
--- a/Tools/idle/FileList.py
+++ b/Tools/idle/FileList.py
@@ -26,12 +26,12 @@ class FileList:
def goodname(self, filename):
- filename = self.canonize(filename)
- key = os.path.normcase(filename)
- if self.dict.has_key(key):
- edit = self.dict[key]
- filename = edit.io.filename or filename
- return filename
+ filename = self.canonize(filename)
+ key = os.path.normcase(filename)
+ if self.dict.has_key(key):
+ edit = self.dict[key]
+ filename = edit.io.filename or filename
+ return filename
def open(self, filename):
assert filename
diff --git a/Tools/idle/FormatParagraph.py b/Tools/idle/FormatParagraph.py
index 76c52f5..ea18cc0 100644
--- a/Tools/idle/FormatParagraph.py
+++ b/Tools/idle/FormatParagraph.py
@@ -28,10 +28,10 @@ class FormatParagraph:
keydefs = {
'<<format-paragraph>>': ['<Alt-q>'],
}
-
+
unix_keydefs = {
'<<format-paragraph>>': ['<Meta-q>'],
- }
+ }
def __init__(self, editwin):
self.editwin = editwin
diff --git a/Tools/idle/IdleConf.py b/Tools/idle/IdleConf.py
index 36cad51..37f4ef1 100644
--- a/Tools/idle/IdleConf.py
+++ b/Tools/idle/IdleConf.py
@@ -10,24 +10,24 @@ class IdleConfParser(ConfigParser):
builtin_sections = {}
for section in ('EditorWindow', 'Colors'):
builtin_sections[section] = section
-
+
def getcolor(self, sec, name):
"""Return a dictionary with foreground and background colors
The return value is appropriate for passing to Tkinter in, e.g.,
a tag_config call.
"""
- fore = self.getdef(sec, name + "-foreground")
- back = self.getdef(sec, name + "-background")
+ fore = self.getdef(sec, name + "-foreground")
+ back = self.getdef(sec, name + "-background")
return {"foreground": fore,
"background": back}
def getdef(self, sec, options, raw=0, vars=None, default=None):
"""Get an option value for given section or return default"""
- try:
+ try:
return self.get(sec, options, raw, vars)
- except (NoSectionError, NoOptionError):
- return default
+ except (NoSectionError, NoOptionError):
+ return default
def getsection(self, section):
"""Return a SectionConfigParser object"""
@@ -37,10 +37,10 @@ class IdleConfParser(ConfigParser):
exts = []
for sec in self.sections():
if self.builtin_sections.has_key(sec):
- continue
- # enable is a bool, but it may not be defined
- if self.getdef(sec, 'enable') != '0':
- exts.append(sec)
+ continue
+ # enable is a bool, but it may not be defined
+ if self.getdef(sec, 'enable') != '0':
+ exts.append(sec)
return exts
def reload(self):
@@ -69,10 +69,10 @@ class SectionConfigParser:
def getint(self, option):
return self.config.getint(self.section, option)
-
+
def getfloat(self, option):
return self.config.getint(self.section, option)
-
+
def getboolean(self, option):
return self.config.getint(self.section, option)
@@ -98,7 +98,7 @@ def load(dir):
genplatfile = os.path.join(dir, "config-mac.txt")
else:
genplatfile = os.path.join(dir, "config-unix.txt")
-
+
platfile = os.path.join(dir, "config-%s.txt" % sys.platform)
try:
@@ -110,4 +110,3 @@ def load(dir):
os.path.join(homedir, ".idle")))
idleconf = IdleConfParser()
-
diff --git a/Tools/idle/IdleHistory.py b/Tools/idle/IdleHistory.py
index aa41b73..b882c92 100644
--- a/Tools/idle/IdleHistory.py
+++ b/Tools/idle/IdleHistory.py
@@ -86,4 +86,3 @@ class History:
self.text.mark_set("insert", "end-1c")
self.text.insert("insert", s)
self.text.see("insert")
-
diff --git a/Tools/idle/MultiScrolledLists.py b/Tools/idle/MultiScrolledLists.py
index 32f6246..6c140df 100644
--- a/Tools/idle/MultiScrolledLists.py
+++ b/Tools/idle/MultiScrolledLists.py
@@ -10,7 +10,7 @@ from Separator import HSeparator
from ScrolledList import ScrolledList
class MultiScrolledLists:
-
+
def __init__(self, root, nlists=2):
assert nlists >= 1
self.root = root
@@ -51,17 +51,17 @@ class MultiScrolledLists:
self.fill(0)
# XXX one after_idle isn't enough; two are...
top.after_idle(self.call_pack_propagate_1)
-
+
def call_pack_propagate_1(self):
self.top.after_idle(self.call_pack_propagate)
-
+
def call_pack_propagate(self):
for frame in self.frames:
frame.pack_propagate(0)
-
+
def close(self, event=None):
self.top.destroy()
-
+
def settitle(self):
short = self.shorttitle()
long = self.longtitle()
@@ -80,23 +80,23 @@ class MultiScrolledLists:
def longtitle(self):
# override this
return "Multi Scrolled Lists"
-
+
def shorttitle(self):
# override this
return None
-
+
def width(self, i):
# override this
return 20
-
+
def height(self, i):
# override this
return 10
-
+
def subtitle(self, i):
# override this
return "Column %d" % i
-
+
def fill(self, i):
for k in range(i, self.nlists):
self.lists[k].clear()
@@ -105,14 +105,14 @@ class MultiScrolledLists:
l = self.items(i)
for s in l:
list.append(s)
-
+
def on_select(self, index, i):
item = self.lists[i].get(index)
del self.path[i:]
self.path.append(item)
if i+1 < self.nlists:
self.fill(i+1)
-
+
def items(self, i):
# override this
l = []
@@ -122,7 +122,7 @@ class MultiScrolledLists:
s = self.path[i-1] + "." + s
l.append(s)
return l
-
+
def on_double(self, index, i):
pass
diff --git a/Tools/idle/MultiStatusBar.py b/Tools/idle/MultiStatusBar.py
index c11db3e..dd6d041 100644
--- a/Tools/idle/MultiStatusBar.py
+++ b/Tools/idle/MultiStatusBar.py
@@ -1,32 +1,32 @@
from Tkinter import *
class MultiStatusBar(Frame):
-
- def __init__(self, master=None, **kw):
- if master is None:
- master = Tk()
- apply(Frame.__init__, (self, master), kw)
- self.labels = {}
- def set_label(self, name, text='', side=LEFT):
- if not self.labels.has_key(name):
- label = Label(self, bd=1, relief=SUNKEN, anchor=W)
- label.pack(side=side)
- self.labels[name] = label
- else:
- label = self.labels[name]
- label.config(text=text)
+ def __init__(self, master=None, **kw):
+ if master is None:
+ master = Tk()
+ apply(Frame.__init__, (self, master), kw)
+ self.labels = {}
+
+ def set_label(self, name, text='', side=LEFT):
+ if not self.labels.has_key(name):
+ label = Label(self, bd=1, relief=SUNKEN, anchor=W)
+ label.pack(side=side)
+ self.labels[name] = label
+ else:
+ label = self.labels[name]
+ label.config(text=text)
def _test():
- b = Frame()
- c = Text(b)
- c.pack(side=TOP)
- a = MultiStatusBar(b)
- a.set_label("one", "hello")
- a.set_label("two", "world")
- a.pack(side=BOTTOM, fill=X)
- b.pack()
- b.mainloop()
+ b = Frame()
+ c = Text(b)
+ c.pack(side=TOP)
+ a = MultiStatusBar(b)
+ a.set_label("one", "hello")
+ a.set_label("two", "world")
+ a.pack(side=BOTTOM, fill=X)
+ b.pack()
+ b.mainloop()
if __name__ == '__main__':
- _test()
+ _test()
diff --git a/Tools/idle/OutputWindow.py b/Tools/idle/OutputWindow.py
index 0c36a88..3d97362 100644
--- a/Tools/idle/OutputWindow.py
+++ b/Tools/idle/OutputWindow.py
@@ -111,17 +111,17 @@ class OnDemandOutputWindow:
# XXX Should use IdlePrefs.ColorPrefs
"stdout": {"foreground": "blue"},
"stderr": {"foreground": "#007700"},
- }
-
+ }
+
def __init__(self, flist):
self.flist = flist
self.owin = None
-
+
def write(self, s, tags, mark):
if not self.owin:
self.setup()
self.owin.write(s, tags, mark)
-
+
def setup(self):
self.owin = owin = OutputWindow(self.flist)
text = owin.text
diff --git a/Tools/idle/ParenMatch.py b/Tools/idle/ParenMatch.py
index a607e49..17d76c2 100644
--- a/Tools/idle/ParenMatch.py
+++ b/Tools/idle/ParenMatch.py
@@ -20,7 +20,7 @@ class ParenMatch:
"""Highlight matching parentheses
There are three supported style of paren matching, based loosely
- on the Emacs options. The style is select based on the
+ on the Emacs options. The style is select based on the
HILITE_STYLE attribute; it can be changed used the set_style
method.
@@ -43,9 +43,9 @@ class ParenMatch:
to the right of a right paren. I don't know how to do that in Tk,
so I haven't bothered.
"""
-
+
menudefs = []
-
+
keydefs = {
'<<flash-open-paren>>' : ('<KeyRelease-parenright>',
'<KeyRelease-bracketright>',
@@ -146,7 +146,7 @@ class LastOpenBracketFinder:
indentwidth = AutoIndent.indentwidth
tabwidth = AutoIndent.tabwidth
context_use_ps1 = AutoIndent.context_use_ps1
-
+
def __init__(self, editwin):
self.editwin = editwin
self.text = editwin.text
@@ -158,7 +158,7 @@ class LastOpenBracketFinder:
startatindex = `startat` + ".0"
# rawtext needs to contain everything up to the last
# character, which was the close paren. the parser also
- # requires that the last line ends with "\n"
+ # requires that the last line ends with "\n"
rawtext = self.text.get(startatindex, "insert")[:-1] + "\n"
y.set_str(rawtext)
bod = y.find_good_parse_start(
@@ -175,7 +175,7 @@ class LastOpenBracketFinder:
lno = index2line(self.text.index("insert"))
i, buf = self._find_offset_in_buf(lno)
if i is None \
- or keysym_type(buf[i]) != right_keysym_type:
+ or keysym_type(buf[i]) != right_keysym_type:
return None
lines_back = string.count(buf[i:], "\n") - 1
# subtract one for the "\n" added to please the parser
@@ -189,4 +189,3 @@ class LastOpenBracketFinder:
icis=self.editwin.is_char_in_string):
return icis(startindex + "%dc" % offset)
return inner
-
diff --git a/Tools/idle/PathBrowser.py b/Tools/idle/PathBrowser.py
index 7ea2410..86cd270 100644
--- a/Tools/idle/PathBrowser.py
+++ b/Tools/idle/PathBrowser.py
@@ -6,7 +6,7 @@ from TreeWidget import TreeItem
from ClassBrowser import ClassBrowser, ModuleBrowserTreeItem
class PathBrowser(ClassBrowser):
-
+
def __init__(self, flist):
self.init(flist)
diff --git a/Tools/idle/PyShell.py b/Tools/idle/PyShell.py
index 06d4f15..86c0f6b 100644
--- a/Tools/idle/PyShell.py
+++ b/Tools/idle/PyShell.py
@@ -124,7 +124,7 @@ class ModifiedColorDelegator(ColorDelegator):
"stderr": cconf.getcolor("stderr"),
"console": cconf.getcolor("console"),
"ERROR": cconf.getcolor("ERROR"),
- None: cconf.getcolor("normal"),
+ None: cconf.getcolor("normal"),
})
diff --git a/Tools/idle/RemoteInterp.py b/Tools/idle/RemoteInterp.py
index 3ad574b..724997c 100644
--- a/Tools/idle/RemoteInterp.py
+++ b/Tools/idle/RemoteInterp.py
@@ -9,7 +9,7 @@ VERBOSE = None
class SocketProtocol:
"""A simple protocol for sending strings across a socket"""
BUF_SIZE = 8192
-
+
def __init__(self, sock):
self.sock = sock
self._buffer = ''
@@ -176,11 +176,11 @@ class CommandProtocol:
def decode_seqno(self, buf):
return struct.unpack("I", buf)[0]
-
+
class StdioRedirector:
"""Redirect sys.std{in,out,err} to a set of file-like objects"""
-
+
def __init__(self, stdin, stdout, stderr):
self.stdin = stdin
self.stdout = stdout
@@ -292,7 +292,7 @@ class RIClient:
self._cmd.dispatch()
except EOFError:
pass
-
+
def handle_stdout(self, buf):
sys.stdout.write(buf)
## sys.stdout.flush()
@@ -339,5 +339,4 @@ if __name__ == "__main__":
startRemoteInterp(id)
else:
file = args[1]
- riExec(id, file)
-
+ riExec(id, file)
diff --git a/Tools/idle/ScriptBinding.py b/Tools/idle/ScriptBinding.py
index e46cb76..b54dfc4 100644
--- a/Tools/idle/ScriptBinding.py
+++ b/Tools/idle/ScriptBinding.py
@@ -34,13 +34,13 @@ To fix case 2, change all tabs to spaces by using Select All followed \
by Untabify Region (both in the Edit menu)."""
class ScriptBinding:
-
+
keydefs = {
'<<check-module>>': ['<Alt-F5>', '<Meta-F5>'],
'<<import-module>>': ['<F5>'],
'<<run-script>>': ['<Control-F5>'],
}
-
+
menudefs = [
('edit', [None,
('Check module', '<<check-module>>'),
diff --git a/Tools/idle/ScrolledList.py b/Tools/idle/ScrolledList.py
index 7fb1c20..92119365 100644
--- a/Tools/idle/ScrolledList.py
+++ b/Tools/idle/ScrolledList.py
@@ -1,7 +1,7 @@
from Tkinter import *
class ScrolledList:
-
+
default = "(None)"
def __init__(self, master, **options):
diff --git a/Tools/idle/Separator.py b/Tools/idle/Separator.py
index 2645e57..7145559 100644
--- a/Tools/idle/Separator.py
+++ b/Tools/idle/Separator.py
@@ -1,7 +1,7 @@
from Tkinter import *
class Separator:
-
+
def __init__(self, master, orient, min=10, thickness=5, bg=None):
self.min = max(1, min)
self.thickness = max(1, thickness)
@@ -10,14 +10,14 @@ class Separator:
self.dim = "width"
self.dir = "x"
self.cursor = "sb_h_double_arrow"
- elif orient in ("v", "vertical"):
- self.side = "top"
- self.dim = "height"
- self.dir = "y"
+ elif orient in ("v", "vertical"):
+ self.side = "top"
+ self.dim = "height"
+ self.dir = "y"
self.cursor = "sb_v_double_arrow"
- else:
- raise ValueError, "Separator: orient should be h or v"
- self.winfo_dim = "winfo_" + self.dim
+ else:
+ raise ValueError, "Separator: orient should be h or v"
+ self.winfo_dim = "winfo_" + self.dim
self.master = master = Frame(master)
master.pack(expand=1, fill="both")
self.f1 = Frame(master)
diff --git a/Tools/idle/StackViewer.py b/Tools/idle/StackViewer.py
index 5b3c87a..ab09db0 100644
--- a/Tools/idle/StackViewer.py
+++ b/Tools/idle/StackViewer.py
@@ -100,7 +100,7 @@ class VariablesTreeItem(ObjectTreeItem):
item = make_objecttreeitem(key + " =", value, setfunction)
sublist.append(item)
return sublist
-
+
def get_stack(t=None, f=None):
if t is None:
t = sys.last_traceback
diff --git a/Tools/idle/ToolTip.py b/Tools/idle/ToolTip.py
index 691f510..eadcdea 100644
--- a/Tools/idle/ToolTip.py
+++ b/Tools/idle/ToolTip.py
@@ -81,7 +81,7 @@ def main():
b.pack()
root.update()
tip = ListboxToolTip(b, ["Hello", "world"])
-
+
# root.mainloop() # not in idle
main()
diff --git a/Tools/idle/WindowList.py b/Tools/idle/WindowList.py
index 6de3e58..7e05a57 100644
--- a/Tools/idle/WindowList.py
+++ b/Tools/idle/WindowList.py
@@ -39,7 +39,7 @@ class WindowList:
def unregister_callback(self, callback):
try:
- self.callbacks.remove(callback)
+ self.callbacks.remove(callback)
except ValueError:
pass
diff --git a/Tools/scripts/byteyears.py b/Tools/scripts/byteyears.py
index bada5a5..f67be70 100755
--- a/Tools/scripts/byteyears.py
+++ b/Tools/scripts/byteyears.py
@@ -12,46 +12,46 @@ from stat import *
# Use lstat() to stat files if it exists, else stat()
try:
- statfunc = os.lstat
+ statfunc = os.lstat
except AttributeError:
- statfunc = os.stat
+ statfunc = os.stat
# Parse options
if sys.argv[1] == '-m':
- itime = ST_MTIME
- del sys.argv[1]
+ itime = ST_MTIME
+ del sys.argv[1]
elif sys.argv[1] == '-c':
- itime = ST_CTIME
- del sys.argv[1]
+ itime = ST_CTIME
+ del sys.argv[1]
elif sys.argv[1] == '-a':
- itime = ST_CTIME
- del sys.argv[1]
+ itime = ST_CTIME
+ del sys.argv[1]
else:
- itime = ST_MTIME
+ itime = ST_MTIME
-secs_per_year = 365.0 * 24.0 * 3600.0 # Scale factor
-now = time.time() # Current time, for age computations
-status = 0 # Exit status, set to 1 on errors
+secs_per_year = 365.0 * 24.0 * 3600.0 # Scale factor
+now = time.time() # Current time, for age computations
+status = 0 # Exit status, set to 1 on errors
# Compute max file name length
maxlen = 1
for file in sys.argv[1:]:
- if len(file) > maxlen: maxlen = len(file)
+ if len(file) > maxlen: maxlen = len(file)
# Process each argument in turn
for file in sys.argv[1:]:
- try:
- st = statfunc(file)
- except os.error, msg:
- sys.stderr.write('can\'t stat ' + `file` + ': ' + `msg` + '\n')
- status = 1
- st = ()
- if st:
- anytime = st[itime]
- size = st[ST_SIZE]
- age = now - anytime
- byteyears = float(size) * float(age) / secs_per_year
- print string.ljust(file, maxlen),
- print string.rjust(`int(byteyears)`, 8)
+ try:
+ st = statfunc(file)
+ except os.error, msg:
+ sys.stderr.write('can\'t stat ' + `file` + ': ' + `msg` + '\n')
+ status = 1
+ st = ()
+ if st:
+ anytime = st[itime]
+ size = st[ST_SIZE]
+ age = now - anytime
+ byteyears = float(size) * float(age) / secs_per_year
+ print string.ljust(file, maxlen),
+ print string.rjust(`int(byteyears)`, 8)
sys.exit(status)
diff --git a/Tools/scripts/checkpyc.py b/Tools/scripts/checkpyc.py
index 7be625c..b38b456 100755
--- a/Tools/scripts/checkpyc.py
+++ b/Tools/scripts/checkpyc.py
@@ -8,58 +8,58 @@ from stat import ST_MTIME
import imp
def main():
- silent = 0
- verbose = 0
- if sys.argv[1:]:
- if sys.argv[1] == '-v':
- verbose = 1
- elif sys.argv[1] == '-s':
- silent = 1
- MAGIC = imp.get_magic()
- if not silent:
- print 'Using MAGIC word', `MAGIC`
- for dirname in sys.path:
- try:
- names = os.listdir(dirname)
- except os.error:
- print 'Cannot list directory', `dirname`
- continue
- if not silent:
- print 'Checking', `dirname`, '...'
- names.sort()
- for name in names:
- if name[-3:] == '.py':
- name = os.path.join(dirname, name)
- try:
- st = os.stat(name)
- except os.error:
- print 'Cannot stat', `name`
- continue
- if verbose:
- print 'Check', `name`, '...'
- name_c = name + 'c'
- try:
- f = open(name_c, 'r')
- except IOError:
- print 'Cannot open', `name_c`
- continue
- magic_str = f.read(4)
- mtime_str = f.read(4)
- f.close()
- if magic_str <> MAGIC:
- print 'Bad MAGIC word in ".pyc" file',
- print `name_c`
- continue
- mtime = get_long(mtime_str)
- if mtime == 0 or mtime == -1:
- print 'Bad ".pyc" file', `name_c`
- elif mtime <> st[ST_MTIME]:
- print 'Out-of-date ".pyc" file',
- print `name_c`
+ silent = 0
+ verbose = 0
+ if sys.argv[1:]:
+ if sys.argv[1] == '-v':
+ verbose = 1
+ elif sys.argv[1] == '-s':
+ silent = 1
+ MAGIC = imp.get_magic()
+ if not silent:
+ print 'Using MAGIC word', `MAGIC`
+ for dirname in sys.path:
+ try:
+ names = os.listdir(dirname)
+ except os.error:
+ print 'Cannot list directory', `dirname`
+ continue
+ if not silent:
+ print 'Checking', `dirname`, '...'
+ names.sort()
+ for name in names:
+ if name[-3:] == '.py':
+ name = os.path.join(dirname, name)
+ try:
+ st = os.stat(name)
+ except os.error:
+ print 'Cannot stat', `name`
+ continue
+ if verbose:
+ print 'Check', `name`, '...'
+ name_c = name + 'c'
+ try:
+ f = open(name_c, 'r')
+ except IOError:
+ print 'Cannot open', `name_c`
+ continue
+ magic_str = f.read(4)
+ mtime_str = f.read(4)
+ f.close()
+ if magic_str <> MAGIC:
+ print 'Bad MAGIC word in ".pyc" file',
+ print `name_c`
+ continue
+ mtime = get_long(mtime_str)
+ if mtime == 0 or mtime == -1:
+ print 'Bad ".pyc" file', `name_c`
+ elif mtime <> st[ST_MTIME]:
+ print 'Out-of-date ".pyc" file',
+ print `name_c`
def get_long(s):
- if len(s) <> 4:
- return -1
- return ord(s[0]) + (ord(s[1])<<8) + (ord(s[2])<<16) + (ord(s[3])<<24)
+ if len(s) <> 4:
+ return -1
+ return ord(s[0]) + (ord(s[1])<<8) + (ord(s[2])<<16) + (ord(s[3])<<24)
main()
diff --git a/Tools/scripts/classfix.py b/Tools/scripts/classfix.py
index 53ea0b8..332db12 100755
--- a/Tools/scripts/classfix.py
+++ b/Tools/scripts/classfix.py
@@ -4,9 +4,9 @@
#
# Fix Python source files to use the new class definition syntax, i.e.,
# the syntax used in Python versions before 0.9.8:
-# class C() = base(), base(), ...: ...
+# class C() = base(), base(), ...: ...
# is changed to the current syntax:
-# class C(base, base, ...): ...
+# class C(base, base, ...): ...
#
# The script uses heuristics to find class definitions that usually
# work but occasionally can fail; carefully check the output!
@@ -39,113 +39,113 @@ dbg = err
rep = sys.stdout.write
def main():
- bad = 0
- if not sys.argv[1:]: # No arguments
- err('usage: ' + sys.argv[0] + ' file-or-directory ...\n')
- sys.exit(2)
- for arg in sys.argv[1:]:
- if os.path.isdir(arg):
- if recursedown(arg): bad = 1
- elif os.path.islink(arg):
- err(arg + ': will not process symbolic links\n')
- bad = 1
- else:
- if fix(arg): bad = 1
- sys.exit(bad)
+ bad = 0
+ if not sys.argv[1:]: # No arguments
+ err('usage: ' + sys.argv[0] + ' file-or-directory ...\n')
+ sys.exit(2)
+ for arg in sys.argv[1:]:
+ if os.path.isdir(arg):
+ if recursedown(arg): bad = 1
+ elif os.path.islink(arg):
+ err(arg + ': will not process symbolic links\n')
+ bad = 1
+ else:
+ if fix(arg): bad = 1
+ sys.exit(bad)
ispythonprog = regex.compile('^[a-zA-Z0-9_]+\.py$')
def ispython(name):
- return ispythonprog.match(name) >= 0
+ return ispythonprog.match(name) >= 0
def recursedown(dirname):
- dbg('recursedown(' + `dirname` + ')\n')
- bad = 0
- try:
- names = os.listdir(dirname)
- except os.error, msg:
- err(dirname + ': cannot list directory: ' + `msg` + '\n')
- return 1
- names.sort()
- subdirs = []
- for name in names:
- if name in (os.curdir, os.pardir): continue
- fullname = os.path.join(dirname, name)
- if os.path.islink(fullname): pass
- elif os.path.isdir(fullname):
- subdirs.append(fullname)
- elif ispython(name):
- if fix(fullname): bad = 1
- for fullname in subdirs:
- if recursedown(fullname): bad = 1
- return bad
+ dbg('recursedown(' + `dirname` + ')\n')
+ bad = 0
+ try:
+ names = os.listdir(dirname)
+ except os.error, msg:
+ err(dirname + ': cannot list directory: ' + `msg` + '\n')
+ return 1
+ names.sort()
+ subdirs = []
+ for name in names:
+ if name in (os.curdir, os.pardir): continue
+ fullname = os.path.join(dirname, name)
+ if os.path.islink(fullname): pass
+ elif os.path.isdir(fullname):
+ subdirs.append(fullname)
+ elif ispython(name):
+ if fix(fullname): bad = 1
+ for fullname in subdirs:
+ if recursedown(fullname): bad = 1
+ return bad
def fix(filename):
-## dbg('fix(' + `filename` + ')\n')
- try:
- f = open(filename, 'r')
- except IOError, msg:
- err(filename + ': cannot open: ' + `msg` + '\n')
- return 1
- head, tail = os.path.split(filename)
- tempname = os.path.join(head, '@' + tail)
- g = None
- # If we find a match, we rewind the file and start over but
- # now copy everything to a temp file.
- lineno = 0
- while 1:
- line = f.readline()
- if not line: break
- lineno = lineno + 1
- while line[-2:] == '\\\n':
- nextline = f.readline()
- if not nextline: break
- line = line + nextline
- lineno = lineno + 1
- newline = fixline(line)
- if newline != line:
- if g is None:
- try:
- g = open(tempname, 'w')
- except IOError, msg:
- f.close()
- err(tempname+': cannot create: '+\
- `msg`+'\n')
- return 1
- f.seek(0)
- lineno = 0
- rep(filename + ':\n')
- continue # restart from the beginning
- rep(`lineno` + '\n')
- rep('< ' + line)
- rep('> ' + newline)
- if g is not None:
- g.write(newline)
-
- # End of file
- f.close()
- if not g: return 0 # No changes
-
- # Finishing touch -- move files
-
- # First copy the file's mode to the temp file
- try:
- statbuf = os.stat(filename)
- os.chmod(tempname, statbuf[ST_MODE] & 07777)
- except os.error, msg:
- err(tempname + ': warning: chmod failed (' + `msg` + ')\n')
- # Then make a backup of the original file as filename~
- try:
- os.rename(filename, filename + '~')
- except os.error, msg:
- err(filename + ': warning: backup failed (' + `msg` + ')\n')
- # Now move the temp file to the original file
- try:
- os.rename(tempname, filename)
- except os.error, msg:
- err(filename + ': rename failed (' + `msg` + ')\n')
- return 1
- # Return succes
- return 0
+## dbg('fix(' + `filename` + ')\n')
+ try:
+ f = open(filename, 'r')
+ except IOError, msg:
+ err(filename + ': cannot open: ' + `msg` + '\n')
+ return 1
+ head, tail = os.path.split(filename)
+ tempname = os.path.join(head, '@' + tail)
+ g = None
+ # If we find a match, we rewind the file and start over but
+ # now copy everything to a temp file.
+ lineno = 0
+ while 1:
+ line = f.readline()
+ if not line: break
+ lineno = lineno + 1
+ while line[-2:] == '\\\n':
+ nextline = f.readline()
+ if not nextline: break
+ line = line + nextline
+ lineno = lineno + 1
+ newline = fixline(line)
+ if newline != line:
+ if g is None:
+ try:
+ g = open(tempname, 'w')
+ except IOError, msg:
+ f.close()
+ err(tempname+': cannot create: '+\
+ `msg`+'\n')
+ return 1
+ f.seek(0)
+ lineno = 0
+ rep(filename + ':\n')
+ continue # restart from the beginning
+ rep(`lineno` + '\n')
+ rep('< ' + line)
+ rep('> ' + newline)
+ if g is not None:
+ g.write(newline)
+
+ # End of file
+ f.close()
+ if not g: return 0 # No changes
+
+ # Finishing touch -- move files
+
+ # First copy the file's mode to the temp file
+ try:
+ statbuf = os.stat(filename)
+ os.chmod(tempname, statbuf[ST_MODE] & 07777)
+ except os.error, msg:
+ err(tempname + ': warning: chmod failed (' + `msg` + ')\n')
+ # Then make a backup of the original file as filename~
+ try:
+ os.rename(filename, filename + '~')
+ except os.error, msg:
+ err(filename + ': warning: backup failed (' + `msg` + ')\n')
+ # Now move the temp file to the original file
+ try:
+ os.rename(tempname, filename)
+ except os.error, msg:
+ err(filename + ': rename failed (' + `msg` + ')\n')
+ return 1
+ # Return succes
+ return 0
# This expression doesn't catch *all* class definition headers,
# but it's pretty darn close.
@@ -159,34 +159,34 @@ baseprog = regex.compile(baseexpr)
import string
def fixline(line):
- if classprog.match(line) < 0: # No 'class' keyword -- no change
- return line
-
- (a0, b0), (a1, b1), (a2, b2) = classprog.regs[:3]
- # a0, b0 = Whole match (up to ':')
- # a1, b1 = First subexpression (up to classname)
- # a2, b2 = Second subexpression (=.*)
- head = line[:b1]
- tail = line[b0:] # Unmatched rest of line
-
- if a2 == b2: # No base classes -- easy case
- return head + ':' + tail
-
- # Get rid of leading '='
- basepart = line[a2+1:b2]
-
- # Extract list of base expressions
- bases = string.splitfields(basepart, ',')
-
- # Strip trailing '()' from each base expression
- for i in range(len(bases)):
- if baseprog.match(bases[i]) >= 0:
- x1, y1 = baseprog.regs[1]
- bases[i] = bases[i][x1:y1]
-
- # Join the bases back again and build the new line
- basepart = string.joinfields(bases, ', ')
-
- return head + '(' + basepart + '):' + tail
+ if classprog.match(line) < 0: # No 'class' keyword -- no change
+ return line
+
+ (a0, b0), (a1, b1), (a2, b2) = classprog.regs[:3]
+ # a0, b0 = Whole match (up to ':')
+ # a1, b1 = First subexpression (up to classname)
+ # a2, b2 = Second subexpression (=.*)
+ head = line[:b1]
+ tail = line[b0:] # Unmatched rest of line
+
+ if a2 == b2: # No base classes -- easy case
+ return head + ':' + tail
+
+ # Get rid of leading '='
+ basepart = line[a2+1:b2]
+
+ # Extract list of base expressions
+ bases = string.splitfields(basepart, ',')
+
+ # Strip trailing '()' from each base expression
+ for i in range(len(bases)):
+ if baseprog.match(bases[i]) >= 0:
+ x1, y1 = baseprog.regs[1]
+ bases[i] = bases[i][x1:y1]
+
+ # Join the bases back again and build the new line
+ basepart = string.joinfields(bases, ', ')
+
+ return head + '(' + basepart + '):' + tail
main()
diff --git a/Tools/scripts/copytime.py b/Tools/scripts/copytime.py
index d01643b..74c29c9 100755
--- a/Tools/scripts/copytime.py
+++ b/Tools/scripts/copytime.py
@@ -7,19 +7,19 @@ import os
from stat import ST_ATIME, ST_MTIME # Really constants 7 and 8
def main():
- if len(sys.argv) <> 3:
- sys.stderr.write('usage: copytime source destination\n')
- sys.exit(2)
- file1, file2 = sys.argv[1], sys.argv[2]
- try:
- stat1 = os.stat(file1)
- except os.error:
- sys.stderr.write(file1 + ': cannot stat\n')
- sys.exit(1)
- try:
- os.utime(file2, (stat1[ST_ATIME], stat1[ST_MTIME]))
- except os.error:
- sys.stderr.write(file2 + ': cannot change time\n')
- sys.exit(2)
+ if len(sys.argv) <> 3:
+ sys.stderr.write('usage: copytime source destination\n')
+ sys.exit(2)
+ file1, file2 = sys.argv[1], sys.argv[2]
+ try:
+ stat1 = os.stat(file1)
+ except os.error:
+ sys.stderr.write(file1 + ': cannot stat\n')
+ sys.exit(1)
+ try:
+ os.utime(file2, (stat1[ST_ATIME], stat1[ST_MTIME]))
+ except os.error:
+ sys.stderr.write(file2 + ': cannot change time\n')
+ sys.exit(2)
main()
diff --git a/Tools/scripts/dutree.py b/Tools/scripts/dutree.py
index 5e78d63..63b3e67 100755
--- a/Tools/scripts/dutree.py
+++ b/Tools/scripts/dutree.py
@@ -4,56 +4,56 @@
import os, string, sys, errno
def main():
- p = os.popen('du ' + string.join(sys.argv[1:]), 'r')
- total, d = None, {}
- for line in p.readlines():
- i = 0
- while line[i] in '0123456789': i = i+1
- size = eval(line[:i])
- while line[i] in ' \t': i = i+1
- file = line[i:-1]
- comps = string.splitfields(file, '/')
- if comps[0] == '': comps[0] = '/'
- if comps[len(comps)-1] == '': del comps[len(comps)-1]
- total, d = store(size, comps, total, d)
- try:
- display(total, d)
- except IOError, e:
- if e.errno != errno.EPIPE:
- raise
+ p = os.popen('du ' + string.join(sys.argv[1:]), 'r')
+ total, d = None, {}
+ for line in p.readlines():
+ i = 0
+ while line[i] in '0123456789': i = i+1
+ size = eval(line[:i])
+ while line[i] in ' \t': i = i+1
+ file = line[i:-1]
+ comps = string.splitfields(file, '/')
+ if comps[0] == '': comps[0] = '/'
+ if comps[len(comps)-1] == '': del comps[len(comps)-1]
+ total, d = store(size, comps, total, d)
+ try:
+ display(total, d)
+ except IOError, e:
+ if e.errno != errno.EPIPE:
+ raise
def store(size, comps, total, d):
- if comps == []:
- return size, d
- if not d.has_key(comps[0]):
- d[comps[0]] = None, {}
- t1, d1 = d[comps[0]]
- d[comps[0]] = store(size, comps[1:], t1, d1)
- return total, d
+ if comps == []:
+ return size, d
+ if not d.has_key(comps[0]):
+ d[comps[0]] = None, {}
+ t1, d1 = d[comps[0]]
+ d[comps[0]] = store(size, comps[1:], t1, d1)
+ return total, d
def display(total, d):
- show(total, d, '')
+ show(total, d, '')
def show(total, d, prefix):
- if not d: return
- list = []
- sum = 0
- for key in d.keys():
- tsub, dsub = d[key]
- list.append((tsub, key))
- if tsub is not None: sum = sum + tsub
-## if sum < total:
-## list.append((total - sum, os.curdir))
- list.sort()
- list.reverse()
- width = len(`list[0][0]`)
- for tsub, key in list:
- if tsub is None:
- psub = prefix
- else:
- print prefix + string.rjust(`tsub`, width) + ' ' + key
- psub = prefix + ' '*(width-1) + '|' + ' '*(len(key)+1)
- if d.has_key(key):
- show(tsub, d[key][1], psub)
+ if not d: return
+ list = []
+ sum = 0
+ for key in d.keys():
+ tsub, dsub = d[key]
+ list.append((tsub, key))
+ if tsub is not None: sum = sum + tsub
+## if sum < total:
+## list.append((total - sum, os.curdir))
+ list.sort()
+ list.reverse()
+ width = len(`list[0][0]`)
+ for tsub, key in list:
+ if tsub is None:
+ psub = prefix
+ else:
+ print prefix + string.rjust(`tsub`, width) + ' ' + key
+ psub = prefix + ' '*(width-1) + '|' + ' '*(len(key)+1)
+ if d.has_key(key):
+ show(tsub, d[key][1], psub)
main()
diff --git a/Tools/scripts/findlinksto.py b/Tools/scripts/findlinksto.py
index 06821cd..e4731a5 100755
--- a/Tools/scripts/findlinksto.py
+++ b/Tools/scripts/findlinksto.py
@@ -10,33 +10,33 @@ import regex
import getopt
def main():
- try:
- opts, args = getopt.getopt(sys.argv[1:], '')
- if len(args) < 2:
- raise getopt.error, 'not enough arguments'
- except getopt.error, msg:
- sys.stdout = sys.stderr
- print msg
- print 'usage: findlinksto pattern directory ...'
- sys.exit(2)
- pat, dirs = args[0], args[1:]
- prog = regex.compile(pat)
- for dirname in dirs:
- os.path.walk(dirname, visit, prog)
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], '')
+ if len(args) < 2:
+ raise getopt.error, 'not enough arguments'
+ except getopt.error, msg:
+ sys.stdout = sys.stderr
+ print msg
+ print 'usage: findlinksto pattern directory ...'
+ sys.exit(2)
+ pat, dirs = args[0], args[1:]
+ prog = regex.compile(pat)
+ for dirname in dirs:
+ os.path.walk(dirname, visit, prog)
def visit(prog, dirname, names):
- if os.path.islink(dirname):
- names[:] = []
- return
- if os.path.ismount(dirname):
- print 'descend into', dirname
- for name in names:
- name = os.path.join(dirname, name)
- try:
- linkto = os.readlink(name)
- if prog.search(linkto) >= 0:
- print name, '->', linkto
- except os.error:
- pass
+ if os.path.islink(dirname):
+ names[:] = []
+ return
+ if os.path.ismount(dirname):
+ print 'descend into', dirname
+ for name in names:
+ name = os.path.join(dirname, name)
+ try:
+ linkto = os.readlink(name)
+ if prog.search(linkto) >= 0:
+ print name, '->', linkto
+ except os.error:
+ pass
main()
diff --git a/Tools/scripts/fixcid.py b/Tools/scripts/fixcid.py
index cf0ec16..836ceed 100755
--- a/Tools/scripts/fixcid.py
+++ b/Tools/scripts/fixcid.py
@@ -46,151 +46,151 @@ dbg = err
rep = sys.stdout.write
def usage():
- progname = sys.argv[0]
- err('Usage: ' + progname +
- ' [-c] [-r] [-s file] ... file-or-directory ...\n')
- err('\n')
- err('-c : substitute inside comments\n')
- err('-r : reverse direction for following -s options\n')
- err('-s substfile : add a file of substitutions\n')
- err('\n')
- err('Each non-empty non-comment line in a substitution file must\n')
- err('contain exactly two words: an identifier and its replacement.\n')
- err('Comments start with a # character and end at end of line.\n')
- err('If an identifier is preceded with a *, it is not substituted\n')
- err('inside a comment even when -c is specified.\n')
+ progname = sys.argv[0]
+ err('Usage: ' + progname +
+ ' [-c] [-r] [-s file] ... file-or-directory ...\n')
+ err('\n')
+ err('-c : substitute inside comments\n')
+ err('-r : reverse direction for following -s options\n')
+ err('-s substfile : add a file of substitutions\n')
+ err('\n')
+ err('Each non-empty non-comment line in a substitution file must\n')
+ err('contain exactly two words: an identifier and its replacement.\n')
+ err('Comments start with a # character and end at end of line.\n')
+ err('If an identifier is preceded with a *, it is not substituted\n')
+ err('inside a comment even when -c is specified.\n')
def main():
- try:
- opts, args = getopt.getopt(sys.argv[1:], 'crs:')
- except getopt.error, msg:
- err('Options error: ' + str(msg) + '\n')
- usage()
- sys.exit(2)
- bad = 0
- if not args: # No arguments
- usage()
- sys.exit(2)
- for opt, arg in opts:
- if opt == '-c':
- setdocomments()
- if opt == '-r':
- setreverse()
- if opt == '-s':
- addsubst(arg)
- for arg in args:
- if os.path.isdir(arg):
- if recursedown(arg): bad = 1
- elif os.path.islink(arg):
- err(arg + ': will not process symbolic links\n')
- bad = 1
- else:
- if fix(arg): bad = 1
- sys.exit(bad)
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], 'crs:')
+ except getopt.error, msg:
+ err('Options error: ' + str(msg) + '\n')
+ usage()
+ sys.exit(2)
+ bad = 0
+ if not args: # No arguments
+ usage()
+ sys.exit(2)
+ for opt, arg in opts:
+ if opt == '-c':
+ setdocomments()
+ if opt == '-r':
+ setreverse()
+ if opt == '-s':
+ addsubst(arg)
+ for arg in args:
+ if os.path.isdir(arg):
+ if recursedown(arg): bad = 1
+ elif os.path.islink(arg):
+ err(arg + ': will not process symbolic links\n')
+ bad = 1
+ else:
+ if fix(arg): bad = 1
+ sys.exit(bad)
# Change this regular expression to select a different set of files
Wanted = '^[a-zA-Z0-9_]+\.[ch]$'
def wanted(name):
- return regex.match(Wanted, name) >= 0
+ return regex.match(Wanted, name) >= 0
def recursedown(dirname):
- dbg('recursedown(' + `dirname` + ')\n')
- bad = 0
- try:
- names = os.listdir(dirname)
- except os.error, msg:
- err(dirname + ': cannot list directory: ' + str(msg) + '\n')
- return 1
- names.sort()
- subdirs = []
- for name in names:
- if name in (os.curdir, os.pardir): continue
- fullname = os.path.join(dirname, name)
- if os.path.islink(fullname): pass
- elif os.path.isdir(fullname):
- subdirs.append(fullname)
- elif wanted(name):
- if fix(fullname): bad = 1
- for fullname in subdirs:
- if recursedown(fullname): bad = 1
- return bad
+ dbg('recursedown(' + `dirname` + ')\n')
+ bad = 0
+ try:
+ names = os.listdir(dirname)
+ except os.error, msg:
+ err(dirname + ': cannot list directory: ' + str(msg) + '\n')
+ return 1
+ names.sort()
+ subdirs = []
+ for name in names:
+ if name in (os.curdir, os.pardir): continue
+ fullname = os.path.join(dirname, name)
+ if os.path.islink(fullname): pass
+ elif os.path.isdir(fullname):
+ subdirs.append(fullname)
+ elif wanted(name):
+ if fix(fullname): bad = 1
+ for fullname in subdirs:
+ if recursedown(fullname): bad = 1
+ return bad
def fix(filename):
-## dbg('fix(' + `filename` + ')\n')
- if filename == '-':
- # Filter mode
- f = sys.stdin
- g = sys.stdout
- else:
- # File replacement mode
- try:
- f = open(filename, 'r')
- except IOError, msg:
- err(filename + ': cannot open: ' + str(msg) + '\n')
- return 1
- head, tail = os.path.split(filename)
- tempname = os.path.join(head, '@' + tail)
- g = None
- # If we find a match, we rewind the file and start over but
- # now copy everything to a temp file.
- lineno = 0
- initfixline()
- while 1:
- line = f.readline()
- if not line: break
- lineno = lineno + 1
- while line[-2:] == '\\\n':
- nextline = f.readline()
- if not nextline: break
- line = line + nextline
- lineno = lineno + 1
- newline = fixline(line)
- if newline != line:
- if g is None:
- try:
- g = open(tempname, 'w')
- except IOError, msg:
- f.close()
- err(tempname+': cannot create: '+
- str(msg)+'\n')
- return 1
- f.seek(0)
- lineno = 0
- initfixline()
- rep(filename + ':\n')
- continue # restart from the beginning
- rep(`lineno` + '\n')
- rep('< ' + line)
- rep('> ' + newline)
- if g is not None:
- g.write(newline)
+## dbg('fix(' + `filename` + ')\n')
+ if filename == '-':
+ # Filter mode
+ f = sys.stdin
+ g = sys.stdout
+ else:
+ # File replacement mode
+ try:
+ f = open(filename, 'r')
+ except IOError, msg:
+ err(filename + ': cannot open: ' + str(msg) + '\n')
+ return 1
+ head, tail = os.path.split(filename)
+ tempname = os.path.join(head, '@' + tail)
+ g = None
+ # If we find a match, we rewind the file and start over but
+ # now copy everything to a temp file.
+ lineno = 0
+ initfixline()
+ while 1:
+ line = f.readline()
+ if not line: break
+ lineno = lineno + 1
+ while line[-2:] == '\\\n':
+ nextline = f.readline()
+ if not nextline: break
+ line = line + nextline
+ lineno = lineno + 1
+ newline = fixline(line)
+ if newline != line:
+ if g is None:
+ try:
+ g = open(tempname, 'w')
+ except IOError, msg:
+ f.close()
+ err(tempname+': cannot create: '+
+ str(msg)+'\n')
+ return 1
+ f.seek(0)
+ lineno = 0
+ initfixline()
+ rep(filename + ':\n')
+ continue # restart from the beginning
+ rep(`lineno` + '\n')
+ rep('< ' + line)
+ rep('> ' + newline)
+ if g is not None:
+ g.write(newline)
- # End of file
- if filename == '-': return 0 # Done in filter mode
- f.close()
- if not g: return 0 # No changes
+ # End of file
+ if filename == '-': return 0 # Done in filter mode
+ f.close()
+ if not g: return 0 # No changes
- # Finishing touch -- move files
+ # Finishing touch -- move files
- # First copy the file's mode to the temp file
- try:
- statbuf = os.stat(filename)
- os.chmod(tempname, statbuf[ST_MODE] & 07777)
- except os.error, msg:
- err(tempname + ': warning: chmod failed (' + str(msg) + ')\n')
- # Then make a backup of the original file as filename~
- try:
- os.rename(filename, filename + '~')
- except os.error, msg:
- err(filename + ': warning: backup failed (' + str(msg) + ')\n')
- # Now move the temp file to the original file
- try:
- os.rename(tempname, filename)
- except os.error, msg:
- err(filename + ': rename failed (' + str(msg) + ')\n')
- return 1
- # Return succes
- return 0
+ # First copy the file's mode to the temp file
+ try:
+ statbuf = os.stat(filename)
+ os.chmod(tempname, statbuf[ST_MODE] & 07777)
+ except os.error, msg:
+ err(tempname + ': warning: chmod failed (' + str(msg) + ')\n')
+ # Then make a backup of the original file as filename~
+ try:
+ os.rename(filename, filename + '~')
+ except os.error, msg:
+ err(filename + ': warning: backup failed (' + str(msg) + ')\n')
+ # Now move the temp file to the original file
+ try:
+ os.rename(tempname, filename)
+ except os.error, msg:
+ err(filename + ': rename failed (' + str(msg) + ')\n')
+ return 1
+ # Return succes
+ return 0
# Tokenizing ANSI C (partly)
@@ -221,98 +221,98 @@ InsideCommentPattern = '\(' + string.joinfields(InsideComment, '\|') + '\)'
InsideCommentProgram = regex.compile(InsideCommentPattern)
def initfixline():
- global Program
- Program = OutsideCommentProgram
+ global Program
+ Program = OutsideCommentProgram
def fixline(line):
- global Program
-## print '-->', `line`
- i = 0
- while i < len(line):
- i = Program.search(line, i)
- if i < 0: break
- found = Program.group(0)
-## if Program is InsideCommentProgram: print '...',
-## else: print ' ',
-## print found
- if len(found) == 2:
- if found == '/*':
- Program = InsideCommentProgram
- elif found == '*/':
- Program = OutsideCommentProgram
- n = len(found)
- if Dict.has_key(found):
- subst = Dict[found]
- if Program is InsideCommentProgram:
- if not Docomments:
- print 'Found in comment:', found
- i = i + n
- continue
- if NotInComment.has_key(found):
-## print 'Ignored in comment:',
-## print found, '-->', subst
-## print 'Line:', line,
- subst = found
-## else:
-## print 'Substituting in comment:',
-## print found, '-->', subst
-## print 'Line:', line,
- line = line[:i] + subst + line[i+n:]
- n = len(subst)
- i = i + n
- return line
+ global Program
+## print '-->', `line`
+ i = 0
+ while i < len(line):
+ i = Program.search(line, i)
+ if i < 0: break
+ found = Program.group(0)
+## if Program is InsideCommentProgram: print '...',
+## else: print ' ',
+## print found
+ if len(found) == 2:
+ if found == '/*':
+ Program = InsideCommentProgram
+ elif found == '*/':
+ Program = OutsideCommentProgram
+ n = len(found)
+ if Dict.has_key(found):
+ subst = Dict[found]
+ if Program is InsideCommentProgram:
+ if not Docomments:
+ print 'Found in comment:', found
+ i = i + n
+ continue
+ if NotInComment.has_key(found):
+## print 'Ignored in comment:',
+## print found, '-->', subst
+## print 'Line:', line,
+ subst = found
+## else:
+## print 'Substituting in comment:',
+## print found, '-->', subst
+## print 'Line:', line,
+ line = line[:i] + subst + line[i+n:]
+ n = len(subst)
+ i = i + n
+ return line
Docomments = 0
def setdocomments():
- global Docomments
- Docomments = 1
+ global Docomments
+ Docomments = 1
Reverse = 0
def setreverse():
- global Reverse
- Reverse = (not Reverse)
+ global Reverse
+ Reverse = (not Reverse)
Dict = {}
NotInComment = {}
def addsubst(substfile):
- try:
- fp = open(substfile, 'r')
- except IOError, msg:
- err(substfile + ': cannot read substfile: ' + str(msg) + '\n')
- sys.exit(1)
- lineno = 0
- while 1:
- line = fp.readline()
- if not line: break
- lineno = lineno + 1
- try:
- i = string.index(line, '#')
- except string.index_error:
- i = -1 # Happens to delete trailing \n
- words = string.split(line[:i])
- if not words: continue
- if len(words) == 3 and words[0] == 'struct':
- words[:2] = [words[0] + ' ' + words[1]]
- elif len(words) <> 2:
- err(substfile + ':' + `lineno` +
- ': warning: bad line: ' + line)
- continue
- if Reverse:
- [value, key] = words
- else:
- [key, value] = words
- if value[0] == '*':
- value = value[1:]
- if key[0] == '*':
- key = key[1:]
- NotInComment[key] = value
- if Dict.has_key(key):
- err(substfile + ':' + `lineno` +
- ': warning: overriding: ' +
- key + ' ' + value + '\n')
- err(substfile + ':' + `lineno` +
- ': warning: previous: ' + Dict[key] + '\n')
- Dict[key] = value
- fp.close()
+ try:
+ fp = open(substfile, 'r')
+ except IOError, msg:
+ err(substfile + ': cannot read substfile: ' + str(msg) + '\n')
+ sys.exit(1)
+ lineno = 0
+ while 1:
+ line = fp.readline()
+ if not line: break
+ lineno = lineno + 1
+ try:
+ i = string.index(line, '#')
+ except string.index_error:
+ i = -1 # Happens to delete trailing \n
+ words = string.split(line[:i])
+ if not words: continue
+ if len(words) == 3 and words[0] == 'struct':
+ words[:2] = [words[0] + ' ' + words[1]]
+ elif len(words) <> 2:
+ err(substfile + ':' + `lineno` +
+ ': warning: bad line: ' + line)
+ continue
+ if Reverse:
+ [value, key] = words
+ else:
+ [key, value] = words
+ if value[0] == '*':
+ value = value[1:]
+ if key[0] == '*':
+ key = key[1:]
+ NotInComment[key] = value
+ if Dict.has_key(key):
+ err(substfile + ':' + `lineno` +
+ ': warning: overriding: ' +
+ key + ' ' + value + '\n')
+ err(substfile + ':' + `lineno` +
+ ': warning: previous: ' + Dict[key] + '\n')
+ Dict[key] = value
+ fp.close()
main()
diff --git a/Tools/scripts/fixheader.py b/Tools/scripts/fixheader.py
index 774b907..9b65a44 100755
--- a/Tools/scripts/fixheader.py
+++ b/Tools/scripts/fixheader.py
@@ -6,44 +6,44 @@ import sys
import string
def main():
- args = sys.argv[1:]
- for file in args:
- process(file)
+ args = sys.argv[1:]
+ for file in args:
+ process(file)
def process(file):
- try:
- f = open(file, 'r')
- except IOError, msg:
- sys.stderr.write('%s: can\'t open: %s\n' % (file, str(msg)))
- return
- data = f.read()
- f.close()
- if data[:2] <> '/*':
- sys.stderr.write('%s does not begin with C comment\n' % file)
- return
- try:
- f = open(file, 'w')
- except IOError, msg:
- sys.stderr.write('%s: can\'t write: %s\n' % (file, str(msg)))
- return
- sys.stderr.write('Processing %s ...\n' % file)
- magic = 'Py_'
- for c in file:
- if c in string.letters + string.digits:
- magic = magic + string.upper(c)
- else: magic = magic + '_'
- sys.stdout = f
- print '#ifndef', magic
- print '#define', magic
- print '#ifdef __cplusplus'
- print 'extern "C" {'
- print '#endif'
- print
- f.write(data)
- print
- print '#ifdef __cplusplus'
- print '}'
- print '#endif'
- print '#endif /*', '!'+magic, '*/'
+ try:
+ f = open(file, 'r')
+ except IOError, msg:
+ sys.stderr.write('%s: can\'t open: %s\n' % (file, str(msg)))
+ return
+ data = f.read()
+ f.close()
+ if data[:2] <> '/*':
+ sys.stderr.write('%s does not begin with C comment\n' % file)
+ return
+ try:
+ f = open(file, 'w')
+ except IOError, msg:
+ sys.stderr.write('%s: can\'t write: %s\n' % (file, str(msg)))
+ return
+ sys.stderr.write('Processing %s ...\n' % file)
+ magic = 'Py_'
+ for c in file:
+ if c in string.letters + string.digits:
+ magic = magic + string.upper(c)
+ else: magic = magic + '_'
+ sys.stdout = f
+ print '#ifndef', magic
+ print '#define', magic
+ print '#ifdef __cplusplus'
+ print 'extern "C" {'
+ print '#endif'
+ print
+ f.write(data)
+ print
+ print '#ifdef __cplusplus'
+ print '}'
+ print '#endif'
+ print '#endif /*', '!'+magic, '*/'
main()
diff --git a/Tools/scripts/fixps.py b/Tools/scripts/fixps.py
index 665c1a2..1e6e114 100755
--- a/Tools/scripts/fixps.py
+++ b/Tools/scripts/fixps.py
@@ -8,26 +8,26 @@ import re
def main():
- for file in sys.argv[1:]:
- try:
- f = open(file, 'r')
- except IOError, msg:
- print file, ': can\'t open :', msg
- continue
- line = f.readline()
- if not re.match('^#! */usr/local/bin/python', line):
- print file, ': not a /usr/local/bin/python script'
- f.close()
- continue
- rest = f.read()
- f.close()
- line = re.sub('/usr/local/bin/python',
- '/usr/bin/env python', line)
- print file, ':', `line`
- f = open(file, "w")
- f.write(line)
- f.write(rest)
- f.close()
+ for file in sys.argv[1:]:
+ try:
+ f = open(file, 'r')
+ except IOError, msg:
+ print file, ': can\'t open :', msg
+ continue
+ line = f.readline()
+ if not re.match('^#! */usr/local/bin/python', line):
+ print file, ': not a /usr/local/bin/python script'
+ f.close()
+ continue
+ rest = f.read()
+ f.close()
+ line = re.sub('/usr/local/bin/python',
+ '/usr/bin/env python', line)
+ print file, ':', `line`
+ f = open(file, "w")
+ f.write(line)
+ f.write(rest)
+ f.close()
main()
diff --git a/Tools/scripts/ftpmirror.py b/Tools/scripts/ftpmirror.py
index 4b02714..c894a7b 100755
--- a/Tools/scripts/ftpmirror.py
+++ b/Tools/scripts/ftpmirror.py
@@ -4,7 +4,7 @@
usage: ftpmirror [-v] [-q] [-i] [-m] [-n] [-r] [-s pat]
[-l username [-p passwd [-a account]]]
- hostname [remotedir [localdir]]
+ hostname [remotedir [localdir]]
-v: verbose
-q: quiet
-i: interactive mode
@@ -28,10 +28,10 @@ from fnmatch import fnmatch
# Print usage message and exit
def usage(*args):
- sys.stdout = sys.stderr
- for msg in args: print msg
- print __doc__
- sys.exit(2)
+ sys.stdout = sys.stderr
+ for msg in args: print msg
+ print __doc__
+ sys.exit(2)
verbose = 1 # 0 for -q, 2 for -v
interactive = 0
@@ -42,356 +42,356 @@ skippats = ['.', '..', '.mirrorinfo']
# Main program: parse command line and start processing
def main():
- global verbose, interactive, mac, rmok, nologin
- try:
- opts, args = getopt.getopt(sys.argv[1:], 'a:bil:mnp:qrs:v')
- except getopt.error, msg:
- usage(msg)
- login = ''
- passwd = ''
- account = ''
- for o, a in opts:
- if o == '-l': login = a
- if o == '-p': passwd = a
- if o == '-a': account = a
- if o == '-v': verbose = verbose + 1
- if o == '-q': verbose = 0
- if o == '-i': interactive = 1
- if o == '-m': mac = 1; nologin = 1; skippats.append('*.o')
- if o == '-n': nologin = 1
- if o == '-r': rmok = 1
- if o == '-s': skippats.append(a)
- if not args: usage('hostname missing')
- host = args[0]
- remotedir = ''
- localdir = ''
- if args[1:]:
- remotedir = args[1]
- if args[2:]:
- localdir = args[2]
- if args[3:]: usage('too many arguments')
- #
- f = ftplib.FTP()
- if verbose: print 'Connecting to %s...' % `host`
- f.connect(host)
- if not nologin:
- if verbose:
- print 'Logging in as %s...' % `login or 'anonymous'`
- f.login(login, passwd, account)
- if verbose: print 'OK.'
- pwd = f.pwd()
- if verbose > 1: print 'PWD =', `pwd`
- if remotedir:
- if verbose > 1: print 'cwd(%s)' % `remotedir`
- f.cwd(remotedir)
- if verbose > 1: print 'OK.'
- pwd = f.pwd()
- if verbose > 1: print 'PWD =', `pwd`
- #
- mirrorsubdir(f, localdir)
+ global verbose, interactive, mac, rmok, nologin
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], 'a:bil:mnp:qrs:v')
+ except getopt.error, msg:
+ usage(msg)
+ login = ''
+ passwd = ''
+ account = ''
+ for o, a in opts:
+ if o == '-l': login = a
+ if o == '-p': passwd = a
+ if o == '-a': account = a
+ if o == '-v': verbose = verbose + 1
+ if o == '-q': verbose = 0
+ if o == '-i': interactive = 1
+ if o == '-m': mac = 1; nologin = 1; skippats.append('*.o')
+ if o == '-n': nologin = 1
+ if o == '-r': rmok = 1
+ if o == '-s': skippats.append(a)
+ if not args: usage('hostname missing')
+ host = args[0]
+ remotedir = ''
+ localdir = ''
+ if args[1:]:
+ remotedir = args[1]
+ if args[2:]:
+ localdir = args[2]
+ if args[3:]: usage('too many arguments')
+ #
+ f = ftplib.FTP()
+ if verbose: print 'Connecting to %s...' % `host`
+ f.connect(host)
+ if not nologin:
+ if verbose:
+ print 'Logging in as %s...' % `login or 'anonymous'`
+ f.login(login, passwd, account)
+ if verbose: print 'OK.'
+ pwd = f.pwd()
+ if verbose > 1: print 'PWD =', `pwd`
+ if remotedir:
+ if verbose > 1: print 'cwd(%s)' % `remotedir`
+ f.cwd(remotedir)
+ if verbose > 1: print 'OK.'
+ pwd = f.pwd()
+ if verbose > 1: print 'PWD =', `pwd`
+ #
+ mirrorsubdir(f, localdir)
# Core logic: mirror one subdirectory (recursively)
def mirrorsubdir(f, localdir):
- pwd = f.pwd()
- if localdir and not os.path.isdir(localdir):
- if verbose: print 'Creating local directory', `localdir`
- try:
- makedir(localdir)
- except os.error, msg:
- print "Failed to establish local directory", `localdir`
- return
- infofilename = os.path.join(localdir, '.mirrorinfo')
- try:
- text = open(infofilename, 'r').read()
- except IOError, msg:
- text = '{}'
- try:
- info = eval(text)
- except (SyntaxError, NameError):
- print 'Bad mirror info in %s' % `infofilename`
- info = {}
- subdirs = []
- listing = []
- if verbose: print 'Listing remote directory %s...' % `pwd`
- f.retrlines('LIST', listing.append)
- filesfound = []
- for line in listing:
- if verbose > 1: print '-->', `line`
- if mac:
- # Mac listing has just filenames;
- # trailing / means subdirectory
- filename = string.strip(line)
- mode = '-'
- if filename[-1:] == '/':
- filename = filename[:-1]
- mode = 'd'
- infostuff = ''
- else:
- # Parse, assuming a UNIX listing
- words = string.split(line, None, 8)
- if len(words) < 6:
- if verbose > 1: print 'Skipping short line'
- continue
- filename = string.lstrip(words[-1])
- i = string.find(filename, " -> ")
- if i >= 0:
- # words[0] had better start with 'l'...
- if verbose > 1:
- print 'Found symbolic link %s' % `filename`
- linkto = filename[i+4:]
- filename = filename[:i]
- infostuff = words[-5:-1]
- mode = words[0]
- skip = 0
- for pat in skippats:
- if fnmatch(filename, pat):
- if verbose > 1:
- print 'Skip pattern', `pat`,
- print 'matches', `filename`
- skip = 1
- break
- if skip:
- continue
- if mode[0] == 'd':
- if verbose > 1:
- print 'Remembering subdirectory', `filename`
- subdirs.append(filename)
- continue
- filesfound.append(filename)
- if info.has_key(filename) and info[filename] == infostuff:
- if verbose > 1:
- print 'Already have this version of',`filename`
- continue
- fullname = os.path.join(localdir, filename)
- tempname = os.path.join(localdir, '@'+filename)
- if interactive:
- doit = askabout('file', filename, pwd)
- if not doit:
- if not info.has_key(filename):
- info[filename] = 'Not retrieved'
- continue
- try:
- os.unlink(tempname)
- except os.error:
- pass
- if mode[0] == 'l':
- if verbose:
- print "Creating symlink %s -> %s" % (
- `filename`, `linkto`)
- try:
- os.symlink(linkto, tempname)
- except IOError, msg:
- print "Can't create %s: %s" % (
- `tempname`, str(msg))
- continue
- else:
- try:
- fp = open(tempname, 'wb')
- except IOError, msg:
- print "Can't create %s: %s" % (
- `tempname`, str(msg))
- continue
- if verbose:
- print 'Retrieving %s from %s as %s...' % \
- (`filename`, `pwd`, `fullname`)
- if verbose:
- fp1 = LoggingFile(fp, 1024, sys.stdout)
- else:
- fp1 = fp
- t0 = time.time()
- try:
- f.retrbinary('RETR ' + filename,
- fp1.write, 8*1024)
- except ftplib.error_perm, msg:
- print msg
- t1 = time.time()
- bytes = fp.tell()
- fp.close()
- if fp1 != fp:
- fp1.close()
- try:
- os.unlink(fullname)
- except os.error:
- pass # Ignore the error
- try:
- os.rename(tempname, fullname)
- except os.error, msg:
- print "Can't rename %s to %s: %s" % (`tempname`,
- `fullname`,
- str(msg))
- continue
- info[filename] = infostuff
- writedict(info, infofilename)
- if verbose and mode[0] != 'l':
- dt = t1 - t0
- kbytes = bytes / 1024.0
- print int(round(kbytes)),
- print 'Kbytes in',
- print int(round(dt)),
- print 'seconds',
- if t1 > t0:
- print '(~%d Kbytes/sec)' % \
- int(round(kbytes/dt),)
- print
- #
- # Remove files from info that are no longer remote
- deletions = 0
- for filename in info.keys():
- if filename not in filesfound:
- if verbose:
- print "Removing obsolete info entry for",
- print `filename`, "in", `localdir or "."`
- del info[filename]
- deletions = deletions + 1
- if deletions:
- writedict(info, infofilename)
- #
- # Remove local files that are no longer in the remote directory
- try:
- if not localdir: names = os.listdir(os.curdir)
- else: names = os.listdir(localdir)
- except os.error:
- names = []
- for name in names:
- if name[0] == '.' or info.has_key(name) or name in subdirs:
- continue
- skip = 0
- for pat in skippats:
- if fnmatch(name, pat):
- if verbose > 1:
- print 'Skip pattern', `pat`,
- print 'matches', `name`
- skip = 1
- break
- if skip:
- continue
- fullname = os.path.join(localdir, name)
- if not rmok:
- if verbose:
- print 'Local file', `fullname`,
- print 'is no longer pertinent'
- continue
- if verbose: print 'Removing local file/dir', `fullname`
- remove(fullname)
- #
- # Recursively mirror subdirectories
- for subdir in subdirs:
- if interactive:
- doit = askabout('subdirectory', subdir, pwd)
- if not doit: continue
- if verbose: print 'Processing subdirectory', `subdir`
- localsubdir = os.path.join(localdir, subdir)
- pwd = f.pwd()
- if verbose > 1:
- print 'Remote directory now:', `pwd`
- print 'Remote cwd', `subdir`
- try:
- f.cwd(subdir)
- except ftplib.error_perm, msg:
- print "Can't chdir to", `subdir`, ":", `msg`
- else:
- if verbose: print 'Mirroring as', `localsubdir`
- mirrorsubdir(f, localsubdir)
- if verbose > 1: print 'Remote cwd ..'
- f.cwd('..')
- newpwd = f.pwd()
- if newpwd != pwd:
- print 'Ended up in wrong directory after cd + cd ..'
- print 'Giving up now.'
- break
- else:
- if verbose > 1: print 'OK.'
+ pwd = f.pwd()
+ if localdir and not os.path.isdir(localdir):
+ if verbose: print 'Creating local directory', `localdir`
+ try:
+ makedir(localdir)
+ except os.error, msg:
+ print "Failed to establish local directory", `localdir`
+ return
+ infofilename = os.path.join(localdir, '.mirrorinfo')
+ try:
+ text = open(infofilename, 'r').read()
+ except IOError, msg:
+ text = '{}'
+ try:
+ info = eval(text)
+ except (SyntaxError, NameError):
+ print 'Bad mirror info in %s' % `infofilename`
+ info = {}
+ subdirs = []
+ listing = []
+ if verbose: print 'Listing remote directory %s...' % `pwd`
+ f.retrlines('LIST', listing.append)
+ filesfound = []
+ for line in listing:
+ if verbose > 1: print '-->', `line`
+ if mac:
+ # Mac listing has just filenames;
+ # trailing / means subdirectory
+ filename = string.strip(line)
+ mode = '-'
+ if filename[-1:] == '/':
+ filename = filename[:-1]
+ mode = 'd'
+ infostuff = ''
+ else:
+ # Parse, assuming a UNIX listing
+ words = string.split(line, None, 8)
+ if len(words) < 6:
+ if verbose > 1: print 'Skipping short line'
+ continue
+ filename = string.lstrip(words[-1])
+ i = string.find(filename, " -> ")
+ if i >= 0:
+ # words[0] had better start with 'l'...
+ if verbose > 1:
+ print 'Found symbolic link %s' % `filename`
+ linkto = filename[i+4:]
+ filename = filename[:i]
+ infostuff = words[-5:-1]
+ mode = words[0]
+ skip = 0
+ for pat in skippats:
+ if fnmatch(filename, pat):
+ if verbose > 1:
+ print 'Skip pattern', `pat`,
+ print 'matches', `filename`
+ skip = 1
+ break
+ if skip:
+ continue
+ if mode[0] == 'd':
+ if verbose > 1:
+ print 'Remembering subdirectory', `filename`
+ subdirs.append(filename)
+ continue
+ filesfound.append(filename)
+ if info.has_key(filename) and info[filename] == infostuff:
+ if verbose > 1:
+ print 'Already have this version of',`filename`
+ continue
+ fullname = os.path.join(localdir, filename)
+ tempname = os.path.join(localdir, '@'+filename)
+ if interactive:
+ doit = askabout('file', filename, pwd)
+ if not doit:
+ if not info.has_key(filename):
+ info[filename] = 'Not retrieved'
+ continue
+ try:
+ os.unlink(tempname)
+ except os.error:
+ pass
+ if mode[0] == 'l':
+ if verbose:
+ print "Creating symlink %s -> %s" % (
+ `filename`, `linkto`)
+ try:
+ os.symlink(linkto, tempname)
+ except IOError, msg:
+ print "Can't create %s: %s" % (
+ `tempname`, str(msg))
+ continue
+ else:
+ try:
+ fp = open(tempname, 'wb')
+ except IOError, msg:
+ print "Can't create %s: %s" % (
+ `tempname`, str(msg))
+ continue
+ if verbose:
+ print 'Retrieving %s from %s as %s...' % \
+ (`filename`, `pwd`, `fullname`)
+ if verbose:
+ fp1 = LoggingFile(fp, 1024, sys.stdout)
+ else:
+ fp1 = fp
+ t0 = time.time()
+ try:
+ f.retrbinary('RETR ' + filename,
+ fp1.write, 8*1024)
+ except ftplib.error_perm, msg:
+ print msg
+ t1 = time.time()
+ bytes = fp.tell()
+ fp.close()
+ if fp1 != fp:
+ fp1.close()
+ try:
+ os.unlink(fullname)
+ except os.error:
+ pass # Ignore the error
+ try:
+ os.rename(tempname, fullname)
+ except os.error, msg:
+ print "Can't rename %s to %s: %s" % (`tempname`,
+ `fullname`,
+ str(msg))
+ continue
+ info[filename] = infostuff
+ writedict(info, infofilename)
+ if verbose and mode[0] != 'l':
+ dt = t1 - t0
+ kbytes = bytes / 1024.0
+ print int(round(kbytes)),
+ print 'Kbytes in',
+ print int(round(dt)),
+ print 'seconds',
+ if t1 > t0:
+ print '(~%d Kbytes/sec)' % \
+ int(round(kbytes/dt),)
+ print
+ #
+ # Remove files from info that are no longer remote
+ deletions = 0
+ for filename in info.keys():
+ if filename not in filesfound:
+ if verbose:
+ print "Removing obsolete info entry for",
+ print `filename`, "in", `localdir or "."`
+ del info[filename]
+ deletions = deletions + 1
+ if deletions:
+ writedict(info, infofilename)
+ #
+ # Remove local files that are no longer in the remote directory
+ try:
+ if not localdir: names = os.listdir(os.curdir)
+ else: names = os.listdir(localdir)
+ except os.error:
+ names = []
+ for name in names:
+ if name[0] == '.' or info.has_key(name) or name in subdirs:
+ continue
+ skip = 0
+ for pat in skippats:
+ if fnmatch(name, pat):
+ if verbose > 1:
+ print 'Skip pattern', `pat`,
+ print 'matches', `name`
+ skip = 1
+ break
+ if skip:
+ continue
+ fullname = os.path.join(localdir, name)
+ if not rmok:
+ if verbose:
+ print 'Local file', `fullname`,
+ print 'is no longer pertinent'
+ continue
+ if verbose: print 'Removing local file/dir', `fullname`
+ remove(fullname)
+ #
+ # Recursively mirror subdirectories
+ for subdir in subdirs:
+ if interactive:
+ doit = askabout('subdirectory', subdir, pwd)
+ if not doit: continue
+ if verbose: print 'Processing subdirectory', `subdir`
+ localsubdir = os.path.join(localdir, subdir)
+ pwd = f.pwd()
+ if verbose > 1:
+ print 'Remote directory now:', `pwd`
+ print 'Remote cwd', `subdir`
+ try:
+ f.cwd(subdir)
+ except ftplib.error_perm, msg:
+ print "Can't chdir to", `subdir`, ":", `msg`
+ else:
+ if verbose: print 'Mirroring as', `localsubdir`
+ mirrorsubdir(f, localsubdir)
+ if verbose > 1: print 'Remote cwd ..'
+ f.cwd('..')
+ newpwd = f.pwd()
+ if newpwd != pwd:
+ print 'Ended up in wrong directory after cd + cd ..'
+ print 'Giving up now.'
+ break
+ else:
+ if verbose > 1: print 'OK.'
# Helper to remove a file or directory tree
def remove(fullname):
- if os.path.isdir(fullname) and not os.path.islink(fullname):
- try:
- names = os.listdir(fullname)
- except os.error:
- names = []
- ok = 1
- for name in names:
- if not remove(os.path.join(fullname, name)):
- ok = 0
- if not ok:
- return 0
- try:
- os.rmdir(fullname)
- except os.error, msg:
- print "Can't remove local directory %s: %s" % \
- (`fullname`, str(msg))
- return 0
- else:
- try:
- os.unlink(fullname)
- except os.error, msg:
- print "Can't remove local file %s: %s" % \
- (`fullname`, str(msg))
- return 0
- return 1
+ if os.path.isdir(fullname) and not os.path.islink(fullname):
+ try:
+ names = os.listdir(fullname)
+ except os.error:
+ names = []
+ ok = 1
+ for name in names:
+ if not remove(os.path.join(fullname, name)):
+ ok = 0
+ if not ok:
+ return 0
+ try:
+ os.rmdir(fullname)
+ except os.error, msg:
+ print "Can't remove local directory %s: %s" % \
+ (`fullname`, str(msg))
+ return 0
+ else:
+ try:
+ os.unlink(fullname)
+ except os.error, msg:
+ print "Can't remove local file %s: %s" % \
+ (`fullname`, str(msg))
+ return 0
+ return 1
# Wrapper around a file for writing to write a hash sign every block.
class LoggingFile:
- def __init__(self, fp, blocksize, outfp):
- self.fp = fp
- self.bytes = 0
- self.hashes = 0
- self.blocksize = blocksize
- self.outfp = outfp
- def write(self, data):
- self.bytes = self.bytes + len(data)
- hashes = int(self.bytes) / self.blocksize
- while hashes > self.hashes:
- self.outfp.write('#')
- self.outfp.flush()
- self.hashes = self.hashes + 1
- self.fp.write(data)
- def close(self):
- self.outfp.write('\n')
+ def __init__(self, fp, blocksize, outfp):
+ self.fp = fp
+ self.bytes = 0
+ self.hashes = 0
+ self.blocksize = blocksize
+ self.outfp = outfp
+ def write(self, data):
+ self.bytes = self.bytes + len(data)
+ hashes = int(self.bytes) / self.blocksize
+ while hashes > self.hashes:
+ self.outfp.write('#')
+ self.outfp.flush()
+ self.hashes = self.hashes + 1
+ self.fp.write(data)
+ def close(self):
+ self.outfp.write('\n')
# Ask permission to download a file.
def askabout(filetype, filename, pwd):
- prompt = 'Retrieve %s %s from %s ? [ny] ' % (filetype, filename, pwd)
- while 1:
- reply = string.lower(string.strip(raw_input(prompt)))
- if reply in ['y', 'ye', 'yes']:
- return 1
- if reply in ['', 'n', 'no', 'nop', 'nope']:
- return 0
- print 'Please answer yes or no.'
+ prompt = 'Retrieve %s %s from %s ? [ny] ' % (filetype, filename, pwd)
+ while 1:
+ reply = string.lower(string.strip(raw_input(prompt)))
+ if reply in ['y', 'ye', 'yes']:
+ return 1
+ if reply in ['', 'n', 'no', 'nop', 'nope']:
+ return 0
+ print 'Please answer yes or no.'
# Create a directory if it doesn't exist. Recursively create the
# parent directory as well if needed.
def makedir(pathname):
- if os.path.isdir(pathname):
- return
- dirname = os.path.dirname(pathname)
- if dirname: makedir(dirname)
- os.mkdir(pathname, 0777)
+ if os.path.isdir(pathname):
+ return
+ dirname = os.path.dirname(pathname)
+ if dirname: makedir(dirname)
+ os.mkdir(pathname, 0777)
# Write a dictionary to a file in a way that can be read back using
# rval() but is still somewhat readable (i.e. not a single long line).
# Also creates a backup file.
def writedict(dict, filename):
- dir, file = os.path.split(filename)
- tempname = os.path.join(dir, '@' + file)
- backup = os.path.join(dir, file + '~')
- try:
- os.unlink(backup)
- except os.error:
- pass
- fp = open(tempname, 'w')
- fp.write('{\n')
- for key, value in dict.items():
- fp.write('%s: %s,\n' % (`key`, `value`))
- fp.write('}\n')
- fp.close()
- try:
- os.rename(filename, backup)
- except os.error:
- pass
- os.rename(tempname, filename)
+ dir, file = os.path.split(filename)
+ tempname = os.path.join(dir, '@' + file)
+ backup = os.path.join(dir, file + '~')
+ try:
+ os.unlink(backup)
+ except os.error:
+ pass
+ fp = open(tempname, 'w')
+ fp.write('{\n')
+ for key, value in dict.items():
+ fp.write('%s: %s,\n' % (`key`, `value`))
+ fp.write('}\n')
+ fp.close()
+ try:
+ os.rename(filename, backup)
+ except os.error:
+ pass
+ os.rename(tempname, filename)
if __name__ == '__main__':
- main()
+ main()
diff --git a/Tools/scripts/gencodec.py b/Tools/scripts/gencodec.py
index 39b42ff..bc70a32 100644
--- a/Tools/scripts/gencodec.py
+++ b/Tools/scripts/gencodec.py
@@ -180,14 +180,14 @@ class Codec(codecs.Codec):
def encode(self,input,errors='strict'):
return codecs.charmap_encode(input,errors,encoding_map)
-
+
def decode(self,input,errors='strict'):
return codecs.charmap_decode(input,errors,decoding_map)
class StreamWriter(Codec,codecs.StreamWriter):
pass
-
+
class StreamReader(Codec,codecs.StreamReader):
pass
@@ -210,7 +210,7 @@ def getregentry():
else:
l.append("decoding_map = {")
splits = 0
-
+
mappings = map.items()
mappings.sort()
append = l.append
@@ -290,7 +290,7 @@ def convertdir(dir,prefix='',comments=1):
print '* conversion failed'
def rewritepythondir(dir,prefix='',comments=1):
-
+
mapnames = os.listdir(dir)
for mapname in mapnames:
if not mapname.endswith('.mapping'):
diff --git a/Tools/scripts/h2py.py b/Tools/scripts/h2py.py
index fd4b267..92f64c0 100755
--- a/Tools/scripts/h2py.py
+++ b/Tools/scripts/h2py.py
@@ -41,110 +41,110 @@ p_char = regex.compile("'\(\\\\.[^\\\\]*\|[^\\\\]\)'")
filedict = {}
try:
- searchdirs=string.splitfields(os.environ['include'],';')
+ searchdirs=string.splitfields(os.environ['include'],';')
except KeyError:
- try:
- searchdirs=string.splitfields(os.environ['INCLUDE'],';')
- except KeyError:
- try:
- if string.find( sys.platform, "beos" ) == 0:
- searchdirs=string.splitfields(os.environ['BEINCLUDES'],';')
- else:
- raise KeyError
- except KeyError:
- searchdirs=['/usr/include']
+ try:
+ searchdirs=string.splitfields(os.environ['INCLUDE'],';')
+ except KeyError:
+ try:
+ if string.find( sys.platform, "beos" ) == 0:
+ searchdirs=string.splitfields(os.environ['BEINCLUDES'],';')
+ else:
+ raise KeyError
+ except KeyError:
+ searchdirs=['/usr/include']
def main():
- global filedict
- opts, args = getopt.getopt(sys.argv[1:], 'i:')
- for o, a in opts:
- if o == '-i':
- ignores.append(regex.compile(a))
- if not args:
- args = ['-']
- for filename in args:
- if filename == '-':
- sys.stdout.write('# Generated by h2py from stdin\n')
- process(sys.stdin, sys.stdout)
- else:
- fp = open(filename, 'r')
- outfile = os.path.basename(filename)
- i = string.rfind(outfile, '.')
- if i > 0: outfile = outfile[:i]
- outfile = string.upper(outfile)
- outfile = outfile + '.py'
- outfp = open(outfile, 'w')
- outfp.write('# Generated by h2py from %s\n' % filename)
- filedict = {}
- for dir in searchdirs:
- if filename[:len(dir)] == dir:
- filedict[filename[len(dir)+1:]] = None # no '/' trailing
- break
- process(fp, outfp)
- outfp.close()
- fp.close()
+ global filedict
+ opts, args = getopt.getopt(sys.argv[1:], 'i:')
+ for o, a in opts:
+ if o == '-i':
+ ignores.append(regex.compile(a))
+ if not args:
+ args = ['-']
+ for filename in args:
+ if filename == '-':
+ sys.stdout.write('# Generated by h2py from stdin\n')
+ process(sys.stdin, sys.stdout)
+ else:
+ fp = open(filename, 'r')
+ outfile = os.path.basename(filename)
+ i = string.rfind(outfile, '.')
+ if i > 0: outfile = outfile[:i]
+ outfile = string.upper(outfile)
+ outfile = outfile + '.py'
+ outfp = open(outfile, 'w')
+ outfp.write('# Generated by h2py from %s\n' % filename)
+ filedict = {}
+ for dir in searchdirs:
+ if filename[:len(dir)] == dir:
+ filedict[filename[len(dir)+1:]] = None # no '/' trailing
+ break
+ process(fp, outfp)
+ outfp.close()
+ fp.close()
def process(fp, outfp, env = {}):
- lineno = 0
- while 1:
- line = fp.readline()
- if not line: break
- lineno = lineno + 1
- n = p_define.match(line)
- if n >= 0:
- # gobble up continuation lines
- while line[-2:] == '\\\n':
- nextline = fp.readline()
- if not nextline: break
- lineno = lineno + 1
- line = line + nextline
- name = p_define.group(1)
- body = line[n:]
- # replace ignored patterns by spaces
- for p in ignores:
- body = regsub.gsub(p, ' ', body)
- # replace char literals by ord(...)
- body = regsub.gsub(p_char, 'ord(\\0)', body)
- stmt = '%s = %s\n' % (name, string.strip(body))
- ok = 0
- try:
- exec stmt in env
- except:
- sys.stderr.write('Skipping: %s' % stmt)
- else:
- outfp.write(stmt)
- n =p_macro.match(line)
- if n >= 0:
- macro, arg = p_macro.group(1, 2)
- body = line[n:]
- for p in ignores:
- body = regsub.gsub(p, ' ', body)
- body = regsub.gsub(p_char, 'ord(\\0)', body)
- stmt = 'def %s(%s): return %s\n' % (macro, arg, body)
- try:
- exec stmt in env
- except:
- sys.stderr.write('Skipping: %s' % stmt)
- else:
- outfp.write(stmt)
- if p_include.match(line) >= 0:
- regs = p_include.regs
- a, b = regs[1]
- filename = line[a:b]
- if not filedict.has_key(filename):
- filedict[filename] = None
- inclfp = None
- for dir in searchdirs:
- try:
- inclfp = open(dir + '/' + filename, 'r')
- break
- except IOError:
- pass
- if inclfp:
- outfp.write(
- '\n# Included from %s\n' % filename)
- process(inclfp, outfp, env)
- else:
- sys.stderr.write('Warning - could not find file %s' % filename)
+ lineno = 0
+ while 1:
+ line = fp.readline()
+ if not line: break
+ lineno = lineno + 1
+ n = p_define.match(line)
+ if n >= 0:
+ # gobble up continuation lines
+ while line[-2:] == '\\\n':
+ nextline = fp.readline()
+ if not nextline: break
+ lineno = lineno + 1
+ line = line + nextline
+ name = p_define.group(1)
+ body = line[n:]
+ # replace ignored patterns by spaces
+ for p in ignores:
+ body = regsub.gsub(p, ' ', body)
+ # replace char literals by ord(...)
+ body = regsub.gsub(p_char, 'ord(\\0)', body)
+ stmt = '%s = %s\n' % (name, string.strip(body))
+ ok = 0
+ try:
+ exec stmt in env
+ except:
+ sys.stderr.write('Skipping: %s' % stmt)
+ else:
+ outfp.write(stmt)
+ n =p_macro.match(line)
+ if n >= 0:
+ macro, arg = p_macro.group(1, 2)
+ body = line[n:]
+ for p in ignores:
+ body = regsub.gsub(p, ' ', body)
+ body = regsub.gsub(p_char, 'ord(\\0)', body)
+ stmt = 'def %s(%s): return %s\n' % (macro, arg, body)
+ try:
+ exec stmt in env
+ except:
+ sys.stderr.write('Skipping: %s' % stmt)
+ else:
+ outfp.write(stmt)
+ if p_include.match(line) >= 0:
+ regs = p_include.regs
+ a, b = regs[1]
+ filename = line[a:b]
+ if not filedict.has_key(filename):
+ filedict[filename] = None
+ inclfp = None
+ for dir in searchdirs:
+ try:
+ inclfp = open(dir + '/' + filename, 'r')
+ break
+ except IOError:
+ pass
+ if inclfp:
+ outfp.write(
+ '\n# Included from %s\n' % filename)
+ process(inclfp, outfp, env)
+ else:
+ sys.stderr.write('Warning - could not find file %s' % filename)
main()
diff --git a/Tools/scripts/ifdef.py b/Tools/scripts/ifdef.py
index 939bea9..da14437 100755
--- a/Tools/scripts/ifdef.py
+++ b/Tools/scripts/ifdef.py
@@ -3,7 +3,7 @@
# Selectively preprocess #ifdef / #ifndef statements.
# Usage:
# ifdef [-Dname] ... [-Uname] ... [file] ...
-#
+#
# This scans the file(s), looking for #ifdef and #ifndef preprocessor
# commands that test for one of the names mentioned in the -D and -U
# options. On standard output it writes a copy of the input file(s)
@@ -35,79 +35,79 @@ defs = []
undefs = []
def main():
- opts, args = getopt.getopt(sys.argv[1:], 'D:U:')
- for o, a in opts:
- if o == '-D':
- defs.append(a)
- if o == '-U':
- undefs.append(a)
- if not args:
- args = ['-']
- for file in args:
- if file == '-':
- process(sys.stdin, sys.stdout)
- else:
- f = open(file, 'r')
- process(f, sys.stdout)
- f.close()
+ opts, args = getopt.getopt(sys.argv[1:], 'D:U:')
+ for o, a in opts:
+ if o == '-D':
+ defs.append(a)
+ if o == '-U':
+ undefs.append(a)
+ if not args:
+ args = ['-']
+ for file in args:
+ if file == '-':
+ process(sys.stdin, sys.stdout)
+ else:
+ f = open(file, 'r')
+ process(f, sys.stdout)
+ f.close()
def process(fpi, fpo):
- keywords = ('if', 'ifdef', 'ifndef', 'else', 'endif')
- ok = 1
- stack = []
- while 1:
- line = fpi.readline()
- if not line: break
- while line[-2:] == '\\\n':
- nextline = fpi.readline()
- if not nextline: break
- line = line + nextline
- tmp = string.strip(line)
- if tmp[:1] != '#':
- if ok: fpo.write(line)
- continue
- tmp = string.strip(tmp[1:])
- words = string.split(tmp)
- keyword = words[0]
- if keyword not in keywords:
- if ok: fpo.write(line)
- continue
- if keyword in ('ifdef', 'ifndef') and len(words) == 2:
- if keyword == 'ifdef':
- ko = 1
- else:
- ko = 0
- word = words[1]
- if word in defs:
- stack.append((ok, ko, word))
- if not ko: ok = 0
- elif word in undefs:
- stack.append((ok, not ko, word))
- if ko: ok = 0
- else:
- stack.append((ok, -1, word))
- if ok: fpo.write(line)
- elif keyword == 'if':
- stack.append((ok, -1, ''))
- if ok: fpo.write(line)
- elif keyword == 'else' and stack:
- s_ok, s_ko, s_word = stack[-1]
- if s_ko < 0:
- if ok: fpo.write(line)
- else:
- s_ko = not s_ko
- ok = s_ok
- if not s_ko: ok = 0
- stack[-1] = s_ok, s_ko, s_word
- elif keyword == 'endif' and stack:
- s_ok, s_ko, s_word = stack[-1]
- if s_ko < 0:
- if ok: fpo.write(line)
- del stack[-1]
- ok = s_ok
- else:
- sys.stderr.write('Unknown keyword %s\n' % keyword)
- if stack:
- sys.stderr.write('stack: %s\n' % stack)
+ keywords = ('if', 'ifdef', 'ifndef', 'else', 'endif')
+ ok = 1
+ stack = []
+ while 1:
+ line = fpi.readline()
+ if not line: break
+ while line[-2:] == '\\\n':
+ nextline = fpi.readline()
+ if not nextline: break
+ line = line + nextline
+ tmp = string.strip(line)
+ if tmp[:1] != '#':
+ if ok: fpo.write(line)
+ continue
+ tmp = string.strip(tmp[1:])
+ words = string.split(tmp)
+ keyword = words[0]
+ if keyword not in keywords:
+ if ok: fpo.write(line)
+ continue
+ if keyword in ('ifdef', 'ifndef') and len(words) == 2:
+ if keyword == 'ifdef':
+ ko = 1
+ else:
+ ko = 0
+ word = words[1]
+ if word in defs:
+ stack.append((ok, ko, word))
+ if not ko: ok = 0
+ elif word in undefs:
+ stack.append((ok, not ko, word))
+ if ko: ok = 0
+ else:
+ stack.append((ok, -1, word))
+ if ok: fpo.write(line)
+ elif keyword == 'if':
+ stack.append((ok, -1, ''))
+ if ok: fpo.write(line)
+ elif keyword == 'else' and stack:
+ s_ok, s_ko, s_word = stack[-1]
+ if s_ko < 0:
+ if ok: fpo.write(line)
+ else:
+ s_ko = not s_ko
+ ok = s_ok
+ if not s_ko: ok = 0
+ stack[-1] = s_ok, s_ko, s_word
+ elif keyword == 'endif' and stack:
+ s_ok, s_ko, s_word = stack[-1]
+ if s_ko < 0:
+ if ok: fpo.write(line)
+ del stack[-1]
+ ok = s_ok
+ else:
+ sys.stderr.write('Unknown keyword %s\n' % keyword)
+ if stack:
+ sys.stderr.write('stack: %s\n' % stack)
main()
diff --git a/Tools/scripts/linktree.py b/Tools/scripts/linktree.py
index 677be39..502873e 100755
--- a/Tools/scripts/linktree.py
+++ b/Tools/scripts/linktree.py
@@ -17,63 +17,63 @@ LINK = '.LINK' # Name of special symlink at the top.
debug = 0
def main():
- if not 3 <= len(sys.argv) <= 4:
- print 'usage:', sys.argv[0], 'oldtree newtree [linkto]'
- return 2
- oldtree, newtree = sys.argv[1], sys.argv[2]
- if len(sys.argv) > 3:
- link = sys.argv[3]
- link_may_fail = 1
- else:
- link = LINK
- link_may_fail = 0
- if not os.path.isdir(oldtree):
- print oldtree + ': not a directory'
- return 1
- try:
- os.mkdir(newtree, 0777)
- except os.error, msg:
- print newtree + ': cannot mkdir:', msg
- return 1
- linkname = os.path.join(newtree, link)
- try:
- os.symlink(os.path.join(os.pardir, oldtree), linkname)
- except os.error, msg:
- if not link_may_fail:
- print linkname + ': cannot symlink:', msg
- return 1
- else:
- print linkname + ': warning: cannot symlink:', msg
- linknames(oldtree, newtree, link)
- return 0
+ if not 3 <= len(sys.argv) <= 4:
+ print 'usage:', sys.argv[0], 'oldtree newtree [linkto]'
+ return 2
+ oldtree, newtree = sys.argv[1], sys.argv[2]
+ if len(sys.argv) > 3:
+ link = sys.argv[3]
+ link_may_fail = 1
+ else:
+ link = LINK
+ link_may_fail = 0
+ if not os.path.isdir(oldtree):
+ print oldtree + ': not a directory'
+ return 1
+ try:
+ os.mkdir(newtree, 0777)
+ except os.error, msg:
+ print newtree + ': cannot mkdir:', msg
+ return 1
+ linkname = os.path.join(newtree, link)
+ try:
+ os.symlink(os.path.join(os.pardir, oldtree), linkname)
+ except os.error, msg:
+ if not link_may_fail:
+ print linkname + ': cannot symlink:', msg
+ return 1
+ else:
+ print linkname + ': warning: cannot symlink:', msg
+ linknames(oldtree, newtree, link)
+ return 0
def linknames(old, new, link):
- if debug: print 'linknames', (old, new, link)
- try:
- names = os.listdir(old)
- except os.error, msg:
- print old + ': warning: cannot listdir:', msg
- return
- for name in names:
- if name not in (os.curdir, os.pardir):
- oldname = os.path.join(old, name)
- linkname = os.path.join(link, name)
- newname = os.path.join(new, name)
- if debug > 1: print oldname, newname, linkname
- if os.path.isdir(oldname) and \
- not os.path.islink(oldname):
- try:
- os.mkdir(newname, 0777)
- ok = 1
- except:
- print newname + \
- ': warning: cannot mkdir:', msg
- ok = 0
- if ok:
- linkname = os.path.join(os.pardir,
- linkname)
- linknames(oldname, newname, linkname)
- else:
- os.symlink(linkname, newname)
+ if debug: print 'linknames', (old, new, link)
+ try:
+ names = os.listdir(old)
+ except os.error, msg:
+ print old + ': warning: cannot listdir:', msg
+ return
+ for name in names:
+ if name not in (os.curdir, os.pardir):
+ oldname = os.path.join(old, name)
+ linkname = os.path.join(link, name)
+ newname = os.path.join(new, name)
+ if debug > 1: print oldname, newname, linkname
+ if os.path.isdir(oldname) and \
+ not os.path.islink(oldname):
+ try:
+ os.mkdir(newname, 0777)
+ ok = 1
+ except:
+ print newname + \
+ ': warning: cannot mkdir:', msg
+ ok = 0
+ if ok:
+ linkname = os.path.join(os.pardir,
+ linkname)
+ linknames(oldname, newname, linkname)
+ else:
+ os.symlink(linkname, newname)
sys.exit(main())
diff --git a/Tools/scripts/lll.py b/Tools/scripts/lll.py
index d107080..cbcd80a 100755
--- a/Tools/scripts/lll.py
+++ b/Tools/scripts/lll.py
@@ -8,18 +8,18 @@
import sys, os
def lll(dirname):
- for name in os.listdir(dirname):
- if name not in (os.curdir, os.pardir):
- full = os.path.join(dirname, name)
- if os.path.islink(full):
- print name, '->', os.readlink(full)
+ for name in os.listdir(dirname):
+ if name not in (os.curdir, os.pardir):
+ full = os.path.join(dirname, name)
+ if os.path.islink(full):
+ print name, '->', os.readlink(full)
args = sys.argv[1:]
if not args: args = [os.curdir]
first = 1
for arg in args:
- if len(args) > 1:
- if not first: print
- first = 0
- print arg + ':'
- lll(arg)
+ if len(args) > 1:
+ if not first: print
+ first = 0
+ print arg + ':'
+ lll(arg)
diff --git a/Tools/scripts/logmerge.py b/Tools/scripts/logmerge.py
index a09fd46..1d9bf2b 100755
--- a/Tools/scripts/logmerge.py
+++ b/Tools/scripts/logmerge.py
@@ -116,7 +116,7 @@ def digest_chunk(chunk):
text.insert(0, revline)
records.append((date, working_file, rev, author, text))
return records
-
+
def format_output(database):
prevtext = None
prev = []
diff --git a/Tools/scripts/mailerdaemon.py b/Tools/scripts/mailerdaemon.py
index 4a0669a..113b376 100755
--- a/Tools/scripts/mailerdaemon.py
+++ b/Tools/scripts/mailerdaemon.py
@@ -166,7 +166,7 @@ def parsedir(dir, modify):
# find all numeric file names and sort them
files = filter(lambda fn, pat=pat: pat.match(fn) is not None, os.listdir('.'))
files.sort(sort_numeric)
-
+
for fn in files:
# Lets try to parse the file.
fp = open(fn)
diff --git a/Tools/scripts/methfix.py b/Tools/scripts/methfix.py
index b0918d6..a9b7c21 100755
--- a/Tools/scripts/methfix.py
+++ b/Tools/scripts/methfix.py
@@ -1,9 +1,9 @@
#! /usr/bin/env python
-# Fix Python source files to avoid using
-# def method(self, (arg1, ..., argn)):
+# Fix Python source files to avoid using
+# def method(self, (arg1, ..., argn)):
# instead of the more rational
-# def method(self, arg1, ..., argn):
+# def method(self, arg1, ..., argn):
#
# Command line arguments are files or directories to be processed.
# Directories are searched recursively for files whose name looks
@@ -37,137 +37,137 @@ dbg = err
rep = sys.stdout.write
def main():
- bad = 0
- if not sys.argv[1:]: # No arguments
- err('usage: ' + sys.argv[0] + ' file-or-directory ...\n')
- sys.exit(2)
- for arg in sys.argv[1:]:
- if os.path.isdir(arg):
- if recursedown(arg): bad = 1
- elif os.path.islink(arg):
- err(arg + ': will not process symbolic links\n')
- bad = 1
- else:
- if fix(arg): bad = 1
- sys.exit(bad)
+ bad = 0
+ if not sys.argv[1:]: # No arguments
+ err('usage: ' + sys.argv[0] + ' file-or-directory ...\n')
+ sys.exit(2)
+ for arg in sys.argv[1:]:
+ if os.path.isdir(arg):
+ if recursedown(arg): bad = 1
+ elif os.path.islink(arg):
+ err(arg + ': will not process symbolic links\n')
+ bad = 1
+ else:
+ if fix(arg): bad = 1
+ sys.exit(bad)
ispythonprog = regex.compile('^[a-zA-Z0-9_]+\.py$')
def ispython(name):
- return ispythonprog.match(name) >= 0
+ return ispythonprog.match(name) >= 0
def recursedown(dirname):
- dbg('recursedown(' + `dirname` + ')\n')
- bad = 0
- try:
- names = os.listdir(dirname)
- except os.error, msg:
- err(dirname + ': cannot list directory: ' + `msg` + '\n')
- return 1
- names.sort()
- subdirs = []
- for name in names:
- if name in (os.curdir, os.pardir): continue
- fullname = os.path.join(dirname, name)
- if os.path.islink(fullname): pass
- elif os.path.isdir(fullname):
- subdirs.append(fullname)
- elif ispython(name):
- if fix(fullname): bad = 1
- for fullname in subdirs:
- if recursedown(fullname): bad = 1
- return bad
+ dbg('recursedown(' + `dirname` + ')\n')
+ bad = 0
+ try:
+ names = os.listdir(dirname)
+ except os.error, msg:
+ err(dirname + ': cannot list directory: ' + `msg` + '\n')
+ return 1
+ names.sort()
+ subdirs = []
+ for name in names:
+ if name in (os.curdir, os.pardir): continue
+ fullname = os.path.join(dirname, name)
+ if os.path.islink(fullname): pass
+ elif os.path.isdir(fullname):
+ subdirs.append(fullname)
+ elif ispython(name):
+ if fix(fullname): bad = 1
+ for fullname in subdirs:
+ if recursedown(fullname): bad = 1
+ return bad
def fix(filename):
-## dbg('fix(' + `filename` + ')\n')
- try:
- f = open(filename, 'r')
- except IOError, msg:
- err(filename + ': cannot open: ' + `msg` + '\n')
- return 1
- head, tail = os.path.split(filename)
- tempname = os.path.join(head, '@' + tail)
- g = None
- # If we find a match, we rewind the file and start over but
- # now copy everything to a temp file.
- lineno = 0
- while 1:
- line = f.readline()
- if not line: break
- lineno = lineno + 1
- if g is None and '\0' in line:
- # Check for binary files
- err(filename + ': contains null bytes; not fixed\n')
- f.close()
- return 1
- if lineno == 1 and g is None and line[:2] == '#!':
- # Check for non-Python scripts
- words = string.split(line[2:])
- if words and regex.search('[pP]ython', words[0]) < 0:
- msg = filename + ': ' + words[0]
- msg = msg + ' script; not fixed\n'
- err(msg)
- f.close()
- return 1
- while line[-2:] == '\\\n':
- nextline = f.readline()
- if not nextline: break
- line = line + nextline
- lineno = lineno + 1
- newline = fixline(line)
- if newline != line:
- if g is None:
- try:
- g = open(tempname, 'w')
- except IOError, msg:
- f.close()
- err(tempname+': cannot create: '+\
- `msg`+'\n')
- return 1
- f.seek(0)
- lineno = 0
- rep(filename + ':\n')
- continue # restart from the beginning
- rep(`lineno` + '\n')
- rep('< ' + line)
- rep('> ' + newline)
- if g is not None:
- g.write(newline)
+## dbg('fix(' + `filename` + ')\n')
+ try:
+ f = open(filename, 'r')
+ except IOError, msg:
+ err(filename + ': cannot open: ' + `msg` + '\n')
+ return 1
+ head, tail = os.path.split(filename)
+ tempname = os.path.join(head, '@' + tail)
+ g = None
+ # If we find a match, we rewind the file and start over but
+ # now copy everything to a temp file.
+ lineno = 0
+ while 1:
+ line = f.readline()
+ if not line: break
+ lineno = lineno + 1
+ if g is None and '\0' in line:
+ # Check for binary files
+ err(filename + ': contains null bytes; not fixed\n')
+ f.close()
+ return 1
+ if lineno == 1 and g is None and line[:2] == '#!':
+ # Check for non-Python scripts
+ words = string.split(line[2:])
+ if words and regex.search('[pP]ython', words[0]) < 0:
+ msg = filename + ': ' + words[0]
+ msg = msg + ' script; not fixed\n'
+ err(msg)
+ f.close()
+ return 1
+ while line[-2:] == '\\\n':
+ nextline = f.readline()
+ if not nextline: break
+ line = line + nextline
+ lineno = lineno + 1
+ newline = fixline(line)
+ if newline != line:
+ if g is None:
+ try:
+ g = open(tempname, 'w')
+ except IOError, msg:
+ f.close()
+ err(tempname+': cannot create: '+\
+ `msg`+'\n')
+ return 1
+ f.seek(0)
+ lineno = 0
+ rep(filename + ':\n')
+ continue # restart from the beginning
+ rep(`lineno` + '\n')
+ rep('< ' + line)
+ rep('> ' + newline)
+ if g is not None:
+ g.write(newline)
- # End of file
- f.close()
- if not g: return 0 # No changes
-
- # Finishing touch -- move files
+ # End of file
+ f.close()
+ if not g: return 0 # No changes
- # First copy the file's mode to the temp file
- try:
- statbuf = os.stat(filename)
- os.chmod(tempname, statbuf[ST_MODE] & 07777)
- except os.error, msg:
- err(tempname + ': warning: chmod failed (' + `msg` + ')\n')
- # Then make a backup of the original file as filename~
- try:
- os.rename(filename, filename + '~')
- except os.error, msg:
- err(filename + ': warning: backup failed (' + `msg` + ')\n')
- # Now move the temp file to the original file
- try:
- os.rename(tempname, filename)
- except os.error, msg:
- err(filename + ': rename failed (' + `msg` + ')\n')
- return 1
- # Return succes
- return 0
+ # Finishing touch -- move files
+
+ # First copy the file's mode to the temp file
+ try:
+ statbuf = os.stat(filename)
+ os.chmod(tempname, statbuf[ST_MODE] & 07777)
+ except os.error, msg:
+ err(tempname + ': warning: chmod failed (' + `msg` + ')\n')
+ # Then make a backup of the original file as filename~
+ try:
+ os.rename(filename, filename + '~')
+ except os.error, msg:
+ err(filename + ': warning: backup failed (' + `msg` + ')\n')
+ # Now move the temp file to the original file
+ try:
+ os.rename(tempname, filename)
+ except os.error, msg:
+ err(filename + ': rename failed (' + `msg` + ')\n')
+ return 1
+ # Return succes
+ return 0
fixpat = '^[ \t]+def +[a-zA-Z0-9_]+ *( *self *, *\(( *\(.*\) *)\) *) *:'
fixprog = regex.compile(fixpat)
def fixline(line):
- if fixprog.match(line) >= 0:
- (a, b), (c, d) = fixprog.regs[1:3]
- line = line[:a] + line[c:d] + line[b:]
- return line
+ if fixprog.match(line) >= 0:
+ (a, b), (c, d) = fixprog.regs[1:3]
+ line = line[:a] + line[c:d] + line[b:]
+ return line
main()
diff --git a/Tools/scripts/mkreal.py b/Tools/scripts/mkreal.py
index a065c17..eda01a8 100755
--- a/Tools/scripts/mkreal.py
+++ b/Tools/scripts/mkreal.py
@@ -15,51 +15,51 @@ error = 'mkreal error'
BUFSIZE = 32*1024
def mkrealfile(name):
- st = os.stat(name) # Get the mode
- mode = S_IMODE(st[ST_MODE])
- linkto = os.readlink(name) # Make sure again it's a symlink
- f_in = open(name, 'r') # This ensures it's a file
- os.unlink(name)
- f_out = open(name, 'w')
- while 1:
- buf = f_in.read(BUFSIZE)
- if not buf: break
- f_out.write(buf)
- del f_out # Flush data to disk before changing mode
- os.chmod(name, mode)
+ st = os.stat(name) # Get the mode
+ mode = S_IMODE(st[ST_MODE])
+ linkto = os.readlink(name) # Make sure again it's a symlink
+ f_in = open(name, 'r') # This ensures it's a file
+ os.unlink(name)
+ f_out = open(name, 'w')
+ while 1:
+ buf = f_in.read(BUFSIZE)
+ if not buf: break
+ f_out.write(buf)
+ del f_out # Flush data to disk before changing mode
+ os.chmod(name, mode)
def mkrealdir(name):
- st = os.stat(name) # Get the mode
- mode = S_IMODE(st[ST_MODE])
- linkto = os.readlink(name)
- files = os.listdir(name)
- os.unlink(name)
- os.mkdir(name, mode)
- os.chmod(name, mode)
- linkto = join(os.pardir, linkto)
- #
- for file in files:
- if file not in (os.curdir, os.pardir):
- os.symlink(join(linkto, file), join(name, file))
+ st = os.stat(name) # Get the mode
+ mode = S_IMODE(st[ST_MODE])
+ linkto = os.readlink(name)
+ files = os.listdir(name)
+ os.unlink(name)
+ os.mkdir(name, mode)
+ os.chmod(name, mode)
+ linkto = join(os.pardir, linkto)
+ #
+ for file in files:
+ if file not in (os.curdir, os.pardir):
+ os.symlink(join(linkto, file), join(name, file))
def main():
- sys.stdout = sys.stderr
- progname = os.path.basename(sys.argv[0])
- if progname == '-c': progname = 'mkreal'
- args = sys.argv[1:]
- if not args:
- print 'usage:', progname, 'path ...'
- sys.exit(2)
- status = 0
- for name in args:
- if not os.path.islink(name):
- print progname+':', name+':', 'not a symlink'
- status = 1
- else:
- if os.path.isdir(name):
- mkrealdir(name)
- else:
- mkrealfile(name)
- sys.exit(status)
+ sys.stdout = sys.stderr
+ progname = os.path.basename(sys.argv[0])
+ if progname == '-c': progname = 'mkreal'
+ args = sys.argv[1:]
+ if not args:
+ print 'usage:', progname, 'path ...'
+ sys.exit(2)
+ status = 0
+ for name in args:
+ if not os.path.islink(name):
+ print progname+':', name+':', 'not a symlink'
+ status = 1
+ else:
+ if os.path.isdir(name):
+ mkrealdir(name)
+ else:
+ mkrealfile(name)
+ sys.exit(status)
main()
diff --git a/Tools/scripts/nm2def.py b/Tools/scripts/nm2def.py
index 6fd17b2..fc1022a 100755
--- a/Tools/scripts/nm2def.py
+++ b/Tools/scripts/nm2def.py
@@ -98,6 +98,6 @@ def main():
f = sys.stdout # open('PC/python_nt.def','w')
f.write(DEF_TEMPLATE % (exports))
f.close()
-
+
if __name__ == '__main__':
main()
diff --git a/Tools/scripts/objgraph.py b/Tools/scripts/objgraph.py
index 4eab79b..e25e5b8 100755
--- a/Tools/scripts/objgraph.py
+++ b/Tools/scripts/objgraph.py
@@ -40,19 +40,19 @@ matcher = regex.compile('\(.*\):\t?........ \(.\) \(.*\)$')
# If there is no list for the key yet, it is created.
#
def store(dict, key, item):
- if dict.has_key(key):
- dict[key].append(item)
- else:
- dict[key] = [item]
+ if dict.has_key(key):
+ dict[key].append(item)
+ else:
+ dict[key] = [item]
# Return a flattened version of a list of strings: the concatenation
# of its elements with intervening spaces.
#
def flat(list):
- s = ''
- for item in list:
- s = s + ' ' + item
- return s[1:]
+ s = ''
+ for item in list:
+ s = s + ' ' + item
+ return s[1:]
# Global variables mapping defined/undefined names to files and back.
#
@@ -65,151 +65,151 @@ undef2file = {}
# Argument is an open file.
#
def readinput(file):
- while 1:
- s = file.readline()
- if not s:
- break
- # If you get any output from this line,
- # it is probably caused by an unexpected input line:
- if matcher.search(s) < 0: s; continue # Shouldn't happen
- (ra, rb), (r1a, r1b), (r2a, r2b), (r3a, r3b) = matcher.regs[:4]
- fn, name, type = s[r1a:r1b], s[r3a:r3b], s[r2a:r2b]
- if type in definitions:
- store(def2file, name, fn)
- store(file2def, fn, name)
- elif type in externals:
- store(file2undef, fn, name)
- store(undef2file, name, fn)
- elif not type in ignore:
- print fn + ':' + name + ': unknown type ' + type
+ while 1:
+ s = file.readline()
+ if not s:
+ break
+ # If you get any output from this line,
+ # it is probably caused by an unexpected input line:
+ if matcher.search(s) < 0: s; continue # Shouldn't happen
+ (ra, rb), (r1a, r1b), (r2a, r2b), (r3a, r3b) = matcher.regs[:4]
+ fn, name, type = s[r1a:r1b], s[r3a:r3b], s[r2a:r2b]
+ if type in definitions:
+ store(def2file, name, fn)
+ store(file2def, fn, name)
+ elif type in externals:
+ store(file2undef, fn, name)
+ store(undef2file, name, fn)
+ elif not type in ignore:
+ print fn + ':' + name + ': unknown type ' + type
# Print all names that were undefined in some module and where they are
# defined.
#
def printcallee():
- flist = file2undef.keys()
- flist.sort()
- for file in flist:
- print file + ':'
- elist = file2undef[file]
- elist.sort()
- for ext in elist:
- if len(ext) >= 8:
- tabs = '\t'
- else:
- tabs = '\t\t'
- if not def2file.has_key(ext):
- print '\t' + ext + tabs + ' *undefined'
- else:
- print '\t' + ext + tabs + flat(def2file[ext])
+ flist = file2undef.keys()
+ flist.sort()
+ for file in flist:
+ print file + ':'
+ elist = file2undef[file]
+ elist.sort()
+ for ext in elist:
+ if len(ext) >= 8:
+ tabs = '\t'
+ else:
+ tabs = '\t\t'
+ if not def2file.has_key(ext):
+ print '\t' + ext + tabs + ' *undefined'
+ else:
+ print '\t' + ext + tabs + flat(def2file[ext])
# Print for each module the names of the other modules that use it.
#
def printcaller():
- files = file2def.keys()
- files.sort()
- for file in files:
- callers = []
- for label in file2def[file]:
- if undef2file.has_key(label):
- callers = callers + undef2file[label]
- if callers:
- callers.sort()
- print file + ':'
- lastfn = ''
- for fn in callers:
- if fn <> lastfn:
- print '\t' + fn
- lastfn = fn
- else:
- print file + ': unused'
+ files = file2def.keys()
+ files.sort()
+ for file in files:
+ callers = []
+ for label in file2def[file]:
+ if undef2file.has_key(label):
+ callers = callers + undef2file[label]
+ if callers:
+ callers.sort()
+ print file + ':'
+ lastfn = ''
+ for fn in callers:
+ if fn <> lastfn:
+ print '\t' + fn
+ lastfn = fn
+ else:
+ print file + ': unused'
# Print undefine names and where they are used.
#
def printundef():
- undefs = {}
- for file in file2undef.keys():
- for ext in file2undef[file]:
- if not def2file.has_key(ext):
- store(undefs, ext, file)
- elist = undefs.keys()
- elist.sort()
- for ext in elist:
- print ext + ':'
- flist = undefs[ext]
- flist.sort()
- for file in flist:
- print '\t' + file
+ undefs = {}
+ for file in file2undef.keys():
+ for ext in file2undef[file]:
+ if not def2file.has_key(ext):
+ store(undefs, ext, file)
+ elist = undefs.keys()
+ elist.sort()
+ for ext in elist:
+ print ext + ':'
+ flist = undefs[ext]
+ flist.sort()
+ for file in flist:
+ print '\t' + file
# Print warning messages about names defined in more than one file.
#
def warndups():
- savestdout = sys.stdout
- sys.stdout = sys.stderr
- names = def2file.keys()
- names.sort()
- for name in names:
- if len(def2file[name]) > 1:
- print 'warning:', name, 'multiply defined:',
- print flat(def2file[name])
- sys.stdout = savestdout
+ savestdout = sys.stdout
+ sys.stdout = sys.stderr
+ names = def2file.keys()
+ names.sort()
+ for name in names:
+ if len(def2file[name]) > 1:
+ print 'warning:', name, 'multiply defined:',
+ print flat(def2file[name])
+ sys.stdout = savestdout
# Main program
#
def main():
- try:
- optlist, args = getopt.getopt(sys.argv[1:], 'cdu')
- except getopt.error:
- sys.stdout = sys.stderr
- print 'Usage:', os.path.basename(sys.argv[0]),
- print '[-cdu] [file] ...'
- print '-c: print callers per objectfile'
- print '-d: print callees per objectfile'
- print '-u: print usage of undefined symbols'
- print 'If none of -cdu is specified, all are assumed.'
- print 'Use "nm -o" to generate the input (on IRIX: "nm -Bo"),'
- print 'e.g.: nm -o /lib/libc.a | objgraph'
- return 1
- optu = optc = optd = 0
- for opt, void in optlist:
- if opt == '-u':
- optu = 1
- elif opt == '-c':
- optc = 1
- elif opt == '-d':
- optd = 1
- if optu == optc == optd == 0:
- optu = optc = optd = 1
- if not args:
- args = ['-']
- for file in args:
- if file == '-':
- readinput(sys.stdin)
- else:
- readinput(open(file, 'r'))
- #
- warndups()
- #
- more = (optu + optc + optd > 1)
- if optd:
- if more:
- print '---------------All callees------------------'
- printcallee()
- if optu:
- if more:
- print '---------------Undefined callees------------'
- printundef()
- if optc:
- if more:
- print '---------------All Callers------------------'
- printcaller()
- return 0
+ try:
+ optlist, args = getopt.getopt(sys.argv[1:], 'cdu')
+ except getopt.error:
+ sys.stdout = sys.stderr
+ print 'Usage:', os.path.basename(sys.argv[0]),
+ print '[-cdu] [file] ...'
+ print '-c: print callers per objectfile'
+ print '-d: print callees per objectfile'
+ print '-u: print usage of undefined symbols'
+ print 'If none of -cdu is specified, all are assumed.'
+ print 'Use "nm -o" to generate the input (on IRIX: "nm -Bo"),'
+ print 'e.g.: nm -o /lib/libc.a | objgraph'
+ return 1
+ optu = optc = optd = 0
+ for opt, void in optlist:
+ if opt == '-u':
+ optu = 1
+ elif opt == '-c':
+ optc = 1
+ elif opt == '-d':
+ optd = 1
+ if optu == optc == optd == 0:
+ optu = optc = optd = 1
+ if not args:
+ args = ['-']
+ for file in args:
+ if file == '-':
+ readinput(sys.stdin)
+ else:
+ readinput(open(file, 'r'))
+ #
+ warndups()
+ #
+ more = (optu + optc + optd > 1)
+ if optd:
+ if more:
+ print '---------------All callees------------------'
+ printcallee()
+ if optu:
+ if more:
+ print '---------------Undefined callees------------'
+ printundef()
+ if optc:
+ if more:
+ print '---------------All Callers------------------'
+ printcaller()
+ return 0
# Call the main program.
# Use its return value as exit status.
# Catch interrupts to avoid stack trace.
#
try:
- sys.exit(main())
+ sys.exit(main())
except KeyboardInterrupt:
- sys.exit(1)
+ sys.exit(1)
diff --git a/Tools/scripts/parseentities.py b/Tools/scripts/parseentities.py
index ab4f830..cf4e17c 100755
--- a/Tools/scripts/parseentities.py
+++ b/Tools/scripts/parseentities.py
@@ -8,7 +8,7 @@
Python snippet defining a dictionary "entitydefs" mapping literal
entity name to character or numeric entity.
- Marc-Andre Lemburg, mal@lemburg.com, 1999.
+ Marc-Andre Lemburg, mal@lemburg.com, 1999.
Use as you like. NO WARRANTIES.
"""
@@ -62,4 +62,3 @@ if __name__ == '__main__':
text = infile.read()
defs = parse(text)
writefile(outfile,defs)
-
diff --git a/Tools/scripts/pathfix.py b/Tools/scripts/pathfix.py
index be04b21..d4e3071 100755
--- a/Tools/scripts/pathfix.py
+++ b/Tools/scripts/pathfix.py
@@ -33,117 +33,117 @@ rep = sys.stdout.write
new_interpreter = None
def main():
- global new_interpreter
- usage = ('usage: %s -i /interpreter file-or-directory ...\n' %
- sys.argv[0])
- try:
- opts, args = getopt.getopt(sys.argv[1:], 'i:')
- except getopt.error, msg:
- err(msg + '\n')
- err(usage)
- sys.exit(2)
- for o, a in opts:
- if o == '-i':
- new_interpreter = a
- if not new_interpreter or new_interpreter[0] != '/' or not args:
- err('-i option or file-or-directory missing\n')
- err(usage)
- sys.exit(2)
- bad = 0
- for arg in args:
- if os.path.isdir(arg):
- if recursedown(arg): bad = 1
- elif os.path.islink(arg):
- err(arg + ': will not process symbolic links\n')
- bad = 1
- else:
- if fix(arg): bad = 1
- sys.exit(bad)
+ global new_interpreter
+ usage = ('usage: %s -i /interpreter file-or-directory ...\n' %
+ sys.argv[0])
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], 'i:')
+ except getopt.error, msg:
+ err(msg + '\n')
+ err(usage)
+ sys.exit(2)
+ for o, a in opts:
+ if o == '-i':
+ new_interpreter = a
+ if not new_interpreter or new_interpreter[0] != '/' or not args:
+ err('-i option or file-or-directory missing\n')
+ err(usage)
+ sys.exit(2)
+ bad = 0
+ for arg in args:
+ if os.path.isdir(arg):
+ if recursedown(arg): bad = 1
+ elif os.path.islink(arg):
+ err(arg + ': will not process symbolic links\n')
+ bad = 1
+ else:
+ if fix(arg): bad = 1
+ sys.exit(bad)
ispythonprog = regex.compile('^[a-zA-Z0-9_]+\.py$')
def ispython(name):
- return ispythonprog.match(name) >= 0
+ return ispythonprog.match(name) >= 0
def recursedown(dirname):
- dbg('recursedown(' + `dirname` + ')\n')
- bad = 0
- try:
- names = os.listdir(dirname)
- except os.error, msg:
- err(dirname + ': cannot list directory: ' + `msg` + '\n')
- return 1
- names.sort()
- subdirs = []
- for name in names:
- if name in (os.curdir, os.pardir): continue
- fullname = os.path.join(dirname, name)
- if os.path.islink(fullname): pass
- elif os.path.isdir(fullname):
- subdirs.append(fullname)
- elif ispython(name):
- if fix(fullname): bad = 1
- for fullname in subdirs:
- if recursedown(fullname): bad = 1
- return bad
+ dbg('recursedown(' + `dirname` + ')\n')
+ bad = 0
+ try:
+ names = os.listdir(dirname)
+ except os.error, msg:
+ err(dirname + ': cannot list directory: ' + `msg` + '\n')
+ return 1
+ names.sort()
+ subdirs = []
+ for name in names:
+ if name in (os.curdir, os.pardir): continue
+ fullname = os.path.join(dirname, name)
+ if os.path.islink(fullname): pass
+ elif os.path.isdir(fullname):
+ subdirs.append(fullname)
+ elif ispython(name):
+ if fix(fullname): bad = 1
+ for fullname in subdirs:
+ if recursedown(fullname): bad = 1
+ return bad
def fix(filename):
-## dbg('fix(' + `filename` + ')\n')
- try:
- f = open(filename, 'r')
- except IOError, msg:
- err(filename + ': cannot open: ' + `msg` + '\n')
- return 1
- line = f.readline()
- fixed = fixline(line)
- if line == fixed:
- rep(filename+': no change\n')
- f.close()
- return
- head, tail = os.path.split(filename)
- tempname = os.path.join(head, '@' + tail)
- try:
- g = open(tempname, 'w')
- except IOError, msg:
- f.close()
- err(tempname+': cannot create: '+`msg`+'\n')
- return 1
- rep(filename + ': updating\n')
- g.write(fixed)
- BUFSIZE = 8*1024
- while 1:
- buf = f.read(BUFSIZE)
- if not buf: break
- g.write(buf)
- g.close()
- f.close()
+## dbg('fix(' + `filename` + ')\n')
+ try:
+ f = open(filename, 'r')
+ except IOError, msg:
+ err(filename + ': cannot open: ' + `msg` + '\n')
+ return 1
+ line = f.readline()
+ fixed = fixline(line)
+ if line == fixed:
+ rep(filename+': no change\n')
+ f.close()
+ return
+ head, tail = os.path.split(filename)
+ tempname = os.path.join(head, '@' + tail)
+ try:
+ g = open(tempname, 'w')
+ except IOError, msg:
+ f.close()
+ err(tempname+': cannot create: '+`msg`+'\n')
+ return 1
+ rep(filename + ': updating\n')
+ g.write(fixed)
+ BUFSIZE = 8*1024
+ while 1:
+ buf = f.read(BUFSIZE)
+ if not buf: break
+ g.write(buf)
+ g.close()
+ f.close()
- # Finishing touch -- move files
+ # Finishing touch -- move files
- # First copy the file's mode to the temp file
- try:
- statbuf = os.stat(filename)
- os.chmod(tempname, statbuf[ST_MODE] & 07777)
- except os.error, msg:
- err(tempname + ': warning: chmod failed (' + `msg` + ')\n')
- # Then make a backup of the original file as filename~
- try:
- os.rename(filename, filename + '~')
- except os.error, msg:
- err(filename + ': warning: backup failed (' + `msg` + ')\n')
- # Now move the temp file to the original file
- try:
- os.rename(tempname, filename)
- except os.error, msg:
- err(filename + ': rename failed (' + `msg` + ')\n')
- return 1
- # Return succes
- return 0
+ # First copy the file's mode to the temp file
+ try:
+ statbuf = os.stat(filename)
+ os.chmod(tempname, statbuf[ST_MODE] & 07777)
+ except os.error, msg:
+ err(tempname + ': warning: chmod failed (' + `msg` + ')\n')
+ # Then make a backup of the original file as filename~
+ try:
+ os.rename(filename, filename + '~')
+ except os.error, msg:
+ err(filename + ': warning: backup failed (' + `msg` + ')\n')
+ # Now move the temp file to the original file
+ try:
+ os.rename(tempname, filename)
+ except os.error, msg:
+ err(filename + ': rename failed (' + `msg` + ')\n')
+ return 1
+ # Return succes
+ return 0
def fixline(line):
- if line[:2] != '#!':
- return line
- if string.find(line, "python") < 0:
- return line
- return '#! %s\n' % new_interpreter
+ if line[:2] != '#!':
+ return line
+ if string.find(line, "python") < 0:
+ return line
+ return '#! %s\n' % new_interpreter
main()
diff --git a/Tools/scripts/pdeps.py b/Tools/scripts/pdeps.py
index fb730f1..18b582b 100755
--- a/Tools/scripts/pdeps.py
+++ b/Tools/scripts/pdeps.py
@@ -5,7 +5,7 @@
# Find dependencies between a bunch of Python modules.
#
# Usage:
-# pdeps file1.py file2.py ...
+# pdeps file1.py file2.py ...
#
# Output:
# Four tables separated by lines like '--- Closure ---':
@@ -29,31 +29,31 @@ import string
# Main program
#
def main():
- args = sys.argv[1:]
- if not args:
- print 'usage: pdeps file.py file.py ...'
- return 2
- #
- table = {}
- for arg in args:
- process(arg, table)
- #
- print '--- Uses ---'
- printresults(table)
- #
- print '--- Used By ---'
- inv = inverse(table)
- printresults(inv)
- #
- print '--- Closure of Uses ---'
- reach = closure(table)
- printresults(reach)
- #
- print '--- Closure of Used By ---'
- invreach = inverse(reach)
- printresults(invreach)
- #
- return 0
+ args = sys.argv[1:]
+ if not args:
+ print 'usage: pdeps file.py file.py ...'
+ return 2
+ #
+ table = {}
+ for arg in args:
+ process(arg, table)
+ #
+ print '--- Uses ---'
+ printresults(table)
+ #
+ print '--- Used By ---'
+ inv = inverse(table)
+ printresults(inv)
+ #
+ print '--- Closure of Uses ---'
+ reach = closure(table)
+ printresults(reach)
+ #
+ print '--- Closure of Used By ---'
+ invreach = inverse(reach)
+ printresults(invreach)
+ #
+ return 0
# Compiled regular expressions to search for import statements
@@ -65,56 +65,56 @@ m_from = regex.compile('^[ \t]*import[ \t]+\([^#]+\)')
# Collect data from one file
#
def process(filename, table):
- fp = open(filename, 'r')
- mod = os.path.basename(filename)
- if mod[-3:] == '.py':
- mod = mod[:-3]
- table[mod] = list = []
- while 1:
- line = fp.readline()
- if not line: break
- while line[-1:] == '\\':
- nextline = fp.readline()
- if not nextline: break
- line = line[:-1] + nextline
- if m_import.match(line) >= 0:
- (a, b), (a1, b1) = m_import.regs[:2]
- elif m_from.match(line) >= 0:
- (a, b), (a1, b1) = m_from.regs[:2]
- else: continue
- words = string.splitfields(line[a1:b1], ',')
- # print '#', line, words
- for word in words:
- word = string.strip(word)
- if word not in list:
- list.append(word)
+ fp = open(filename, 'r')
+ mod = os.path.basename(filename)
+ if mod[-3:] == '.py':
+ mod = mod[:-3]
+ table[mod] = list = []
+ while 1:
+ line = fp.readline()
+ if not line: break
+ while line[-1:] == '\\':
+ nextline = fp.readline()
+ if not nextline: break
+ line = line[:-1] + nextline
+ if m_import.match(line) >= 0:
+ (a, b), (a1, b1) = m_import.regs[:2]
+ elif m_from.match(line) >= 0:
+ (a, b), (a1, b1) = m_from.regs[:2]
+ else: continue
+ words = string.splitfields(line[a1:b1], ',')
+ # print '#', line, words
+ for word in words:
+ word = string.strip(word)
+ if word not in list:
+ list.append(word)
# Compute closure (this is in fact totally general)
#
def closure(table):
- modules = table.keys()
- #
- # Initialize reach with a copy of table
- #
- reach = {}
- for mod in modules:
- reach[mod] = table[mod][:]
- #
- # Iterate until no more change
- #
- change = 1
- while change:
- change = 0
- for mod in modules:
- for mo in reach[mod]:
- if mo in modules:
- for m in reach[mo]:
- if m not in reach[mod]:
- reach[mod].append(m)
- change = 1
- #
- return reach
+ modules = table.keys()
+ #
+ # Initialize reach with a copy of table
+ #
+ reach = {}
+ for mod in modules:
+ reach[mod] = table[mod][:]
+ #
+ # Iterate until no more change
+ #
+ change = 1
+ while change:
+ change = 0
+ for mod in modules:
+ for mo in reach[mod]:
+ if mo in modules:
+ for m in reach[mo]:
+ if m not in reach[mod]:
+ reach[mod].append(m)
+ change = 1
+ #
+ return reach
# Invert a table (this is again totally general).
@@ -122,13 +122,13 @@ def closure(table):
# so there may be empty lists in the inverse.
#
def inverse(table):
- inv = {}
- for key in table.keys():
- if not inv.has_key(key):
- inv[key] = []
- for item in table[key]:
- store(inv, item, key)
- return inv
+ inv = {}
+ for key in table.keys():
+ if not inv.has_key(key):
+ inv[key] = []
+ for item in table[key]:
+ store(inv, item, key)
+ return inv
# Store "item" in "dict" under "key".
@@ -136,32 +136,32 @@ def inverse(table):
# If there is no list for the key yet, it is created.
#
def store(dict, key, item):
- if dict.has_key(key):
- dict[key].append(item)
- else:
- dict[key] = [item]
+ if dict.has_key(key):
+ dict[key].append(item)
+ else:
+ dict[key] = [item]
# Tabulate results neatly
#
def printresults(table):
- modules = table.keys()
- maxlen = 0
- for mod in modules: maxlen = max(maxlen, len(mod))
- modules.sort()
- for mod in modules:
- list = table[mod]
- list.sort()
- print string.ljust(mod, maxlen), ':',
- if mod in list:
- print '(*)',
- for ref in list:
- print ref,
- print
+ modules = table.keys()
+ maxlen = 0
+ for mod in modules: maxlen = max(maxlen, len(mod))
+ modules.sort()
+ for mod in modules:
+ list = table[mod]
+ list.sort()
+ print string.ljust(mod, maxlen), ':',
+ if mod in list:
+ print '(*)',
+ for ref in list:
+ print ref,
+ print
# Call main and honor exit status
try:
- sys.exit(main())
+ sys.exit(main())
except KeyboardInterrupt:
- sys.exit(1)
+ sys.exit(1)
diff --git a/Tools/scripts/pindent.py b/Tools/scripts/pindent.py
index 6eba021..318c20e 100755
--- a/Tools/scripts/pindent.py
+++ b/Tools/scripts/pindent.py
@@ -97,236 +97,236 @@ start = 'if', 'while', 'for', 'try', 'def', 'class'
class PythonIndenter:
- def __init__(self, fpi = sys.stdin, fpo = sys.stdout,
- indentsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
- self.fpi = fpi
- self.fpo = fpo
- self.indentsize = indentsize
- self.tabsize = tabsize
- self.lineno = 0
- self.expandtabs = expandtabs
- self._write = fpo.write
- self.kwprog = re.compile(
- r'^\s*(?P<kw>[a-z]+)'
- r'(\s+(?P<id>[a-zA-Z_]\w*))?'
- r'[^\w]')
- self.endprog = re.compile(
- r'^\s*#?\s*end\s+(?P<kw>[a-z]+)'
- r'(\s+(?P<id>[a-zA-Z_]\w*))?'
- r'[^\w]')
- self.wsprog = re.compile(r'^[ \t]*')
- # end def __init__
-
- def write(self, line):
- if self.expandtabs:
- self._write(string.expandtabs(line, self.tabsize))
- else:
- self._write(line)
- # end if
- # end def write
-
- def readline(self):
- line = self.fpi.readline()
- if line: self.lineno = self.lineno + 1
- # end if
- return line
- # end def readline
-
- def error(self, fmt, *args):
- if args: fmt = fmt % args
- # end if
- sys.stderr.write('Error at line %d: %s\n' % (self.lineno, fmt))
- self.write('### %s ###\n' % fmt)
- # end def error
-
- def getline(self):
- line = self.readline()
- while line[-2:] == '\\\n':
- line2 = self.readline()
- if not line2: break
- # end if
- line = line + line2
- # end while
- return line
- # end def getline
-
- def putline(self, line, indent = None):
- if indent is None:
- self.write(line)
- return
- # end if
- tabs, spaces = divmod(indent*self.indentsize, self.tabsize)
- i = 0
- m = self.wsprog.match(line)
- if m: i = m.end()
- # end if
- self.write('\t'*tabs + ' '*spaces + line[i:])
- # end def putline
-
- def reformat(self):
- stack = []
- while 1:
- line = self.getline()
- if not line: break # EOF
- # end if
- m = self.endprog.match(line)
- if m:
- kw = 'end'
- kw2 = m.group('kw')
- if not stack:
- self.error('unexpected end')
- elif stack[-1][0] != kw2:
- self.error('unmatched end')
- # end if
- del stack[-1:]
- self.putline(line, len(stack))
- continue
- # end if
- m = self.kwprog.match(line)
- if m:
- kw = m.group('kw')
- if kw in start:
- self.putline(line, len(stack))
- stack.append((kw, kw))
- continue
- # end if
- if next.has_key(kw) and stack:
- self.putline(line, len(stack)-1)
- kwa, kwb = stack[-1]
- stack[-1] = kwa, kw
- continue
- # end if
- # end if
- self.putline(line, len(stack))
- # end while
- if stack:
- self.error('unterminated keywords')
- for kwa, kwb in stack:
- self.write('\t%s\n' % kwa)
- # end for
- # end if
- # end def reformat
-
- def delete(self):
- begin_counter = 0
- end_counter = 0
- while 1:
- line = self.getline()
- if not line: break # EOF
- # end if
- m = self.endprog.match(line)
- if m:
- end_counter = end_counter + 1
- continue
- # end if
- m = self.kwprog.match(line)
- if m:
- kw = m.group('kw')
- if kw in start:
- begin_counter = begin_counter + 1
- # end if
- # end if
- self.putline(line)
- # end while
- if begin_counter - end_counter < 0:
- sys.stderr.write('Warning: input contained more end tags than expected\n')
- elif begin_counter - end_counter > 0:
- sys.stderr.write('Warning: input contained less end tags than expected\n')
- # end if
- # end def delete
-
- def complete(self):
- self.indentsize = 1
- stack = []
- todo = []
- current, firstkw, lastkw, topid = 0, '', '', ''
- while 1:
- line = self.getline()
- i = 0
- m = self.wsprog.match(line)
- if m: i = m.end()
- # end if
- m = self.endprog.match(line)
- if m:
- thiskw = 'end'
- endkw = m.group('kw')
- thisid = m.group('id')
- else:
- m = self.kwprog.match(line)
- if m:
- thiskw = m.group('kw')
- if not next.has_key(thiskw):
- thiskw = ''
- # end if
- if thiskw in ('def', 'class'):
- thisid = m.group('id')
- else:
- thisid = ''
- # end if
- elif line[i:i+1] in ('\n', '#'):
- todo.append(line)
- continue
- else:
- thiskw = ''
- # end if
- # end if
- indent = len(string.expandtabs(line[:i], self.tabsize))
- while indent < current:
- if firstkw:
- if topid:
- s = '# end %s %s\n' % (
- firstkw, topid)
- else:
- s = '# end %s\n' % firstkw
- # end if
- self.putline(s, current)
- firstkw = lastkw = ''
- # end if
- current, firstkw, lastkw, topid = stack[-1]
- del stack[-1]
- # end while
- if indent == current and firstkw:
- if thiskw == 'end':
- if endkw != firstkw:
- self.error('mismatched end')
- # end if
- firstkw = lastkw = ''
- elif not thiskw or thiskw in start:
- if topid:
- s = '# end %s %s\n' % (
- firstkw, topid)
- else:
- s = '# end %s\n' % firstkw
- # end if
- self.putline(s, current)
- firstkw = lastkw = topid = ''
- # end if
- # end if
- if indent > current:
- stack.append((current, firstkw, lastkw, topid))
- if thiskw and thiskw not in start:
- # error
- thiskw = ''
- # end if
- current, firstkw, lastkw, topid = \
- indent, thiskw, thiskw, thisid
- # end if
- if thiskw:
- if thiskw in start:
- firstkw = lastkw = thiskw
- topid = thisid
- else:
- lastkw = thiskw
- # end if
- # end if
- for l in todo: self.write(l)
- # end for
- todo = []
- if not line: break
- # end if
- self.write(line)
- # end while
- # end def complete
+ def __init__(self, fpi = sys.stdin, fpo = sys.stdout,
+ indentsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
+ self.fpi = fpi
+ self.fpo = fpo
+ self.indentsize = indentsize
+ self.tabsize = tabsize
+ self.lineno = 0
+ self.expandtabs = expandtabs
+ self._write = fpo.write
+ self.kwprog = re.compile(
+ r'^\s*(?P<kw>[a-z]+)'
+ r'(\s+(?P<id>[a-zA-Z_]\w*))?'
+ r'[^\w]')
+ self.endprog = re.compile(
+ r'^\s*#?\s*end\s+(?P<kw>[a-z]+)'
+ r'(\s+(?P<id>[a-zA-Z_]\w*))?'
+ r'[^\w]')
+ self.wsprog = re.compile(r'^[ \t]*')
+ # end def __init__
+
+ def write(self, line):
+ if self.expandtabs:
+ self._write(string.expandtabs(line, self.tabsize))
+ else:
+ self._write(line)
+ # end if
+ # end def write
+
+ def readline(self):
+ line = self.fpi.readline()
+ if line: self.lineno = self.lineno + 1
+ # end if
+ return line
+ # end def readline
+
+ def error(self, fmt, *args):
+ if args: fmt = fmt % args
+ # end if
+ sys.stderr.write('Error at line %d: %s\n' % (self.lineno, fmt))
+ self.write('### %s ###\n' % fmt)
+ # end def error
+
+ def getline(self):
+ line = self.readline()
+ while line[-2:] == '\\\n':
+ line2 = self.readline()
+ if not line2: break
+ # end if
+ line = line + line2
+ # end while
+ return line
+ # end def getline
+
+ def putline(self, line, indent = None):
+ if indent is None:
+ self.write(line)
+ return
+ # end if
+ tabs, spaces = divmod(indent*self.indentsize, self.tabsize)
+ i = 0
+ m = self.wsprog.match(line)
+ if m: i = m.end()
+ # end if
+ self.write('\t'*tabs + ' '*spaces + line[i:])
+ # end def putline
+
+ def reformat(self):
+ stack = []
+ while 1:
+ line = self.getline()
+ if not line: break # EOF
+ # end if
+ m = self.endprog.match(line)
+ if m:
+ kw = 'end'
+ kw2 = m.group('kw')
+ if not stack:
+ self.error('unexpected end')
+ elif stack[-1][0] != kw2:
+ self.error('unmatched end')
+ # end if
+ del stack[-1:]
+ self.putline(line, len(stack))
+ continue
+ # end if
+ m = self.kwprog.match(line)
+ if m:
+ kw = m.group('kw')
+ if kw in start:
+ self.putline(line, len(stack))
+ stack.append((kw, kw))
+ continue
+ # end if
+ if next.has_key(kw) and stack:
+ self.putline(line, len(stack)-1)
+ kwa, kwb = stack[-1]
+ stack[-1] = kwa, kw
+ continue
+ # end if
+ # end if
+ self.putline(line, len(stack))
+ # end while
+ if stack:
+ self.error('unterminated keywords')
+ for kwa, kwb in stack:
+ self.write('\t%s\n' % kwa)
+ # end for
+ # end if
+ # end def reformat
+
+ def delete(self):
+ begin_counter = 0
+ end_counter = 0
+ while 1:
+ line = self.getline()
+ if not line: break # EOF
+ # end if
+ m = self.endprog.match(line)
+ if m:
+ end_counter = end_counter + 1
+ continue
+ # end if
+ m = self.kwprog.match(line)
+ if m:
+ kw = m.group('kw')
+ if kw in start:
+ begin_counter = begin_counter + 1
+ # end if
+ # end if
+ self.putline(line)
+ # end while
+ if begin_counter - end_counter < 0:
+ sys.stderr.write('Warning: input contained more end tags than expected\n')
+ elif begin_counter - end_counter > 0:
+ sys.stderr.write('Warning: input contained less end tags than expected\n')
+ # end if
+ # end def delete
+
+ def complete(self):
+ self.indentsize = 1
+ stack = []
+ todo = []
+ current, firstkw, lastkw, topid = 0, '', '', ''
+ while 1:
+ line = self.getline()
+ i = 0
+ m = self.wsprog.match(line)
+ if m: i = m.end()
+ # end if
+ m = self.endprog.match(line)
+ if m:
+ thiskw = 'end'
+ endkw = m.group('kw')
+ thisid = m.group('id')
+ else:
+ m = self.kwprog.match(line)
+ if m:
+ thiskw = m.group('kw')
+ if not next.has_key(thiskw):
+ thiskw = ''
+ # end if
+ if thiskw in ('def', 'class'):
+ thisid = m.group('id')
+ else:
+ thisid = ''
+ # end if
+ elif line[i:i+1] in ('\n', '#'):
+ todo.append(line)
+ continue
+ else:
+ thiskw = ''
+ # end if
+ # end if
+ indent = len(string.expandtabs(line[:i], self.tabsize))
+ while indent < current:
+ if firstkw:
+ if topid:
+ s = '# end %s %s\n' % (
+ firstkw, topid)
+ else:
+ s = '# end %s\n' % firstkw
+ # end if
+ self.putline(s, current)
+ firstkw = lastkw = ''
+ # end if
+ current, firstkw, lastkw, topid = stack[-1]
+ del stack[-1]
+ # end while
+ if indent == current and firstkw:
+ if thiskw == 'end':
+ if endkw != firstkw:
+ self.error('mismatched end')
+ # end if
+ firstkw = lastkw = ''
+ elif not thiskw or thiskw in start:
+ if topid:
+ s = '# end %s %s\n' % (
+ firstkw, topid)
+ else:
+ s = '# end %s\n' % firstkw
+ # end if
+ self.putline(s, current)
+ firstkw = lastkw = topid = ''
+ # end if
+ # end if
+ if indent > current:
+ stack.append((current, firstkw, lastkw, topid))
+ if thiskw and thiskw not in start:
+ # error
+ thiskw = ''
+ # end if
+ current, firstkw, lastkw, topid = \
+ indent, thiskw, thiskw, thisid
+ # end if
+ if thiskw:
+ if thiskw in start:
+ firstkw = lastkw = thiskw
+ topid = thisid
+ else:
+ lastkw = thiskw
+ # end if
+ # end if
+ for l in todo: self.write(l)
+ # end for
+ todo = []
+ if not line: break
+ # end if
+ self.write(line)
+ # end while
+ # end def complete
# end class PythonIndenter
@@ -336,134 +336,134 @@ class PythonIndenter:
# - xxx_file(filename): process file in place, return true iff changed
def complete_filter(input = sys.stdin, output = sys.stdout,
- stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
- pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs)
- pi.complete()
+ stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
+ pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs)
+ pi.complete()
# end def complete_filter
def delete_filter(input= sys.stdin, output = sys.stdout,
- stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
- pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs)
- pi.delete()
+ stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
+ pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs)
+ pi.delete()
# end def delete_filter
def reformat_filter(input = sys.stdin, output = sys.stdout,
- stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
- pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs)
- pi.reformat()
+ stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
+ pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs)
+ pi.reformat()
# end def reformat_filter
class StringReader:
- def __init__(self, buf):
- self.buf = buf
- self.pos = 0
- self.len = len(self.buf)
- # end def __init__
- def read(self, n = 0):
- if n <= 0:
- n = self.len - self.pos
- else:
- n = min(n, self.len - self.pos)
- # end if
- r = self.buf[self.pos : self.pos + n]
- self.pos = self.pos + n
- return r
- # end def read
- def readline(self):
- i = string.find(self.buf, '\n', self.pos)
- return self.read(i + 1 - self.pos)
- # end def readline
- def readlines(self):
- lines = []
- line = self.readline()
- while line:
- lines.append(line)
- line = self.readline()
- # end while
- return lines
- # end def readlines
- # seek/tell etc. are left as an exercise for the reader
+ def __init__(self, buf):
+ self.buf = buf
+ self.pos = 0
+ self.len = len(self.buf)
+ # end def __init__
+ def read(self, n = 0):
+ if n <= 0:
+ n = self.len - self.pos
+ else:
+ n = min(n, self.len - self.pos)
+ # end if
+ r = self.buf[self.pos : self.pos + n]
+ self.pos = self.pos + n
+ return r
+ # end def read
+ def readline(self):
+ i = string.find(self.buf, '\n', self.pos)
+ return self.read(i + 1 - self.pos)
+ # end def readline
+ def readlines(self):
+ lines = []
+ line = self.readline()
+ while line:
+ lines.append(line)
+ line = self.readline()
+ # end while
+ return lines
+ # end def readlines
+ # seek/tell etc. are left as an exercise for the reader
# end class StringReader
class StringWriter:
- def __init__(self):
- self.buf = ''
- # end def __init__
- def write(self, s):
- self.buf = self.buf + s
- # end def write
- def getvalue(self):
- return self.buf
- # end def getvalue
+ def __init__(self):
+ self.buf = ''
+ # end def __init__
+ def write(self, s):
+ self.buf = self.buf + s
+ # end def write
+ def getvalue(self):
+ return self.buf
+ # end def getvalue
# end class StringWriter
def complete_string(source, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
- input = StringReader(source)
- output = StringWriter()
- pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs)
- pi.complete()
- return output.getvalue()
+ input = StringReader(source)
+ output = StringWriter()
+ pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs)
+ pi.complete()
+ return output.getvalue()
# end def complete_string
def delete_string(source, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
- input = StringReader(source)
- output = StringWriter()
- pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs)
- pi.delete()
- return output.getvalue()
+ input = StringReader(source)
+ output = StringWriter()
+ pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs)
+ pi.delete()
+ return output.getvalue()
# end def delete_string
def reformat_string(source, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
- input = StringReader(source)
- output = StringWriter()
- pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs)
- pi.reformat()
- return output.getvalue()
+ input = StringReader(source)
+ output = StringWriter()
+ pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs)
+ pi.reformat()
+ return output.getvalue()
# end def reformat_string
def complete_file(filename, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
- source = open(filename, 'r').read()
- result = complete_string(source, stepsize, tabsize, expandtabs)
- if source == result: return 0
- # end if
- import os
- try: os.rename(filename, filename + '~')
- except os.error: pass
- # end try
- f = open(filename, 'w')
- f.write(result)
- f.close()
- return 1
+ source = open(filename, 'r').read()
+ result = complete_string(source, stepsize, tabsize, expandtabs)
+ if source == result: return 0
+ # end if
+ import os
+ try: os.rename(filename, filename + '~')
+ except os.error: pass
+ # end try
+ f = open(filename, 'w')
+ f.write(result)
+ f.close()
+ return 1
# end def complete_file
def delete_file(filename, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
- source = open(filename, 'r').read()
- result = delete_string(source, stepsize, tabsize, expandtabs)
- if source == result: return 0
- # end if
- import os
- try: os.rename(filename, filename + '~')
- except os.error: pass
- # end try
- f = open(filename, 'w')
- f.write(result)
- f.close()
- return 1
+ source = open(filename, 'r').read()
+ result = delete_string(source, stepsize, tabsize, expandtabs)
+ if source == result: return 0
+ # end if
+ import os
+ try: os.rename(filename, filename + '~')
+ except os.error: pass
+ # end try
+ f = open(filename, 'w')
+ f.write(result)
+ f.close()
+ return 1
# end def delete_file
def reformat_file(filename, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
- source = open(filename, 'r').read()
- result = reformat_string(source, stepsize, tabsize, expandtabs)
- if source == result: return 0
- # end if
- import os
- try: os.rename(filename, filename + '~')
- except os.error: pass
- # end try
- f = open(filename, 'w')
- f.write(result)
- f.close()
- return 1
+ source = open(filename, 'r').read()
+ result = reformat_string(source, stepsize, tabsize, expandtabs)
+ if source == result: return 0
+ # end if
+ import os
+ try: os.rename(filename, filename + '~')
+ except os.error: pass
+ # end try
+ f = open(filename, 'w')
+ f.write(result)
+ f.close()
+ return 1
# end def reformat_file
# Test program when called as a script
@@ -482,62 +482,62 @@ the program acts as a filter (reads stdin, writes stdout).
""" % vars()
def error_both(op1, op2):
- sys.stderr.write('Error: You can not specify both '+op1+' and -'+op2[0]+' at the same time\n')
- sys.stderr.write(usage)
- sys.exit(2)
+ sys.stderr.write('Error: You can not specify both '+op1+' and -'+op2[0]+' at the same time\n')
+ sys.stderr.write(usage)
+ sys.exit(2)
# end def error_both
def test():
- import getopt
- try:
- opts, args = getopt.getopt(sys.argv[1:], 'cdrs:t:e')
- except getopt.error, msg:
- sys.stderr.write('Error: %s\n' % msg)
- sys.stderr.write(usage)
- sys.exit(2)
- # end try
- action = None
- stepsize = STEPSIZE
- tabsize = TABSIZE
- expandtabs = EXPANDTABS
- for o, a in opts:
- if o == '-c':
- if action: error_both(o, action)
- # end if
- action = 'complete'
- elif o == '-d':
- if action: error_both(o, action)
- # end if
- action = 'delete'
- elif o == '-r':
- if action: error_both(o, action)
- # end if
- action = 'reformat'
- elif o == '-s':
- stepsize = string.atoi(a)
- elif o == '-t':
- tabsize = string.atoi(a)
- elif o == '-e':
- expandtabs = 1
- # end if
- # end for
- if not action:
- sys.stderr.write(
- 'You must specify -c(omplete), -d(elete) or -r(eformat)\n')
- sys.stderr.write(usage)
- sys.exit(2)
- # end if
- if not args or args == ['-']:
- action = eval(action + '_filter')
- action(sys.stdin, sys.stdout, stepsize, tabsize, expandtabs)
- else:
- action = eval(action + '_file')
- for file in args:
- action(file, stepsize, tabsize, expandtabs)
- # end for
- # end if
+ import getopt
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], 'cdrs:t:e')
+ except getopt.error, msg:
+ sys.stderr.write('Error: %s\n' % msg)
+ sys.stderr.write(usage)
+ sys.exit(2)
+ # end try
+ action = None
+ stepsize = STEPSIZE
+ tabsize = TABSIZE
+ expandtabs = EXPANDTABS
+ for o, a in opts:
+ if o == '-c':
+ if action: error_both(o, action)
+ # end if
+ action = 'complete'
+ elif o == '-d':
+ if action: error_both(o, action)
+ # end if
+ action = 'delete'
+ elif o == '-r':
+ if action: error_both(o, action)
+ # end if
+ action = 'reformat'
+ elif o == '-s':
+ stepsize = string.atoi(a)
+ elif o == '-t':
+ tabsize = string.atoi(a)
+ elif o == '-e':
+ expandtabs = 1
+ # end if
+ # end for
+ if not action:
+ sys.stderr.write(
+ 'You must specify -c(omplete), -d(elete) or -r(eformat)\n')
+ sys.stderr.write(usage)
+ sys.exit(2)
+ # end if
+ if not args or args == ['-']:
+ action = eval(action + '_filter')
+ action(sys.stdin, sys.stdout, stepsize, tabsize, expandtabs)
+ else:
+ action = eval(action + '_file')
+ for file in args:
+ action(file, stepsize, tabsize, expandtabs)
+ # end for
+ # end if
# end def test
if __name__ == '__main__':
- test()
+ test()
# end if
diff --git a/Tools/scripts/ptags.py b/Tools/scripts/ptags.py
index f7f7eb5..ea8eb3f 100755
--- a/Tools/scripts/ptags.py
+++ b/Tools/scripts/ptags.py
@@ -39,7 +39,7 @@ def treat_file(file):
tags.append(s)
while 1:
line = fp.readline()
- if not line:
+ if not line:
break
m = matcher.match(line)
if m:
diff --git a/Tools/scripts/redemo.py b/Tools/scripts/redemo.py
index 535e756..1eed8f8 100644
--- a/Tools/scripts/redemo.py
+++ b/Tools/scripts/redemo.py
@@ -4,159 +4,159 @@ from Tkinter import *
import re
class ReDemo:
-
- def __init__(self, master):
- self.master = master
-
- self.promptdisplay = Label(self.master, anchor=W,
- text="Enter a Perl-style regular expression:")
- self.promptdisplay.pack(side=TOP, fill=X)
-
- self.regexdisplay = Entry(self.master)
- self.regexdisplay.pack(fill=X)
- self.regexdisplay.focus_set()
-
- self.addoptions()
-
- self.statusdisplay = Label(self.master, text="", anchor=W)
- self.statusdisplay.pack(side=TOP, fill=X)
-
- self.labeldisplay = Label(self.master, anchor=W,
- text="Enter a string to search:")
- self.labeldisplay.pack(fill=X)
- self.labeldisplay.pack(fill=X)
-
- self.showframe = Frame(master)
- self.showframe.pack(fill=X, anchor=W)
-
- self.showvar = StringVar(master)
- self.showvar.set("first")
-
- self.showfirstradio = Radiobutton(self.showframe,
- text="Highlight first match",
- variable=self.showvar,
- value="first",
- command=self.recompile)
- self.showfirstradio.pack(side=LEFT)
-
- self.showallradio = Radiobutton(self.showframe,
- text="Highlight all matches",
- variable=self.showvar,
- value="all",
- command=self.recompile)
- self.showallradio.pack(side=LEFT)
-
- self.stringdisplay = Text(self.master, width=60, height=4)
- self.stringdisplay.pack(fill=BOTH, expand=1)
- self.stringdisplay.tag_configure("hit", background="yellow")
-
- self.grouplabel = Label(self.master, text="Groups:", anchor=W)
- self.grouplabel.pack(fill=X)
-
- self.grouplist = Listbox(self.master)
- self.grouplist.pack(expand=1, fill=BOTH)
-
- self.regexdisplay.bind('<Key>', self.recompile)
- self.stringdisplay.bind('<Key>', self.reevaluate)
-
- self.compiled = None
- self.recompile()
-
- btags = self.regexdisplay.bindtags()
- self.regexdisplay.bindtags(btags[1:] + btags[:1])
-
- btags = self.stringdisplay.bindtags()
- self.stringdisplay.bindtags(btags[1:] + btags[:1])
-
- def addoptions(self):
- self.frames = []
- self.boxes = []
- self.vars = []
- for name in ('IGNORECASE',
- 'LOCALE',
- 'MULTILINE',
- 'DOTALL',
- 'VERBOSE'):
- if len(self.boxes) % 3 == 0:
- frame = Frame(self.master)
- frame.pack(fill=X)
- self.frames.append(frame)
- val = getattr(re, name)
- var = IntVar()
- box = Checkbutton(frame,
- variable=var, text=name,
- offvalue=0, onvalue=val,
- command=self.recompile)
- box.pack(side=LEFT)
- self.boxes.append(box)
- self.vars.append(var)
-
- def getflags(self):
- flags = 0
- for var in self.vars:
- flags = flags | var.get()
- flags = flags
- return flags
-
- def recompile(self, event=None):
- try:
- self.compiled = re.compile(self.regexdisplay.get(),
- self.getflags())
- bg = self.promptdisplay['background']
- self.statusdisplay.config(text="", background=bg)
- except re.error, msg:
- self.compiled = None
- self.statusdisplay.config(
- text="re.error: %s" % str(msg),
- background="red")
- self.reevaluate()
-
- def reevaluate(self, event=None):
- try:
- self.stringdisplay.tag_remove("hit", "1.0", END)
- except TclError:
- pass
- try:
- self.stringdisplay.tag_remove("hit0", "1.0", END)
- except TclError:
- pass
- self.grouplist.delete(0, END)
- if not self.compiled:
- return
- self.stringdisplay.tag_configure("hit", background="yellow")
- self.stringdisplay.tag_configure("hit0", background="orange")
- text = self.stringdisplay.get("1.0", END)
- last = 0
- nmatches = 0
- while last <= len(text):
- m = self.compiled.search(text, last)
- if m is None:
- break
- first, last = m.span()
- if last == first:
- last = first+1
- tag = "hit0"
- else:
- tag = "hit"
- pfirst = "1.0 + %d chars" % first
- plast = "1.0 + %d chars" % last
- self.stringdisplay.tag_add(tag, pfirst, plast)
- if nmatches == 0:
- self.stringdisplay.yview_pickplace(pfirst)
- groups = list(m.groups())
- groups.insert(0, m.group())
- for i in range(len(groups)):
- g = "%2d: %s" % (i, `groups[i]`)
- self.grouplist.insert(END, g)
- nmatches = nmatches + 1
- if self.showvar.get() == "first":
- break
-
- if nmatches == 0:
- self.statusdisplay.config(text="(no match)",
- background="yellow")
- else:
- self.statusdisplay.config(text="")
+
+ def __init__(self, master):
+ self.master = master
+
+ self.promptdisplay = Label(self.master, anchor=W,
+ text="Enter a Perl-style regular expression:")
+ self.promptdisplay.pack(side=TOP, fill=X)
+
+ self.regexdisplay = Entry(self.master)
+ self.regexdisplay.pack(fill=X)
+ self.regexdisplay.focus_set()
+
+ self.addoptions()
+
+ self.statusdisplay = Label(self.master, text="", anchor=W)
+ self.statusdisplay.pack(side=TOP, fill=X)
+
+ self.labeldisplay = Label(self.master, anchor=W,
+ text="Enter a string to search:")
+ self.labeldisplay.pack(fill=X)
+ self.labeldisplay.pack(fill=X)
+
+ self.showframe = Frame(master)
+ self.showframe.pack(fill=X, anchor=W)
+
+ self.showvar = StringVar(master)
+ self.showvar.set("first")
+
+ self.showfirstradio = Radiobutton(self.showframe,
+ text="Highlight first match",
+ variable=self.showvar,
+ value="first",
+ command=self.recompile)
+ self.showfirstradio.pack(side=LEFT)
+
+ self.showallradio = Radiobutton(self.showframe,
+ text="Highlight all matches",
+ variable=self.showvar,
+ value="all",
+ command=self.recompile)
+ self.showallradio.pack(side=LEFT)
+
+ self.stringdisplay = Text(self.master, width=60, height=4)
+ self.stringdisplay.pack(fill=BOTH, expand=1)
+ self.stringdisplay.tag_configure("hit", background="yellow")
+
+ self.grouplabel = Label(self.master, text="Groups:", anchor=W)
+ self.grouplabel.pack(fill=X)
+
+ self.grouplist = Listbox(self.master)
+ self.grouplist.pack(expand=1, fill=BOTH)
+
+ self.regexdisplay.bind('<Key>', self.recompile)
+ self.stringdisplay.bind('<Key>', self.reevaluate)
+
+ self.compiled = None
+ self.recompile()
+
+ btags = self.regexdisplay.bindtags()
+ self.regexdisplay.bindtags(btags[1:] + btags[:1])
+
+ btags = self.stringdisplay.bindtags()
+ self.stringdisplay.bindtags(btags[1:] + btags[:1])
+
+ def addoptions(self):
+ self.frames = []
+ self.boxes = []
+ self.vars = []
+ for name in ('IGNORECASE',
+ 'LOCALE',
+ 'MULTILINE',
+ 'DOTALL',
+ 'VERBOSE'):
+ if len(self.boxes) % 3 == 0:
+ frame = Frame(self.master)
+ frame.pack(fill=X)
+ self.frames.append(frame)
+ val = getattr(re, name)
+ var = IntVar()
+ box = Checkbutton(frame,
+ variable=var, text=name,
+ offvalue=0, onvalue=val,
+ command=self.recompile)
+ box.pack(side=LEFT)
+ self.boxes.append(box)
+ self.vars.append(var)
+
+ def getflags(self):
+ flags = 0
+ for var in self.vars:
+ flags = flags | var.get()
+ flags = flags
+ return flags
+
+ def recompile(self, event=None):
+ try:
+ self.compiled = re.compile(self.regexdisplay.get(),
+ self.getflags())
+ bg = self.promptdisplay['background']
+ self.statusdisplay.config(text="", background=bg)
+ except re.error, msg:
+ self.compiled = None
+ self.statusdisplay.config(
+ text="re.error: %s" % str(msg),
+ background="red")
+ self.reevaluate()
+
+ def reevaluate(self, event=None):
+ try:
+ self.stringdisplay.tag_remove("hit", "1.0", END)
+ except TclError:
+ pass
+ try:
+ self.stringdisplay.tag_remove("hit0", "1.0", END)
+ except TclError:
+ pass
+ self.grouplist.delete(0, END)
+ if not self.compiled:
+ return
+ self.stringdisplay.tag_configure("hit", background="yellow")
+ self.stringdisplay.tag_configure("hit0", background="orange")
+ text = self.stringdisplay.get("1.0", END)
+ last = 0
+ nmatches = 0
+ while last <= len(text):
+ m = self.compiled.search(text, last)
+ if m is None:
+ break
+ first, last = m.span()
+ if last == first:
+ last = first+1
+ tag = "hit0"
+ else:
+ tag = "hit"
+ pfirst = "1.0 + %d chars" % first
+ plast = "1.0 + %d chars" % last
+ self.stringdisplay.tag_add(tag, pfirst, plast)
+ if nmatches == 0:
+ self.stringdisplay.yview_pickplace(pfirst)
+ groups = list(m.groups())
+ groups.insert(0, m.group())
+ for i in range(len(groups)):
+ g = "%2d: %s" % (i, `groups[i]`)
+ self.grouplist.insert(END, g)
+ nmatches = nmatches + 1
+ if self.showvar.get() == "first":
+ break
+
+ if nmatches == 0:
+ self.statusdisplay.config(text="(no match)",
+ background="yellow")
+ else:
+ self.statusdisplay.config(text="")
# Main function, run when invoked as a stand-alone Python program.
diff --git a/Tools/scripts/suff.py b/Tools/scripts/suff.py
index 826e236..e085cd0 100755
--- a/Tools/scripts/suff.py
+++ b/Tools/scripts/suff.py
@@ -7,23 +7,23 @@
import sys
def main():
- files = sys.argv[1:]
- suffixes = {}
- for file in files:
- suff = getsuffix(file)
- if not suffixes.has_key(suff):
- suffixes[suff] = []
- suffixes[suff].append(file)
- keys = suffixes.keys()
- keys.sort()
- for suff in keys:
- print `suff`, len(suffixes[suff])
+ files = sys.argv[1:]
+ suffixes = {}
+ for file in files:
+ suff = getsuffix(file)
+ if not suffixes.has_key(suff):
+ suffixes[suff] = []
+ suffixes[suff].append(file)
+ keys = suffixes.keys()
+ keys.sort()
+ for suff in keys:
+ print `suff`, len(suffixes[suff])
def getsuffix(file):
- suff = ''
- for i in range(len(file)):
- if file[i] == '.':
- suff = file[i:]
- return suff
+ suff = ''
+ for i in range(len(file)):
+ if file[i] == '.':
+ suff = file[i:]
+ return suff
main()
diff --git a/Tools/scripts/sum5.py b/Tools/scripts/sum5.py
index 09bc686..6d3b965 100755
--- a/Tools/scripts/sum5.py
+++ b/Tools/scripts/sum5.py
@@ -25,73 +25,73 @@ StringType = type('')
FileType = type(sys.stdin)
def sum(*files):
- sts = 0
- if files and type(files[-1]) == FileType:
- out, files = files[-1], files[:-1]
- else:
- out = sys.stdout
- if len(files) == 1 and type(files[0]) != StringType:
- files = files[0]
- for f in files:
- if type(f) == StringType:
- if f == '-':
- sts = printsumfp(sys.stdin, '<stdin>', out) or sts
- else:
- sts = printsum(f, out) or sts
- else:
- sts = sum(f, out) or sts
- return sts
+ sts = 0
+ if files and type(files[-1]) == FileType:
+ out, files = files[-1], files[:-1]
+ else:
+ out = sys.stdout
+ if len(files) == 1 and type(files[0]) != StringType:
+ files = files[0]
+ for f in files:
+ if type(f) == StringType:
+ if f == '-':
+ sts = printsumfp(sys.stdin, '<stdin>', out) or sts
+ else:
+ sts = printsum(f, out) or sts
+ else:
+ sts = sum(f, out) or sts
+ return sts
def printsum(file, out = sys.stdout):
- try:
- fp = open(file, rmode)
- except IOError, msg:
- sys.stderr.write('%s: Can\'t open: %s\n' % (file, msg))
- return 1
- if fnfilter:
- file = fnfilter(file)
- sts = printsumfp(fp, file, out)
- fp.close()
- return sts
+ try:
+ fp = open(file, rmode)
+ except IOError, msg:
+ sys.stderr.write('%s: Can\'t open: %s\n' % (file, msg))
+ return 1
+ if fnfilter:
+ file = fnfilter(file)
+ sts = printsumfp(fp, file, out)
+ fp.close()
+ return sts
def printsumfp(fp, file, out = sys.stdout):
- m = md5.md5()
- try:
- while 1:
- data = fp.read(bufsize)
- if not data: break
- m.update(data)
- except IOError, msg:
- sys.stderr.write('%s: I/O error: %s\n' % (file, msg))
- return 1
- out.write('%s %s\n' % (hexify(m.digest()), file))
- return 0
+ m = md5.md5()
+ try:
+ while 1:
+ data = fp.read(bufsize)
+ if not data: break
+ m.update(data)
+ except IOError, msg:
+ sys.stderr.write('%s: I/O error: %s\n' % (file, msg))
+ return 1
+ out.write('%s %s\n' % (hexify(m.digest()), file))
+ return 0
def hexify(s):
- res = ''
- for c in s:
- res = res + '%02x' % ord(c)
- return res
+ res = ''
+ for c in s:
+ res = res + '%02x' % ord(c)
+ return res
def main(args = sys.argv[1:], out = sys.stdout):
- global fnfilter, rmode, bufsize
- import getopt
- try:
- opts, args = getopt.getopt(args, 'blts:')
- except getopt.error, msg:
- sys.stderr.write('%s: %s\n%s' % (sys.argv[0], msg, usage))
- return 2
- for o, a in opts:
- if o == '-l':
- fnfilter = os.path.basename
- if o == '-b':
- rmode = 'rb'
- if o == '-t':
- rmode = 'r'
- if o == '-s':
- bufsize = string.atoi(a)
- if not args: args = ['-']
- return sum(args, out)
+ global fnfilter, rmode, bufsize
+ import getopt
+ try:
+ opts, args = getopt.getopt(args, 'blts:')
+ except getopt.error, msg:
+ sys.stderr.write('%s: %s\n%s' % (sys.argv[0], msg, usage))
+ return 2
+ for o, a in opts:
+ if o == '-l':
+ fnfilter = os.path.basename
+ if o == '-b':
+ rmode = 'rb'
+ if o == '-t':
+ rmode = 'r'
+ if o == '-s':
+ bufsize = string.atoi(a)
+ if not args: args = ['-']
+ return sum(args, out)
if __name__ == '__main__' or __name__ == sys.argv[0]:
- sys.exit(main(sys.argv[1:], sys.stdout))
+ sys.exit(main(sys.argv[1:], sys.stdout))
diff --git a/Tools/scripts/texi2html.py b/Tools/scripts/texi2html.py
index 8c747aa..dfe96db 100755
--- a/Tools/scripts/texi2html.py
+++ b/Tools/scripts/texi2html.py
@@ -46,13 +46,13 @@ blprog = re.compile('^[ \t]*$') # Blank line
kwprog = re.compile('@[a-z]+') # Keyword (embedded, usually
# with {} args)
spprog = re.compile('[\n@{}&<>]') # Special characters in
- # running text
+ # running text
#
# menu item (Yuck!)
miprog = re.compile('^\* ([^:]*):(:|[ \t]*([^\t,\n.]+)([^ \t\n]*))[ \t\n]*')
-
+
class HTMLNode:
"""Some of the parser's functionality is separated into this class.
@@ -1568,7 +1568,7 @@ def test():
print_headers = 0
cont = 0
html3 = 0
-
+
while sys.argv[1:2] == ['-d']:
debugging = debugging + 1
del sys.argv[1:2]
diff --git a/Tools/scripts/trace.py b/Tools/scripts/trace.py
index d8016b0..78715e0 100644
--- a/Tools/scripts/trace.py
+++ b/Tools/scripts/trace.py
@@ -261,7 +261,7 @@ def find_executable_linenos(filename):
# The only way I know to find line numbers is to look for the
# SET_LINENO instructions. Isn't there some way to get it from
# the AST?
-
+
return _find_LINENO(code)
### XXX because os.path.commonprefix seems broken by my way of thinking...
@@ -279,7 +279,7 @@ def commonprefix(dirs):
if i == 0: return ''
break
return os.sep.join(prefix)
-
+
def create_results_log(results, dirname = ".", show_missing = 1,
save_counts = 0):
import re
@@ -297,7 +297,7 @@ def create_results_log(results, dirname = ".", show_missing = 1,
results.update(results.__class__(counts, modules))
except IOError:
pass
-
+
# there are many places where this is insufficient, like a blank
# line embedded in a multiline string.
blank = re.compile(r'^\s*(#.*)?$')
@@ -307,7 +307,7 @@ def create_results_log(results, dirname = ".", show_missing = 1,
tfdir = tempfile.gettempdir()
for key in per_file.keys():
filename = key
-
+
# skip some "files" we don't care about...
if filename == "<string>":
continue
@@ -484,7 +484,7 @@ class Trace:
print '%s(%d): ??' % (modulename, lineno)
return self.trace
-
+
def _err_exit(msg):
sys.stderr.write("%s: %s\n" % (sys.argv[0], msg))
diff --git a/Tools/scripts/treesync.py b/Tools/scripts/treesync.py
index ded0b17..96beba0 100755
--- a/Tools/scripts/treesync.py
+++ b/Tools/scripts/treesync.py
@@ -17,7 +17,7 @@ entry in the master tree are synchronized. This means:
copy the slave to the master
else (the master is newer):
copy the master to the slave
-
+
normalizing the slave means replacing CRLF with LF when the master
doesn't use CRLF
@@ -59,7 +59,7 @@ def main():
print "slavedir masterdir"
return
process(slave, master)
-
+
def process(slave, master):
cvsdir = os.path.join(master, "CVS")
if not os.path.isdir(cvsdir):
diff --git a/Tools/scripts/which.py b/Tools/scripts/which.py
index a05d919..96e242c 100755
--- a/Tools/scripts/which.py
+++ b/Tools/scripts/which.py
@@ -11,7 +11,7 @@ import sys, os, string
from stat import *
def msg(str):
- sys.stderr.write(str + '\n')
+ sys.stderr.write(str + '\n')
pathlist = string.splitfields(os.environ['PATH'], ':')
@@ -19,38 +19,38 @@ sts = 0
longlist = ''
if sys.argv[1:] and sys.argv[1][:2] == '-l':
- longlist = sys.argv[1]
- del sys.argv[1]
+ longlist = sys.argv[1]
+ del sys.argv[1]
for prog in sys.argv[1:]:
- ident = ()
- for dir in pathlist:
- file = os.path.join(dir, prog)
- try:
- st = os.stat(file)
- except os.error:
- continue
- if not S_ISREG(st[ST_MODE]):
- msg(file + ': not a disk file')
- else:
- mode = S_IMODE(st[ST_MODE])
- if mode & 0111:
- if not ident:
- print file
- ident = st[:3]
- else:
- if st[:3] == ident:
- s = 'same as: '
- else:
- s = 'also: '
- msg(s + file)
- else:
- msg(file + ': not executable')
- if longlist:
- sts = os.system('ls ' + longlist + ' ' + file)
- if sts: msg('"ls -l" exit status: ' + `sts`)
- if not ident:
- msg(prog + ': not found')
- sts = 1
+ ident = ()
+ for dir in pathlist:
+ file = os.path.join(dir, prog)
+ try:
+ st = os.stat(file)
+ except os.error:
+ continue
+ if not S_ISREG(st[ST_MODE]):
+ msg(file + ': not a disk file')
+ else:
+ mode = S_IMODE(st[ST_MODE])
+ if mode & 0111:
+ if not ident:
+ print file
+ ident = st[:3]
+ else:
+ if st[:3] == ident:
+ s = 'same as: '
+ else:
+ s = 'also: '
+ msg(s + file)
+ else:
+ msg(file + ': not executable')
+ if longlist:
+ sts = os.system('ls ' + longlist + ' ' + file)
+ if sts: msg('"ls -l" exit status: ' + `sts`)
+ if not ident:
+ msg(prog + ': not found')
+ sts = 1
sys.exit(sts)
diff --git a/Tools/scripts/xxci.py b/Tools/scripts/xxci.py
index d8608a0..2567bc5 100755
--- a/Tools/scripts/xxci.py
+++ b/Tools/scripts/xxci.py
@@ -16,102 +16,102 @@ EXECMAGIC = '\001\140\000\010'
MAXSIZE = 200*1024 # Files this big must be binaries and are skipped.
def getargs():
- args = sys.argv[1:]
- if args:
- return args
- print 'No arguments, checking almost *, in "ls -t" order'
- list = []
- for file in os.listdir(os.curdir):
- if not skipfile(file):
- list.append((getmtime(file), file))
- list.sort()
- if not list:
- print 'Nothing to do -- exit 1'
- sys.exit(1)
- list.sort()
- list.reverse()
- for mtime, file in list: args.append(file)
- return args
+ args = sys.argv[1:]
+ if args:
+ return args
+ print 'No arguments, checking almost *, in "ls -t" order'
+ list = []
+ for file in os.listdir(os.curdir):
+ if not skipfile(file):
+ list.append((getmtime(file), file))
+ list.sort()
+ if not list:
+ print 'Nothing to do -- exit 1'
+ sys.exit(1)
+ list.sort()
+ list.reverse()
+ for mtime, file in list: args.append(file)
+ return args
def getmtime(file):
- try:
- st = os.stat(file)
- return st[ST_MTIME]
- except os.error:
- return -1
+ try:
+ st = os.stat(file)
+ return st[ST_MTIME]
+ except os.error:
+ return -1
badnames = ['tags', 'TAGS', 'xyzzy', 'nohup.out', 'core']
badprefixes = ['.', ',', '@', '#', 'o.']
badsuffixes = \
- ['~', '.a', '.o', '.old', '.bak', '.orig', '.new', '.prev', '.not', \
- '.pyc', '.fdc', '.rgb', '.elc', ',v']
+ ['~', '.a', '.o', '.old', '.bak', '.orig', '.new', '.prev', '.not', \
+ '.pyc', '.fdc', '.rgb', '.elc', ',v']
ignore = []
def setup():
- ignore[:] = badnames
- for p in badprefixes:
- ignore.append(p + '*')
- for p in badsuffixes:
- ignore.append('*' + p)
- try:
- f = open('.xxcign', 'r')
- except IOError:
- return
- ignore[:] = ignore + string.split(f.read())
+ ignore[:] = badnames
+ for p in badprefixes:
+ ignore.append(p + '*')
+ for p in badsuffixes:
+ ignore.append('*' + p)
+ try:
+ f = open('.xxcign', 'r')
+ except IOError:
+ return
+ ignore[:] = ignore + string.split(f.read())
def skipfile(file):
- for p in ignore:
- if fnmatch.fnmatch(file, p): return 1
- try:
- st = os.lstat(file)
- except os.error:
- return 1 # Doesn't exist -- skip it
- # Skip non-plain files.
- if not S_ISREG(st[ST_MODE]): return 1
- # Skip huge files -- probably binaries.
- if st[ST_SIZE] >= MAXSIZE: return 1
- # Skip executables
- try:
- data = open(file, 'r').read(len(EXECMAGIC))
- if data == EXECMAGIC: return 1
- except:
- pass
- return 0
+ for p in ignore:
+ if fnmatch.fnmatch(file, p): return 1
+ try:
+ st = os.lstat(file)
+ except os.error:
+ return 1 # Doesn't exist -- skip it
+ # Skip non-plain files.
+ if not S_ISREG(st[ST_MODE]): return 1
+ # Skip huge files -- probably binaries.
+ if st[ST_SIZE] >= MAXSIZE: return 1
+ # Skip executables
+ try:
+ data = open(file, 'r').read(len(EXECMAGIC))
+ if data == EXECMAGIC: return 1
+ except:
+ pass
+ return 0
def badprefix(file):
- for bad in badprefixes:
- if file[:len(bad)] == bad: return 1
- return 0
+ for bad in badprefixes:
+ if file[:len(bad)] == bad: return 1
+ return 0
def badsuffix(file):
- for bad in badsuffixes:
- if file[-len(bad):] == bad: return 1
- return 0
+ for bad in badsuffixes:
+ if file[-len(bad):] == bad: return 1
+ return 0
def go(args):
- for file in args:
- print file + ':'
- if differing(file):
- showdiffs(file)
- if askyesno('Check in ' + file + ' ? '):
- sts = os.system('rcs -l ' + file) # ignored
- sts = os.system('ci -l ' + file)
+ for file in args:
+ print file + ':'
+ if differing(file):
+ showdiffs(file)
+ if askyesno('Check in ' + file + ' ? '):
+ sts = os.system('rcs -l ' + file) # ignored
+ sts = os.system('ci -l ' + file)
def differing(file):
- cmd = 'co -p ' + file + ' 2>/dev/null | cmp -s - ' + file
- sts = os.system(cmd)
- return sts != 0
+ cmd = 'co -p ' + file + ' 2>/dev/null | cmp -s - ' + file
+ sts = os.system(cmd)
+ return sts != 0
def showdiffs(file):
- cmd = 'rcsdiff ' + file + ' 2>&1 | ${PAGER-more}'
- sts = os.system(cmd)
+ cmd = 'rcsdiff ' + file + ' 2>&1 | ${PAGER-more}'
+ sts = os.system(cmd)
def askyesno(prompt):
- s = raw_input(prompt)
- return s in ['y', 'yes']
+ s = raw_input(prompt)
+ return s in ['y', 'yes']
try:
- setup()
- go(getargs())
+ setup()
+ go(getargs())
except KeyboardInterrupt:
- print '[Intr]'
+ print '[Intr]'