def get_config(): show_taskbaricon = True hgighlight_taskbaricon = True version2cmenu = False try: from _winreg import HKEY_CURRENT_USER, OpenKey, QueryValueEx hkey = OpenKey(HKEY_CURRENT_USER, r'Software\TortoiseHg') t = ('1', 'True') try: show_taskbaricon = QueryValueEx(hkey, 'ShowTaskbarIcon')[0] in t except EnvironmentError: pass try: hgighlight_taskbaricon = QueryValueEx(hkey, 'HighlightTaskbarIcon')[0] in t except EnvironmentError: pass # Upgrade user's context menu, once per major release try: version2cmenu = QueryValueEx(hkey, 'ContextMenuVersion')[0] == '2' except EnvironmentError: pass try: if not version2cmenu: from _winreg import CreateKey, SetValueEx, REG_SZ try: promoted = QueryValueEx(hkey, 'PromotedItems')[0] except EnvironmentError: promoted = '' plist = [i.strip() for i in promoted.split(',')] hkey = CreateKey(HKEY_CURRENT_USER, r'Software\TortoiseHg') if u'log' in plist: idx = plist.index(u'log') plist[idx] = u'workbench' SetValueEx(hkey, 'PromotedItems', 0, REG_SZ, ','.join(plist)) SetValueEx(hkey, 'ContextMenuVersion', 0, REG_SZ, '2') except EnvironmentError: pass except (ImportError, WindowsError): pass return (show_taskbaricon, hgighlight_taskbaricon)
def check_system_path(): hive = HKEY_LOCAL_MACHINE key = r'SYSTEM\CurrentControlSet\Control\Session Manager\Environment' with OpenKey(hive, key, 0, KEY_READ) as regkey: path, type = QueryValueEx(regkey, 'PATH') path = [p.strip().rstrip('\\') for p in path.split(';') if p.strip()] for p in path: if os.path.isfile(os.path.join(p, 'sadm.py')): eprintc('\nSadm is in the system path. It should be removed because the system path setting may conflict with the user path setting.', WARNING_COLOR) break
) try: subkey = subkey.encode(getdefaultencoding()) except UnicodeEncodeError: subkey = subkey.encode('utf-8') try: key = OpenKeyEx(HKEY_LOCAL_MACHINE, subkey, 0, KEY_READ) except WindowsError: continue try: dllNames, _ = QueryValueEx(key, 'EventMessageFile') for dllName in dllNames.split(';'): dllName = expandvars(dllName.strip()) if not isfile(dllName): continue dllHandle = LoadLibraryEx( dllName, 0, LOAD_LIBRARY_AS_DATAFILE) if not dllHandle: continue try: message = FormatMessageW(FORMAT_MESSAGE_FROM_HMODULE, dllHandle, ev_obj.EventID, LANGID, ev_obj.StringInserts) except error:
localonly = False includepaths = [] excludepaths = [] try: from _winreg import HKEY_CURRENT_USER, OpenKey, QueryValueEx from win32api import GetTickCount CACHE_TIMEOUT = 5000 try: hkey = OpenKey(HKEY_CURRENT_USER, r"Software\TortoiseHg") enabled = QueryValueEx(hkey, 'EnableOverlays')[0] in ('1', 'True') localonly = QueryValueEx(hkey, 'LocalDisksOnly')[0] in ('1', 'True') incs = QueryValueEx(hkey, 'IncludePath')[0] excs = QueryValueEx(hkey, 'ExcludePath')[0] debugging = QueryValueEx(hkey, 'OverlayDebug')[0] in ('1', 'True') for p in incs.split(';'): path = p.strip() if path: includepaths.append(path) for p in excs.split(';'): path = p.strip() if path: excludepaths.append(path) except EnvironmentError: pass except ImportError: from time import time as GetTickCount CACHE_TIMEOUT = 5.0 debugging = debugthg.debug('O') if debugging:
includepaths = [] excludepaths = [] try: from _winreg import HKEY_CURRENT_USER, OpenKey, QueryValueEx from win32api import GetTickCount CACHE_TIMEOUT = 5000 try: hkey = OpenKey(HKEY_CURRENT_USER, r"Software\TortoiseHg") enabled = QueryValueEx(hkey, "EnableOverlays")[0] in ("1", "True") localonly = QueryValueEx(hkey, "LocalDisksOnly")[0] in ("1", "True") incs = QueryValueEx(hkey, "IncludePath")[0] excs = QueryValueEx(hkey, "ExcludePath")[0] debugging = QueryValueEx(hkey, "OverlayDebug")[0] in ("1", "True") for p in incs.split(";"): path = p.strip() if path: includepaths.append(path) for p in excs.split(";"): path = p.strip() if path: excludepath.append(path) except EnvironmentError: pass except ImportError: from time import time as GetTickCount CACHE_TIMEOUT = 5.0 debugging = debugthg.debug("O")
localonly = False includepaths = [] excludepaths = [] try: from _winreg import HKEY_CURRENT_USER, OpenKey, QueryValueEx from win32api import GetTickCount CACHE_TIMEOUT = 5000 try: hkey = OpenKey(HKEY_CURRENT_USER, r"Software\TortoiseHg") enabled = QueryValueEx(hkey, 'EnableOverlays')[0] in ('1', 'True') localonly = QueryValueEx(hkey, 'LocalDisksOnly')[0] in ('1', 'True') incs = QueryValueEx(hkey, 'IncludePath')[0] excs = QueryValueEx(hkey, 'ExcludePath')[0] debugging = QueryValueEx(hkey, 'OverlayDebug')[0] in ('1', 'True') for p in incs.split(';'): path = p.strip() if path: includepaths.append(path) for p in excs.split(';'): path = p.strip() if path: excludepaths.append(path) except EnvironmentError: pass except ImportError: from time import time as GetTickCount CACHE_TIMEOUT = 5.0 debugging = debugthg.debug('O') if debugging:
def get_user_path(): hive = HKEY_CURRENT_USER key = 'Environment' with OpenKey(hive, key, 0, KEY_READ) as regkey: path, type = QueryValueEx(regkey, 'PATH') return [p.strip().rstrip('\\') for p in path.split(';') if p.strip()]
def get_events(self, logtype, server=''): log = OpenEventLog(server, logtype) if not log: return flags = EVENTLOG_BACKWARDS_READ | EVENTLOG_SEQUENTIAL_READ events = ReadEventLog(log, flags, 0) try: events = True while events: events = ReadEventLog(log, flags, 0) if not events: break for ev_obj in events: if not ev_obj.StringInserts: continue message = None if ev_obj.SourceName not in self._formatters_cache and ev_obj.SourceName not in BLACKLIST: try: key = OpenKeyEx( HKEY_LOCAL_MACHINE, r'SYSTEM\CurrentControlSet\Services\EventLog\{}\{}' .format(logtype, ev_obj.SourceName), 0, KEY_READ) except WindowsError: continue try: dllNames, _ = QueryValueEx(key, 'EventMessageFile') for dllName in dllNames.split(';'): dllName = expandvars(dllName.strip()) if not isfile(dllName): continue dllHandle = LoadLibraryEx( dllName, 0, LOAD_LIBRARY_AS_DATAFILE) if not dllHandle: continue try: message = FormatMessageW( FORMAT_MESSAGE_FROM_HMODULE, dllHandle, ev_obj.EventID, LANGID, ev_obj.StringInserts) except error: FreeLibrary(dllHandle) continue if message: self._formatters_cache[ ev_obj.SourceName] = dllHandle break if not message: self._formatters_cache[ ev_obj.SourceName] = None message = '\n'.join(ev_obj.StringInserts) except WindowsError: self._formatters_cache[ev_obj.SourceName] = None elif ev_obj.SourceName in BLACKLIST or not self._formatters_cache[ ev_obj.SourceName]: message = '\n'.join(ev_obj.StringInserts) else: try: message = FormatMessageW( FORMAT_MESSAGE_FROM_HMODULE, self._formatters_cache[ev_obj.SourceName], ev_obj.EventID, LANGID, ev_obj.StringInserts) except error: message = '\n'.join(ev_obj.StringInserts) user = '' if ev_obj.Sid is not None: try: domain, domain_user, _ = LookupAccountSid( server, ev_obj.Sid) user = u'{}\\{}'.format(domain, domain_user) except error: user = str(ev_obj.Sid) if not message: continue yield { 'id': int(winerror.HRESULT_CODE(ev_obj.EventID)), 'record': ev_obj.RecordNumber, 'date': int(ev_obj.TimeGenerated), 'computer': ev_obj.ComputerName, 'category': ev_obj.EventCategory, 'msg': message, 'source': ev_obj.SourceName, 'type': EventLog.event_types.get(ev_obj.EventType, 'UNKNOWN'), 'user': user } except GeneratorExit: pass finally: for source in self._formatters_cache.keys(): if self._formatters_cache[source]: FreeLibrary(self._formatters_cache[source]) del self._formatters_cache[source] CloseEventLog(log)