home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2563 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  1.3 KB  |  50 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import time
  5. import os
  6. import win32api
  7. import win32evtlog
  8.  
  9. def BackupClearLog(logType):
  10.     datePrefix = time.strftime('%Y%m%d', time.localtime(time.time()))
  11.     fileExists = 1
  12.     retry = 0
  13.     while fileExists:
  14.         if retry == 0:
  15.             index = ''
  16.         else:
  17.             index = '-%d' % retry
  18.         
  19.         try:
  20.             fname = os.path.join(win32api.GetTempPath(), '%s%s-%s' % (datePrefix, index, logType) + '.evt')
  21.             os.stat(fname)
  22.         except os.error:
  23.             fileExists = 0
  24.  
  25.         retry = retry + 1
  26.     
  27.     try:
  28.         hlog = win32evtlog.OpenEventLog(None, logType)
  29.     except win32evtlogutil.error:
  30.         details = None
  31.         print 'Could not open the event log', details
  32.         return None
  33.  
  34.     
  35.     try:
  36.         if win32evtlog.GetNumberOfEventLogRecords(hlog) == 0:
  37.             print 'No records in event log %s - not backed up' % logType
  38.             return None
  39.         win32evtlog.ClearEventLog(hlog, fname)
  40.         print 'Backed up %s log to %s' % (logType, fname)
  41.     finally:
  42.         win32evtlog.CloseEventLog(hlog)
  43.  
  44.  
  45. if __name__ == '__main__':
  46.     BackupClearLog('Application')
  47.     BackupClearLog('System')
  48.     BackupClearLog('Security')
  49.  
  50.