Skip to content

Commit

Permalink
Added better "access denied" handling in msi_cleanup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Vasily Litvinov committed Mar 19, 2014
1 parent c8ed19e commit 12444a5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
14 changes: 12 additions & 2 deletions msi_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from common_helpers import MB
import os
import glob
import errno

def getCachedMsiFiles(ext):
'''
Expand Down Expand Up @@ -72,8 +73,17 @@ def orphanCleanup(name, ext, enumerator):
for orphan in orphanFiles:
try:
os.remove(orphan)
except Exception, e:
print 'Cannot remove "%s": %r' % (orphan, e)
except OSError as ex:
if ex.errno == errno.EACCES:
reason = 'access denied'
else:
reason = '%s <%r>' % (ex, ex)
except BaseException as ex:
reason = '%s <%r>' % (ex, ex)
else:
reason = ''
if reason:
print 'Cannot remove "%s": %s' % (orphan, reason)
else:
print 'Cancelled by user'
else:
Expand Down
5 changes: 2 additions & 3 deletions msi_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import ctypes
from ctypes.wintypes import DWORD
from ctypes import c_char_p, POINTER, c_uint, pointer
from win32elevate import elevateAdminRights

LPDWORD = POINTER(DWORD)

Expand Down Expand Up @@ -153,5 +152,5 @@ def getAllProducts():
yield MsiProduct(productGuid.value)

if __name__ == '__main__':
sys.stderr.write('This is helper module not intended for standalone run\n')
sys.exit(1)
import sys
sys.exit('This is helper module not intended for standalone run\n')

0 comments on commit 12444a5

Please sign in to comment.