[Patch #1005491 ] use __name__ == '__main__' in scripts

This commit is contained in:
Andrew M. Kuchling 2004-08-09 17:27:55 +00:00
parent 6c542b731c
commit e236b38731
34 changed files with 257 additions and 200 deletions

View file

@ -9,6 +9,8 @@
import sys, os, time
from stat import *
def main():
# Use lstat() to stat files if it exists, else stat()
try:
statfunc = os.lstat
@ -54,3 +56,6 @@ for filename in sys.argv[1:]:
print repr(int(byteyears)).rjust(8)
sys.exit(status)
if __name__ == '__main__':
main()

View file

@ -62,4 +62,5 @@ def get_long(s):
return -1
return ord(s[0]) + (ord(s[1])<<8) + (ord(s[2])<<16) + (ord(s[3])<<24)
if __name__ == '__main__':
main()

View file

@ -186,4 +186,5 @@ def fixline(line):
return head + '(' + basepart + '):' + tail
if __name__ == '__main__':
main()

View file

@ -22,4 +22,5 @@ def main():
sys.stderr.write(file2 + ': cannot change time\n')
sys.exit(2)
if __name__ == '__main__':
main()

View file

@ -1,8 +1,9 @@
#! /usr/bin/env python
"Replace CRLF with LF in argument files. Print names of changed files."
import sys, os
def main():
for filename in sys.argv[1:]:
if os.path.isdir(filename):
print filename, "Directory!"
@ -17,3 +18,7 @@ for filename in sys.argv[1:]:
f = open(filename, "wb")
f.write(newdata)
f.close()
if __name__ == '__main__':
main()

View file

@ -68,4 +68,5 @@ def getmtime(filename):
return 0
return st[stat.ST_MTIME]
sys.exit(main())
if __name__ == '__main__':
main()

View file

@ -8,6 +8,8 @@
import sys, os, time, difflib, optparse
def main():
usage = "usage: %prog [options] fromfile tofile"
parser = optparse.OptionParser(usage)
parser.add_option("-c", action="store_true", default=False, help='Produce a context format diff (default)')
@ -38,3 +40,6 @@ else:
diff = difflib.context_diff(fromlines, tolines, fromfile, tofile, fromdate, todate, n=n)
sys.stdout.writelines(diff)
if __name__ == '__main__':
main()

View file

@ -56,4 +56,5 @@ def show(total, d, prefix):
if d.has_key(key):
show(tsub, d[key][1], psub)
if __name__ == '__main__':
main()

View file

@ -39,4 +39,5 @@ def visit(prog, dirname, names):
except os.error:
pass
if __name__ == '__main__':
main()

View file

@ -310,4 +310,5 @@ def addsubst(substfile):
Dict[key] = value
fp.close()
if __name__ == '__main__':
main()

View file

@ -45,4 +45,5 @@ def process(filename):
print '#endif'
print '#endif /*', '!'+magic, '*/'
if __name__ == '__main__':
main()

View file

@ -29,5 +29,5 @@ def main():
f.write(rest)
f.close()
if __name__ == '__main__':
main()

View file

@ -19,4 +19,5 @@ def main():
url = "http://www.google.com/search?q=%s" % s
webbrowser.open(url)
if __name__ == '__main__':
main()

View file

@ -75,4 +75,5 @@ def main():
output.close()
webbrowser.open("file:" + os.path.abspath(outputfilename))
if __name__ == '__main__':
main()

View file

@ -171,4 +171,5 @@ def process(fp, outfp, env = {}):
sys.stderr.write('Warning - could not find file %s\n' %
filename)
if __name__ == '__main__':
main()

View file

@ -1,4 +1,5 @@
#! /usr/bin/env python
from idlelib.PyShell import main
if __name__ == '__main__':
main()

View file

@ -109,4 +109,5 @@ def process(fpi, fpo):
if stack:
sys.stderr.write('stack: %s\n' % stack)
if __name__ == '__main__':
main()

View file

@ -3,6 +3,8 @@
"Replace LF with CRLF in argument files. Print names of changed files."
import sys, re, os
def main():
for filename in sys.argv[1:]:
if os.path.isdir(filename):
print filename, "Directory!"
@ -17,3 +19,6 @@ for filename in sys.argv[1:]:
f = open(filename, "wb")
f.write(newdata)
f.close()
if __name__ == '__main__':
main()

View file

@ -76,4 +76,5 @@ def linknames(old, new, link):
else:
os.symlink(linkname, newname)
if __name__ == '__main__':
sys.exit(main())

View file

@ -13,7 +13,7 @@ def lll(dirname):
full = os.path.join(dirname, name)
if os.path.islink(full):
print name, '->', os.readlink(full)
def main():
args = sys.argv[1:]
if not args: args = [os.curdir]
first = 1
@ -23,3 +23,7 @@ for arg in args:
first = 0
print arg + ':'
lll(arg)
if __name__ == '__main__':
main()

View file

@ -177,6 +177,7 @@ def format_output(database):
prev.append((date, working_file, rev, author))
prevtext = text
if __name__ == '__main__':
try:
main()
except IOError, e:

View file

@ -167,5 +167,5 @@ def fixline(line):
line = line[:a] + line[c:d] + line[b:]
return line
if __name__ == '__main__':
main()

View file

@ -62,4 +62,5 @@ def main():
mkrealfile(name)
sys.exit(status)
if __name__ == '__main__':
main()

View file

@ -208,6 +208,7 @@ def main():
# Use its return value as exit status.
# Catch interrupts to avoid stack trace.
#
if __name__ == '__main__':
try:
sys.exit(main())
except KeyboardInterrupt:

View file

@ -145,4 +145,6 @@ def fixline(line):
return line
return '#! %s\n' % new_interpreter
if __name__ == '__main__':
main()

View file

@ -160,6 +160,7 @@ def printresults(table):
# Call main and honor exit status
if __name__ == '__main__':
try:
sys.exit(main())
except KeyboardInterrupt:

View file

@ -49,4 +49,5 @@ def treat_file(filename):
s = name + '\t' + filename + '\t/^' + content + '/\n'
tags.append(s)
if __name__ == '__main__':
main()

View file

@ -1,4 +1,5 @@
#!/usr/bin/env python
import pydoc
if __name__ == '__main__':
pydoc.cli()

View file

@ -2,4 +2,6 @@
# importing itself (Python began allowing import of .pyw files
# between 2.2a1 and 2.2a2).
import pydoc
if __name__ == '__main__':
pydoc.gui()

View file

@ -1,5 +1,6 @@
from distutils.core import setup
if __name__ == '__main__':
setup(
scripts=[
'byteyears.py',

View file

@ -26,4 +26,5 @@ def getsuffix(filename):
suff = filename[i:]
return suff
if __name__ == '__main__':
main()

View file

@ -201,4 +201,5 @@ def okay(prompt, answer='ask'):
print "Yes or No please -- try again:"
return okay(prompt)
if __name__ == '__main__':
main()

View file

@ -13,6 +13,7 @@ from stat import *
def msg(str):
sys.stderr.write(str + '\n')
def main():
pathlist = os.environ['PATH'].split(os.pathsep)
sts = 0
@ -54,3 +55,7 @@ for prog in sys.argv[1:]:
sts = 1
sys.exit(sts)
if __name__ == '__main__':
main()

View file

@ -109,6 +109,7 @@ def askyesno(prompt):
s = raw_input(prompt)
return s in ['y', 'yes']
if __name__ == '__main__':
try:
setup()
go(getargs())