Temp File Cleanup for McMillan Installer Pgms

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • achrist@easystreet.com

    Temp File Cleanup for McMillan Installer Pgms

    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(pathN ame):
    accessTime = os.stat(pathNam e)[stat.ST_ATIME]
    createTime = os.stat(pathNam e)[stat.ST_CTIME]
    modifiedTime = os.stat(pathNam e)[stat.ST_MTIME]
    return (((currentTime - accessTime) > 5000) or (
    (currentTime - createTime) > 50000)) and (
    (currentTime - modifiedTime) > 5000)


    def GetMEISubdirect ories(aDir):
    for fName in os.listdir(aDir ):
    if fnmatch.fnmatch (fName, "*"):
    if fName.lower()[:4] == '_mei':
    fullName = os.path.join(aD ir, fName)
    fMode = os.stat(fullNam e)[stat.ST_MODE]
    if stat.S_ISDIR(fM ode):
    yield fullName

    def GetMEIFiles(aDi r):
    for fName in os.listdir(aDir ):
    if fName.lower()[:4] == '_mei':
    fullName = os.path.join(aD ir, fName)
    fMode = os.stat(fullNam e)[stat.ST_MODE]
    if stat.S_ISREG(fM ode):
    yield fullName


    def GetTempLocation ():
    return tempfile.gettem pdir()

    def GetMEIDirectori es():
    return filter(
    PathIsOld,
    GetMEISubdirect ories(GetTempLo cation())
    )

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

    for d in GetMEIDirectori es():
    DeleteMEIDirect ory(d)

    for f in GetMEIFiles(Get TempLocation()) :
    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
Working...