make8x3.py :  » Mobile » Python-for-PalmOS » Python-1.5.2+reduced-1.0 » PC » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Mobile » Python for PalmOS 
Python for PalmOS » Python 1.5.2 reduced 1.0 » PC » make8x3.py
#! /usr/bin/env 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()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.