Ejemplo n.º 1
0
    def handle(self, **options):

        helpers.debug_with_pdb(**options)

        try:
            with transaction.atomic():

                management.call_command('flush', *helpers.filter_dict({
                    '--no-input': not options['interactive'],
                }))
                management.call_command('makemigrations')
                management.call_command('migrate')

                for fixture in PRE_PROBLEMS_FIXTURES:
                    self.load_fixture(fixture)

                # (loadprobs will call collectstatic.)
                management.call_command('loadprobs', *helpers.filter_dict({
                    '--no-input': not options['interactive'],
                    '--debug': options['debug'],
                    '--clear': options['clear']
                }))
                self.stdout.write('')

                if options['skiplater']:
                    return

                for fixture in POST_PROBLEMS_FIXTURES:
                    self.load_fixture(fixture)

                announcements_dir = join(BASE_DIR, 'announcements')
                for basename in glob.glob(os.path.join(announcements_dir, '*.yaml')):
                    print(basename)
                    path = join(announcements_dir, basename)
                    if isfile(path):
                        management.call_command('announce', path)

        except helpers.ForeseenCommandError as err:
            raise err
        except Exception as err:
            self.stderr.write("Unforeseen exception encountered; rolling back")
            raise CommandError(err)
        else:
            self.stdout.write("Successfully (re)loaded all fixtures and problems")
Ejemplo n.º 2
0
    def handle(self, **options):

        helpers.debug_with_pdb(**options)

        self.stdout.write("Beginning transaction\n")

        try:
            with transaction.atomic():

                management.call_command('flush', *helpers.filter_dict({
                    '--no-input': not options['interactive'],
                }))
                management.call_command('migrate')

                for fixture in PRE_PROBLEMS_FIXTURES:
                    self.load_fixture(fixture)

                # (loadprobs will call collectstatic.)
                management.call_command('loadprobs', *helpers.filter_dict({
                    '--no-input': not options['interactive'],
                    '--debug': options['debug'],
                    '--clear': options['clear']
                }))
                self.stdout.write('')

                if not options['skiplater']:

                    for fixture in POST_PROBLEMS_FIXTURES:
                        self.load_fixture(fixture)

                    announcements_dir = join(BASE_DIR, 'announcements')
                    for basename in glob.glob(os.path.join(announcements_dir, '*.yaml')):
                        print(basename)
                        path = join(announcements_dir, basename)
                        if isfile(path):
                            management.call_command('announce', path)

        except Exception as err:
            self.stderr.write("Unforeseen exception encountered; rolled back transaction")
            raise CommandError(err)
        else:
            self.stdout.write("Successfully (re)loaded all fixtures and problems")
Ejemplo n.º 3
0
    def handle(self, **options):

        write = self.stdout.write
        self.processed_problems = []

        # Initialize error handling
        self.errored = False
        self.debug = options[helpers.DEBUG_OPTION_NAME]
        helpers.debug_with_pdb(**options)

        # Delete any existing files after confirmation
        if isdir(PROBLEMS_STATIC_DIR):
            message = textwrap.dedent("""\
                You have requested to load problems into the database and collect static files
                to the intermediate location as specified in your settings:

                    {}

                This will DELETE ALL FILES in this location!
                Are you sure you want to do this?

                Type 'yes' to continue, or 'no' to cancel:\
                """.format(PROBLEMS_STATIC_DIR))
            if options['interactive'] and input(message) != "yes":
                raise CommandError("Loading problems cancelled.")
            write("Deleting all files in the intermediate location\n\n")
            shutil.rmtree(PROBLEMS_STATIC_DIR)
        os.makedirs(PROBLEMS_STATIC_DIR, exist_ok=True)

        # Load problems
        for window_basename, window_path in self.walk(PROBLEMS_DIR):
            for prob_basename, prob_path in self.walk(window_path):
                self.process_problem_folder(window_basename=window_basename,
                                            prob_basename=prob_basename,
                                            prob_path=prob_path)

        # Stop if errors were encountered
        if self.errored:
            write("")
            raise CommandError(
                "Exception(s) were encountered; database was not modified")

        # Collect all static files to final location
        write("")
        write("Collecting static files to final location")
        management.call_command(
            'collectstatic',
            *helpers.filter_dict({
                '--no-input': not options['interactive'],
                # '--clear': options['clear'],
            }))

        self.stdout.write("Beginning transaction to actually save problems\n")
        try:

            # Actually load problems
            with transaction.atomic():
                print(self.processed_problems)
                for problem in self.processed_problems:
                    print("Saving {} to window {}".format(
                        problem, problem.window))
                    problem.save()

            # Delete unprocessed problems
            self.delete_unprocessed(options)

        except Exception as err:
            self.stderr.write(
                "Unforeseen exception encountered while saving problems; rolled back transaction"
            )
            raise CommandError(err)
Ejemplo n.º 4
0
    def handle(self, **options):

        write = self.stdout.write
        self.processed_problems = []

        # Initialize error handling
        self.errored = False
        self.debug = options[helpers.DEBUG_OPTION_NAME]
        helpers.debug_with_pdb(**options)

        # Delete any existing files after confirmation
        if isdir(PROBLEMS_STATIC_DIR):
            message = textwrap.dedent("""\
                You have requested to load problems into the database and collect static files
                to the intermediate location as specified in your settings:

                    {}

                This will DELETE ALL FILES in this location!
                Are you sure you want to do this?

                Type 'yes' to continue, or 'no' to cancel:\
                """.format(PROBLEMS_STATIC_DIR))
            if options['interactive'] and input(message) != "yes":
                raise CommandError("Loading problems cancelled.")
            write("Deleting all files in the intermediate location\n\n")
            shutil.rmtree(PROBLEMS_STATIC_DIR)
        os.makedirs(PROBLEMS_STATIC_DIR, exist_ok=True)

        # Load problems
        for window_basename, window_path in self.walk(PROBLEMS_DIR):
            for prob_basename, prob_path in self.walk(window_path):
                self.process_problem_folder(
                    window_basename=window_basename,
                    prob_basename=prob_basename,
                    prob_path=prob_path
                )

        # Stop if errors were encountered
        if self.errored:
            write("")
            raise CommandError("Exception(s) were encountered; database was not modified")

        # Collect all static files to final location
        write("")
        write("Collecting static files to final location")
        management.call_command('collectstatic', *helpers.filter_dict({
            '--no-input': not options['interactive'],
            # '--clear': options['clear'],
        }))


        self.stdout.write("Beginning transaction to actually save problems\n")
        try:

            # Actually load problems
            with transaction.atomic():
                print(self.processed_problems)
                for problem in self.processed_problems:
                    print("Saving {} to window {}".format(problem, problem.window))
                    problem.save()

            # Delete unprocessed problems
            self.delete_unprocessed(options)

        except Exception as err:
            self.stderr.write("Unforeseen exception encountered while saving problems; rolled back transaction")
            raise CommandError(err)