blob: a75620952eeecca9956e8cc3a5d3833eb5e1acf3 [file] [log] [blame]
Guido van Rossumd69a84b1997-04-02 06:11:55 +00001#! /usr/bin/env python
Guido van Rossum950a1261996-07-30 17:38:17 +00002
3# This program reads all *.py and test/*.py in "libDir", and
Guido van Rossum8731e5c1997-10-07 14:55:11 +00004# copies those files with illegal DOS names to libDir/dos-8x3.
Guido van Rossum950a1261996-07-30 17:38:17 +00005# Names are illegal if they are longer than 8x3 chars or if they
6# contain uppercase chars. It also tests for name collisions.
Guido van Rossum8731e5c1997-10-07 14:55:11 +00007# You must first create the directory libDir/dos-8x3 yourself.
8# You should remove all files in dos-8x3 if you run it again.
Guido van Rossum950a1261996-07-30 17:38:17 +00009
Guido van Rossum8731e5c1997-10-07 14:55:11 +000010# CHANGE libDir TO THE CORRECT DIRECTORY. RM dos-8x3/* FIRST.
Guido van Rossum950a1261996-07-30 17:38:17 +000011
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.
Guido van Rossum8731e5c1997-10-07 14:55:11 +000019 destDir = os.path.join(libDir, "dos-8x3")
Guido van Rossum950a1261996-07-30 17:38:17 +000020 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()