def _LoadDll(dll_path): """Tries to load, hence initializing, the given DLL. Args: dll_path: the path to the DLL to test. Returns: True on success, False on failure. """ mode = (win32con.SEM_FAILCRITICALERRORS | win32con.SEM_NOALIGNMENTFAULTEXCEPT | win32con.SEM_NOGPFAULTERRORBOX | win32con.SEM_NOOPENFILEERRORBOX) old_mode = win32api.SetErrorMode(mode) try: handle = win32api.LoadLibrary(dll_path) if not handle: return False win32api.FreeLibrary(handle) except pywintypes.error as e: # pylint: disable=E1101 _LOGGER.error('Error: %s', e) return False finally: win32api.SetErrorMode(old_mode) return True
def driveReady(drive): """ Validates a Drive""" returnValue = 0 oldError = win32api.SetErrorMode( 1 ) try: win32api.GetVolumeInformation(drive) except: returnValue = 0 else: returnValue = 1 win32api.SetErrorMode(oldError) return returnValue
def drive_is_ok(self, letter, debug=False): import win32api, win32file with self.lock: oldError = win32api.SetErrorMode(1) #SEM_FAILCRITICALERRORS = 1 try: ans = True try: win32file.GetDiskFreeSpaceEx(letter+':\\') except Exception as e: if debug: prints('Unable to get free space for drive:', letter) prints(as_unicode(e)) ans = False return ans finally: win32api.SetErrorMode(oldError)
def DisableCrashDialog(): """ Disable Windows' crash dialog box, which pops up when a process exits with an unhandled fault. This causes the process to hang on the Buildbots. We duplicate this function from SConstruct because ErrorMode flags are overwritten in scons due to race conditions. See bug https://code.google.com/p/nativeclient/issues/detail?id=2968 """ if sys.platform == 'win32': import win32api import win32con # The double call is to preserve existing flags, as discussed at # http://blogs.msdn.com/oldnewthing/archive/2004/07/27/198410.aspx new_flags = win32con.SEM_NOGPFAULTERRORBOX existing_flags = win32api.SetErrorMode(new_flags) win32api.SetErrorMode(existing_flags | new_flags)
def drive_is_ok(letter, max_tries=10, debug=False): import win32api, win32file with drive_ok_lock: oldError = win32api.SetErrorMode(1) # SEM_FAILCRITICALERRORS = 1 try: for i in range(max_tries): try: win32file.GetDiskFreeSpaceEx(letter+':\\') return True except Exception as e: if i >= max_tries - 1 and debug: prints('Unable to get free space for drive:', letter) prints(as_unicode(e)) time.sleep(0.2) return False finally: win32api.SetErrorMode(oldError)
def _launch_idle_process(self, command_line, dir=None): (hChildStdinRd, hChildStdinWr) = win32pipe.CreatePipe(None, 0) (hChildStdoutRd, hChildStdoutWr) = win32pipe.CreatePipe(None, 0) hChildStdinRd = self.make_inheritable(hChildStdinRd) hChildStdoutWr = self.make_inheritable(hChildStdoutWr) startupinfo = win32process.STARTUPINFO() startupinfo.dwFlags = \ win32process.STARTF_USESTDHANDLES | \ win32process.STARTF_USESHOWWINDOW startupinfo.hStdInput = hChildStdinRd startupinfo.hStdOutput = hChildStdoutWr startupinfo.hStdError = hChildStdoutWr appName = None commandLine = command_line processAttributes = None threadAttributes = None bInheritHandles = 1 dwCreationFlags = win32process.IDLE_PRIORITY_CLASS newEnvironment = os.environ currentDirectory = None if dir: currentDirectory = os.path.normpath(os.path.join(os.getcwd(), dir)) ## no dialog boxes that hang the build system SEM_FAILCRITICALERRORS = 0x0001 SEM_NOGPFAULTERRORBOX = 0x0002 SEM_NOALIGNMENTFAULTEXCEPT = 0x0004 SEM_NOOPENFILEERRORBOX = 0x8000 win32api.SetErrorMode( SEM_FAILCRITICALERRORS|\ SEM_NOGPFAULTERRORBOX|\ SEM_NOOPENFILEERRORBOX) try: (hProcess, hThread, dwProcessId, dwThreadId) = \ win32process.CreateProcess( appName, commandLine, processAttributes, threadAttributes, bInheritHandles, dwCreationFlags, newEnvironment, currentDirectory, startupinfo) except pywintypes.error: return None ## close the thread handle, as well as the other I/O handles win32api.CloseHandle(hThread) win32api.CloseHandle(hChildStdinRd) win32api.CloseHandle(hChildStdoutWr) return hProcess, hChildStdinWr, hChildStdoutRd
def _disable_windows_error_popup(): """Set error mode to disable Windows error popup This setting is effective for current process and all the child processes """ # disable nasty critical error pop-ups on Windows import win32api, win32con win32api.SetErrorMode(win32con.SEM_FAILCRITICALERRORS | win32con.SEM_NOOPENFILEERRORBOX)
def main(): # Define required and optional command-line arguments. parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, description="Script for safely using Natlink's inputFromFile() " "function.\n\n" "This script is intended to be run in a dedicated process in " "order to work around potential page faults." ) parser.add_argument( "file", type=argparse.FileType("r"), help="Name of the wave file to take input from." ) parser.add_argument( "--no-utt-detect", default=False, action="store_true", help="Do not perform utterance detection (i.e. don't split speech " "at pauses) when processing the specified wave file. Use this if " "the file contains only one utterance." ) # Parse command-line arguments. args = parser.parse_args() # Get the filename and uttdetect arguments. f = args.file filename = f.name f.close() # Close the file object created by argparse uttdetect = 0 if args.no_utt_detect else 1 # Instruct Windows to suppress the error reporting window if this script # causes a page fault. win32api.SetErrorMode(win32con.SEM_NOGPFAULTERRORBOX) # Connect to NatSpeak. natlink.natConnect() try: # Process the specified wave file using the specified options. natlink.inputFromFile(filename, 0, [], uttdetect) finally: # Disconnect from NatSpeak. natlink.natDisconnect()
os.path.join(os.path.dirname(__file__), '..', 'lib', 'python2.7', 'site-packages')) sys.path.append( os.path.join(os.path.dirname(__file__), '..', 'lib', 'python2.7', 'dist-packages')) import Wammu import Wammu.Locales from Wammu.Locales import ugettext as _ # Disable warning about missing files # This can be caused by attempt to import Python modules, which don't # have all DLLs satisfied. if sys.platform.startswith('win'): import win32api import win32con win32api.SetErrorMode(win32con.SEM_NOOPENFILEERRORBOX) def version(): ''' Displays version information. ''' print(_('Wammu - Windowed Gammu version %s') % Wammu.__version__) def usage(): ''' Shows program usage. ''' version() print(_('Usage: %s [OPTION...]' % os.path.basename(__file__)))
# along with this program. If not, see <http://www.gnu.org/licenses/>. """ Launcher """ import os import sys if 'posix' == os.name: if os.path.isdir('/usr/share/bleachbit'): # This path contains bleachbit/{C,G}LI.py . This section is # unnecessary if installing BleachBit in site-packages. sys.path.append('/usr/share/') if os.name == 'nt': # change error handling to avoid popup with GTK 3 # https://github.com/bleachbit/bleachbit/issues/651 import win32api import win32con win32api.SetErrorMode(win32con.SEM_FAILCRITICALERRORS | win32con.SEM_NOGPFAULTERRORBOX | win32con.SEM_NOOPENFILEERRORBOX) if 1 == len(sys.argv): import bleachbit.GUI app = bleachbit.GUI.Bleachbit() sys.exit(app.run(sys.argv)) else: import bleachbit.CLI bleachbit.CLI.process_cmd_line()
def RunServer(installSH=True): logger = logging.getLogger('maestrod.RunServer') try: # Tell windows to not pop up annoying error dialog boxes. if sys.platform.startswith("win"): win32api.SetErrorMode(win32con.SEM_FAILCRITICALERRORS | win32con.SEM_NOGPFAULTERRORBOX | win32con.SEM_NOALIGNMENTFAULTEXCEPT | win32con.SEM_NOOPENFILEERRORBOX) def logCB(percent, message): logger.info(message) # env = maestro.core.Environment() # env.initialize(None, progressCB=logCB) cluster_server = MaestroServer() cluster_server.loadServices() env = maestro.core.Environment() # Fallback settings for the SSL private key and certificate if none are # given in the maestrod configuration. default_pk_path = os.path.join(const.EXEC_DIR, 'server.pem') default_cert_path = os.path.join(const.EXEC_DIR, 'server.pem') # Set the private key file. First, we check the maestrod settings to # see if a private key file is named. pk_path = env.settings.get('ssl/key_file', default_pk_path) # Ensure that we are using an absolute path to the private key. This is # done largely for backwards compatibility with installations migrated # from pre-0.4 releases that are likely to have server.pem in the # maestrod installation directory. if not os.path.isabs(pk_path) and \ os.path.dirname(pk_path) != const.EXEC_DIR: pk_path = os.path.join(const.EXEC_DIR, pk_path) # Set the certificate. First, we check the maestrod settings to see if a # certificate. cert_path = env.settings.get('ssl/cert_file', default_cert_path) # Ensure that we are using an absolute path to the certificate. This is # done largely for backwards compatibility with installations migrated # from pre-0.4 releases that are likely to have server.pem in the # maestrod installation directory. if not os.path.isabs(cert_path) and \ os.path.dirname(cert_path) != const.EXEC_DIR: cert_path = os.path.join(const.EXEC_DIR, cert_path) if not os.path.exists(pk_path): logger.error("Server private key %s does not exist!" % pk_path) if not os.path.exists(cert_path): logger.error("Server certificate %s does not exist!" % cert_path) logger.info("SSL private key: " + pk_path) logger.info("SSL certificate: " + cert_path) #reactor.listenTCP(8789, pb.PBServerFactory(cluster_server.mEventManager)) factory = pboverssl.PBServerFactory(_AuthServerWrapper()) #reactor.listenTCP(8789, factory) reactor.listenSSL(8789, factory, ssl.DefaultOpenSSLContextFactory(pk_path, cert_path)) looping_call = task.LoopingCall(cluster_server.update) looping_call.start(0.1) reactor.run(installSignalHandlers=installSH) except Exception, ex: logger.error(ex) raise