'Works an an appropriate ordering for the models.
This isn\'t essential, but makes the script look nicer because
more instances can be defined on their first try.'

def _queue_models(self, models, context):

    MAX_CYCLES = 5
    model_queue = []
    number_remaining_models = len(models)
    allowed_cycles = MAX_CYCLES
    while (number_remaining_models > 0):
        previous_number_remaining_models = number_remaining_models
        model = models.pop(0)
        if check_dependencies(model, model_queue, context['__avaliable_models']):
            model_class = ModelCode(model=model, context=context, stdout=self.stdout, stderr=self.stderr, options=self.options)
            model_queue.append(model_class)
        else:
            models.append(model)
        number_remaining_models = len(models)
        if (number_remaining_models == previous_number_remaining_models):
            allowed_cycles -= 1
            if (allowed_cycles <= 0):
                missing_models = [ModelCode(model=m, context=context, stdout=self.stdout, stderr=self.stderr, options=self.options) for m in models]
                model_queue += missing_models
                models[:] = missing_models
                break
        else:
            allowed_cycles = MAX_CYCLES
    return model_queue
