<commit_before>#!/usr/bin/python
#
# Copyright 2015 <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.
"""See docstring for PackageInfoReader class"""

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

from autopkglib import Processor, ProcessorError


__all__ = ["PackageInfoReader"]


class PackageInfoReader(Processor):
    """Extracts attributes from a PackageInfo file extracted from a flat package."""

    description = __doc__
    input_variables = {
        "info_path": {
            "required": True,
            "description": (
                "Path to a PackageInfo file to be read. "),
        },
    }
    output_variables = {
        "packageinfo_reader_output_variables": {
            "description": (
                "Output variables per packageinfo attributes. "
                "Note that this output variable is used as both a "
                "placeholder for documentation and for auditing purposes. "
                "One should use the actual named output variables as values "
                "to refer to the output of this processor.")
        },
    }


    def main(self):
        # Check whether this is at least a valid path
        if not os.path.exists(path):
            raise ProcessorError("Path '%s' doesn't exist!" % path)

        # Try to read the PackageInfo file
        self.output("Reading: %s" % path)
        try:
            tree = ET.parse(path)
            info = tree.getroot()
        except Error as err:
            raise ProcessorError(err)

        # Copy each PackageInfo's key's value and assign to new env variables
        self.env["packageinfo_reader_output_variables"] = {}
        for key in root.attrib:
            self.env["packageinfo_" + str(key)] = info.attrib.get(key)
            self.output(
                "Assigning value of '%s' to output variable '%s'"
                % (self.env["packageinfo_" + str(key)], info.attrib.get(key)))
            # This one is for documentation/recordkeeping
            self.env["plist_reader_output_variables"]["packageinfo_" + str(key)] = (
                self.env[info.attrib.get(key)])
     


if __name__ == '__main__':
    PROCESSOR = PackageInfoReader()<commit_msg>Fixed incorrect reference to plist<commit_after>#!/usr/bin/python
#
# Copyright 2015 <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.
"""See docstring for PackageInfoReader class"""

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

from autopkglib import Processor, ProcessorError


__all__ = ["PackageInfoReader"]


class PackageInfoReader(Processor):
    """Extracts attributes from a PackageInfo file extracted from a flat package."""

    description = __doc__
    input_variables = {
        "info_path": {
            "required": True,
            "description": (
                "Path to a PackageInfo file to be read. "),
        },
    }
    output_variables = {
        "packageinfo_reader_output_variables": {
            "description": (
                "Output variables per packageinfo attributes. "
                "Note that this output variable is used as both a "
                "placeholder for documentation and for auditing purposes. "
                "One should use the actual named output variables as values "
                "to refer to the output of this processor.")
        },
    }


    def main(self):
    	path = self.env["info_path"]
        # Check whether this is at least a valid path
        if not os.path.exists(path):
            raise ProcessorError("Path '%s' doesn't exist!" % path)

        # Try to read the PackageInfo file
        self.output("Reading: %s" % path)
        try:
            tree = ET.parse(path)
            info = tree.getroot()
        except Error as err:
            raise ProcessorError(err)

        # Copy each PackageInfo's key's value and assign to new env variables
        self.env["packageinfo_reader_output_variables"] = {}
        for key in info.attrib:
            self.env["packageinfo_" + str(key)] = info.attrib.get(key)
            self.output(
                "Assigning value of '%s' to output variable '%s'"
                % (self.env["packageinfo_" + str(key)], info.attrib.get(key)))
            # This one is for documentation/recordkeeping
            self.env["packageinfo_reader_output_variables"]["packageinfo_" + str(key)] = (
                self.env["packageinfo_" + str(key)])
     


if __name__ == '__main__':
    PROCESSOR = PackageInfoReader()
{'fraction_non_alphanumeric': 0.09239529757531227, 'fraction_numerical': 0.0029390154298310064, 'mean_word_length': 2.4462025316455698, 'pattern_counts': {'":': 10, '<': 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': '5280868', 'n_tokens_mistral': 1461, 'n_tokens_neox': 1402, 'n_words': 516}