home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 January / maximum-cd-2011-01.iso / DiscContents / calibre-0.7.26.msi / file_2684 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-10-31  |  3.9 KB  |  107 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import win32api
  5. import win32con
  6. import winerror
  7. import win32evtlog
  8. import string
  9. error = win32api.error
  10. langid = win32api.MAKELANGID(win32con.LANG_NEUTRAL, win32con.SUBLANG_NEUTRAL)
  11.  
  12. def AddSourceToRegistry(appName, msgDLL = None, eventLogType = 'Application', eventLogFlags = None):
  13.     if msgDLL is None:
  14.         msgDLL = win32evtlog.__file__
  15.     
  16.     hkey = win32api.RegCreateKey(win32con.HKEY_LOCAL_MACHINE, 'SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s\\%s' % (eventLogType, appName))
  17.     win32api.RegSetValueEx(hkey, 'EventMessageFile', 0, win32con.REG_EXPAND_SZ, msgDLL)
  18.     if eventLogFlags is None:
  19.         eventLogFlags = win32evtlog.EVENTLOG_ERROR_TYPE | win32evtlog.EVENTLOG_WARNING_TYPE | win32evtlog.EVENTLOG_INFORMATION_TYPE
  20.     
  21.     win32api.RegSetValueEx(hkey, 'TypesSupported', 0, win32con.REG_DWORD, eventLogFlags)
  22.     win32api.RegCloseKey(hkey)
  23.  
  24.  
  25. def RemoveSourceFromRegistry(appName, eventLogType = 'Application'):
  26.     
  27.     try:
  28.         win32api.RegDeleteKey(win32con.HKEY_LOCAL_MACHINE, 'SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s\\%s' % (eventLogType, appName))
  29.     except win32api.error:
  30.         (hr, fn, desc) = None
  31.         if hr != winerror.ERROR_FILE_NOT_FOUND:
  32.             raise 
  33.         hr != winerror.ERROR_FILE_NOT_FOUND
  34.  
  35.  
  36.  
  37. def ReportEvent(appName, eventID, eventCategory = 0, eventType = win32evtlog.EVENTLOG_ERROR_TYPE, strings = None, data = None, sid = None):
  38.     hAppLog = win32evtlog.RegisterEventSource(None, appName)
  39.     win32evtlog.ReportEvent(hAppLog, eventType, eventCategory, eventID, sid, strings, data)
  40.     win32evtlog.DeregisterEventSource(hAppLog)
  41.  
  42.  
  43. def FormatMessage(eventLogRecord, logType = 'Application'):
  44.     keyName = 'SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s\\%s' % (logType, eventLogRecord.SourceName)
  45.     handle = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, keyName)
  46.     
  47.     try:
  48.         dllNames = win32api.RegQueryValueEx(handle, 'EventMessageFile')[0].split(';')
  49.         data = None
  50.         for dllName in dllNames:
  51.             
  52.             try:
  53.                 dllName = win32api.ExpandEnvironmentStrings(dllName)
  54.                 dllHandle = win32api.LoadLibraryEx(dllName, 0, win32con.DONT_RESOLVE_DLL_REFERENCES)
  55.                 
  56.                 try:
  57.                     data = win32api.FormatMessageW(win32con.FORMAT_MESSAGE_FROM_HMODULE, dllHandle, eventLogRecord.EventID, langid, eventLogRecord.StringInserts)
  58.                 finally:
  59.                     win32api.FreeLibrary(dllHandle)
  60.  
  61.             except win32api.error:
  62.                 pass
  63.  
  64.             if data is not None:
  65.                 break
  66.                 continue
  67.     finally:
  68.         win32api.RegCloseKey(handle)
  69.  
  70.     if not data:
  71.         pass
  72.     return u''
  73.  
  74.  
  75. def SafeFormatMessage(eventLogRecord, logType = None):
  76.     if logType is None:
  77.         logType = 'Application'
  78.     
  79.     
  80.     try:
  81.         return FormatMessage(eventLogRecord, logType)
  82.     except win32api.error:
  83.         if eventLogRecord.StringInserts is None:
  84.             desc = ''
  85.         else:
  86.             desc = u', '.join(eventLogRecord.StringInserts)
  87.         return u'<The description for Event ID ( %d ) in Source ( %r ) could not be found. It contains the following insertion string(s):%r.>' % (winerror.HRESULT_CODE(eventLogRecord.EventID), eventLogRecord.SourceName, desc)
  88.  
  89.  
  90.  
  91. def FeedEventLogRecords(feeder, machineName = None, logName = 'Application', readFlags = None):
  92.     if readFlags is None:
  93.         readFlags = win32evtlog.EVENTLOG_BACKWARDS_READ | win32evtlog.EVENTLOG_SEQUENTIAL_READ
  94.     
  95.     h = win32evtlog.OpenEventLog(machineName, logName)
  96.     
  97.     try:
  98.         while None:
  99.             objects = win32evtlog.ReadEventLog(h, readFlags, 0)
  100.             if not objects:
  101.                 break
  102.             
  103.         win32evtlog.CloseEventLog(h)
  104.         return None
  105.  
  106.  
  107.