<commit_before>#!/usr/bin/env python
#
# Copyright 2013 <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import subprocess
import xml.etree.ElementTree as ET

from glob import glob
from tempfile import mkdtemp
from shutil import rmtree
from autopkglib.DmgMounter import DmgMounter
from autopkglib import ProcessorError

__all__ = ["OracleJava7Versioner"]


class OracleJava7Versioner(DmgMounter):
    description = "Extracts a ."
    input_variables = {
        "dmg_path": {
            "required": True,
            "description": "Path to a dmg containing the Oracle Java 7 JRE.",
        },
    }
    output_variables = {
        "plugin_cfbundleversion": {
            "description": "CFBundleVersion used by the web plugin.",
        },
        "plugin_displayname": {
            "description": "Release name, ie. 'Java 7 Update N'.",
        },
    }

    __doc__ = description

    def main(self):
        mount_point = self.mount(self.env["dmg_path"])
        # Wrap all other actions in a try/finally so the image is always
        # unmounted.
        try:
            tmp = mkdtemp(prefix='autopkg')
            pkgpath = glob(os.path.join(mount_point, "*.pkg"))[0]
            xarcmd = ["/usr/bin/xar", "-x", "-C", tmp, "-f", 
                      pkgpath, "--exclude", "Payload"]
            subprocess.call(xarcmd)
            with open(os.path.join(
                tmp, "javaappletplugin.pkg/PackageInfo"), "r") as fd:
                pkginfo = fd.read()
            rmtree(tmp)

            root = ET.fromstring(pkginfo)
            version = root.find(
                "./bundle[@id='com.oracle.java.JavaAppletPlugin']").get(
                "CFBundleVersion")

            self.env["plugin_cfbundleversion"] = version
            self.env["plugin_displayname"] = os.path.basename(
                pkgpath).split(".pkg")[0]
            self.output("CFBundleVersion is %s" % version)
        except BaseException as e:
            raise ProcessorError(e)
        finally:
            self.unmount(self.env["dmg_path"])

if __name__ == "__main__":
    processor = OracleJava7Versioner()
    processor.execute_shell()<commit_msg>OracleJava7: support for Python 2.6<commit_after>#!/usr/bin/env python
#
# Copyright 2013 <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import subprocess
import xml.etree.ElementTree as ET

from glob import glob
from tempfile import mkdtemp
from shutil import rmtree
from autopkglib.DmgMounter import DmgMounter
from autopkglib import ProcessorError

__all__ = ["OracleJava7Versioner"]


class OracleJava7Versioner(DmgMounter):
    description = "Extracts a ."
    input_variables = {
        "dmg_path": {
            "required": True,
            "description": "Path to a dmg containing the Oracle Java 7 JRE.",
        },
    }
    output_variables = {
        "plugin_cfbundleversion": {
            "description": "CFBundleVersion used by the web plugin.",
        },
        "plugin_displayname": {
            "description": "Release name, ie. 'Java 7 Update N'.",
        },
    }

    __doc__ = description

    def main(self):
        mount_point = self.mount(self.env["dmg_path"])
        # Wrap all other actions in a try/finally so the image is always
        # unmounted.
        try:
            tmp = mkdtemp(prefix='autopkg')
            pkgpath = glob(os.path.join(mount_point, "*.pkg"))[0]
            xarcmd = ["/usr/bin/xar", "-x", "-C", tmp, "-f", 
                      pkgpath, "--exclude", "Payload"]
            subprocess.call(xarcmd)
            with open(os.path.join(
                tmp, "javaappletplugin.pkg/PackageInfo"), "r") as fd:
                pkginfo = fd.read()
            rmtree(tmp)

            root = ET.fromstring(pkginfo)
            bundles = root.findall("bundle")
            for bundle in bundles:
                if bundle.get("id") == "com.oracle.java.JavaAppletPlugin":
                    version = bundle.get("CFBundleVersion")

            self.env["plugin_cfbundleversion"] = version
            self.env["plugin_displayname"] = os.path.basename(
                pkgpath).split(".pkg")[0]
            self.output("CFBundleVersion is %s" % version)
        except BaseException as e:
            raise ProcessorError(e)
        finally:
            self.unmount(self.env["dmg_path"])

if __name__ == "__main__":
    processor = OracleJava7Versioner()
    processor.execute_shell()
{'fraction_non_alphanumeric': 0.10738007380073801, 'fraction_numerical': 0.006088560885608856, 'mean_word_length': 2.3966165413533833, 'pattern_counts': {'":': 17, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6627467', 'n_tokens_mistral': 1584, 'n_tokens_neox': 1532, 'n_words': 460}