Merge lp:~jamesh/bindwood/dev-install into lp:bindwood

Proposed by James Henstridge
Status: Merged
Approved by: dobey
Approved revision: 26
Merged at revision: 26
Proposed branch: lp:~jamesh/bindwood/dev-install
Merge into: lp:bindwood
Diff against target: 86 lines (+82/-0)
1 file modified
dev-install (+82/-0)
To merge this branch: bzr merge lp:~jamesh/bindwood/dev-install
Reviewer Review Type Date Requested Status
dobey (community) Approve
Eric Casteleijn (community) Approve
Review via email: mp+47015@code.launchpad.net

Commit message

Add a script for installing the extension into a Firefox profile.

Description of the change

Just a simple script to help with development. This will install the extension into a named Firefox profile such that it runs out of the branch checkout directory. This removes the need to rebuild and reinstall the XPI to test changes.

To post a comment you must log in.
Revision history for this message
Eric Casteleijn (thisfred) wrote :

Cool, +1

review: Approve
Revision history for this message
dobey (dobey) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'dev-install'
2--- dev-install 1970-01-01 00:00:00 +0000
3+++ dev-install 2011-01-21 07:29:53 +0000
4@@ -0,0 +1,82 @@
5+#!/usr/bin/python
6+"""Install an extension proxy into a Firefox profile pointing here.
7+
8+This is based on the method described on the Mozilla developer wiki:
9+
10+https://developer.mozilla.org/en/setting_up_extension_development_environment
11+
12+This provides an alternative to building and installing XPIs during
13+development.
14+"""
15+
16+import os
17+import ConfigParser
18+import sys
19+from xml.etree import cElementTree as ET
20+
21+
22+profiles_ini = os.path.join(
23+ os.environ['HOME'], '.mozilla', 'firefox', 'profiles.ini')
24+
25+
26+def get_profile_dirs(profiles_ini):
27+ """Get a map of Firefox profile names to profile directories."""
28+ cp = ConfigParser.ConfigParser()
29+ cp.read(profiles_ini)
30+ profiles = {}
31+ for section in cp.sections():
32+ if not section.startswith('Profile'):
33+ continue
34+ name = cp.get(section, 'name')
35+ path = cp.get(section, 'path')
36+ if cp.getboolean(section, 'isrelative'):
37+ path = os.path.join(os.path.dirname(profiles_ini), path)
38+ profiles[name] = path
39+ return profiles
40+
41+
42+def get_extension_id(install_rdf):
43+ """Get the extension ID from a Firefox extension install.rdf file."""
44+ # This isn't doing proper RDF processing, but should work for most
45+ # extension RDF files.
46+ tree = ET.parse(install_rdf)
47+ id_node = tree.find(
48+ '{http://www.w3.org/1999/02/22-rdf-syntax-ns#}Description/'
49+ '{http://www.mozilla.org/2004/em-rdf#}id')
50+ assert id_node is not None, "Could not find extension ID"
51+ return id_node.text
52+
53+
54+def install_extension_proxy(extension_dir, profile_dir):
55+ """Install an extension proxy file to a Firefox profile."""
56+ extension_dir = os.path.realpath(extension_dir)
57+ extension_id = get_extension_id(
58+ os.path.join(extension_dir, 'install.rdf'))
59+ proxy_file = os.path.join(profile_dir, 'extensions', extension_id)
60+ if os.path.exists(proxy_file):
61+ os.remove(proxy_file)
62+ fp = open(proxy_file, "wb")
63+ fp.write(extension_dir)
64+ fp.close()
65+ # Make sure the new extension is reloaded on next startup.
66+ for file in ['extensions.cache', 'extensions.ini', 'extensions.rdf']:
67+ path = os.path.join(profile_dir, file)
68+ if os.path.exists(path):
69+ os.remove(path)
70+
71+
72+def main(argv):
73+ """Install the extension into a named profile."""
74+ if len(argv) < 2:
75+ sys.stderr.write('usage: %s PROFILE\n' % argv[0])
76+ return 1
77+ profile_name = argv[1]
78+ profiles = get_profile_dirs(profiles_ini)
79+ if profile_name not in profiles:
80+ sys.stderr.write('Unknown profile %s\n' % profile_name)
81+ install_extension_proxy('.', profiles[profile_name])
82+
83+
84+if __name__ == '__main__':
85+ sys.exit(main(sys.argv))
86+

Subscribers

People subscribed via source and target branches