parameters: (self)
return_statement: return binary
docstring: Finds the binary for self.names if one was not provided.
docstring_summary: Finds the binary for self.names if one was not provided.
docstring_tokens: Finds the binary for self . names if one was not provided .
function: def find_binary(self):
          """Finds the binary for self.names if one was not provided."""
          binary = None
          if sys.platform in ('linux2', 'sunos5', 'solaris') \
                  or sys.platform.startswith('freebsd'):
              for name in reversed(self.names):
                  binary = findInPath(name)
          elif os.name == 'nt' or sys.platform == 'cygwin':
  
              # find the default executable from the windows registry
              try:
                  import _winreg
              except ImportError:
                  pass
              else:
                  sam_flags = [0]
                  # KEY_WOW64_32KEY etc only appeared in 2.6+, but that's OK as
                  # only 2.6+ has functioning 64bit builds.
                  if hasattr(_winreg, "KEY_WOW64_32KEY"):
                      if "64 bit" in sys.version:
                          # a 64bit Python should also look in the 32bit registry
                          sam_flags.append(_winreg.KEY_WOW64_32KEY)
                      else:
                          # possibly a 32bit Python on 64bit Windows, so look in
                          # the 64bit registry incase there is a 64bit app.
                          sam_flags.append(_winreg.KEY_WOW64_64KEY)
                  for sam_flag in sam_flags:
                      try:
                          # assumes self.app_name is defined, as it should be for
                          # implementors
                          keyname = r"Software\Mozilla\Mozilla %s" % self.app_name
                          sam = _winreg.KEY_READ | sam_flag
                          app_key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, keyname, 0, sam)
                          version, _type = _winreg.QueryValueEx(app_key, "CurrentVersion")
                          version_key = _winreg.OpenKey(app_key, version + r"\Main")
                          path, _ = _winreg.QueryValueEx(version_key, "PathToExe")
                          return path
                      except _winreg.error:
                          pass
  
              # search for the binary in the path            
              for name in reversed(self.names):
                  binary = findInPath(name)
                  if sys.platform == 'cygwin':
                      program_files = os.environ['PROGRAMFILES']
                  else:
                      program_files = os.environ['ProgramFiles']
  
                  if binary is None:
                      for bin in [(program_files, 'Mozilla Firefox', 'firefox.exe'),
                                  (os.environ.get("ProgramFiles(x86)"),'Mozilla Firefox', 'firefox.exe'),
                                  (program_files, 'Nightly', 'firefox.exe'),
                                  (os.environ.get("ProgramFiles(x86)"),'Nightly', 'firefox.exe'),
                                  (program_files, 'Aurora', 'firefox.exe'),
                                  (os.environ.get("ProgramFiles(x86)"),'Aurora', 'firefox.exe')
                                  ]:
                          path = os.path.join(*bin)
                          if os.path.isfile(path):
                              binary = path
                              break
          elif sys.platform == 'darwin':
              for bundle_name in self.bundle_names:
                  # Look for the application bundle in the user's home directory
                  # or the system-wide /Applications directory.  If we don't find
                  # it in one of those locations, we move on to the next possible
                  # bundle name.
                  appdir = os.path.join("~/Applications/%s.app" % bundle_name)
                  if not os.path.isdir(appdir):
                      appdir = "/Applications/%s.app" % bundle_name
                  if not os.path.isdir(appdir):
                      continue
  
                  # Look for a binary with any of the possible binary names
                  # inside the application bundle.
                  for binname in self.names:
                      binpath = os.path.join(appdir,
                                             "Contents/MacOS/%s-bin" % binname)
                      if (os.path.isfile(binpath)):
                          binary = binpath
                          break
  
                  if binary:
                      break
  
          if binary is None:
              raise Exception('Mozrunner could not locate your binary, you will need to set it.')
          return binary
function_tokens: def find_binary ( self ) : binary = None if sys . platform in ( 'linux2' , 'sunos5' , 'solaris' ) or sys . platform . startswith ( 'freebsd' ) : for name in reversed ( self . names ) : binary = findInPath ( name ) elif os . name == 'nt' or sys . platform == 'cygwin' : # find the default executable from the windows registry try : import _winreg except ImportError : pass else : sam_flags = [ 0 ] # KEY_WOW64_32KEY etc only appeared in 2.6+, but that's OK as # only 2.6+ has functioning 64bit builds. if hasattr ( _winreg , "KEY_WOW64_32KEY" ) : if "64 bit" in sys . version : # a 64bit Python should also look in the 32bit registry sam_flags . append ( _winreg . KEY_WOW64_32KEY ) else : # possibly a 32bit Python on 64bit Windows, so look in # the 64bit registry incase there is a 64bit app. sam_flags . append ( _winreg . KEY_WOW64_64KEY ) for sam_flag in sam_flags : try : # assumes self.app_name is defined, as it should be for # implementors keyname = r"Software\Mozilla\Mozilla %s" % self . app_name sam = _winreg . KEY_READ | sam_flag app_key = _winreg . OpenKey ( _winreg . HKEY_LOCAL_MACHINE , keyname , 0 , sam ) version , _type = _winreg . QueryValueEx ( app_key , "CurrentVersion" ) version_key = _winreg . OpenKey ( app_key , version + r"\Main" ) path , _ = _winreg . QueryValueEx ( version_key , "PathToExe" ) return path except _winreg . error : pass # search for the binary in the path             for name in reversed ( self . names ) : binary = findInPath ( name ) if sys . platform == 'cygwin' : program_files = os . environ [ 'PROGRAMFILES' ] else : program_files = os . environ [ 'ProgramFiles' ] if binary is None : for bin in [ ( program_files , 'Mozilla Firefox' , 'firefox.exe' ) , ( os . environ . get ( "ProgramFiles(x86)" ) , 'Mozilla Firefox' , 'firefox.exe' ) , ( program_files , 'Nightly' , 'firefox.exe' ) , ( os . environ . get ( "ProgramFiles(x86)" ) , 'Nightly' , 'firefox.exe' ) , ( program_files , 'Aurora' , 'firefox.exe' ) , ( os . environ . get ( "ProgramFiles(x86)" ) , 'Aurora' , 'firefox.exe' ) ] : path = os . path . join ( * bin ) if os . path . isfile ( path ) : binary = path break elif sys . platform == 'darwin' : for bundle_name in self . bundle_names : # Look for the application bundle in the user's home directory # or the system-wide /Applications directory.  If we don't find # it in one of those locations, we move on to the next possible # bundle name. appdir = os . path . join ( "~/Applications/%s.app" % bundle_name ) if not os . path . isdir ( appdir ) : appdir = "/Applications/%s.app" % bundle_name if not os . path . isdir ( appdir ) : continue # Look for a binary with any of the possible binary names # inside the application bundle. for binname in self . names : binpath = os . path . join ( appdir , "Contents/MacOS/%s-bin" % binname ) if ( os . path . isfile ( binpath ) ) : binary = binpath break if binary : break if binary is None : raise Exception ( 'Mozrunner could not locate your binary, you will need to set it.' ) return binary