Skip to content

Commit

Permalink
Updating xpi install to align with mozprofile
Browse files Browse the repository at this point in the history
  • Loading branch information
AutomatedTester committed Apr 22, 2014
1 parent 0184147 commit 983d5b2
Showing 1 changed file with 57 additions and 19 deletions.
76 changes: 57 additions & 19 deletions py/selenium/webdriver/firefox/firefox_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import os
import re
import shutil
import sys
import tempfile
import zipfile

Expand All @@ -40,6 +41,10 @@
EXTENSION_NAME = "fxdriver@googlecode.com"


class AddonFormatError(Exception):
"""Exception for not well-formed add-on manifest files"""


class FirefoxProfile(object):
ANONYMOUS_PROFILE_NAME = "WEBDRIVER_ANONYMOUS_PROFILE"
DEFAULT_PREFERENCES = None
Expand Down Expand Up @@ -280,20 +285,22 @@ def _install_extension(self, addon, unpack=True):

def _addon_details(self, addon_path):
"""
returns a dictionary of details about the addon
- addon_path : path to the addon directory
Returns:
{'id': 'rainbow@colors.org', # id of the addon
'version': '1.4', # version of the addon
'name': 'Rainbow', # name of the addon
'unpack': False } # whether to unpack the addon
Returns a dictionary of details about the addon.
:param addon_path: path to the add-on directory or XPI
Returns::
{'id': u'rainbow@colors.org', # id of the addon
'version': u'1.4', # version of the addon
'name': u'Rainbow', # name of the addon
'unpack': False } # whether to unpack the addon
"""

# TODO: We don't use the unpack variable yet, but we should: bug 662683
details = {
'id': None,
'unpack': False,
'name': None,
'unpack': True,
'version': None
}

Expand All @@ -316,17 +323,48 @@ def get_text(element):
rc.append(node.data)
return ''.join(rc).strip()

doc = minidom.parse(os.path.join(addon_path, 'install.rdf'))
if not os.path.exists(addon_path):
raise IOError('Add-on path does not exist: %s' % addon_path)

# Get the namespaces abbreviations
em = get_namespace_id(doc, "http://www.mozilla.org/2004/em-rdf#")
rdf = get_namespace_id(doc, "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
try:
if zipfile.is_zipfile(addon_path):
# Bug 944361 - We cannot use 'with' together with zipFile because
# it will cause an exception thrown in Python 2.6.
try:
compressed_file = zipfile.ZipFile(addon_path, 'r')
manifest = compressed_file.read('install.rdf')
finally:
compressed_file.close()
elif os.path.isdir(addon_path):
with open(os.path.join(addon_path, 'install.rdf'), 'r') as f:
manifest = f.read()
else:
raise IOError('Add-on path is neither an XPI nor a directory: %s' % addon_path)
except (IOError, KeyError), e:
raise AddonFormatError, str(e), sys.exc_info()[2]

description = doc.getElementsByTagName(rdf + "Description").item(0)
for node in description.childNodes:
# Remove the namespace prefix from the tag for comparison
entry = node.nodeName.replace(em, "")
if entry in details.keys():
details.update({entry: get_text(node)})
try:
doc = minidom.parseString(manifest)

# Get the namespaces abbreviations
em = get_namespace_id(doc, 'http://www.mozilla.org/2004/em-rdf#')
rdf = get_namespace_id(doc, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#')

description = doc.getElementsByTagName(rdf + 'Description').item(0)
for node in description.childNodes:
# Remove the namespace prefix from the tag for comparison
entry = node.nodeName.replace(em, "")
if entry in details.keys():
details.update({entry: get_text(node)})
except Exception, e:
raise AddonFormatError, str(e), sys.exc_info()[2]

# turn unpack into a true/false value
if isinstance(details['unpack'], basestring):
details['unpack'] = details['unpack'].lower() == 'true'

# If no ID is set, the add-on is invalid
if details.get('id') is None:
raise AddonFormatError('Add-on id could not be found.')

return details

0 comments on commit 983d5b2

Please sign in to comment.