Temp File Cleanup for McMillan Installer Pgms

Discussion in 'Python' started by achrist@easystreet.com, Aug 31, 2003.

  1. Guest

    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
     
    , Aug 31, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Peuser

    OpenGL with Mcmillan Installer?

    Michael Peuser, Aug 23, 2003, in forum: Python
    Replies:
    0
    Views:
    306
    Michael Peuser
    Aug 23, 2003
  2. Harald Schneider
    Replies:
    1
    Views:
    2,334
    Harald Schneider
    Dec 1, 2003
  3. simo
    Replies:
    0
    Views:
    257
  4. mrstephengross
    Replies:
    0
    Views:
    347
    mrstephengross
    Mar 10, 2006
  5. A. Farber
    Replies:
    3
    Views:
    264
    Ben Morrow
    Mar 3, 2004
Loading...

Share This Page