Temp File Cleanup for McMillan Installer Pgms

A

achrist

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top