summaryrefslogtreecommitdiffstats
path: root/PC/make8x3.py
blob: d894c70f2dba67ea7f1e8c9391d09b792161e055 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#! /usr/local/bin/python

# This program reads all *.py and test/*.py in "libDir", and
# copies those files with illegal DOS names to libDir/dos_8x3.
# Names are illegal if they are longer than 8x3 chars or if they
# contain uppercase chars.  It also tests for name collisions.
# You must first create the directory libDir/dos_8x3 yourself.
# You should remove all files in dos_8x3 if you run it again.

# CHANGE libDir TO THE CORRECT DIRECTORY.  RM dos_8x3/* FIRST.

import sys, os, regex, string

libDir = "./Lib"	# Location of Python Lib

def make8x3():
  reg_uppercase = regex.compile("[A-Z]")
  collisions = {}	# See if all names are unique in first 8 chars.
  destDir = os.path.join(libDir, "dos_8x3")
  if not os.path.isdir(destDir):
    print "Please create the directory", destDir, "first."
    err()
  while 1:
    ans = raw_input("Ok to copy to " + destDir + " [yn]? ")
    if not ans:
      continue
    elif ans[0] == "n":
      err()
    elif ans[0] == "y":
      break
  for dirname in libDir, os.path.join(libDir, "test"):
    for filename in os.listdir(dirname):
      if filename[-3:] == ".py":
        name = filename[0:-3]
        if len(name) > 8 or reg_uppercase.search(name) >= 0:
          shortName = string.lower(name[0:8])
          if collisions.has_key(shortName):
            print "Name not unique in first 8 chars:", collisions[shortName], name
          else:
            collisions[shortName] = name
            fin = open(os.path.join(dirname, filename), "r")
            dest = os.path.join(destDir, shortName + ".py")
            fout = open(dest, "w")
            fout.write(fin.read())
            fin.close()
            fout.close()
            os.chmod(dest, 0644)
      elif filename == "." or filename == "..":
        continue
      elif filename[-4:] == ".pyc":
        continue
      elif filename == "Makefile":
        continue
      else:
        parts = string.splitfields(filename, ".")
        if len(parts) > 2 or \
           len(parts[0]) > 8 or \
           reg_uppercase.search(filename) >= 0 or \
           (len(parts) > 1 and len(parts[1]) > 3):
                 print "Illegal DOS name", os.path.join(dirname, filename)
  sys.exit(0)
def err():
  print "No files copied."
  sys.exit(1)
            

if __name__ == "__main__":
  make8x3()