def package_firefox(build):
	development_dir = path.join('development', 'firefox')
	release_dir = path.join('release', 'firefox')
	if not path.isdir(release_dir):
		os.makedirs(release_dir)

	xpi_filename = '{name}.xpi'.format(name=build.config['xml_safe_name'])
	IGNORED_FILES = ['.hgignore', '.DS_Store',
					 'application.ini', xpi_filename]

	with cd(development_dir):
		zipf = zipfile.ZipFile(xpi_filename, 'w', zipfile.ZIP_DEFLATED)
		for dirpath, dirnames, filenames in os.walk('.'):
			filenames = list(filter_filenames(filenames, IGNORED_FILES))
			dirnames[:] = filter_dirnames(dirnames)
			for filename in filenames:
				abspath = os.path.join(dirpath, filename)
				LOG.info('Adding: %s' % abspath)
				zipf.write(abspath)
		zipf.close()
	shutil.move(path.join(development_dir, xpi_filename), path.join(release_dir, xpi_filename))
def package_firefox(build):
	development_dir = path.join('development', 'firefox')
	release_dir = path.join('release', 'firefox')
	if not path.isdir(release_dir):
		os.makedirs(release_dir)

	xpi_filename = '{name}.xpi'.format(name=build.config['xml_safe_name'])
	IGNORED_FILES = ['.hgignore', '.DS_Store', 'install.rdf',
					 'application.ini', xpi_filename]

	with cd(development_dir):
		zipf = zipfile.ZipFile(xpi_filename, 'w', zipfile.ZIP_DEFLATED)
		for dirpath, dirnames, filenames in os.walk('.'):
			filenames = list(filter_filenames(filenames, IGNORED_FILES))
			dirnames[:] = filter_dirnames(dirnames)
			for filename in filenames:
				abspath = os.path.join(dirpath, filename)
				LOG.info('Adding: %s' % abspath)
				zipf.write(abspath)
		zipf.close()
	shutil.move(path.join(development_dir, xpi_filename), path.join(release_dir, xpi_filename))
示例#3
0
def package_chrome(build):
    development_dir = path.join("development", "chrome")
    release_dir = path.join("release", "chrome")
    if not path.isdir(release_dir):
        os.makedirs(release_dir)

    # Make sure we have openssl otherwise show manual instructions
    openssl_check = lib.PopenWithoutNewConsole('openssl version',
                                               shell=True,
                                               stdout=PIPE,
                                               stderr=STDOUT)
    if openssl_check.wait() != 0:
        msg = """Packaging a Chrome extensions requires openssl.
Alternatively you can manually package it. The required steps are:

	1) Go to chrome:extensions in the Chrome browser
	2) Make sure "developer mode" is on (top right corner)')
	3) Use "Pack extension" and use use this for the root: 
	   
        <app dir>/{chrome_folder}

More information on packaging Chrome extensions can be found here:
	http://legacy-docs.trigger.io/en/v1.4/best_practice/release_browser.html#chrome
	http://code.google.com/chrome/extensions/packaging.html
""".format(chrome_folder="development/chrome")
        LOG.info(msg)
        raise CouldNotLocate("Make sure 'openssl' is in your path")

    # We need a private key to package chrome extensions
    crx_key = build.tool_config.get('chrome.profile.crx_key')
    crx_key_path = build.tool_config.get('chrome.profile.crx_key_path')

    if not crx_key:
        key_msg = """Packaging a Chrome extension requires a private key.
You can generate this key with openssl:

    openssl genrsa -out crxkey.pem 2048

Keep this key safe and secure. It is needed to sign all future versions
of the extension. Add the following to <app dir>/local_config.json to use the key:

    "chrome": {
        "profile": {
            "crx_key": "crxkey.pem",
            "crx_key_path": "<path to crxkey.pem>",
        }
    }
"""
        LOG.info(key_msg)
        return

    # HACK: build.usercode seems to be the only way to get a reference to the app directory.
    crx_key_file = path.realpath(
        path.join(build.usercode, '..', crx_key_path, crx_key))
    crx_filename = '{name}.crx'.format(name=build.config['xml_safe_name'])
    IGNORED_FILES = ['.hgignore', '.DS_Store', 'application.ini', crx_filename]

    # Create standard zip file
    with cd(development_dir):
        zipf = zipfile.ZipFile(crx_filename, 'w', zipfile.ZIP_DEFLATED)
        for dirpath, dirnames, filenames in os.walk('.'):
            filenames = list(filter_filenames(filenames, IGNORED_FILES))
            dirnames[:] = filter_dirnames(dirnames)
            for filename in filenames:
                abspath = os.path.join(dirpath, filename)
                LOG.info('Adding: %s' % abspath)
                zipf.write(abspath)
        zipf.close()

    # Generate signature
    signature, pubkey = _generate_signature(
        path.join(development_dir, crx_filename), crx_key_file)

    # Combine magic, public key and signature into header and prepend to zip file
    magic = 'Cr24'
    version = struct.pack('<I', 2)
    pubkey_len = struct.pack('<I', len(pubkey))
    signature_len = struct.pack('<I', len(signature))

    with open(path.join(development_dir, crx_filename), 'rb') as crx:
        zip_data = crx.read()

    with open(path.join(development_dir, crx_filename), 'wb') as crx:
        data = [
            magic, version, pubkey_len, signature_len, pubkey, signature,
            zip_data
        ]
        for d in data:
            crx.write(d)

    shutil.move(path.join(development_dir, crx_filename),
                path.join(release_dir, crx_filename))
def package_chrome(build):
	development_dir = path.join("development", "chrome")
	release_dir = path.join("release", "chrome")
	if not path.isdir(release_dir):
		os.makedirs(release_dir)

	# Make sure we have openssl otherwise show manual instructions
	openssl_check = lib.PopenWithoutNewConsole('openssl version', shell=True, stdout=PIPE, stderr=STDOUT)
	if openssl_check.wait() != 0:
		msg = """Packaging a Chrome extensions requires openssl.
Alternatively you can manually package it. The required steps are:

	1) Go to chrome:extensions in the Chrome browser
	2) Make sure "developer mode" is on (top right corner)')
	3) Use "Pack extension" and use use this for the root: 
	   
        <app dir>/{chrome_folder}

More information on packaging Chrome extensions can be found here:
	http://legacy-docs.trigger.io/en/v1.4/best_practice/release_browser.html#chrome
	http://code.google.com/chrome/extensions/packaging.html
""".format(chrome_folder="development/chrome")
		LOG.info(msg)
		raise CouldNotLocate("Make sure 'openssl' is in your path")

	# We need a private key to package chrome extensions
	crx_key = build.tool_config.get('chrome.profile.crx_key')
	crx_key_path = build.tool_config.get('chrome.profile.crx_key_path')

	if not crx_key:
		key_msg = """Packaging a Chrome extension requires a private key.
You can generate this key with openssl:

    openssl genrsa -out crxkey.pem 2048

Keep this key safe and secure. It is needed to sign all future versions
of the extension. Add the following to <app dir>/local_config.json to use the key:

    "chrome": {
        "profile": {
            "crx_key": "crxkey.pem",
            "crx_key_path": "<path to crxkey.pem>",
        }
    }
"""
		LOG.info(key_msg)
		return

	# HACK: build.usercode seems to be the only way to get a reference to the app directory.
	crx_key_file = path.realpath(path.join(build.usercode, '..', crx_key_path, crx_key))
	crx_filename = '{name}.crx'.format(name=build.config['xml_safe_name'])
	IGNORED_FILES = ['.hgignore', '.DS_Store',
					 'application.ini', crx_filename]

	# Create standard zip file
	with cd(development_dir):
		zipf = zipfile.ZipFile(crx_filename, 'w', zipfile.ZIP_DEFLATED)
		for dirpath, dirnames, filenames in os.walk('.'):
			filenames = list(filter_filenames(filenames, IGNORED_FILES))
			dirnames[:] = filter_dirnames(dirnames)
			for filename in filenames:
				abspath = os.path.join(dirpath, filename)
				LOG.info('Adding: %s' % abspath)
				zipf.write(abspath)
		zipf.close()

	# Generate signature
	signature, pubkey = _generate_signature(path.join(development_dir, crx_filename), crx_key_file)

	# Combine magic, public key and signature into header and prepend to zip file
	magic = 'Cr24'
	version = struct.pack('<I', 2)
	pubkey_len = struct.pack('<I', len(pubkey))
	signature_len = struct.pack('<I', len(signature))

	with open(path.join(development_dir, crx_filename), 'rb') as crx:
		zip_data = crx.read()

	with open(path.join(development_dir, crx_filename), 'wb') as crx:
		data = [magic, version, pubkey_len, signature_len, pubkey, signature, zip_data]
		for d in data:
			crx.write(d)

	shutil.move(path.join(development_dir, crx_filename), path.join(release_dir, crx_filename))