19

Jan

Filed in Code, Python with 2 comments |

(Because I didn’t know what else to call it).

Anyways, I updated to Firefox 3 when RC1 came out. I figure, “hey, it’s about to be released, extensions will work soon”. Then they go and back down. Me being as a developer as I am (generally lazy), I didn’t want to uninstall. Plus there’s the fact that the new autocomplete is pretty shiny.

I quickly learned that you could simply swap out the version number in the manifest to allow the addon to load. Granted, this can cause problems, but I’m willing to face problems as long as I can at least *try* to use Firebug :)

So this morning I drafted up a quick Python script which will actually run through a list of files and update the min/maxVersion fields as needed. I plan to throw up a quick web form this weekend to let you do it by simply pointing to the URL or uploading the .XPI and then installing the updated one.

Update: I went ahead and created a little webpage which executes the Python script and feeds the updated extension back to you. Check out the Firefox Addon Version Converter.

Source: Firefox Extension Version Changer

"""
Firefox Addon Version Updater
Created by David Cramer (http://www.davidcramer.net/)
 
Use this to update the minVersion and/or maxVersion fields in the firefox
extension manifest files.
 
e.g. convert extension to 3.x
python convert.py <file.xpi> --max-version=3.*
"""
 
 
import zipfile
import re
 
MIN_VERSION = False
MAX_VERSION = '3.*'
 
regexp = r'(?m)<em:id>{%(target_id)s}</em:id>\s*<em:minVersion>(.+)</em:minVersion>\s*<em:maxVersion>(.+)</em:maxVersion>'
 
def tweak_addon_version_reqs(filepath, min_version=None, max_version=None):
    if min_version is None:
        min_version = MIN_VERSION
    if max_version is None:
        max_version = MAX_VERSION
    archive = zipfile.ZipFile(filepath, 'a')
    for fname in archive.namelist():
        if fname[-4:] == '.rdf':
            data = archive.read(fname)
            # FireFox
            target_id = 'ec8030f7-c20a-464f-9b0e-13a3a9e97384'
            opts = {
                'target_id': target_id,
                'min_version': min_version or '\g<1>',
                'max_version': max_version or '\g<2>',
            }
            data = re.sub(regexp % opts, r'<em:id>{%(target_id)s}</em:id>' \
            '<em:minVersion>%(min_version)s</em:minVersion>' \
            '<em:maxVersion>%(max_version)s</em:maxVersion>' % opts, data)
            archive.writestr(fname, data)
            break
    archive.close()
 
def main():
    from optparse import OptionParser
    usage = "usage: %prog [options] files"
    parser = OptionParser(usage)
    parser.add_option("-b", "--min-version", dest="min_version",
                  help="modify minVersion field")
    parser.add_option("-e", "--max-version", dest="max_version",
                  help="modify maxVersion field")
    options, files = parser.parse_args()
    if not files:
        parser.error("you must specify at least one file")
    for fname in files:
        tweak_addon_version_reqs(fname, options.min_version, options.max_version)
 
if __name__ == '__main__':
    main()

2 Responses to "Firefox Extension Version Changer"

Subscribe to this topic with RSS or get the Trackback URL
Akeem McLennon (Feb 23rd):

I just tried using it with Firefox Beta 3 and Firebug, but it said the extension was incompatible.

Leave A Reply

 Username (*required)

 Email Address (*private)

 Website (*optional)

Note: Comments moderation may be active so there is no need to resubmit your comment.