def _build_extension(self, builder_class, project_path, out_path, cmd_args, build_steps, ignore):
        key = builder_class.key
        info = ExtensionInfo()
        kango_path = sys.path[0]
        builder = builder_class(info, kango_path)

        project_src_path = os.path.join(project_path, 'src')
        framework_src_path = os.path.join(kango_path, 'src', 'js')
        certificates_path = os.path.abspath(os.path.join(project_path, 'certificates'))

        builder.migrate((os.path.join(project_src_path, key)))

        logger.info('Building %s extension...' % key)

        extension_out_path = os.path.join(out_path, key)
        shutil.rmtree(extension_out_path, True)

        # merge framework and project sources
        self._copy_extension_files(info, framework_src_path, extension_out_path, key, ignore)
        self._copy_extension_files(info, project_src_path, extension_out_path, key, ignore)

        # copy files from additional source path
        additional_source_path = cmd_args.additional_source_path
        if additional_source_path is not None:
            paths = additional_source_path.split(';')
            for path in paths:
                self._copy_extension_files(info, path, extension_out_path, key, ignore)

        # add locales
        locales = list(self._get_locales(extension_out_path))
        if len(locales) > 0:
            info.locales = locales
            if info.default_locale == '':
                die('"locales" directory exists, but "default_locale" is not set')
            elif info.default_locale not in locales:
                die('Locale "%s" doesn\'t exist' % info.default_locale)

        builder.setup_update(out_path)
        extension_out_path = builder.build(extension_out_path, os.path.join(project_src_path, key), certificates_path,
                                           cmd_args)
        if extension_out_path:
            info.framework_version = '%s %s' % (settings.VERSION, settings.BUILD)
            info.framework_package_id = settings.PACKAGE_ID
            info.save(os.path.join(extension_out_path, self.EXTENSION_INFO_NAME))

            if not builder.has_native_require:
                self._wrap_js_modules(info, extension_out_path)

            # execute build steps
            for step in build_steps:
                step.pre_pack(extension_out_path, project_path, info, cmd_args)

            if not cmd_args.no_pack:
                builder.pack(out_path, os.path.abspath(extension_out_path), os.path.join(project_src_path, key),
                             certificates_path, cmd_args)
        else:
            die("Can't build %s extension" % key)
Esempio n. 2
0
    def _build_extension(self, builder_class, project_path, out_path, cmd_args, build_steps, ignore):
        key = builder_class.key
        info = ExtensionInfo()
        kango_path = sys.path[0]
        builder = builder_class(info, kango_path)

        project_src_path = os.path.join(project_path, 'src')
        framework_src_path = os.path.join(kango_path, 'src', 'js')
        certificates_path = os.path.abspath(os.path.join(project_path, 'certificates'))

        builder.migrate((os.path.join(project_src_path, key)))

        logger.info('Building %s extension...' % key)

        extension_out_path = os.path.join(out_path, key)
        shutil.rmtree(extension_out_path, True)

        # merge framework and project sources
        self._copy_extension_files(info, framework_src_path, extension_out_path, key, ignore)
        self._copy_extension_files(info, project_src_path, extension_out_path, key, ignore)

        # copy files from additional source path
        additional_source_path = cmd_args.additional_source_path
        if additional_source_path is not None:
            paths = additional_source_path.split(';')
            for path in paths:
                self._copy_extension_files(info, path, extension_out_path, key, ignore)

        # add locales
        locales = list(self._get_locales(extension_out_path))
        if len(locales) > 0:
            info.locales = locales
            if info.default_locale == '':
                die('"locales" directory exists, but "default_locale" is not set')
            elif info.default_locale not in locales:
                die('Locale "%s" doesn\'t exist' % info.default_locale)

        builder.setup_update(out_path)
        extension_out_path = builder.build(extension_out_path, os.path.join(project_src_path, key), certificates_path,
                                           cmd_args)
        if extension_out_path:
            info.framework_version = '%s %s' % (settings.VERSION, settings.BUILD)
            info.framework_package_id = settings.PACKAGE_ID
            info.save(os.path.join(extension_out_path, self.EXTENSION_INFO_NAME))

            if not builder.has_native_require:
                self._wrap_js_modules(info, extension_out_path)

            # execute build steps
            for step in build_steps:
                step.pre_pack(extension_out_path, project_path, info, cmd_args)

            if not cmd_args.no_pack:
                builder.pack(out_path, os.path.abspath(extension_out_path), os.path.join(project_src_path, key),
                             certificates_path, cmd_args)
        else:
            die("Can't build %s extension" % key)
 def _load_builders(self):
     import kango.builders.chrome
     import kango.builders.firefox
     import kango.builders.safari
     self._builder_cls = [
         kango.builders.chrome.ExtensionBuilder,
         kango.builders.firefox.ExtensionBuilder,
         kango.builders.safari.ExtensionBuilder
     ]
     try:
         import kango.builders.internet_explorer
         self._builder_cls.append(kango.builders.internet_explorer.ExtensionBuilder)
     except ImportError:
         logger.info('Contact [email protected] to enable IE support')
Esempio n. 4
0
 def __init__(self):
     import kango.builders.chrome
     import kango.builders.firefox
     import kango.builders.safari
     self._builders = [
         kango.builders.chrome.ExtensionBuilder,
         kango.builders.firefox.ExtensionBuilder,
         kango.builders.safari.ExtensionBuilder
     ]
     try:
         import kango.builders.internet_explorer
         self._builders.append(kango.builders.internet_explorer.ExtensionBuilder)
     except ImportError:
         logger.info('Contact [email protected] to enable IE support')
    def pack(self, output_path, extension_path, project_src_path,
             certificates_path):
        if not os.path.exists(certificates_path):
            os.makedirs(certificates_path)
        pem_path = os.path.join(certificates_path, 'chrome.pem')
        extension_dst = os.path.abspath(
            os.path.join(extension_path, '../', 'chrome.crx'))

        crx_path = os.path.join(output_path,
                                self.get_full_package_name(self._info))

        chrome_path = self.get_chrome_path()
        if chrome_path is not None:
            args = [
                chrome_path,
                '--pack-extension=%s' % extension_path, '--no-message-box'
            ]
            if os.path.isfile(pem_path):
                args.append('--pack-extension-key=%s' % pem_path)

            subprocess.Popen(args,
                             stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE).communicate()

            try:
                shutil.move(
                    os.path.abspath(
                        os.path.join(extension_path, '../', 'chrome.pem')),
                    pem_path)
            except:
                pass

            shutil.move(extension_dst, crx_path)
        else:
            logger.info('Chrome/Chromium is not installed, trying OpenSSL...')
            try:
                zip_path = self._pack_zip(output_path, extension_path)
                self._pack_via_open_ssl(zip_path, pem_path, crx_path)
            except:
                logger.error("Can't build extension with OpenSSL")

        if self._info.update_url != '':
            manifest_path = os.path.join(extension_path,
                                         self._manifest_filename)
            manifest = self._load_manifest(manifest_path)
            del manifest['update_url']
            self._save_manifest(manifest, manifest_path)

        self._pack_zip(output_path, extension_path)
Esempio n. 6
0
    def process(self):

        setup_logger()

        parser = argparse.ArgumentParser(description='%s %s' % (__title__, settings.VERSION))
        subparsers = parser.add_subparsers()

        for command_class in self._commands:
            command = command_class()
            subparser = command.init_subparser(subparsers)
            subparser.set_defaults(execute=command.execute)

        args = parser.parse_args()

        logger.info('Running %s v%s' % (__title__, settings.VERSION))

        args.execute(args)
Esempio n. 7
0
    def process(self):

        setup_logger()

        parser = argparse.ArgumentParser(description='%s %s' % (__title__, settings.VERSION))
        subparsers = parser.add_subparsers()

        for command_class in self._commands:
            command = command_class()
            subparser = command.init_subparser(subparsers)
            subparser.set_defaults(execute=command.execute)

        args = parser.parse_args()

        logger.info('Running %s v%s' % (__title__, settings.VERSION))

        args.execute(args)
Esempio n. 8
0
    def pack(self, output_path, extension_path, project_src_path, certificates_path, cmd_args):
        if not os.path.exists(certificates_path):
            os.makedirs(certificates_path)
        pem_path = os.path.join(certificates_path, 'chrome.pem')
        extension_dst = os.path.abspath(os.path.join(extension_path, '../', 'chrome.crx'))

        crx_path = os.path.join(output_path, self.get_full_package_name(self._info))

        chrome_path = self.get_chrome_path()
        if chrome_path is not None:
            args = [chrome_path, '--pack-extension=%s' % extension_path, '--no-message-box']
            if os.path.isfile(pem_path):
                args.append('--pack-extension-key=%s' % pem_path)

            subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()

            try:
                shutil.move(os.path.abspath(os.path.join(extension_path, '../', 'chrome.pem')), pem_path)
            except:
                pass

            shutil.move(extension_dst, crx_path)
        else:
            logger.info('Chrome/Chromium is not installed, trying OpenSSL...')
            try:
                zip_path = self._pack_zip(output_path, extension_path)
                self._pack_via_open_ssl(zip_path, pem_path, crx_path)
            except:
                logger.error("Can't build extension with OpenSSL")

        if self._info.update_url != '':
            manifest_path = os.path.join(extension_path, self._manifest_filename)
            manifest = self._load_manifest(manifest_path)
            del manifest['update_url']
            self._save_manifest(manifest, manifest_path)

        self._pack_zip(output_path, extension_path)
Esempio n. 9
0
    def create(self, project_directory, project_name):
        if project_directory == sys.path[0]:
            die('You must set project directory')

        if project_name is None:
            print 'Input project name: ',
            project_name = sys.stdin.readline()[:-1]

        logger.info('Creating project...')

        template_path = os.path.join(self.templates_directory,
                                     'browser_button')

        self._create_dir(project_directory)

        src_dir = os.path.join(project_directory, 'src')

        self._create_dir(os.path.join(src_dir, 'common'))
        self._create_dir(os.path.join(project_directory, 'certificates'))

        copy_dir_contents(template_path, src_dir)
        copy_dir_contents(
            os.path.join(sys.path[0], 'src', 'js', 'common', 'icons'),
            os.path.join(src_dir, 'common', 'icons'))

        info = ExtensionInfo()
        info_path = os.path.join(src_dir, 'common', self._extension_info_name)
        info.load(info_path)
        info.name = project_name
        info.save(info_path)

        self._create_extension_info(os.path.join(src_dir, 'firefox'),
                                    {'id': self.generate_uuid()})

        if self.opennssl_available():
            try:
                self._generate_private_key(
                    os.path.join(project_directory, 'certificates/chrome.pem'))
                self._create_extension_info(
                    os.path.join(src_dir, 'chrome'), {
                        'id':
                        self.get_chrome_extension_id(
                            os.path.join(project_directory,
                                         'certificates/chrome.pem'))
                    })
            except:
                logger.warning(
                    'OpenSSL found but failed to generate chrome extension id. Please set your Chrome extension id manually'
                )
        else:
            logger.warning(
                'OpenSSL not found, please set your Chrome extension id manually'
            )
            self._create_extension_info(os.path.join(src_dir, 'chrome'),
                                        {'id': self.generate_uuid()})

        bho_clsid = self.generate_uuid()
        toolbar_clsid = self.generate_uuid()
        engine_clsid = self.generate_uuid()

        self._create_extension_info(
            os.path.join(src_dir, 'ie'), {
                'id': bho_clsid,
                'com_objects': {
                    'bho': {
                        'clsid':
                        bho_clsid,
                        'iid':
                        self.get_iid_from_id(
                            '{06E7211D-0650-43CF-8498-4C81E83AEAAA}',
                            bho_clsid),
                        'libid':
                        self.generate_uuid()
                    },
                    'toolbar': {
                        'clsid':
                        toolbar_clsid,
                        'iid':
                        self.get_iid_from_id(
                            '{A0207057-3461-4F7F-B689-D016B7A03964}',
                            toolbar_clsid)
                    },
                    'engine': {
                        'clsid':
                        engine_clsid,
                        'iid':
                        self.get_iid_from_id(
                            '{06ADA96E-5E8C-4550-BEBF-141EFD188227}',
                            engine_clsid),
                        'libid':
                        self.generate_uuid()
                    }
                }
            })

        self._create_extension_info(
            os.path.join(src_dir, 'safari'), {
                'id':
                'com.kangoextensions.' +
                get_prefix_from_name(project_name).lower(),
                'developer_id':
                'YOUR_SAFARI_DEVELOPER_ID'
            })

        logger.info('Project created in directory %s' %
                    os.path.abspath(project_directory))
Esempio n. 10
0
    def create(self, project_directory, project_name):
        if project_directory == sys.path[0]:
            die('You must set project directory')

        if project_name is None:
            print 'Input project name: ',
            project_name = sys.stdin.readline()[:-1]

        logger.info('Creating project...')

        template_path = os.path.join(self.templates_directory, 'browser_button')

        self._create_dir(project_directory)

        src_dir = os.path.join(project_directory, 'src')

        self._create_dir(os.path.join(src_dir, 'common'))
        self._create_dir(os.path.join(project_directory, 'certificates'))

        copy_dir_contents(template_path, src_dir)
        copy_dir_contents(os.path.join(sys.path[0], 'src', 'js', 'common', 'icons'), os.path.join(src_dir, 'common', 'icons'))

        info = kango.ExtensionInfo()
        info_path = os.path.join(src_dir, 'common', self._extension_info_name)
        info.load(info_path)
        info.name = project_name
        info.save(info_path)

        self._create_extension_info(os.path.join(src_dir, 'firefox'), {'id': self.generate_uuid()})

        if self.opennssl_available():
            try:
                self._generate_private_key(os.path.join(project_directory, 'certificates/chrome.pem'))
                self._create_extension_info(os.path.join(src_dir, 'chrome'), {'id': self.get_chrome_extension_id(os.path.join(project_directory, 'certificates/chrome.pem'))})
            except:
                logger.warning('OpenSSL found but failed to generate chrome extension id. Please set your Chrome extension id manually')
        else:
            logger.warning('OpenSSL not found, please set your Chrome extension id manually')
            self._create_extension_info(os.path.join(src_dir, 'chrome'), {'id': self.generate_uuid()})

        bho_clsid = self.generate_uuid()
        toolbar_clsid = self.generate_uuid()
        engine_clsid = self.generate_uuid()

        self._create_extension_info(os.path.join(src_dir, 'ie'), {
            'id': bho_clsid,
            'com_objects': {
                'bho': {
                    'clsid': bho_clsid,
                    'iid': self.get_iid_from_id('{06E7211D-0650-43CF-8498-4C81E83AEAAA}', bho_clsid),
                    'libid': self.generate_uuid()
                },
                'toolbar': {
                    'clsid': toolbar_clsid,
                    'iid': self.get_iid_from_id('{A0207057-3461-4F7F-B689-D016B7A03964}', toolbar_clsid)
                },
                'engine': {
                    'clsid': engine_clsid,
                    'iid': self.get_iid_from_id('{06ADA96E-5E8C-4550-BEBF-141EFD188227}', engine_clsid),
                    'libid': self.generate_uuid()
                }
            }
        })

        self._create_extension_info(os.path.join(src_dir, 'safari'), {
            'id': 'com.kangoextensions.' + get_prefix_from_name(project_name).lower(),
            'developer_id': 'YOUR_SAFARI_DEVELOPER_ID'
        })

        self._create_extension_info(os.path.join(src_dir, 'opera'), {
            'id': 'http://kangoextensions.com/extensions/' + get_prefix_from_name(project_name).lower() + '/'
        })

        logger.info('Project created in directory %s' % os.path.abspath(project_directory))