#NEWLINE# def _install_extension( self , addon , unpack = True ) : #NEWLINE# #INDENT# '\n            Installs addon from a filepath, url\n            or directory of addons in the profile.\n            - path: url, path to .xpi, or directory of addons\n            - unpack: whether to unpack unless specified otherwise in the install.rdf\n        ' #NEWLINE# if ( addon == WEBDRIVER_EXT ) : #NEWLINE# #INDENT# addon = os . path . join ( os . path . dirname ( __file__ ) , WEBDRIVER_EXT ) #NEWLINE# #UNINDENT# tmpdir = None #NEWLINE# xpifile = None #NEWLINE# if addon . endswith ( '.xpi' ) : #NEWLINE# #INDENT# tmpdir = tempfile . mkdtemp ( suffix = ( '.' + os . path . split ( addon ) [ ( - 1 ) ] ) ) #NEWLINE# compressed_file = zipfile . ZipFile ( addon , 'r' ) #NEWLINE# for name in compressed_file . namelist ( ) : #NEWLINE# #INDENT# if name . endswith ( '/' ) : #NEWLINE# #INDENT# os . makedirs ( os . path . join ( tmpdir , name ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not os . path . isdir ( os . path . dirname ( os . path . join ( tmpdir , name ) ) ) ) : #NEWLINE# #INDENT# os . makedirs ( os . path . dirname ( os . path . join ( tmpdir , name ) ) ) #NEWLINE# #UNINDENT# data = compressed_file . read ( name ) #NEWLINE# with open ( os . path . join ( tmpdir , name ) , 'wb' ) as f : #NEWLINE# #INDENT# f . write ( data ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# xpifile = addon #NEWLINE# addon = tmpdir #NEWLINE# #UNINDENT# addon_details = self . _addon_details ( addon ) #NEWLINE# addon_id = addon_details . get ( 'id' ) #NEWLINE# assert addon_id , ( 'The addon id could not be found: %s' % addon ) #NEWLINE# extensions_path = os . path . join ( self . profile_dir , 'extensions' ) #NEWLINE# addon_path = os . path . join ( extensions_path , addon_id ) #NEWLINE# if ( ( not unpack ) and ( not addon_details [ 'unpack' ] ) and xpifile ) : #NEWLINE# #INDENT# if ( not os . path . exists ( extensions_path ) ) : #NEWLINE# #INDENT# os . makedirs ( extensions_path ) #NEWLINE# #UNINDENT# shutil . copy ( data , ( addon_path + '.xpi' ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# shutil . copytree ( addon , addon_path , symlinks = True ) #NEWLINE# #UNINDENT# if tmpdir : #NEWLINE# #INDENT# shutil . rmtree ( tmpdir )