aboutsummaryrefslogtreecommitdiff
path: root/demo/scripts
diff options
context:
space:
mode:
authorSkip Montanaro <[email protected]>2021-02-16 14:40:46 -0600
committerSkip Montanaro <[email protected]>2021-02-16 14:40:46 -0600
commita19a216bc60160c162e616145ef091dd18ce4e61 (patch)
treefa4bdff21f9b04a125c84a2bfab8a1c738359e15 /demo/scripts
downloadpython-0.9.1-patched-QoL-a19a216bc60160c162e616145ef091dd18ce4e61.tar.xz
python-0.9.1-patched-QoL-a19a216bc60160c162e616145ef091dd18ce4e61.zip
Python 0.9.1 as posted in alt.sources
Diffstat (limited to 'demo/scripts')
-rwxr-xr-xdemo/scripts/findlinksto.py29
-rwxr-xr-xdemo/scripts/mkreal.py65
-rwxr-xr-xdemo/scripts/ptags.py66
-rwxr-xr-xdemo/scripts/suff.py29
-rwxr-xr-xdemo/scripts/xxci.py77
5 files changed, 266 insertions, 0 deletions
diff --git a/demo/scripts/findlinksto.py b/demo/scripts/findlinksto.py
new file mode 100755
index 0000000..210441e
--- /dev/null
+++ b/demo/scripts/findlinksto.py
@@ -0,0 +1,29 @@
+#! /ufs/guido/bin/sgi/python
+
+# findlinksto
+#
+# find symbolic links to a given path
+
+import posix, path, sys
+
+def visit(pattern, dirname, names):
+ if path.islink(dirname):
+ names[:] = []
+ return
+ if path.ismount(dirname):
+ print 'descend into', dirname
+ n = len(pattern)
+ for name in names:
+ name = path.cat(dirname, name)
+ try:
+ linkto = posix.readlink(name)
+ if linkto[:n] = pattern:
+ print name, '->', linkto
+ except posix.error:
+ pass
+
+def main(pattern, args):
+ for dirname in args:
+ path.walk(dirname, visit, pattern)
+
+main(sys.argv[1], sys.argv[2:])
diff --git a/demo/scripts/mkreal.py b/demo/scripts/mkreal.py
new file mode 100755
index 0000000..19fef28
--- /dev/null
+++ b/demo/scripts/mkreal.py
@@ -0,0 +1,65 @@
+#! /ufs/guido/bin/sgi/python
+
+# mkreal
+#
+# turn a symlink to a directory into a real directory
+
+import sys
+import posix
+import path
+from stat import *
+
+cat = path.cat
+
+error = 'mkreal error'
+
+BUFSIZE = 32*1024
+
+def mkrealfile(name):
+ st = posix.stat(name) # Get the mode
+ mode = S_IMODE(st[ST_MODE])
+ linkto = posix.readlink(name) # Make sure again it's a symlink
+ f_in = open(name, 'r') # This ensures it's a file
+ posix.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
+ posix.chmod(name, mode)
+
+def mkrealdir(name):
+ st = posix.stat(name) # Get the mode
+ mode = S_IMODE(st[ST_MODE])
+ linkto = posix.readlink(name)
+ files = posix.listdir(name)
+ posix.unlink(name)
+ posix.mkdir(name, mode)
+ posix.chmod(name, mode)
+ linkto = cat('..', linkto)
+ #
+ for file in files:
+ if file not in ('.', '..'):
+ posix.symlink(cat(linkto, file), cat(name, file))
+
+def main():
+ sys.stdout = sys.stderr
+ progname = path.basename(sys.argv[0])
+ args = sys.argv[1:]
+ if not args:
+ print 'usage:', progname, 'path ...'
+ sys.exit(2)
+ status = 0
+ for name in args:
+ if not path.islink(name):
+ print progname+':', name+':', 'not a symlink'
+ status = 1
+ else:
+ if path.isdir(name):
+ mkrealdir(name)
+ else:
+ mkrealfile(name)
+ sys.exit(status)
+
+main()
diff --git a/demo/scripts/ptags.py b/demo/scripts/ptags.py
new file mode 100755
index 0000000..0f99650
--- /dev/null
+++ b/demo/scripts/ptags.py
@@ -0,0 +1,66 @@
+#! /ufs/guido/bin/sgi/python
+
+# ptags
+#
+Create a tags file for Python programs
+# Tagged are:
+# - functions (even inside other defs or classes)
+# - classes
+# - filenames
+# Warns about files it cannot open.
+# No warnings about duplicate tags.
+
+import sys
+import posix
+import path
+import string
+
+keywords = ['def', 'class'] # If you add keywords, update starts!!!
+starts = 'dc' # Starting characters of keywords
+
+whitespace = string.whitespace
+identchars = string.letters + string.digits + '_'
+
+tags = [] # Modified!
+
+def main():
+ args = sys.argv[1:]
+ for file in args: treat_file(file)
+ if tags:
+ fp = open('tags', 'w')
+ tags.sort()
+ for s in tags: fp.write(s)
+
+def treat_file(file):
+ try:
+ fp = open(file, 'r')
+ except:
+ print 'Cannot open', file
+ return
+ base = path.basename(file)
+ if base[-3:] = '.py': base = base[:-3]
+ s = base + '\t' + file + '\t' + '1\n'
+ tags.append(s)
+ while 1:
+ line = fp.readline()
+ if not line: break
+ maketag(line, file)
+
+def maketag(line, file):
+ i = 0
+ while line[i:i+1] in whitespace: i = i+1
+ if line[i:i+1] not in starts: return
+ n = len(line)
+ j = i
+ while i < n and line[i] not in whitespace: i = i+1
+ if line[j:i] not in keywords: return
+ while i < n and line[i] in whitespace: i = i+1
+ j = i
+ while i < n and line[i] in identchars: i = i+1
+ name = line[j:i]
+ while i < n and line[i] in whitespace: i = i+1
+ if i < n and line[i] = '(': i = i+1
+ s = name + '\t' + file + '\t' + '/^' + line[:i] + '/\n'
+ tags.append(s)
+
+main()
diff --git a/demo/scripts/suff.py b/demo/scripts/suff.py
new file mode 100755
index 0000000..f6bd6bf
--- /dev/null
+++ b/demo/scripts/suff.py
@@ -0,0 +1,29 @@
+#! /ufs/guido/bin/sgi/python
+
+# suff
+#
+# show different suffixes amongst arguments
+
+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])
+
+def getsuffix(file):
+ suff = ''
+ for i in range(len(file)):
+ if file[i] = '.':
+ suff = file[i:]
+ return suff
+
+main()
diff --git a/demo/scripts/xxci.py b/demo/scripts/xxci.py
new file mode 100755
index 0000000..43ea316
--- /dev/null
+++ b/demo/scripts/xxci.py
@@ -0,0 +1,77 @@
+#! /ufs/guido/bin/sgi/python
+
+# xxci
+#
+# check in files for which rcsdiff returns nonzero exit status
+
+import sys
+import posix
+import stat
+import path
+import commands
+
+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 *'
+ for file in posix.listdir('.'):
+ if not skipfile(file):
+ args.append(file)
+ if not args:
+ print 'Nothing to do -- exit 1'
+ sys.exit(1)
+ args.sort()
+ return args
+
+badnames = ['tags', 'xyzzy']
+badprefixes = ['.', ',', '@', '#', 'o.']
+badsuffixes = \
+ ['~', '.a', '.o', '.old', '.bak', '.orig', '.new', '.prev', '.not']
+# XXX Should generalize even more to use fnmatch!
+
+def skipfile(file):
+ if file in badnames or \
+ badprefix(file) or badsuffix(file) or \
+ path.islink(file) or path.isdir(file):
+ return 1
+ # Skip huge files -- probably binaries.
+ try:
+ st = posix.stat(file)
+ except posix.error:
+ return 1 # Doesn't exist -- skip it
+ return st[stat.ST_SIZE] >= MAXSIZE
+
+def badprefix(file):
+ 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
+
+def go(args):
+ for file in args:
+ print file + ':'
+ if run('rcsdiff -c', file):
+ if askyesno('Check in ' + file + ' ? '):
+ sts = run('rcs -l', file) # ignored
+ # can't use run() here because it's interactive
+ sts = posix.system('ci -l ' + file)
+
+def run(cmd, file):
+ sts, output = commands.getstatusoutput(cmd + commands.mkarg(file))
+ if sts:
+ print output
+ print 'Exit status', sts
+ return sts
+
+def askyesno(prompt):
+ s = raw_input(prompt)
+ return s in ['y', 'yes']
+
+go(getargs())