Temp File Cleanup for McMillan Installer Pgms

achrist at easystreet.com achrist at easystreet.com
Sun Aug 31 03:18:47 EDT 2003


After using the McMillan installer and executables built with 
it for a while,  I've noticed some residual files accumulating 
on my disk.  The installer docs mentions these.

Here's code I wrote to clean these up:

--------------------Program Fillows----------------------

import fnmatch
import os
import os.path
import stat
import tempfile
import time

currentTime = time.time()

def PathIsOld(pathName):
    accessTime = os.stat(pathName)[stat.ST_ATIME]
    createTime = os.stat(pathName)[stat.ST_CTIME]
    modifiedTime = os.stat(pathName)[stat.ST_MTIME]
    return (((currentTime - accessTime) > 5000) or (
             (currentTime - createTime) > 50000)) and (
             (currentTime - modifiedTime) > 5000)


def GetMEISubdirectories(aDir):
    for fName in os.listdir(aDir):
        if fnmatch.fnmatch(fName, "*"):
            if fName.lower()[:4] == '_mei':
                fullName = os.path.join(aDir, fName)
                fMode = os.stat(fullName)[stat.ST_MODE]
                if stat.S_ISDIR(fMode):
                    yield fullName

def GetMEIFiles(aDir):
    for fName in os.listdir(aDir):
        if fName.lower()[:4] == '_mei':
            fullName = os.path.join(aDir, fName)
            fMode = os.stat(fullName)[stat.ST_MODE]
            if stat.S_ISREG(fMode):
                yield fullName


def GetTempLocation():
    return tempfile.gettempdir()

def GetMEIDirectories():
    return filter(
            PathIsOld,
            GetMEISubdirectories(GetTempLocation())
            )

def DeleteMEIDirectory(d):
    for fileName in os.listdir(d):
        fullName = os.path.join(d, fileName)
        try:
            os.remove(fullName)
        except:
            pass
    try:
        os.rmdir(d)
    except:
        pass

for d in GetMEIDirectories():
    DeleteMEIDirectory(d)

for f in GetMEIFiles(GetTempLocation()):
    if PathIsOld(f):
        os.remove(f)

-----------------------End of Program -------------------------

What are the top 10 reasons for not including this in every
program that I turn into an executable with the McMillan
installer?

TIA



Al




More information about the Python-list mailing list