blob: d894c70f2dba67ea7f1e8c9391d09b792161e055 [file] [log] [blame]
Guido van Rossum950a1261996-07-30 17:38:17 +00001#! /usr/local/bin/python
2
3# This program reads all *.py and test/*.py in "libDir", and
4# copies those files with illegal DOS names to libDir/dos_8x3.
5# Names are illegal if they are longer than 8x3 chars or if they
6# contain uppercase chars. It also tests for name collisions.
7# You must first create the directory libDir/dos_8x3 yourself.
8# You should remove all files in dos_8x3 if you run it again.
9
10# CHANGE libDir TO THE CORRECT DIRECTORY. RM dos_8x3/* FIRST.
11
12import sys, os, regex, string
13
14libDir = "./Lib" # Location of Python Lib
15
16def make8x3():
17 reg_uppercase = regex.compile("[A-Z]")
18 collisions = {} # See if all names are unique in first 8 chars.
19 destDir = os.path.join(libDir, "dos_8x3")
20 if not os.path.isdir(destDir):
21 print "Please create the directory", destDir, "first."
22 err()
23 while 1:
24 ans = raw_input("Ok to copy to " + destDir + " [yn]? ")
25 if not ans:
26 continue
27 elif ans[0] == "n":
28 err()
29 elif ans[0] == "y":
30 break
31 for dirname in libDir, os.path.join(libDir, "test"):
32 for filename in os.listdir(dirname):
33 if filename[-3:] == ".py":
34 name = filename[0:-3]
35 if len(name) > 8 or reg_uppercase.search(name) >= 0:
36 shortName = string.lower(name[0:8])
37 if collisions.has_key(shortName):
38 print "Name not unique in first 8 chars:", collisions[shortName], name
39 else:
40 collisions[shortName] = name
41 fin = open(os.path.join(dirname, filename), "r")
42 dest = os.path.join(destDir, shortName + ".py")
43 fout = open(dest, "w")
44 fout.write(fin.read())
45 fin.close()
46 fout.close()
47 os.chmod(dest, 0644)
48 elif filename == "." or filename == "..":
49 continue
50 elif filename[-4:] == ".pyc":
51 continue
52 elif filename == "Makefile":
53 continue
54 else:
55 parts = string.splitfields(filename, ".")
56 if len(parts) > 2 or \
57 len(parts[0]) > 8 or \
58 reg_uppercase.search(filename) >= 0 or \
59 (len(parts) > 1 and len(parts[1]) > 3):
60 print "Illegal DOS name", os.path.join(dirname, filename)
61 sys.exit(0)
62def err():
63 print "No files copied."
64 sys.exit(1)
65
66
67if __name__ == "__main__":
68 make8x3()