parameters: (self, addon)
docstring: Installs the given addon in the profile.
docstring_summary: Installs the given addon in the profile.
docstring_tokens: Installs the given addon in the profile .
function: def install_addon(self, addon):
          """Installs the given addon in the profile."""
          tmpdir = None
          if addon.endswith('.xpi'):
              tmpdir = tempfile.mkdtemp(suffix = "." + os.path.split(addon)[-1])
              compressed_file = zipfile.ZipFile(addon, "r")
              for name in compressed_file.namelist():
                  if name.endswith('/'):
                      makedirs(os.path.join(tmpdir, name))
                  else:
                      if not os.path.isdir(os.path.dirname(os.path.join(tmpdir, name))):
                          makedirs(os.path.dirname(os.path.join(tmpdir, name)))
                      data = compressed_file.read(name)
                      f = open(os.path.join(tmpdir, name), 'wb')
                      f.write(data) ; f.close()
              addon = tmpdir
  
          tree = ElementTree.ElementTree(file=os.path.join(addon, 'install.rdf'))
          # description_element =
          # tree.find('.//{http://www.w3.org/1999/02/22-rdf-syntax-ns#}Description/')
  
          desc = tree.find('.//{http://www.w3.org/1999/02/22-rdf-syntax-ns#}Description')
          apps = desc.findall('.//{http://www.mozilla.org/2004/em-rdf#}targetApplication')
          for app in apps:
            desc.remove(app)
          if len(desc) and desc.attrib.has_key('{http://www.mozilla.org/2004/em-rdf#}id'):
              addon_id = desc.attrib['{http://www.mozilla.org/2004/em-rdf#}id']
          elif len(desc) and desc.find('.//{http://www.mozilla.org/2004/em-rdf#}id') is not None:
              addon_id = desc.find('.//{http://www.mozilla.org/2004/em-rdf#}id').text
          else:
              about = [e for e in tree.findall(
                          './/{http://www.w3.org/1999/02/22-rdf-syntax-ns#}Description') if
                           e.get('{http://www.w3.org/1999/02/22-rdf-syntax-ns#}about') ==
                           'urn:mozilla:install-manifest'
                      ]
  
              x = e.find('.//{http://www.w3.org/1999/02/22-rdf-syntax-ns#}Description')
  
              if len(about) == 0:
                  addon_element = tree.find('.//{http://www.mozilla.org/2004/em-rdf#}id')
                  addon_id = addon_element.text
              else:
                  addon_id = about[0].get('{http://www.mozilla.org/2004/em-rdf#}id')
  
          addon_path = os.path.join(self.profile, 'extensions', addon_id)
          copytree(addon, addon_path, preserve_symlinks=1)
          self.addons_installed.append(addon_path)
function_tokens: def install_addon ( self , addon ) : tmpdir = None if addon . endswith ( '.xpi' ) : tmpdir = tempfile . mkdtemp ( suffix = "." + os . path . split ( addon ) [ - 1 ] ) compressed_file = zipfile . ZipFile ( addon , "r" ) for name in compressed_file . namelist ( ) : if name . endswith ( '/' ) : makedirs ( os . path . join ( tmpdir , name ) ) else : if not os . path . isdir ( os . path . dirname ( os . path . join ( tmpdir , name ) ) ) : makedirs ( os . path . dirname ( os . path . join ( tmpdir , name ) ) ) data = compressed_file . read ( name ) f = open ( os . path . join ( tmpdir , name ) , 'wb' ) f . write ( data ) f . close ( ) addon = tmpdir tree = ElementTree . ElementTree ( file = os . path . join ( addon , 'install.rdf' ) ) # description_element = # tree.find('.//{http://www.w3.org/1999/02/22-rdf-syntax-ns#}Description/') desc = tree . find ( './/{http://www.w3.org/1999/02/22-rdf-syntax-ns#}Description' ) apps = desc . findall ( './/{http://www.mozilla.org/2004/em-rdf#}targetApplication' ) for app in apps : desc . remove ( app ) if len ( desc ) and desc . attrib . has_key ( '{http://www.mozilla.org/2004/em-rdf#}id' ) : addon_id = desc . attrib [ '{http://www.mozilla.org/2004/em-rdf#}id' ] elif len ( desc ) and desc . find ( './/{http://www.mozilla.org/2004/em-rdf#}id' ) is not None : addon_id = desc . find ( './/{http://www.mozilla.org/2004/em-rdf#}id' ) . text else : about = [ e for e in tree . findall ( './/{http://www.w3.org/1999/02/22-rdf-syntax-ns#}Description' ) if e . get ( '{http://www.w3.org/1999/02/22-rdf-syntax-ns#}about' ) == 'urn:mozilla:install-manifest' ] x = e . find ( './/{http://www.w3.org/1999/02/22-rdf-syntax-ns#}Description' ) if len ( about ) == 0 : addon_element = tree . find ( './/{http://www.mozilla.org/2004/em-rdf#}id' ) addon_id = addon_element . text else : addon_id = about [ 0 ] . get ( '{http://www.mozilla.org/2004/em-rdf#}id' ) addon_path = os . path . join ( self . profile , 'extensions' , addon_id ) copytree ( addon , addon_path , preserve_symlinks = 1 ) self . addons_installed . append ( addon_path )