<commit_before># Case Conductor is a Test Case Management system.
# Copyright (C) 2011-12 Mozilla
#
# This file is part of Case Conductor.
#
# Case Conductor is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Case Conductor is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Case Conductor.  If not, see <http://www.gnu.org/licenses/>.
from django.core.management.base import BaseCommand, CommandError

import json

from cc.model.core.models import Product, ProductVersion
from cc.model.library.case_importer import CaseImporter

class Command(BaseCommand):
    args = '<product_name> <product_version> <filename>'
    help = 'Imports the cases from a JSON file into the specified Product Version'


    def handle(self, *args, **options):
        if len(args) < 3:
            raise CommandError("Usage: {1}".format(self.args)

        try:
            with open(args[2]) as cases_text:

                # try to import this as JSON
                try:
                    case_data = json.load(cases_text)

                except ValueError as e:
                    raise CommandError(
                        "Could not parse JSON because {1}".format(e))

                # @@@: support importing as CSV.  Rather than returning an error above,
                # just try CSV import instead.


                try:
                    product = Product.objects.get(name=args[0])

                except Product.DoesNotExist:
                    raise CommandError('Product "{1}" does not exist'.format(args[0]))

                try:
                    product_version = ProductVersion.objects.get(product=product, version=args[1])

                except ProductVersion.DoesNotExist:
                    raise CommandError('Product Version "{1}" does not exist'.format(
                        product_version))

                result = CaseImporter().import_cases(product_version, case_data)
                "\n".join(lines)
                self.stdout.write()


        except IOError as (errno, strerror):
            raise CommandError("I/O error({0}): {1}".format(errno, strerror))

<commit_msg>more fixes to management command<commit_after># Case Conductor is a Test Case Management system.
# Copyright (C) 2011-12 Mozilla
#
# This file is part of Case Conductor.
#
# Case Conductor is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Case Conductor is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Case Conductor.  If not, see <http://www.gnu.org/licenses/>.
from django.core.management.base import BaseCommand, CommandError

import json

from cc.model.core.models import Product, ProductVersion
from cc.model.library.case_importer import CaseImporter

class Command(BaseCommand):
    args = '<product_name> <product_version> <filename>'
    help = 'Imports the cases from a JSON file into the specified Product Version'


    def handle(self, *args, **options):
        if len(args) < 3:
            raise CommandError("Usage: {1}".format(self.args)

        try:
            with open(args[2]) as cases_text:

                # try to import this as JSON
                try:
                    case_data = json.load(cases_text)

                except ValueError as e:
                    raise CommandError(
                        "Could not parse JSON because {1}".format(e))

                # @@@: support importing as CSV.  Rather than returning an error above,
                # just try CSV import instead.


                try:
                    product = Product.objects.get(name=args[0])

                except Product.DoesNotExist:
                    raise CommandError('Product "{1}" does not exist'.format(args[0]))

                try:
                    product_version = ProductVersion.objects.get(product=product, version=args[1])

                except ProductVersion.DoesNotExist:
                    raise CommandError('Product Version "{1}" does not exist'.format(
                        product_version))

                self.write_result(CaseImporter().import_cases(product_version, case_data))


        except IOError as (errno, strerror):
            raise CommandError("I/O error({0}): {1}".format(errno, strerror))

    def write_result(self, result):
        "\n".join(lines)
        self.stdout.write()

{'fraction_non_alphanumeric': 0.08344653599844751, 'fraction_numerical': 0.006986221618474675, 'mean_word_length': 2.3576547231270357, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '972117', 'n_tokens_mistral': 1361, 'n_tokens_neox': 1260, 'n_words': 496}