コード例 #1
0
def package_ie(build, **kw):
    'Run NSIS'

    nsis_check = lib.PopenWithoutNewConsole('makensis -VERSION',
                                            shell=True,
                                            stdout=PIPE,
                                            stderr=STDOUT)
    stdout, stderr = nsis_check.communicate()

    if nsis_check.returncode != 0:
        raise CouldNotLocate(
            "Make sure the 'makensis' executable is in your path")

    # JCB: need to check nsis version in stdout here?

    development_dir = path.join("development", "ie")
    release_dir = path.join("release", "ie")
    if not path.isdir(release_dir):
        os.makedirs(release_dir)

    for arch in ('x86', 'x64'):
        nsi_filename = "setup-{arch}.nsi".format(arch=arch)

        package = lib.PopenWithoutNewConsole('makensis {nsi}'.format(
            nsi=path.join(development_dir, "dist", nsi_filename)),
                                             stdout=PIPE,
                                             stderr=STDOUT,
                                             shell=True)

        out, err = package.communicate()

        if package.returncode != 0:
            raise IEError("problem running {arch} IE build: {stdout}".format(
                arch=arch, stdout=out))

        # move output to release directory of IE directory
        for exe in glob.glob(development_dir + "/dist/*.exe"):
            shutil.move(
                exe,
                path.join(
                    release_dir, "{name}-{version}-{arch}.exe".format(
                        name=build.config.get('name', 'Forge App'),
                        version=build.config.get('version', '0.1'),
                        arch=arch)))
コード例 #2
0
def _install_sdk_automatically():
    # Attempt download
    temp_d = tempfile.mkdtemp()
    try:
        LOG.info('Downloading Android SDK (about 30MB, may take some time)')
        if sys.platform.startswith('win'):
            path_info = _download_sdk_for_windows(temp_d)
        elif sys.platform.startswith('darwin'):
            path_info = _download_sdk_for_mac(temp_d)
        elif sys.platform.startswith('linux'):
            path_info = _download_sdk_for_linux(temp_d)

        _update_sdk(path_info)

        LOG.info('Android SDK update complete')
        return path_info
    except Exception, e:
        LOG.error(e)
        raise CouldNotLocate(
            "Automatic SDK download failed, please install manually and specify with the --android.sdk flag"
        )
コード例 #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))
コード例 #4
0
def package_ie(build, **kw):
    'Sign executables, Run NSIS'

    # On OS X use the nsis executable and files we ship
    if sys.platform.startswith('darwin'):
        nsis_osx = os.path.realpath(
            os.path.join(os.path.dirname(__file__), '../lib/nsis_osx'))
        nsis_cmd = 'NSISDIR={}/share/nsis PATH={}/bin/:$PATH makensis'.format(
            nsis_osx, nsis_osx)
    else:
        nsis_cmd = 'makensis'
    LOG.debug("Using nsis command: {nsis_cmd}".format(nsis_cmd=nsis_cmd))

    nsis_check = lib.PopenWithoutNewConsole(
        "{nsis_cmd} -VERSION".format(nsis_cmd=nsis_cmd),
        shell=True,
        stdout=PIPE,
        stderr=STDOUT)
    stdout, stderr = nsis_check.communicate()

    if nsis_check.returncode != 0:
        raise CouldNotLocate(
            "Make sure the 'makensis' executable is in your path")

    # JCB: need to check nsis version in stdout here?

    # Sign executables
    certificate = build.tool_config.get('ie.profile.developer_certificate')
    certificate_path = build.tool_config.get(
        'ie.profile.developer_certificate_path')
    certificate_password = build.tool_config.get(
        'ie.profile.developer_certificate_password')
    if certificate:
        # Figure out which signtool to use
        signtool = _check_signtool(build)
        if signtool == None:
            raise CouldNotLocate(
                "Make sure the 'signtool' or 'osslsigncode' executable is in your path"
            )
        LOG.info('Signing IE executables with: {signtool}'.format(
            signtool=signtool))

        _sign_app(build=build,
                  signtool=signtool,
                  certificate=certificate,
                  certificate_path=certificate_path,
                  certificate_password=certificate_password)

    development_dir = path.join("development", "ie")
    release_dir = path.join("release", "ie")
    if not path.isdir(release_dir):
        os.makedirs(release_dir)

    for arch in ('x86', 'x64'):
        nsi_filename = "setup-{arch}.nsi".format(arch=arch)

        package = lib.PopenWithoutNewConsole('{nsis_cmd} {nsi}'.format(
            nsis_cmd=nsis_cmd,
            nsi=path.join(development_dir, "dist", nsi_filename)),
                                             stdout=PIPE,
                                             stderr=STDOUT,
                                             shell=True)

        out, err = package.communicate()

        if package.returncode != 0:
            raise IEError("problem running {arch} IE build: {stdout}".format(
                arch=arch, stdout=out))

        # move output to release directory of IE directory and sign it
        for exe in glob.glob(development_dir + "/dist/*.exe"):
            destination = path.join(
                release_dir, "{name}-{version}-{arch}.exe".format(
                    name=build.config.get('name', 'Forge App'),
                    version=build.config.get('version', '0.1'),
                    arch=arch))
            shutil.move(exe, destination)
            if certificate:
                _sign_executable(build=build,
                                 signtool=signtool,
                                 target=destination,
                                 certificate=certificate,
                                 certificate_path=certificate_path,
                                 certificate_password=certificate_password)