summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-10-11 08:07:57 (GMT)
committerGitHub <noreply@github.com>2022-10-11 08:07:57 (GMT)
commite0ae9ddffe0a708d0d3f5b8cc10488d466fc43c4 (patch)
treebc97c042724b8c89a29d36f81b1f804070622784 /Tools
parentb399115ef18945f7526492225d72a512048ad20d (diff)
downloadcpython-e0ae9ddffe0a708d0d3f5b8cc10488d466fc43c4.zip
cpython-e0ae9ddffe0a708d0d3f5b8cc10488d466fc43c4.tar.gz
cpython-e0ae9ddffe0a708d0d3f5b8cc10488d466fc43c4.tar.bz2
gh-97669: Remove outdated example scripts (#97675) (#98167)
Remove outdated example scripts of the Tools/scripts/ directory: * gprof2html.py * md5sum.py * nm2def.py * pathfix.py * win_add2path.py Remove test_gprof2html, test_md5sum and test_pathfix of test_tools.
Diffstat (limited to 'Tools')
-rw-r--r--Tools/scripts/README9
-rwxr-xr-xTools/scripts/gprof2html.py87
-rwxr-xr-xTools/scripts/md5sum.py93
-rwxr-xr-xTools/scripts/nm2def.py104
-rwxr-xr-xTools/scripts/pathfix.py225
-rw-r--r--Tools/scripts/win_add2path.py58
6 files changed, 0 insertions, 576 deletions
diff --git a/Tools/scripts/README b/Tools/scripts/README
index 70ea5f4..2fccecc 100644
--- a/Tools/scripts/README
+++ b/Tools/scripts/README
@@ -4,20 +4,11 @@ useful while building, extending or managing Python.
2to3 Main script for running the 2to3 conversion tool
abitype.py Converts a C file to use the PEP 384 type definition API
combinerefs.py A helper for analyzing PYTHONDUMPREFS output
-diff.py Print file diffs in context, unified, or ndiff formats
-gprof2html.py Transform gprof(1) output into useful HTML
idle3 Main program to start IDLE
-md5sum.py Print MD5 checksums of argument files
-ndiff.py Intelligent diff between text files (Tim Peters)
-nm2def.py Create a template for PC/python_nt.def (Marc Lemburg)
-parseentities.py Utility for parsing HTML entity definitions
parse_html5_entities.py Utility for parsing HTML5 entity definitions
patchcheck.py Perform common checks and cleanup before committing
-pathfix.py Change #!/usr/local/bin/python into something else
-ptags.py Create vi tags file for Python modules
pydoc3 Python documentation browser
reindent.py Change .py files to use 4-space indents
run_tests.py Run the test suite with more sensible default options
stable_abi.py Stable ABI checks and file generators.
untabify.py Replace tabs with spaces in argument files
-win_add2path.py Add Python to the search path on Windows
diff --git a/Tools/scripts/gprof2html.py b/Tools/scripts/gprof2html.py
deleted file mode 100755
index bf0530e..0000000
--- a/Tools/scripts/gprof2html.py
+++ /dev/null
@@ -1,87 +0,0 @@
-#! /usr/bin/env python3
-
-"""Transform gprof(1) output into useful HTML."""
-
-import html
-import os
-import re
-import sys
-import webbrowser
-
-header = """\
-<html>
-<head>
- <title>gprof output (%s)</title>
-</head>
-<body>
-<pre>
-"""
-
-trailer = """\
-</pre>
-</body>
-</html>
-"""
-
-def add_escapes(filename):
- with open(filename, encoding="utf-8") as fp:
- for line in fp:
- yield html.escape(line)
-
-def gprof2html(input, output, filename):
- output.write(header % filename)
- for line in input:
- output.write(line)
- if line.startswith(" time"):
- break
- labels = {}
- for line in input:
- m = re.match(r"(.* )(\w+)\n", line)
- if not m:
- output.write(line)
- break
- stuff, fname = m.group(1, 2)
- labels[fname] = fname
- output.write('%s<a name="flat:%s" href="#call:%s">%s</a>\n' %
- (stuff, fname, fname, fname))
- for line in input:
- output.write(line)
- if line.startswith("index % time"):
- break
- for line in input:
- m = re.match(r"(.* )(\w+)(( &lt;cycle.*&gt;)? \[\d+\])\n", line)
- if not m:
- output.write(line)
- if line.startswith("Index by function name"):
- break
- continue
- prefix, fname, suffix = m.group(1, 2, 3)
- if fname not in labels:
- output.write(line)
- continue
- if line.startswith("["):
- output.write('%s<a name="call:%s" href="#flat:%s">%s</a>%s\n' %
- (prefix, fname, fname, fname, suffix))
- else:
- output.write('%s<a href="#call:%s">%s</a>%s\n' %
- (prefix, fname, fname, suffix))
- for line in input:
- for part in re.findall(r"(\w+(?:\.c)?|\W+)", line):
- if part in labels:
- part = '<a href="#call:%s">%s</a>' % (part, part)
- output.write(part)
- output.write(trailer)
-
-
-def main():
- filename = "gprof.out"
- if sys.argv[1:]:
- filename = sys.argv[1]
- outputfilename = filename + ".html"
- input = add_escapes(filename)
- with open(outputfilename, "w", encoding="utf-8") as output:
- gprof2html(input, output, filename)
- webbrowser.open("file:" + os.path.abspath(outputfilename))
-
-if __name__ == '__main__':
- main()
diff --git a/Tools/scripts/md5sum.py b/Tools/scripts/md5sum.py
deleted file mode 100755
index f910576..0000000
--- a/Tools/scripts/md5sum.py
+++ /dev/null
@@ -1,93 +0,0 @@
-#! /usr/bin/env python3
-
-"""Python utility to print MD5 checksums of argument files.
-"""
-
-
-bufsize = 8096
-fnfilter = None
-rmode = 'rb'
-
-usage = """
-usage: md5sum.py [-b] [-t] [-l] [-s bufsize] [file ...]
--b : read files in binary mode (default)
--t : read files in text mode (you almost certainly don't want this!)
--l : print last pathname component only
--s bufsize: read buffer size (default %d)
-file ... : files to sum; '-' or no files means stdin
-""" % bufsize
-
-import io
-import sys
-import os
-import getopt
-from hashlib import md5
-
-def sum(*files):
- sts = 0
- if files and isinstance(files[-1], io.IOBase):
- out, files = files[-1], files[:-1]
- else:
- out = sys.stdout
- if len(files) == 1 and not isinstance(files[0], str):
- files = files[0]
- for f in files:
- if isinstance(f, str):
- 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(filename, out=sys.stdout):
- try:
- fp = open(filename, rmode)
- except IOError as msg:
- sys.stderr.write('%s: Can\'t open: %s\n' % (filename, msg))
- return 1
- with fp:
- if fnfilter:
- filename = fnfilter(filename)
- sts = printsumfp(fp, filename, out)
- return sts
-
-def printsumfp(fp, filename, out=sys.stdout):
- m = md5()
- try:
- while 1:
- data = fp.read(bufsize)
- if not data:
- break
- if isinstance(data, str):
- data = data.encode(fp.encoding)
- m.update(data)
- except IOError as msg:
- sys.stderr.write('%s: I/O error: %s\n' % (filename, msg))
- return 1
- out.write('%s %s\n' % (m.hexdigest(), filename))
- return 0
-
-def main(args = sys.argv[1:], out=sys.stdout):
- global fnfilter, rmode, bufsize
- try:
- opts, args = getopt.getopt(args, 'blts:')
- except getopt.error as 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
- elif o == '-b':
- rmode = 'rb'
- elif o == '-t':
- rmode = 'r'
- elif o == '-s':
- bufsize = int(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))
diff --git a/Tools/scripts/nm2def.py b/Tools/scripts/nm2def.py
deleted file mode 100755
index a885ebd..0000000
--- a/Tools/scripts/nm2def.py
+++ /dev/null
@@ -1,104 +0,0 @@
-#! /usr/bin/env python3
-"""nm2def.py
-
-Helpers to extract symbols from Unix libs and auto-generate
-Windows definition files from them. Depends on nm(1). Tested
-on Linux and Solaris only (-p option to nm is for Solaris only).
-
-By Marc-Andre Lemburg, Aug 1998.
-
-Additional notes: the output of nm is supposed to look like this:
-
-acceler.o:
-000001fd T PyGrammar_AddAccelerators
- U PyGrammar_FindDFA
-00000237 T PyGrammar_RemoveAccelerators
- U _IO_stderr_
- U exit
- U fprintf
- U free
- U malloc
- U printf
-
-grammar1.o:
-00000000 T PyGrammar_FindDFA
-00000034 T PyGrammar_LabelRepr
- U _PyParser_TokenNames
- U abort
- U printf
- U sprintf
-
-...
-
-Even if this isn't the default output of your nm, there is generally an
-option to produce this format (since it is the original v7 Unix format).
-
-"""
-import os, sys
-
-PYTHONLIB = 'libpython%d.%d.a' % sys.version_info[:2]
-PC_PYTHONLIB = 'Python%d%d.dll' % sys.version_info[:2]
-NM = 'nm -p -g %s' # For Linux, use "nm -g %s"
-
-def symbols(lib=PYTHONLIB,types=('T','C','D')):
-
- with os.popen(NM % lib) as pipe:
- lines = pipe.readlines()
- lines = [s.strip() for s in lines]
- symbols = {}
- for line in lines:
- if len(line) == 0 or ':' in line:
- continue
- items = line.split()
- if len(items) != 3:
- continue
- address, type, name = items
- if type not in types:
- continue
- symbols[name] = address,type
- return symbols
-
-def export_list(symbols):
-
- data = []
- code = []
- for name,(addr,type) in symbols.items():
- if type in ('C','D'):
- data.append('\t'+name)
- else:
- code.append('\t'+name)
- data.sort()
- data.append('')
- code.sort()
- return ' DATA\n'.join(data)+'\n'+'\n'.join(code)
-
-# Definition file template
-DEF_TEMPLATE = """\
-EXPORTS
-%s
-"""
-
-# Special symbols that have to be included even though they don't
-# pass the filter
-SPECIALS = (
- )
-
-def filter_Python(symbols,specials=SPECIALS):
-
- for name in list(symbols.keys()):
- if name[:2] == 'Py' or name[:3] == '_Py':
- pass
- elif name not in specials:
- del symbols[name]
-
-def main():
-
- s = symbols(PYTHONLIB)
- filter_Python(s)
- exports = export_list(s)
- 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/pathfix.py b/Tools/scripts/pathfix.py
deleted file mode 100755
index f957b11..0000000
--- a/Tools/scripts/pathfix.py
+++ /dev/null
@@ -1,225 +0,0 @@
-#!/usr/bin/env python3
-
-# Change the #! line (shebang) occurring in Python scripts. The new interpreter
-# pathname must be given with a -i option.
-#
-# Command line arguments are files or directories to be processed.
-# Directories are searched recursively for files whose name looks
-# like a python module.
-# Symbolic links are always ignored (except as explicit directory
-# arguments).
-# The original file is kept as a back-up (with a "~" attached to its name),
-# -n flag can be used to disable this.
-
-# Sometimes you may find shebangs with flags such as `#! /usr/bin/env python -si`.
-# Normally, pathfix overwrites the entire line, including the flags.
-# To change interpreter and keep flags from the original shebang line, use -k.
-# If you want to keep flags and add to them one single literal flag, use option -a.
-
-
-# Undoubtedly you can do this using find and sed or perl, but this is
-# a nice example of Python code that recurses down a directory tree
-# and uses regular expressions. Also note several subtleties like
-# preserving the file's mode and avoiding to even write a temp file
-# when no changes are needed for a file.
-#
-# NB: by changing only the function fixfile() you can turn this
-# into a program for a different change to Python programs...
-
-import sys
-import os
-from stat import *
-import getopt
-
-err = sys.stderr.write
-dbg = err
-rep = sys.stdout.write
-
-new_interpreter = None
-preserve_timestamps = False
-create_backup = True
-keep_flags = False
-add_flags = b''
-
-
-def main():
- global new_interpreter
- global preserve_timestamps
- global create_backup
- global keep_flags
- global add_flags
-
- usage = ('usage: %s -i /interpreter -p -n -k -a file-or-directory ...\n' %
- sys.argv[0])
- try:
- opts, args = getopt.getopt(sys.argv[1:], 'i:a:kpn')
- except getopt.error as msg:
- err(str(msg) + '\n')
- err(usage)
- sys.exit(2)
- for o, a in opts:
- if o == '-i':
- new_interpreter = a.encode()
- if o == '-p':
- preserve_timestamps = True
- if o == '-n':
- create_backup = False
- if o == '-k':
- keep_flags = True
- if o == '-a':
- add_flags = a.encode()
- if b' ' in add_flags:
- err("-a option doesn't support whitespaces")
- sys.exit(2)
- if not new_interpreter or not new_interpreter.startswith(b'/') 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)
-
-
-def ispython(name):
- return name.endswith('.py')
-
-
-def recursedown(dirname):
- dbg('recursedown(%r)\n' % (dirname,))
- bad = 0
- try:
- names = os.listdir(dirname)
- except OSError as msg:
- err('%s: cannot list directory: %r\n' % (dirname, msg))
- 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(%r)\n' % (filename,))
- try:
- f = open(filename, 'rb')
- except IOError as msg:
- err('%s: cannot open: %r\n' % (filename, msg))
- return 1
- with f:
- line = f.readline()
- fixed = fixline(line)
- if line == fixed:
- rep(filename+': no change\n')
- return
- head, tail = os.path.split(filename)
- tempname = os.path.join(head, '@' + tail)
- try:
- g = open(tempname, 'wb')
- except IOError as msg:
- err('%s: cannot create: %r\n' % (tempname, msg))
- return 1
- with g:
- rep(filename + ': updating\n')
- g.write(fixed)
- BUFSIZE = 8*1024
- while 1:
- buf = f.read(BUFSIZE)
- if not buf: break
- g.write(buf)
-
- # Finishing touch -- move files
-
- mtime = None
- atime = None
- # First copy the file's mode to the temp file
- try:
- statbuf = os.stat(filename)
- mtime = statbuf.st_mtime
- atime = statbuf.st_atime
- os.chmod(tempname, statbuf[ST_MODE] & 0o7777)
- except OSError as msg:
- err('%s: warning: chmod failed (%r)\n' % (tempname, msg))
- # Then make a backup of the original file as filename~
- if create_backup:
- try:
- os.rename(filename, filename + '~')
- except OSError as msg:
- err('%s: warning: backup failed (%r)\n' % (filename, msg))
- else:
- try:
- os.remove(filename)
- except OSError as msg:
- err('%s: warning: removing failed (%r)\n' % (filename, msg))
- # Now move the temp file to the original file
- try:
- os.rename(tempname, filename)
- except OSError as msg:
- err('%s: rename failed (%r)\n' % (filename, msg))
- return 1
- if preserve_timestamps:
- if atime and mtime:
- try:
- os.utime(filename, (atime, mtime))
- except OSError as msg:
- err('%s: reset of timestamp failed (%r)\n' % (filename, msg))
- return 1
- # Return success
- return 0
-
-
-def parse_shebang(shebangline):
- shebangline = shebangline.rstrip(b'\n')
- start = shebangline.find(b' -')
- if start == -1:
- return b''
- return shebangline[start:]
-
-
-def populate_flags(shebangline):
- old_flags = b''
- if keep_flags:
- old_flags = parse_shebang(shebangline)
- if old_flags:
- old_flags = old_flags[2:]
- if not (old_flags or add_flags):
- return b''
- # On Linux, the entire string following the interpreter name
- # is passed as a single argument to the interpreter.
- # e.g. "#! /usr/bin/python3 -W Error -s" runs "/usr/bin/python3 "-W Error -s"
- # so shebang should have single '-' where flags are given and
- # flag might need argument for that reasons adding new flags is
- # between '-' and original flags
- # e.g. #! /usr/bin/python3 -sW Error
- return b' -' + add_flags + old_flags
-
-
-def fixline(line):
- if not line.startswith(b'#!'):
- return line
-
- if b"python" not in line:
- return line
-
- flags = populate_flags(line)
- return b'#! ' + new_interpreter + flags + b'\n'
-
-
-if __name__ == '__main__':
- main()
diff --git a/Tools/scripts/win_add2path.py b/Tools/scripts/win_add2path.py
deleted file mode 100644
index 1c9aedc..0000000
--- a/Tools/scripts/win_add2path.py
+++ /dev/null
@@ -1,58 +0,0 @@
-"""Add Python to the search path on Windows
-
-This is a simple script to add Python to the Windows search path. It
-modifies the current user (HKCU) tree of the registry.
-
-Copyright (c) 2008 by Christian Heimes <christian@cheimes.de>
-Licensed to PSF under a Contributor Agreement.
-"""
-
-import sys
-import site
-import os
-import winreg
-
-HKCU = winreg.HKEY_CURRENT_USER
-ENV = "Environment"
-PATH = "PATH"
-DEFAULT = "%PATH%"
-
-def modify():
- pythonpath = os.path.dirname(os.path.normpath(sys.executable))
- scripts = os.path.join(pythonpath, "Scripts")
- appdata = os.environ["APPDATA"]
- if hasattr(site, "USER_SITE"):
- usersite = site.USER_SITE.replace(appdata, "%APPDATA%")
- userpath = os.path.dirname(usersite)
- userscripts = os.path.join(userpath, "Scripts")
- else:
- userscripts = None
-
- with winreg.CreateKey(HKCU, ENV) as key:
- try:
- envpath = winreg.QueryValueEx(key, PATH)[0]
- except OSError:
- envpath = DEFAULT
-
- paths = [envpath]
- for path in (pythonpath, scripts, userscripts):
- if path and path not in envpath and os.path.isdir(path):
- paths.append(path)
-
- envpath = os.pathsep.join(paths)
- winreg.SetValueEx(key, PATH, 0, winreg.REG_EXPAND_SZ, envpath)
- return paths, envpath
-
-def main():
- paths, envpath = modify()
- if len(paths) > 1:
- print("Path(s) added:")
- print('\n'.join(paths[1:]))
- else:
- print("No path was added")
- print("\nPATH is now:\n%s\n" % envpath)
- print("Expanded:")
- print(winreg.ExpandEnvironmentStrings(envpath))
-
-if __name__ == '__main__':
- main()