'Create a new repository in the tool shed and populate it with the contents of a gzip compressed
tar archive that was exported as part or all of the contents of a capsule.'

def create_repository_and_import_archive(self, repository_archive_dict, import_results_tups):

    results_message = ''
    name = repository_archive_dict.get('name', None)
    username = repository_archive_dict.get('owner', None)
    if ((name is None) or (username is None)):
        ok = False
        results_message += ('Import    failed:    required    repository    name    <b>%s</b>    or    owner    <b>%s</b>    is    missing.' % (str(name), str(username)))
        import_results_tups.append((ok, (str(name), str(username)), results_message))
    else:
        status = repository_archive_dict.get('status', None)
        if (status is None):
            type = repository_archive_dict.get('type', 'unrestricted')
            description = repository_archive_dict.get('description', '')
            long_description = repository_archive_dict.get('long_description', '')
            user = common_util.get_user_by_username(self.app, username)
            if (user is None):
                ok = False
                results_message += ('Import    failed:    repository    owner    <b>%s</b>    does    not    have    an    account    in    this    Tool    Shed.' % str(username))
                import_results_tups.append((ok, (str(name), str(username)), results_message))
            else:
                user_id = user.id
                category_ids = []
                category_names = repository_archive_dict.get('category_names', [])
                for category_name in category_names:
                    category = suc.get_category_by_name(self.app, category_name)
                    if (category is None):
                        results_message += ('This    Tool    Shed    does    not    have    the    category    <b>%s</b>    so    it    ' % str(category_name))
                        results_message += 'will    not    be    associated    with    this    repository.'
                    else:
                        category_ids.append(self.app.security.encode_id(category.id))
                (repository, create_message) = repository_util.create_repository(self.app, name, type, description, long_description, user_id=user_id, category_ids=category_ids)
                if create_message:
                    results_message += create_message
                results_dict = self.import_repository_archive(repository, repository_archive_dict)
                ok = results_dict.get('ok', False)
                error_message = results_dict.get('error_message', '')
                if error_message:
                    results_message += error_message
                import_results_tups.append((ok, (str(name), str(username)), results_message))
        else:
            ok = True
            results_message += ('Import    not    necessary:    repository    status    for    this    Tool    Shed    is:    %s.' % str(status))
            import_results_tups.append((ok, (str(name), str(username)), results_message))
    return import_results_tups
