#!/usr/bin/env python # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. import argparse import json import uuid import sys import os.path parser = argparse.ArgumentParser(description='Create install.rdf from manifest.json') parser.add_argument('--locale') parser.add_argument('--profile') parser.add_argument('--uuid') parser.add_argument('dir') args = parser.parse_args() manifestFile = os.path.join(args.dir, 'manifest.json') manifest = json.load(open(manifestFile)) locale = args.locale if not locale: locale = manifest.get('default_locale', 'en-US') def process_locale(s): if s.startswith('__MSG_') and s.endswith('__'): tag = s[6:-2] path = os.path.join(args.dir, '_locales', locale, 'messages.json') data = json.load(open(path)) return data[tag]['message'] else: return s id = args.uuid if not id: id = '{' + str(uuid.uuid4()) + '}' name = process_locale(manifest['name']) desc = process_locale(manifest['description']) version = manifest['version'] installFile = open(os.path.join(args.dir, 'install.rdf'), 'w') print >>installFile, '' print >>installFile, '>installFile, ' xmlns:em="http://www.mozilla.org/2004/em-rdf#">' print >>installFile print >>installFile, ' ' print >>installFile, ' {}'.format(id) print >>installFile, ' 2' print >>installFile, ' {}'.format(name) print >>installFile, ' {}'.format(desc) print >>installFile, ' {}'.format(version) print >>installFile, ' true' print >>installFile, ' ' print >>installFile, ' ' print >>installFile, ' {ec8030f7-c20a-464f-9b0e-13a3a9e97384}' print >>installFile, ' 4.0' print >>installFile, ' 50.0' print >>installFile, ' ' print >>installFile, ' ' print >>installFile, ' ' print >>installFile, '' installFile.close() bootstrapPath = os.path.join(os.path.dirname(sys.argv[0]), 'bootstrap.js') data = open(bootstrapPath).read() boot = open(os.path.join(args.dir, 'bootstrap.js'), 'w') boot.write(data) boot.close() if args.profile: os.system('mkdir -p {}/extensions'.format(args.profile)) output = open(args.profile + '/extensions/' + id, 'w') print >>output, os.path.realpath(args.dir) output.close() else: dir = os.path.realpath(args.dir) if dir[-1] == os.sep: dir = dir[:-1] os.system('cd "{}"; zip ../"{}".xpi -r *'.format(args.dir, os.path.basename(dir)))