<commit_before>__author__ = 'katharine'

import json
import os
import os.path
import uuid

SDK_VERSION = "3"


class PebbleProjectException(Exception):
    pass


class InvalidProjectException(PebbleProjectException):
    pass


class OutdatedProjectException(PebbleProjectException):
    pass


class PebbleProject(object):
    def __init__(self, project_dir=None):
        self.project_dir = project_dir if project_dir is not None else os.getcwd()
        self.check_project_directory(self.project_dir)
        self._parse_project()

    @staticmethod
    def check_project_directory(project_dir):
        """Check to see if the current directory matches what is created by PblProjectCreator.run.

        Raises an InvalidProjectException or an OutdatedProjectException if everything isn't quite right.
        """

        if not os.path.isdir(os.path.join(project_dir, 'src')):
            raise InvalidProjectException

        with open(os.path.join(project_dir, "appinfo.json"), "r") as f:
            app_info = json.load(f)

        if os.path.islink(os.path.join(project_dir, 'pebble_app.ld')) \
                or os.path.exists(os.path.join(project_dir, 'resources/src/resource_map.json')) \
                or not os.path.exists(os.path.join(project_dir, 'wscript')) \
                or not 'sdkVersion' in app_info.keys() \
                or app_info.get("sdkVersion", None) != SDK_VERSION:
            raise OutdatedProjectException

    def _parse_project(self):
        with open(os.path.join(self.project_dir, 'appinfo.json')) as f:<commit_msg>Add a more helpful error message when appinfo.json is invalid<commit_after>__author__ = 'katharine'

import json
import os
import os.path
import uuid

SDK_VERSION = "3"


class PebbleProjectException(Exception):
    pass


class InvalidProjectException(PebbleProjectException):
    pass


class OutdatedProjectException(PebbleProjectException):
    pass


class PebbleProject(object):
    def __init__(self, project_dir=None):
        self.project_dir = project_dir if project_dir is not None else os.getcwd()
        self.check_project_directory(self.project_dir)
        self._parse_project()

    @staticmethod
    def check_project_directory(project_dir):
        """Check to see if the current directory matches what is created by PblProjectCreator.run.

        Raises an InvalidProjectException or an OutdatedProjectException if everything isn't quite right.
        """

        if not os.path.isdir(os.path.join(project_dir, 'src')):
            raise InvalidProjectException

        with open(os.path.join(project_dir, "appinfo.json"), "r") as f:
            try:
                app_info = json.load(f)
            except ValueError as ex:
                raise Exception("Could not parse appinfo.json because of the following error: %s" % ex)

        if os.path.islink(os.path.join(project_dir, 'pebble_app.ld')) \
                or os.path.exists(os.path.join(project_dir, 'resources/src/resource_map.json')) \
                or not os.path.exists(os.path.join(project_dir, 'wscript')) \
                or not 'sdkVersion' in app_info.keys() \
                or app_info.get("sdkVersion", None) != SDK_VERSION:
            raise OutdatedProjectException

    def _parse_project(self):
        with open(os.path.join(self.project_dir, 'appinfo.json')) as f:
{'fraction_non_alphanumeric': 0.09491017964071856, 'fraction_numerical': 0.0005988023952095808, 'mean_word_length': 2.986873508353222, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '3669155', 'n_tokens_mistral': 1006, 'n_tokens_neox': 970, 'n_words': 237}