aboutsummaryrefslogtreecommitdiff
path: root/demo/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'demo/scripts')
-rwxr-xr-xdemo/scripts/findlinksto.py32
-rwxr-xr-xdemo/scripts/mkreal.py82
-rwxr-xr-xdemo/scripts/ptags.py74
-rwxr-xr-xdemo/scripts/suff.py32
-rwxr-xr-xdemo/scripts/xxci.py86
5 files changed, 153 insertions, 153 deletions
diff --git a/demo/scripts/findlinksto.py b/demo/scripts/findlinksto.py
index 210441e..35f5eea 100755
--- a/demo/scripts/findlinksto.py
+++ b/demo/scripts/findlinksto.py
@@ -7,23 +7,23 @@
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
+ 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)
+ 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
index 19fef28..1d62ba0 100755
--- a/demo/scripts/mkreal.py
+++ b/demo/scripts/mkreal.py
@@ -16,50 +16,50 @@ 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)
+ 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))
+ 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)
+ 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
index 0f99650..8886a71 100755
--- a/demo/scripts/ptags.py
+++ b/demo/scripts/ptags.py
@@ -15,52 +15,52 @@ import posix
import path
import string
-keywords = ['def', 'class'] # If you add keywords, update starts!!!
-starts = 'dc' # Starting characters of keywords
+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!
+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)
+ 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)
+ 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)
+ 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
index f6bd6bf..d6abecc 100755
--- a/demo/scripts/suff.py
+++ b/demo/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/demo/scripts/xxci.py b/demo/scripts/xxci.py
index 43ea316..7f6a402 100755
--- a/demo/scripts/xxci.py
+++ b/demo/scripts/xxci.py
@@ -13,65 +13,65 @@ 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
+ 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']
+ ['~', '.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
+ 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
+ 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 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)
+ 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
+ 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']
+ s = raw_input(prompt)
+ return s in ['y', 'yes']
go(getargs())